Skip to content

Commit d7248c2

Browse files
committed
consolidate supported snowflake auth method checks
1 parent 9390478 commit d7248c2

File tree

5 files changed

+48
-26
lines changed

5 files changed

+48
-26
lines changed

src/platform/notebooks/deepnote/integrationTypes.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,13 @@ export interface BigQueryIntegrationConfig extends BaseIntegrationConfig {
6565
}
6666

6767
// Import and re-export Snowflake auth constants from shared module
68-
import { SnowflakeAuthMethod, SnowflakeAuthMethods, SUPPORTED_SNOWFLAKE_AUTH_METHODS } from './snowflakeAuthConstants';
69-
export { SnowflakeAuthMethod, SnowflakeAuthMethods, SUPPORTED_SNOWFLAKE_AUTH_METHODS };
68+
import {
69+
SnowflakeAuthMethod,
70+
SnowflakeAuthMethods,
71+
SUPPORTED_SNOWFLAKE_AUTH_METHODS,
72+
isSupportedSnowflakeAuthMethod
73+
} from './snowflakeAuthConstants';
74+
export { SnowflakeAuthMethod, SnowflakeAuthMethods, SUPPORTED_SNOWFLAKE_AUTH_METHODS, isSupportedSnowflakeAuthMethod };
7075

7176
/**
7277
* Base Snowflake configuration with common fields

src/platform/notebooks/deepnote/snowflakeAuthConstants.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const SnowflakeAuthMethods = {
1010
SERVICE_ACCOUNT_KEY_PAIR: 'SERVICE_ACCOUNT_KEY_PAIR'
1111
} as const;
1212

13-
export type SnowflakeAuthMethod = (typeof SnowflakeAuthMethods)[keyof typeof SnowflakeAuthMethods] | null;
13+
export type SnowflakeAuthMethod = (typeof SnowflakeAuthMethods)[keyof typeof SnowflakeAuthMethods];
1414

1515
/**
1616
* Supported auth methods that we can configure in VSCode
@@ -21,3 +21,13 @@ export const SUPPORTED_SNOWFLAKE_AUTH_METHODS = [
2121
SnowflakeAuthMethods.SERVICE_ACCOUNT_KEY_PAIR
2222
] as const;
2323

24+
export type SupportedSnowflakeAuthMethod = (typeof SUPPORTED_SNOWFLAKE_AUTH_METHODS)[number];
25+
26+
/**
27+
* Type guard to check if a value is a supported Snowflake auth method
28+
* @param value The value to check
29+
* @returns true if the value is one of the supported auth methods
30+
*/
31+
export function isSupportedSnowflakeAuthMethod(value: unknown): value is SupportedSnowflakeAuthMethod {
32+
return (SUPPORTED_SNOWFLAKE_AUTH_METHODS as readonly unknown[]).includes(value);
33+
}

src/platform/notebooks/deepnote/sqlIntegrationEnvironmentVariablesProvider.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
DATAFRAME_SQL_INTEGRATION_ID,
1111
IntegrationConfig,
1212
IntegrationType,
13-
SnowflakeAuthMethods
13+
SnowflakeAuthMethods,
14+
isSupportedSnowflakeAuthMethod
1415
} from './integrationTypes';
1516

