Skip to content

Commit c3359c1

Browse files
committed
feat(athena-driver): add session-token and database env vars
1 parent 2d12eff commit c3359c1

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

packages/cubejs-athena-driver/src/AthenaDriver.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ interface AthenaDriverOptions extends AthenaClientConfig {
3030
readOnly?: boolean
3131
accessKeyId?: string
3232
secretAccessKey?: string
33+
sessionToken?: string
3334
workGroup?: string
3435
catalog?: string
3536
schema?: string
37+
database?: string
3638
S3OutputLocation?: string
3739
exportBucket?: string
3840
pollTimeout?: number
@@ -103,6 +105,10 @@ export class AthenaDriver extends BaseDriver implements DriverInterface {
103105
config.secretAccessKey ||
104106
getEnv('athenaAwsSecret', { dataSource });
105107

108+
const sessionToken =
109+
config.sessionToken ||
110+
getEnv('athenaAwsSessionToken', { dataSource });
111+
106112
const { schema, ...restConfig } = config;
107113

108114
this.schema = schema ||
@@ -112,7 +118,7 @@ export class AthenaDriver extends BaseDriver implements DriverInterface {
112118
this.config = {
113119
...restConfig,
114120
credentials: accessKeyId && secretAccessKey
115-
? { accessKeyId, secretAccessKey }
121+
? { accessKeyId, secretAccessKey, sessionToken }
116122
: undefined,
117123
region:
118124
config.region ||
@@ -127,6 +133,9 @@ export class AthenaDriver extends BaseDriver implements DriverInterface {
127133
catalog:
128134
config.catalog ||
129135
getEnv('athenaAwsCatalog', { dataSource }),
136+
database:
137+
config.database ||
138+
getEnv('athenaAwsDatabase', { dataSource }),
130139
exportBucket:
131140
config.exportBucket ||
132141
getEnv('dbExportBucket', { dataSource }),
@@ -274,7 +283,10 @@ export class AthenaDriver extends BaseDriver implements DriverInterface {
274283
ResultConfiguration: {
275284
OutputLocation: this.config.S3OutputLocation
276285
},
277-
...(this.config.catalog != null ? { QueryExecutionContext: { Catalog: this.config.catalog } } : {})
286+
QueryExecutionContext: {
287+
Catalog: this.config.catalog,
288+
Database: this.config.database
289+
}
278290
};
279291
const { QueryExecutionId } = await this.athena.startQueryExecution(request);
280292
return { QueryExecutionId: checkNonNullable('StartQueryExecution', QueryExecutionId) };

packages/cubejs-backend-shared/src/env.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,18 @@ const variables: Record<string, (...args: any) => any> = {
848848
process.env[keyByDataSource('CUBEJS_AWS_SECRET', dataSource)]
849849
),
850850

851+
/**
852+
* Athena AWS secret.
853+
*/
854+
athenaAwsSessionToken: ({
855+
dataSource
856+
}: {
857+
dataSource: string,
858+
}) => (
859+
// TODO (buntarb): this name is a common. Deprecate and replace?
860+
process.env[keyByDataSource('CUBEJS_AWS_SESSION_TOKEN', dataSource)]
861+
),
862+
851863
/**
852864
* Athena AWS region.
853865
*/
@@ -902,6 +914,20 @@ const variables: Record<string, (...args: any) => any> = {
902914
]
903915
),
904916

917+
/**
918+
* Athena AWS Database.
919+
*/
920+
athenaAwsDatabase: ({
921+
dataSource
922+
}: {
923+
dataSource: string,
924+
}) => (
925+
// TODO (buntarb): Deprecate and replace?
926+
process.env[
927+
keyByDataSource('CUBEJS_AWS_ATHENA_DATABASE', dataSource)
928+
]
929+
),
930+
905931
/** ****************************************************************
906932
* BigQuery Driver *
907933
***************************************************************** */

0 commit comments

Comments
 (0)