Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
add databases and schemas on sync UI
adilson4252eb27b0c0
diff --git a/backend/src/server/routes/v1/app-connection-routers/snowflake-connection-router.ts b/backend/src/server/routes/v1/app-connection-routers/snowflake-connection-router.tsindex 41141b77bc..f8a3299bbd 100644--- a/backend/src/server/routes/v1/app-connection-routers/snowflake-connection-router.ts+++ b/backend/src/server/routes/v1/app-connection-routers/snowflake-connection-router.ts@@ -1,9 +1,14 @@+import { z } from "zod";++import { readLimit } from "@app/server/config/rateLimiter";+import { verifyAuth } from "@app/server/plugins/auth/verify-auth";import { AppConnection } from "@app/services/app-connection/app-connection-enums";import {CreateSnowflakeConnectionSchema,SanitizedSnowflakeConnectionSchema,UpdateSnowflakeConnectionSchema} from "@app/services/app-connection/snowflake";+import { AuthMode } from "@app/services/auth/auth-type";import { registerAppConnectionEndpoints } from "./app-connection-endpoints";@@ -15,4 +20,66 @@ export const registerSnowflakeConnectionRouter = async (server: FastifyZodProvidcreateSchema: CreateSnowflakeConnectionSchema,updateSchema: UpdateSnowflakeConnectionSchema});++ // The below endpoints are not exposed and for Infisical App use++ server.route({+ method: "GET",+ url: `/:connectionId/databases`,+ config: {+ rateLimit: readLimit+ },+ schema: {+ operationId: "listSnowflakeDatabases",+ params: z.object({+ connectionId: z.string().uuid()+ }),+ response: {+ 200: z.object({+ databases: z.object({ name: z.string() }).array()+ })+ }+ },+ onRequest: verifyAuth([AuthMode.JWT]),+ handler: async (req) => {+ const { connectionId } = req.params;++ const databases = await server.services.appConnection.snowflake.listDatabases(connectionId, req.permission);++ return { databases };+ }+ });++ server.route({+ method: "GET",+ url: `/:connectionId/schemas`,+ config: {+ rateLimit: readLimit+ },+ schema: {+ operationId: "listSnowflakeSchemas",+ params: z.object({+ connectionId: z.string().uuid()+ }),+ querystring: z.object({+ database: z.string().min(1)+ }),+ response: {+ 200: z.object({+ schemas: z.object({ name: z.string() }).array()+ })+ }+ },+ onRequest: verifyAuth([AuthMode.JWT]),+ handler: async (req) => {+ const {+ params: { connectionId },+ query: { database }+ } = req;++ const schemas = await server.services.appConnection.snowflake.listSchemas(connectionId, database, req.permission);++ return { schemas };+ }+ });};diff --git a/backend/src/services/app-connection/app-connection-service.ts b/backend/src/services/app-connection/app-connection-service.tsindex 98492d9fc1..238bcf1d52 100644--- a/backend/src/services/app-connection/app-connection-service.ts+++ b/backend/src/services/app-connection/app-connection-service.ts@@ -138,6 +138,7 @@ import { ValidateRenderConnectionCredentialsSchema } from "./render/render-conneimport { renderConnectionService } from "./render/render-connection-service";import { ValidateSmbConnectionCredentialsSchema } from "./smb";import { ValidateSnowflakeConnectionCredentialsSchema } from "./snowflake";+import { snowflakeConnectionService } from "./snowflake/snowflake-connection-service";import { ValidateSshConnectionCredentialsSchema } from "./ssh";import { ValidateSupabaseConnectionCredentialsSchema } from "./supabase";import { supabaseConnectionService } from "./supabase/supabase-connection-service";@@ -1117,6 +1118,7 @@ export const appConnectionServiceFactory = ({azureEntraId: azureEntraIdConnectionService(connectAppConnectionById, appConnectionDAL, kmsService),doppler: dopplerConnectionService(connectAppConnectionById),digicert: digicertConnectionService(connectAppConnectionById),- travisCI: travisCIConnectionService(connectAppConnectionById)+ travisCI: travisCIConnectionService(connectAppConnectionById),+ snowflake: snowflakeConnectionService(connectAppConnectionById)};};diff --git a/backend/src/services/app-connection/snowflake/index.ts b/backend/src/services/app-connection/snowflake/index.tsindex 3de04d812f..1a133d6ed6 100644--- a/backend/src/services/app-connection/snowflake/index.ts+++ b/backend/src/services/app-connection/snowflake/index.ts@@ -1,4 +1,5 @@export * from "./snowflake-connection-enums";export * from "./snowflake-connection-fns";export * from "./snowflake-connection-schemas";+export * from "./snowflake-connection-service";export * from "./snowflake-connection-types";diff --git a/backend/src/services/app-connection/snowflake/snowflake-connection-fns.ts b/backend/src/services/app-connection/snowflake/snowflake-connection-fns.tsindex 23dec135c9..0ec6dae465 100644--- a/backend/src/services/app-connection/snowflake/snowflake-connection-fns.ts+++ b/backend/src/services/app-connection/snowflake/snowflake-connection-fns.ts@@ -5,10 +5,12 @@ import { sanitizeString } from "@app/lib/fn";import { AppConnection } from "@app/services/app-connection/app-connection-enums";import { SnowflakeConnectionMethod } from "./snowflake-connection-enums";-import { TSnowflakeConnectionConfig } from "./snowflake-connection-types";+import { TSnowflakeConnection, TSnowflakeConnectionConfig } from "./snowflake-connection-types";const noop = () => {};+export const quoteSnowflakeIdent = (name: string) => `"${name.replace(/"/g, '""')}"`;+export const getSnowflakeConnectionListItem = () => {return {name: "Snowflake" as const,@@ -17,52 +19,114 @@ export const getSnowflakeConnectionListItem = () => {};};-export const validateSnowflakeConnectionCredentials = async (config: TSnowflakeConnectionConfig) => {- const { account, username, password } = config.credentials;+export const getSnowflakeClient = async (credentials: TSnowflakeConnection["credentials"]) => {+ const client = snowflake.createConnection({+ account: credentials.account,+ username: credentials.username,+ password: credentials.password,+ application: "Infisical"+ });- let client: snowflake.Connection | undefined;- try {- client = snowflake.createConnection({- account,- username,- password,- application: "Infisical"- });+ await new Promise<void>((resolve, reject) => {+ client.connectAsync((err) => (err ? reject(err) : resolve())).catch(reject);+ });- await new Promise<void>((resolve, reject) => {- client.connectAsync((err) => (err ? reject(err) : resolve())).catch(reject);+ let timeoutHandle: NodeJS.Timeout | undefined;+ const isValid = await Promise.race<boolean>([+ client.isValidAsync(),+ new Promise<boolean>((_, reject) => {+ timeoutHandle = setTimeout(+ () => reject(new BadRequestError({ message: "Snowflake connection validation timed out" })),+ 10000+ );+ })+ ]).finally(() => {+ if (timeoutHandle) clearTimeout(timeoutHandle);+ });++ if (!isValid) {+ throw new BadRequestError({+ message:+ "Snowflake connection is not valid - heartbeat failed; verify credentials, network access, and that the account is not locked"});+ }- let timeoutHandle: NodeJS.Timeout | undefined;- const isValid = await Promise.race<boolean>([- client.isValidAsync(),- new Promise<boolean>((_, reject) => {- timeoutHandle = setTimeout(- () => reject(new BadRequestError({ message: "Snowflake connection validation timed out" })),- 10000- );- })- ]).finally(() => {- if (timeoutHandle) clearTimeout(timeoutHandle);+ return client;+};++export const executeSnowflakeSql = <TRow = Record<string, unknown>>(+ client: snowflake.Connection,+ sqlText: string,+ binds?: snowflake.Binds+): Promise<TRow[]> =>+ new Promise((resolve, reject) => {+ client.execute({+ sqlText,+ binds,+ complete: (err, _stmt, rows) => {+ if (err) return reject(err);+ return resolve((rows ?? []) as TRow[]);+ }});+ });- if (!isValid) {- throw new BadRequestError({- message:- "Snowflake connection is not valid - heartbeat failed; verify credentials, network access, and that the account is not locked"- });- }+export const withSnowflakeClient = async <T>(+ credentials: TSnowflakeConnection["credentials"],+ fn: (client: snowflake.Connection) => Promise<T>+): Promise<T> => {+ let client: snowflake.Connection | undefined;+ try {+ client = await getSnowflakeClient(credentials);+ return await fn(client);+ } finally {+ if (client) client.destroy(noop);+ }+};+const sanitizeSnowflakeError = (+ err: unknown,+ credentials: TSnowflakeConnection["credentials"],+ errorPrefix: string+) => {+ const sanitizedErrorMessage = sanitizeString({+ unsanitizedString: (err as Error)?.message ?? "",+ tokens: [credentials.password, credentials.username, credentials.account]+ });+ return new BadRequestError({+ message: `${errorPrefix}: ${sanitizedErrorMessage || "verify credentials and permissions"}`+ });+};++export const validateSnowflakeConnectionCredentials = async (config: TSnowflakeConnectionConfig) => {+ try {+ await withSnowflakeClient(config.credentials, async () => undefined);return config.credentials;} catch (err) {- const sanitizedErrorMessage = sanitizeString({- unsanitizedString: (err as Error)?.message,- tokens: [password, username, account]+ throw sanitizeSnowflakeError(err, config.credentials, "Unable to validate connection");+ }+};++export const listSnowflakeDatabases = async (credentials: TSnowflakeConnection["credentials"]) => {+ try {+ return await withSnowflakeClient(credentials, async (client) => {+ const rows = await executeSnowflakeSql<{ name?: string }>(client, "SHOW DATABASES");+ return rows.flatMap((row) => (row.name ? [{ name: row.name }] : []));});- throw new BadRequestError({- message: `Unable to validate connection: ${sanitizedErrorMessage || "verify credentials"}`+ } catch (err) {+ throw sanitizeSnowflakeError(err, credentials, "Unable to list Snowflake databases");+ }+};++export const listSnowflakeSchemas = async (credentials: TSnowflakeConnection["credentials"], database: string) => {+ try {+ return await withSnowflakeClient(credentials, async (client) => {+ const rows = await executeSnowflakeSql<{ name?: string }>(+ client,+ `SHOW SCHEMAS IN DATABASE ${quoteSnowflakeIdent(database)}`+ );+ return rows.flatMap((row) => (row.name ? [{ name: row.name }] : []));});- } finally {- if (client) client.destroy(noop);+ } catch (err) {+ throw sanitizeSnowflakeError(err, credentials, "Unable to list Snowflake schemas");}};diff --git a/backend/src/services/app-connection/snowflake/snowflake-connection-service.ts b/backend/src/services/app-connection/snowflake/snowflake-connection-service.tsnew file mode 100644index 0000000000..5b09bd648c--- /dev/null+++ b/backend/src/services/app-connection/snowflake/snowflake-connection-service.ts@@ -0,0 +1,30 @@+import { OrgServiceActor } from "@app/lib/types";+import { AppConnection } from "@app/services/app-connection/app-connection-enums";+import {+ listSnowflakeDatabases,+ listSnowflakeSchemas+} from "@app/services/app-connection/snowflake/snowflake-connection-fns";+import { TSnowflakeConnection } from "@app/services/app-connection/snowflake/snowflake-connection-types";++type TGetAppConnectionFunc = (+ app: AppConnection,+ connectionId: string,+ actor: OrgServiceActor+) => Promise<TSnowflakeConnection>;++export const snowflakeConnectionService = (getAppConnection: TGetAppConnectionFunc) => {+ const listDatabases = async (connectionId: string, actor: OrgServiceActor) => {+ const appConnection = await getAppConnection(AppConnection.Snowflake, connectionId, actor);+ return listSnowflakeDatabases(appConnection.credentials);+ };++ const listSchemas = async (connectionId: string, database: string, actor: OrgServiceActor) => {+ const appConnection = await getAppConnection(AppConnection.Snowflake, connectionId, actor);+ return listSnowflakeSchemas(appConnection.credentials, database);+ };++ return {+ listDatabases,+ listSchemas+ };+};diff --git a/backend/src/services/secret-sync/snowflake/snowflake-sync-fns.ts b/backend/src/services/secret-sync/snowflake/snowflake-sync-fns.tsindex 5d3de10609..9e23a2ad5c 100644--- a/backend/src/services/secret-sync/snowflake/snowflake-sync-fns.ts+++ b/backend/src/services/secret-sync/snowflake/snowflake-sync-fns.ts@@ -1,8 +1,12 @@import snowflake from "snowflake-sdk";-import { BadRequestError } from "@app/lib/errors";import { sanitizeSqlLikeString, sanitizeString } from "@app/lib/fn";-import { TSnowflakeConnection } from "@app/services/app-connection/snowflake";+import {+ executeSnowflakeSql,+ quoteSnowflakeIdent,+ TSnowflakeConnection,+ withSnowflakeClient+} from "@app/services/app-connection/snowflake";import { SecretSyncError } from "@app/services/secret-sync/secret-sync-errors";import { matchesSchema } from "@app/services/secret-sync/secret-sync-fns";import { SECRET_SYNC_NAME_MAP } from "@app/services/secret-sync/secret-sync-maps";@@ -10,74 +14,19 @@ import { TSecretMap } from "@app/services/secret-sync/secret-sync-types";import { TSnowflakeSyncWithCredentials } from "./snowflake-sync-types";-const noop = () => {};--const quoteIdent = (name: string) => `"${name.replace(/"/g, '""')}"`;-const buildFqn = (database: string, schema: string, name: string) =>- `${quoteIdent(database)}.${quoteIdent(schema)}.${quoteIdent(name)}`;--const getClient = async (credentials: TSnowflakeConnection["credentials"]) => {- const client = snowflake.createConnection({- account: credentials.account,- username: credentials.username,- password: credentials.password,- application: "Infisical"- });-- await new Promise<void>((resolve, reject) => {- client.connectAsync((err) => (err ? reject(err) : resolve())).catch(reject);- });-- let timeoutHandle: NodeJS.Timeout | undefined;- const isValid = await Promise.race<boolean>([- client.isValidAsync(),- new Promise<boolean>((_, reject) => {- timeoutHandle = setTimeout(- () => reject(new BadRequestError({ message: "Snowflake connection validation timed out" })),- 10000- );- })- ]).finally(() => {- if (timeoutHandle) clearTimeout(timeoutHandle);- });-- if (!isValid) {- throw new BadRequestError({- message:- "Snowflake connection is not valid - heartbeat failed; verify credentials, network access, and that the account is not locked"- });- }-- return client;-};--const executeSql = <TRow = Record<string, unknown>>(- client: snowflake.Connection,- sqlText: string,- binds?: snowflake.Binds-): Promise<TRow[]> =>- new Promise((resolve, reject) => {- client.execute({- sqlText,- binds,- complete: (err, _stmt, rows) => {- if (err) return reject(err);- return resolve((rows ?? []) as TRow[]);- }- });- });+ `${quoteSnowflakeIdent(database)}.${quoteSnowflakeIdent(schema)}.${quoteSnowflakeIdent(name)}`;const databaseExists = async (client: snowflake.Connection, database: string) => {- const rows = await executeSql(client, "SHOW DATABASES LIKE ?", [sanitizeSqlLikeString(database)]);+ const rows = await executeSnowflakeSql(client, "SHOW DATABASES LIKE ?", [sanitizeSqlLikeString(database)]);return rows.length > 0;};const schemaExists = async (client: snowflake.Connection, database: string, schema: string) => {try {- const rows = await executeSql(+ const rows = await executeSnowflakeSql(client,- `SHOW SCHEMAS LIKE '${sanitizeSqlLikeString(schema)}' IN DATABASE ${database}`+ `SHOW SCHEMAS LIKE '${sanitizeSqlLikeString(schema)}' IN DATABASE ${quoteSnowflakeIdent(database)}`);return rows.length > 0;} catch (err) {@@ -92,9 +41,9 @@ const listExistingSecretNames = async (database: string,schema: string): Promise<string[]> => {- const rows = await executeSql<{ name: string }>(+ const rows = await executeSnowflakeSql<{ name: string }>(client,- `SHOW SECRETS IN SCHEMA ${quoteIdent(database)}.${quoteIdent(schema)}`+ `SHOW SECRETS IN SCHEMA ${quoteSnowflakeIdent(database)}.${quoteSnowflakeIdent(schema)}`);return rows.map((row) => row.name).filter((name): name is string => typeof name === "string");};@@ -106,7 +55,7 @@ const upsertSecret = async (name: string,value: string) => {- await executeSql(+ await executeSnowflakeSql(client,`CREATE OR REPLACE SECRET ${buildFqn(database, schema, name)} TYPE = GENERIC_STRING SECRET_STRING = ?`,[value]@@ -114,7 +63,7 @@ const upsertSecret = async (};const dropSecret = async (client: snowflake.Connection, database: string, schema: string, name: string) => {- await executeSql(client, `DROP SECRET IF EXISTS ${buildFqn(database, schema, name)}`);+ await executeSnowflakeSql(client, `DROP SECRET IF EXISTS ${buildFqn(database, schema, name)}`);};const wrapSnowflakeError = (err: unknown, credentials: TSnowflakeConnection["credentials"]): SecretSyncError => {@@ -136,52 +85,48 @@ export const SnowflakeSyncFns = {connection} = secretSync;- let client: snowflake.Connection | undefined;try {- try {- client = await getClient(connection.credentials);- } catch (err) {- throw wrapSnowflakeError(err, connection.credentials);- }-- if (!(await databaseExists(client, database))) {- throw new SecretSyncError({- message: `Database "${database}" does not exist or is not accessible with the connected Snowflake user`,- shouldRetry: false- });- }-- if (!(await schemaExists(client, database, schema))) {- throw new SecretSyncError({- message: `Schema "${schema}" does not exist in database "${database}" or is not accessible with the connected Snowflake user`,- shouldRetry: false- });- }-- for await (const [key, entry] of Object.entries(secretMap)) {- try {- await upsertSecret(client, database, schema, key, entry.value);- } catch (err) {- throw new SecretSyncError({ error: err, secretKey: key });+ await withSnowflakeClient(connection.credentials, async (client) => {+ if (!(await databaseExists(client, database))) {+ throw new SecretSyncError({+ message: `Database "${database}" does not exist or is not accessible with the connected Snowflake user`,+ shouldRetry: false+ });}- }-- if (secretSync.syncOptions.disableSecretDeletion) return;- const existingNames = await listExistingSecretNames(client, database, schema);+ if (!(await schemaExists(client, database, schema))) {+ throw new SecretSyncError({+ message: `Schema "${schema}" does not exist in database "${database}" or is not accessible with the connected Snowflake user`,+ shouldRetry: false+ });+ }- for await (const existingName of existingNames) {- if (!matchesSchema(existingName, secretSync.environment?.slug || "", secretSync.syncOptions.keySchema)) {- // eslint-disable-next-line no-continue- continue;+ for await (const [key, entry] of Object.entries(secretMap)) {+ try {+ await upsertSecret(client, database, schema, key, entry.value);+ } catch (err) {+ throw new SecretSyncError({ error: err, secretKey: key });+ }}- if (!(existingName in secretMap)) {- await dropSecret(client, database, schema, existingName);+ if (secretSync.syncOptions.disableSecretDeletion) return;++ const existingNames = await listExistingSecretNames(client, database, schema);++ for await (const existingName of existingNames) {+ if (!matchesSchema(existingName, secretSync.environment?.slug || "", secretSync.syncOptions.keySchema)) {+ // eslint-disable-next-line no-continue+ continue;+ }++ if (!(existingName in secretMap)) {+ await dropSecret(client, database, schema, existingName);+ }}- }- } finally {- if (client) client.destroy(noop);+ });+ } catch (err) {+ if (err instanceof SecretSyncError) throw err;+ throw wrapSnowflakeError(err, connection.credentials);}},@@ -195,19 +140,15 @@ export const SnowflakeSyncFns = {connection} = secretSync;- let client: snowflake.Connection | undefined;try {- try {- client = await getClient(connection.credentials);- } catch (err) {- throw wrapSnowflakeError(err, connection.credentials);- }-- for await (const key of Object.keys(secretMap)) {- await dropSecret(client, database, schema, key);- }- } finally {- if (client) client.destroy(noop);+ await withSnowflakeClient(connection.credentials, async (client) => {+ for await (const key of Object.keys(secretMap)) {+ await dropSecret(client, database, schema, key);+ }+ });+ } catch (err) {+ if (err instanceof SecretSyncError) throw err;+ throw wrapSnowflakeError(err, connection.credentials);}}};diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/SnowflakeSyncFields.tsx b/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/SnowflakeSyncFields.tsxindex d3afeecd97..09b780248a 100644--- a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/SnowflakeSyncFields.tsx+++ b/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/SnowflakeSyncFields.tsx@@ -1,7 +1,14 @@-import { Controller, useFormContext } from "react-hook-form";+import { Controller, useFormContext, useWatch } from "react-hook-form";+import { SingleValue } from "react-select";import { SecretSyncConnectionField } from "@app/components/secret-syncs/forms/SecretSyncConnectionField";-import { FormControl, Input } from "@app/components/v2";+import { FilterableSelect, FormControl } from "@app/components/v2";+import {+ TSnowflakeDatabase,+ TSnowflakeSchema,+ useSnowflakeConnectionListDatabases,+ useSnowflakeConnectionListSchemas+} from "@app/hooks/api/appConnections/snowflake";import { SecretSync } from "@app/hooks/api/secretSyncs";import { TSecretSyncForm } from "../schemas";@@ -11,6 +18,21 @@ export const SnowflakeSyncFields = () => {TSecretSyncForm & { destination: SecretSync.Snowflake }>();+ const connectionId = useWatch({ name: "connection.id", control });+ const database = useWatch({ name: "destinationConfig.database", control });++ const { data: databases = [], isPending: isDatabasesPending } =+ useSnowflakeConnectionListDatabases(connectionId, {+ enabled: Boolean(connectionId)+ });++ const { data: schemas = [], isPending: isSchemasPending } = useSnowflakeConnectionListSchemas(+ { connectionId, database },+ {+ enabled: Boolean(connectionId) && Boolean(database)+ }+ );+return (<><SecretSyncConnectionField@@ -29,9 +51,21 @@ export const SnowflakeSyncFields = () => {errorText={error?.message}label="Database"tooltipClassName="max-w-sm"- tooltipText="The name of the Snowflake database that contains the target schema. The database must already exist."+ tooltipText="The Snowflake database that contains the target schema. The database must already exist.">- <Input value={value} onChange={onChange} placeholder="MY_DATABASE" />+ <FilterableSelect+ isLoading={isDatabasesPending && Boolean(connectionId)}+ isDisabled={!connectionId}+ value={databases.find((db) => db.name === value) ?? null}+ onChange={(option) => {+ setValue("destinationConfig.schema", "");+ onChange((option as SingleValue<TSnowflakeDatabase>)?.name ?? "");+ }}+ options={databases}+ placeholder="Select a database..."+ getOptionLabel={(option) => option.name}+ getOptionValue={(option) => option.name}+ /></FormControl>)}/>@@ -45,9 +79,18 @@ export const SnowflakeSyncFields = () => {errorText={error?.message}label="Schema"tooltipClassName="max-w-sm"- tooltipText="The name of the Snowflake schema (within the selected database) where secrets will be created. The schema must already exist."+ tooltipText="The Snowflake schema (within the selected database) where secrets will be created. The schema must already exist.">- <Input value={value} onChange={onChange} placeholder="MY_SCHEMA" />+ <FilterableSelect+ isLoading={isSchemasPending && Boolean(connectionId) && Boolean(database)}+ isDisabled={!connectionId || !database}+ value={schemas.find((schema) => schema.name === value) ?? null}+ onChange={(option) => onChange((option as SingleValue<TSnowflakeSchema>)?.name ?? "")}+ options={schemas}+ placeholder="Select a schema..."+ getOptionLabel={(option) => option.name}+ getOptionValue={(option) => option.name}+ /></FormControl>)}/>diff --git a/frontend/src/hooks/api/appConnections/snowflake/index.ts b/frontend/src/hooks/api/appConnections/snowflake/index.tsnew file mode 100644index 0000000000..2c1906d369--- /dev/null+++ b/frontend/src/hooks/api/appConnections/snowflake/index.ts@@ -0,0 +1,2 @@+export * from "./queries";+export * from "./types";diff --git a/frontend/src/hooks/api/appConnections/snowflake/queries.tsx b/frontend/src/hooks/api/appConnections/snowflake/queries.tsxnew file mode 100644index 0000000000..80532ca328--- /dev/null+++ b/frontend/src/hooks/api/appConnections/snowflake/queries.tsx@@ -0,0 +1,65 @@+import { useQuery, UseQueryOptions } from "@tanstack/react-query";++import { apiRequest } from "@app/config/request";+import { appConnectionKeys } from "@app/hooks/api/appConnections";++import { TListSnowflakeSchemas, TSnowflakeDatabase, TSnowflakeSchema } from "./types";++const snowflakeConnectionKeys = {+ all: [...appConnectionKeys.all, "snowflake"] as const,+ listDatabases: (connectionId: string) =>+ [...snowflakeConnectionKeys.all, "databases", connectionId] as const,+ listSchemas: ({ connectionId, database }: TListSnowflakeSchemas) =>+ [...snowflakeConnectionKeys.all, "schemas", connectionId, database] as const+};++export const useSnowflakeConnectionListDatabases = (+ connectionId: string,+ options?: Omit<+ UseQueryOptions<+ TSnowflakeDatabase[],+ unknown,+ TSnowflakeDatabase[],+ ReturnType<typeof snowflakeConnectionKeys.listDatabases>+ >,+ "queryKey" | "queryFn"+ >+) => {+ return useQuery({+ queryKey: snowflakeConnectionKeys.listDatabases(connectionId),+ queryFn: async () => {+ const { data } = await apiRequest.get<{ databases: TSnowflakeDatabase[] }>(+ `/api/v1/app-connections/snowflake/${connectionId}/databases`+ );++ return data.databases;+ },+ ...options+ });+};++export const useSnowflakeConnectionListSchemas = (+ { connectionId, database }: TListSnowflakeSchemas,+ options?: Omit<+ UseQueryOptions<+ TSnowflakeSchema[],+ unknown,+ TSnowflakeSchema[],+ ReturnType<typeof snowflakeConnectionKeys.listSchemas>+ >,+ "queryKey" | "queryFn"+ >+) => {+ return useQuery({+ queryKey: snowflakeConnectionKeys.listSchemas({ connectionId, database }),+ queryFn: async () => {+ const { data } = await apiRequest.get<{ schemas: TSnowflakeSchema[] }>(+ `/api/v1/app-connections/snowflake/${connectionId}/schemas`,+ { params: { database } }+ );++ return data.schemas;+ },+ ...options+ });+};diff --git a/frontend/src/hooks/api/appConnections/snowflake/types.ts b/frontend/src/hooks/api/appConnections/snowflake/types.tsnew file mode 100644index 0000000000..e71fa955c3--- /dev/null+++ b/frontend/src/hooks/api/appConnections/snowflake/types.ts@@ -0,0 +1,12 @@+export type TSnowflakeDatabase = {+ name: string;+};++export type TSnowflakeSchema = {+ name: string;+};++export type TListSnowflakeSchemas = {+ connectionId: string;+ database: string;+};diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/SnowflakeConnectionForm.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/SnowflakeConnectionForm.tsxindex 0f7d79b44f..ba68b5459f 100644--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/SnowflakeConnectionForm.tsx+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/SnowflakeConnectionForm.tsx@@ -2,16 +2,7 @@ import { Controller, FormProvider, useForm } from "react-hook-form";import { zodResolver } from "@hookform/resolvers/zod";import { z } from "zod";-import {- Button,- FormControl,- Input,- ModalClose,- SecretInput,- Select,- SelectItem-} from "@app/components/v2";-import { APP_CONNECTION_MAP, getAppConnectionMethodDetails } from "@app/helpers/appConnections";+import { Button, FormControl, Input, ModalClose, SecretInput } from "@app/components/v2";import { AppConnection } from "@app/hooks/api/appConnections/enums";import {SnowflakeConnectionMethod,@@ -92,36 +83,6 @@ export const SnowflakeConnectionForm = ({ appConnection, onSubmit }: Props) => {)}/>- <Controller- name="method"- control={control}- render={({ field: { value, onChange }, fieldState: { error } }) => (- <FormControl- tooltipText={`The method you would like to use to connect with ${- APP_CONNECTION_MAP[AppConnection.Snowflake].name- }. This field cannot be changed after creation.`}- errorText={error?.message}- isError={Boolean(error?.message)}- label="Method"- >- <Select- isDisabled={isUpdate}- value={value}- onValueChange={(val) => onChange(val)}- className="w-full border border-mineshaft-500"- position="popper"- dropdownContainerClassName="max-w-none"- >- {Object.values(SnowflakeConnectionMethod).map((method) => (- <SelectItem value={method} key={method}>- {getAppConnectionMethodDetails(method).name}- </SelectItem>- ))}- </Select>- </FormControl>- )}- />-<Controllername="credentials.username"control={control}