1617
/**
@@ -85,10 +86,16 @@ function convertIntegrationConfigToJson(config: IntegrationConfig): string {
8586
// Service account key-pair: snowflake://{username}@{account}/{database}?warehouse={warehouse}&role={role}&authenticator=snowflake_jwt&application=YourApp
8687
const encodedAccount = encodeURIComponent(config.account);
8788

89+
// Check if this is a supported auth method
90+
if (!isSupportedSnowflakeAuthMethod(config.authMethod)) {
91+
throw new UnsupportedIntegrationError(
92+
`Snowflake integration with auth method '${config.authMethod}' is not supported in VSCode`
93+
);
94+
}
95+
8896
let url: string;
8997
const params: Record<string, unknown> = {};
9098

91-
// Check if this is a supported auth method
9299
if (config.authMethod === null || config.authMethod === SnowflakeAuthMethods.PASSWORD) {
93100
// Username+password authentication
94101
const encodedUsername = encodeURIComponent(config.username);
@@ -109,8 +116,16 @@ function convertIntegrationConfigToJson(config: IntegrationConfig): string {
109116
if (queryString) {
110117
url += `?${queryString}`;
111118
}
112-
} else if (config.authMethod === SnowflakeAuthMethods.SERVICE_ACCOUNT_KEY_PAIR) {
113-
// Service account key-pair authentication
119+
} else {
120+
// Service account key-pair authentication (the only other supported method)
121+
// TypeScript needs help narrowing the type here
122+
if (config.authMethod !== SnowflakeAuthMethods.SERVICE_ACCOUNT_KEY_PAIR) {
123+
// This should never happen due to the type guard above, but TypeScript needs this
124+
throw new UnsupportedIntegrationError(
125+
`Snowflake integration with auth method '${config.authMethod}' is not supported in VSCode`
126+
);
127+
}
128+
114129
const encodedUsername = encodeURIComponent(config.username);
115130
const database = config.database ? `/${encodeURIComponent(config.database)}` : '';
116131
url = `snowflake://${encodedUsername}@${encodedAccount}${database}`;
@@ -135,11 +150,6 @@ function convertIntegrationConfigToJson(config: IntegrationConfig): string {
135150
if (config.privateKeyPassphrase) {
136151
params.private_key_passphrase = config.privateKeyPassphrase;
137152
}
138-
} else {
139-
// Unsupported auth method
140-
throw new UnsupportedIntegrationError(
141-
`Snowflake integration with auth method '${config.authMethod}' is not supported in VSCode`
142-
);
143153
}
144154

145155
return JSON.stringify({

src/webviews/webview-side/integrations/SnowflakeForm.tsx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import * as React from 'react';
22
import { format, getLocString } from '../react-common/locReactSide';
3-
import { SnowflakeIntegrationConfig, SnowflakeAuthMethod, SnowflakeAuthMethods } from './types';
3+
import {
4+
SnowflakeIntegrationConfig,
5+
SnowflakeAuthMethod,
6+
SnowflakeAuthMethods,
7+
isSupportedSnowflakeAuthMethod
8+
} from './types';
49

510
export interface ISnowflakeFormProps {
611
integrationId: string;
@@ -10,15 +15,6 @@ export interface ISnowflakeFormProps {
1015
onCancel: () => void;
1116
}
1217

13-
// Helper to check if auth method is supported
14-
function isAuthMethodSupported(authMethod: SnowflakeAuthMethod): boolean {
15-
return (
16-
authMethod === null ||
17-
authMethod === SnowflakeAuthMethods.PASSWORD ||
18-
authMethod === SnowflakeAuthMethods.SERVICE_ACCOUNT_KEY_PAIR
19-
);
20-
}
21-
2218
// Helper to get initial values from existing config
2319
function getInitialValues(existingConfig: SnowflakeIntegrationConfig | null) {
2420
if (!existingConfig) {
@@ -64,7 +60,7 @@ export const SnowflakeForm: React.FC<ISnowflakeFormProps> = ({
6460
onSave,
6561
onCancel
6662
}) => {
67-
const isUnsupported = existingConfig ? !isAuthMethodSupported(existingConfig.authMethod) : false;
63+
const isUnsupported = existingConfig ? !isSupportedSnowflakeAuthMethod(existingConfig.authMethod) : false;
6864
const initialValues = getInitialValues(existingConfig);
6965

7066
const [name, setName] = React.useState(existingConfig?.name || integrationName || '');
@@ -206,7 +202,7 @@ export const SnowflakeForm: React.FC<ISnowflakeFormProps> = ({
206202
</label>
207203
<select
208204
id="authMethod"
209-
value={authMethod ?? ''}
205+
value={authMethod}
210206
onChange={(e) => setAuthMethod(e.target.value as SnowflakeAuthMethod)}
211207
disabled={isUnsupported}
212208
>

src/webviews/webview-side/integrations/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import {
22
SnowflakeAuthMethod,
33
SnowflakeAuthMethods,
4-
SUPPORTED_SNOWFLAKE_AUTH_METHODS
4+
SUPPORTED_SNOWFLAKE_AUTH_METHODS,
5+
isSupportedSnowflakeAuthMethod
56
} from '../../../platform/notebooks/deepnote/snowflakeAuthConstants';
67

78
export type IntegrationType = 'postgres' | 'bigquery' | 'snowflake';
89

910
export type IntegrationStatus = 'connected' | 'disconnected' | 'error';
1011

1112
// Re-export Snowflake auth constants for convenience
12-
export { SnowflakeAuthMethod, SnowflakeAuthMethods, SUPPORTED_SNOWFLAKE_AUTH_METHODS };
13+
export { SnowflakeAuthMethod, SnowflakeAuthMethods, SUPPORTED_SNOWFLAKE_AUTH_METHODS, isSupportedSnowflakeAuthMethod };
1314

1415
export interface BaseIntegrationConfig {
1516
id: string;

0 commit comments

Comments
 (0)