@@ -153,6 +153,7 @@ interface SnowflakeDriverOptions {
153153 clientSessionKeepAlive ?: boolean ,
154154 database ?: string ,
155155 authenticator ?: string ,
156+ oauthToken ?: string ,
156157 oauthTokenPath ?: string ,
157158 token ?: string ,
158159 privateKeyPath ?: string ,
@@ -189,7 +190,7 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
189190 /**
190191 * Returns the configurable driver options
191192 * Note: It returns the unprefixed option names.
192- * In case of using multisources options need to be prefixed manually.
193+ * In case of using multi-sources options need to be prefixed manually.
193194 */
194195 public static driverEnvVariables ( ) {
195196 return [
@@ -202,6 +203,7 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
202203 'CUBEJS_DB_SNOWFLAKE_ROLE' ,
203204 'CUBEJS_DB_SNOWFLAKE_CLIENT_SESSION_KEEP_ALIVE' ,
204205 'CUBEJS_DB_SNOWFLAKE_AUTHENTICATOR' ,
206+ 'CUBEJS_DB_SNOWFLAKE_OAUTH_TOKEN' ,
205207 'CUBEJS_DB_SNOWFLAKE_OAUTH_TOKEN_PATH' ,
206208 'CUBEJS_DB_SNOWFLAKE_HOST' ,
207209 'CUBEJS_DB_SNOWFLAKE_PRIVATE_KEY' ,
@@ -286,6 +288,7 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
286288 username : getEnv ( 'dbUser' , { dataSource } ) ,
287289 password : getEnv ( 'dbPass' , { dataSource } ) ,
288290 authenticator : getEnv ( 'snowflakeAuthenticator' , { dataSource } ) ,
291+ oauthToken : getEnv ( 'snowflakeOAuthToken' , { dataSource } ) ,
289292 oauthTokenPath : getEnv ( 'snowflakeOAuthTokenPath' , { dataSource } ) ,
290293 privateKeyPath : getEnv ( 'snowflakePrivateKeyPath' , { dataSource } ) ,
291294 privateKeyPass : getEnv ( 'snowflakePrivateKeyPass' , { dataSource } ) ,
@@ -423,12 +426,39 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
423426 return token . trim ( ) ;
424427 }
425428
426- private async createConnection ( ) {
429+ private async prepareConnectOptions ( ) : Promise < snowflake . ConnectionOptions > {
430+ const config : Record < string , any > = {
431+ account : this . config . account ,
432+ region : this . config . region ,
433+ host : this . config . host ,
434+ application : this . config . application ,
435+ authenticator : this . config . authenticator ,
436+ clientSessionKeepAlive : this . config . clientSessionKeepAlive ,
437+ database : this . config . database ,
438+ warehouse : this . config . warehouse ,
439+ role : this . config . role ,
440+ resultPrefetch : this . config . resultPrefetch ,
441+ } ;
442+
427443 if ( this . config . authenticator ?. toUpperCase ( ) === 'OAUTH' ) {
428- this . config . token = await this . readOAuthToken ( ) ;
444+ config . token = this . config . oauthToken || await this . readOAuthToken ( ) ;
445+ } else if ( this . config . authenticator ?. toUpperCase ( ) === 'SNOWFLAKE_JWT' ) {
446+ config . username = this . config . username ;
447+ config . privateKey = this . config . privateKey ;
448+ config . privateKeyPath = this . config . privateKeyPath ;
449+ config . privateKeyPass = this . config . privateKeyPass ;
450+ } else {
451+ config . username = this . config . username ;
452+ config . password = this . config . password ;
429453 }
430454
431- return snowflake . createConnection ( this . config ) ;
455+ return config as snowflake . ConnectionOptions ;
456+ }
457+
458+ private async createConnection ( ) {
459+ const config = await this . prepareConnectOptions ( ) ;
460+
461+ return snowflake . createConnection ( config ) ;
432462 }
433463
434464 /**
0 commit comments