Skip to content

Commit 068560b

Browse files
feat: Introduce dremioAuthToken config
- Adds the dremioAuthToken config to support the dremio cloud driver
1 parent 11437c2 commit 068560b

File tree

3 files changed

+38
-18
lines changed

3 files changed

+38
-18
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,23 @@ const variables: Record<string, (...args: any) => any> = {
16261626
]
16271627
),
16281628

1629+
/** ****************************************************************
1630+
* Dremio Driver *
1631+
***************************************************************** */
1632+
1633+
/**
1634+
* Dremio Auth Token
1635+
*/
1636+
dremioAuthToken: ({
1637+
dataSource,
1638+
}: {
1639+
dataSource: string,
1640+
}) => (
1641+
process.env[
1642+
keyByDataSource('CUBEJS_DB_DREMIO_AUTH_TOKEN', dataSource)
1643+
]
1644+
),
1645+
16291646
/** ****************************************************************
16301647
* Cube Store Driver *
16311648
***************************************************************** */

packages/cubejs-dremio-driver/README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ Pure Javascript Dremio driver.
1313

1414
To use this driver with [Dremio Cloud](https://docs.dremio.com/cloud/reference/api/), use the following setup:
1515

16-
| Environment Variable | Value |
17-
| -------------------- | -------------------------------------------------- |
18-
| CUBEJS_DB_TYPE | dremio |
19-
| CUBEJS_DB_URL | https://api.dremio.cloud/v0/projects/${PROJECT_ID} |
20-
| CUBEJS_DB_NAME | ${DB_NAME} |
21-
| CUBEJS_DB_PASS | Bearer ${PERSONAL_ACCESS_TOKEN} |
22-
23-
> It's important to note that "Bearer" is required for using personal access tokens.
16+
| Environment Variable | Value |
17+
| --------------------------- | -------------------------------------------------- |
18+
| CUBEJS_DB_TYPE | dremio |
19+
| CUBEJS_DB_URL | https://api.dremio.cloud/v0/projects/${PROJECT_ID} |
20+
| CUBEJS_DB_NAME | ${DB_NAME} |
21+
| CUBEJS_DB_DREMIO_AUTH_TOKEN | ${PERSONAL_ACCESS_TOKEN} |
22+
23+
> [!NOTE]
24+
> When `CUBEJS_DB_URL` is set it takes precedence over `CUBEJS_DB_HOST` and it
25+
> is assumed that the driver is connecting to the Dremio Cloud API.
2426
2527
## Support
2628

packages/cubejs-dremio-driver/driver/DremioDriver.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ class DremioDriver extends BaseDriver {
5353
config.dbUrl ||
5454
getEnv('dbUrl', { dataSource }) ||
5555
'',
56+
dremioAuthToken:
57+
config.dremioAuthToken ||
58+
getEnv('dremioAuthToken', { dataSource }) ||
59+
'',
5660
host:
5761
config.host ||
5862
getEnv('dbHost', { dataSource }) ||
@@ -88,20 +92,16 @@ class DremioDriver extends BaseDriver {
8892
if (this.config.dbUrl) {
8993
this.config.url = this.config.dbUrl;
9094
this.config.apiVersion = '';
91-
this.config.auth = 'PAT';
95+
if (this.config.dremioAuthToken === '') {
96+
throw new Error('dremioAuthToken is blank');
97+
}
9298
} else {
9399
const protocol = (this.config.ssl === true || this.config.ssl === 'true')
94100
? 'https'
95101
: 'http';
96102
this.config.url = `${protocol}://${this.config.host}:${this.config.port}`;
97103
this.config.apiVersion = '/api/v3';
98104
}
99-
100-
if (this.config.auth === 'PAT' || this.config.password.startsWith('Bearer ')) {
101-
this.config.auth = 'PAT';
102-
} else {
103-
this.config.auth = 'BASIC';
104-
}
105105
}
106106

107107
/**
@@ -120,17 +120,18 @@ class DremioDriver extends BaseDriver {
120120
* @protected
121121
*/
122122
async getToken() {
123-
if (this.config.auth === 'PAT') {
123+
if (this.config.dremioAuthToken) {
124+
const bearerToken = `Bearer ${this.config.dremioAuthToken}`;
124125
await axios.get(
125126
`${this.config.url}${this.config.apiVersion}/catalog`,
126127
{
127128
headers: {
128-
Authorization: this.config.password
129+
Authorization: bearerToken
129130
},
130131
},
131132
);
132133

133-
return this.config.password;
134+
return bearerToken;
134135
}
135136

136137
if (this.authToken && this.authToken.expires > new Date().getTime()) {

0 commit comments

Comments
 (0)