Skip to content

Commit

Permalink
syncing up to 841e6810a1dfb3c82e139d6a365aa44a5360e8c0
Browse files Browse the repository at this point in the history
Co-authored-by: Joey Greco <57115019+joeyagreco@users.noreply.github.com>
  • Loading branch information
superblocksadmin and joeyagreco committed Nov 8, 2024
1 parent 784a34b commit 674ac1c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 28 deletions.
4 changes: 2 additions & 2 deletions helm/agent/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
apiVersion: v2
appVersion: v1.14.0
appVersion: v1.16.0
description: A Helm chart for the Superblocks On-Prem Agent
name: superblocks-agent
type: application
version: 2.32.0
version: 2.33.0
48 changes: 27 additions & 21 deletions workers/javascript/packages/plugins/snowflake/src/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,11 @@ describe('connectionOptionsFromDatasourceConfiguration', () => {
});
});

it('works for key-pair without key-pair password', async () => {
it('works for key-pair without private key password', async () => {
const datasourceConfiguration = {
connectionType: 'key-pair',
authentication: {
username: 'user',
password: 'pass',
custom: {
account: { value: 'account' }
}
Expand All @@ -100,9 +99,31 @@ describe('connectionOptionsFromDatasourceConfiguration', () => {

expect(connectionOptions).toEqual({
account: 'account',
username: 'user',
authenticator: 'SNOWFLAKE_JWT',
privateKey: 'pk'
});
});

it('trims leading and trailing whitespace from private key', async () => {
const datasourceConfiguration = {
connectionType: 'key-pair',
authentication: {
username: 'user',
custom: {
account: { value: 'account' }
}
},
keyPair: {
privateKey: ' pk '
}
} as SnowflakeDatasourceConfiguration;
const connectionOptions = connectionOptionsFromDatasourceConfiguration(datasourceConfiguration);

expect(connectionOptions).toEqual({
account: 'account',
username: 'user',
password: 'pass',
authenticator: 'SNOWFLAKE_JWT',
privateKey: 'pk'
});
});
Expand All @@ -113,8 +134,6 @@ describe('connectionOptionsFromDatasourceConfiguration', () => {
connectionType: 'key-pair',
authentication: {
username: 'user',
password: 'pass',

custom: {
account: { value: 'account' }
}
Expand Down Expand Up @@ -157,9 +176,8 @@ y4BdZfATsd4Q1gjGoALvDK0i7pwG+40wxmKFDkj95QmskRMSX8q0DUg=

expect(connectionOptions).toEqual({
account: 'account',
username: 'user',
password: 'pass',
authenticator: 'SNOWFLAKE_JWT',
username: 'user',
privateKey: `-----BEGIN PRIVATE KEY-----
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCXjMqyEL55ZO7b
/20zZeOPOCeWT87Z2L+mt7fz0Jw9F9Qi7xjopxfadEf9+lAKzFA0WqpaflF0CkUh
Expand Down Expand Up @@ -192,19 +210,17 @@ oBHJaYtVCXd3VBWCVLcfnw==
});
});

it('fails for key-pair when privateKey is not present', () => {
it('fails for key-pair when required fields are not present', () => {
expect(() =>
connectionOptionsFromDatasourceConfiguration({
connectionType: 'key-pair',
authentication: {
username: 'user',
password: 'pass',
custom: {
account: { value: 'account' }
}
}
})
).toThrow('Missing required fields: privateKey');
).toThrow('Missing required fields: username,privateKey');
});

it('fails when authentication is not present', () => {
Expand All @@ -230,14 +246,4 @@ oBHJaYtVCXd3VBWCVLcfnw==
'Missing required fields: account,username,password,authenticatorUrl'
);
});

it('fails with missing fields listed for connection type key-pair', () => {
const datasourceConfiguration = {
connectionType: 'key-pair',
authentication: {}
} as SnowflakeDatasourceConfiguration;
expect(() => connectionOptionsFromDatasourceConfiguration(datasourceConfiguration)).toThrow(
'Missing required fields: account,username,password,privateKey'
);
});
});
13 changes: 8 additions & 5 deletions workers/javascript/packages/plugins/snowflake/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ export function connectionOptionsFromDatasourceConfiguration(datasourceConfigura
if (!auth.username) {
missingFields.push('username');
}
if (!auth.password) {
missingFields.push('password');
}

switch (datasourceConfiguration.connectionType) {
case 'key-pair': {
Expand All @@ -42,22 +39,25 @@ export function connectionOptionsFromDatasourceConfiguration(datasourceConfigura
}

handleMissingFields(missingFields);
let privateKey = datasourceConfiguration.keyPair.privateKey;
// remove leading and trailing whitespace, as snowflake will not accept private keys with that
let privateKey = datasourceConfiguration.keyPair.privateKey.trim();
let password = datasourceConfiguration?.keyPair?.password;
if (password) {
privateKey = getPrivateKeyValue({ privateKey, password });
}
return {
account: auth.custom.account.value,
username: auth.username,
password: auth.password,
authenticator: 'SNOWFLAKE_JWT',
privateKey
};
}
case 'okta': {
// https://docs.snowflake.com/en/developer-guide/node-js/nodejs-driver-authenticate#using-native-sso-through-okta

if (!auth.password) {
missingFields.push('password');
}
if (!datasourceConfiguration?.okta?.authenticatorUrl) {
missingFields.push('authenticatorUrl');
}
Expand All @@ -71,6 +71,9 @@ export function connectionOptionsFromDatasourceConfiguration(datasourceConfigura
};
}
default: {
if (!auth.password) {
missingFields.push('password');
}
if (!auth.custom?.databaseName?.value) {
missingFields.push('databaseName');
}
Expand Down

0 comments on commit 674ac1c

Please sign in to comment.