mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat(Snowflake Node): Add support for Key-Pair authentication (#14833)
This commit is contained in:
committed by
GitHub
parent
c02696241b
commit
4302c5f474
@@ -1,5 +1,43 @@
|
||||
import pick from 'lodash/pick';
|
||||
import type snowflake from 'snowflake-sdk';
|
||||
|
||||
const commonConnectionFields = [
|
||||
'account',
|
||||
'database',
|
||||
'schema',
|
||||
'warehouse',
|
||||
'role',
|
||||
'clientSessionKeepAlive',
|
||||
] as const;
|
||||
|
||||
export type SnowflakeCredential = Pick<
|
||||
snowflake.ConnectionOptions,
|
||||
(typeof commonConnectionFields)[number]
|
||||
> &
|
||||
(
|
||||
| {
|
||||
authentication: 'password';
|
||||
username?: string;
|
||||
password?: string;
|
||||
}
|
||||
| {
|
||||
authentication: 'keyPair';
|
||||
privateKey: string;
|
||||
}
|
||||
);
|
||||
|
||||
export const getConnectionOptions = (credential: SnowflakeCredential) => {
|
||||
const connectionOptions: snowflake.ConnectionOptions = pick(credential, commonConnectionFields);
|
||||
if (credential.authentication === 'keyPair') {
|
||||
connectionOptions.authenticator = 'SNOWFLAKE_JWT';
|
||||
connectionOptions.privateKey = credential.privateKey;
|
||||
} else {
|
||||
connectionOptions.username = credential.username;
|
||||
connectionOptions.password = credential.password;
|
||||
}
|
||||
return connectionOptions;
|
||||
};
|
||||
|
||||
export async function connect(conn: snowflake.Connection) {
|
||||
return await new Promise<void>((resolve, reject) => {
|
||||
conn.connect((error) => (error ? reject(error) : resolve()));
|
||||
|
||||
Reference in New Issue
Block a user