Skip to content

Commit a2b277b

Browse files
committed
fix: path
1 parent 0de1978 commit a2b277b

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

packages/cubejs-snowflake-driver/src/SnowflakeDriver.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ interface SnowflakeDriverOptions {
164164
clientSessionKeepAlive?: boolean,
165165
database?: string,
166166
authenticator?: string,
167+
oauthTokenPath?: string,
167168
token?: string,
168169
privateKeyPath?: string,
169170
privateKeyPass?: string,
@@ -269,6 +270,7 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
269270
username: getEnv('dbUser', { dataSource }),
270271
password: getEnv('dbPass', { dataSource }),
271272
authenticator: getEnv('snowflakeAuthenticator', { dataSource }),
273+
oauthTokenPath: getEnv('snowflakeOAuthTokenPath', { dataSource }),
272274
privateKeyPath: getEnv('snowflakePrivateKeyPath', { dataSource }),
273275
privateKeyPass: getEnv('snowflakePrivateKeyPass', { dataSource }),
274276
privateKey,
@@ -391,15 +393,26 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
391393
return undefined;
392394
}
393395

394-
private async readOAuthToken(dataSource: string) {
395-
const tokenPath = getEnv('snowflakeOAuthTokenPath', { dataSource });
396+
private async readOAuthToken() {
397+
const tokenPath = this.config.oauthTokenPath;
398+
399+
if (!tokenPath) {
400+
return undefined;
401+
}
402+
403+
try {
404+
await fs.access(tokenPath);
405+
} catch (error) {
406+
throw new Error(`File ${tokenPath} provided by CUBEJS_DB_SNOWFLAKE_OAUTH_TOKEN_PATH does not exist.`);
407+
}
408+
396409
const token = await fs.readFile(tokenPath, 'utf8');
397410
return token.trim();
398411
}
399412

400413
private async createConnection() {
401414
if (this.config.authenticator?.toUpperCase() === 'OAUTH') {
402-
this.config.token = await this.readOAuthToken(this.config.dataSource);
415+
this.config.token = await this.readOAuthToken();
403416
}
404417

405418
const connection = snowflake.createConnection(this.config);

0 commit comments

Comments
 (0)