Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Proxy config section to snowflake connector #2200

Merged
merged 10 commits into from
Jul 16, 2024
5 changes: 5 additions & 0 deletions .changeset/perfect-lobsters-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@evidence-dev/snowflake': minor
---

Add Proxy config section/options to snowflake connector
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Follow these steps to submit a pull request for your changes:
3. Test your changes to make sure all results are as expected
4. Format your code to prevent linting errors `pnpm run format`
5. Add a [changeset](#adding-a-changeset)
6. Open a pull request against the `main` branch of the `evidence` repo
6. Open a pull request against the `next` branch of the `evidence` repo

[Here's an example of a pull request](https://github.com/evidence-dev/evidence/pull/165) from a community member who built Evidence's MySQL connector.

Expand Down
93 changes: 68 additions & 25 deletions packages/datasources/snowflake/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,27 @@ const getCredentials = (database = {}) => {
const role = database.role;
const schema = database.schema;

// https://docs.snowflake.com/en/developer-guide/node-js/nodejs-driver-connect#label-nodejs-proxy-connection
const proxyOptions = database.proxy
? {
proxyHost: database.proxy.host,
proxyPort: database.proxy.port,
proxyUser: database.proxy.username,
proxyPassword: database.proxy.password,
proxyProtocol: database.proxy.protocol
}
: {};

const baseOptions = {
account,
database: default_database,
username,
warehouse,
role,
schema,
...proxyOptions
};

if (authenticator === 'snowflake_jwt') {
const private_key = database.private_key;
const passphrase = database.passphrase;
Expand All @@ -168,45 +189,25 @@ const getCredentials = (database = {}) => {
});

return {
...baseOptions,
privateKey: decrypted_private_key,
username,
account,
database: default_database,
warehouse,
role,
schema,
authenticator
};
} else if (authenticator === 'externalbrowser') {
return {
username,
account,
database: default_database,
warehouse,
role,
schema,
...baseOptions,
authenticator
};
} else if (authenticator === 'okta') {
return {
username,
...baseOptions,
password: database.password,
account,
database: default_database,
warehouse,
role,
schema,
authenticator: database.okta_url
};
} else {
return {
username,
password: database.password,
account,
database: default_database,
warehouse,
schema,
role
...baseOptions,
password: database.password
};
}
};
Expand Down Expand Up @@ -381,5 +382,47 @@ module.exports.options = {
}
}
}
},
proxy: {
title: 'Connect through an authenticated proxy?',
type: 'boolean',
secret: false,
required: false,
nest: true,
children: {
[true]: {
host: {
title: 'Host',
type: 'string',
secret: false,
required: true
},
port: {
title: 'Port',
type: 'number',
secret: false,
required: true
},
username: {
title: 'Username',
type: 'string',
secret: true,
shown: true,
required: false
},
password: {
title: 'Password',
type: 'string',
secret: true,
required: false
},
protocol: {
title: 'Protocol',
type: 'string',
secret: false,
required: false
}
}
}
}
};
Loading