mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
fix(Snowflake Node): Fix key-pair credentials (#16635)
Co-authored-by: Elias Meire <elias@meire.dev> Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import { createPrivateKey } from 'crypto';
|
||||
import pick from 'lodash/pick';
|
||||
import type snowflake from 'snowflake-sdk';
|
||||
|
||||
import { formatPrivateKey } from '@utils/utilities';
|
||||
|
||||
const commonConnectionFields = [
|
||||
'account',
|
||||
'database',
|
||||
@@ -22,15 +25,35 @@ export type SnowflakeCredential = Pick<
|
||||
}
|
||||
| {
|
||||
authentication: 'keyPair';
|
||||
username: string;
|
||||
privateKey: string;
|
||||
passphrase?: string;
|
||||
}
|
||||
);
|
||||
|
||||
const extractPrivateKey = (credential: { privateKey: string; passphrase?: string }) => {
|
||||
const key = formatPrivateKey(credential.privateKey as string);
|
||||
|
||||
if (!credential.passphrase) return key;
|
||||
|
||||
const privateKeyObject = createPrivateKey({
|
||||
key,
|
||||
format: 'pem',
|
||||
passphrase: credential.passphrase as string,
|
||||
});
|
||||
|
||||
return privateKeyObject.export({
|
||||
format: 'pem',
|
||||
type: 'pkcs8',
|
||||
}) as 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;
|
||||
connectionOptions.username = credential.username;
|
||||
connectionOptions.privateKey = extractPrivateKey(credential);
|
||||
} else {
|
||||
connectionOptions.username = credential.username;
|
||||
connectionOptions.password = credential.password;
|
||||
|
||||
Reference in New Issue
Block a user