Skip to content

Commit d2c2fcd

Browse files
feat(dremio-driver): Add Dremio Cloud Support (#8956)
* feat: Add Dremio Cloud Support - Adds support to cubejs-dremio-driver for Dremio Cloud - Adds support for personal access tokens for Dremio Server * feat: Introduce dremioAuthToken config - Adds the dremioAuthToken config to support the dremio cloud driver --------- Co-authored-by: Konstantin Burkalev <[email protected]>
1 parent ad4e8e3 commit d2c2fcd

File tree

3 files changed

+75
-12
lines changed

3 files changed

+75
-12
lines changed

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

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

1650+
/** ****************************************************************
1651+
* Dremio Driver *
1652+
***************************************************************** */
1653+
1654+
/**
1655+
* Dremio Auth Token
1656+
*/
1657+
dremioAuthToken: ({
1658+
dataSource,
1659+
}: {
1660+
dataSource: string,
1661+
}) => (
1662+
process.env[
1663+
keyByDataSource('CUBEJS_DB_DREMIO_AUTH_TOKEN', dataSource)
1664+
]
1665+
),
1666+
16501667
/** ****************************************************************
16511668
* Cube Store Driver *
16521669
***************************************************************** */

packages/cubejs-dremio-driver/README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,26 @@
99

1010
Pure Javascript Dremio driver.
1111

12+
## Dremio Cloud
13+
14+
To use this driver with [Dremio Cloud](https://docs.dremio.com/cloud/reference/api/), use the following setup:
15+
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.
26+
1227
## Support
1328

14-
This package is **community supported** and should be used at your own risk.
29+
This package is **community supported** and should be used at your own risk.
1530

16-
While the Cube Dev team is happy to review and accept future community contributions, we don't have active plans for further development. This includes bug fixes unless they affect different parts of Cube.js. **We're looking for maintainers for this package.** If you'd like to become a maintainer, please contact us in Cube.js Slack.
31+
While the Cube Dev team is happy to review and accept future community contributions, we don't have active plans for further development. This includes bug fixes unless they affect different parts of Cube.js. **We're looking for maintainers for this package.** If you'd like to become a maintainer, please contact us in Cube.js Slack.
1732

1833
## License
1934

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

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ class DremioDriver extends BaseDriver {
4949
assertDataSource('default');
5050

5151
this.config = {
52+
dbUrl:
53+
config.dbUrl ||
54+
getEnv('dbUrl', { dataSource }) ||
55+
'',
56+
dremioAuthToken:
57+
config.dremioAuthToken ||
58+
getEnv('dremioAuthToken', { dataSource }) ||
59+
'',
5260
host:
5361
config.host ||
5462
getEnv('dbHost', { dataSource }) ||
@@ -80,11 +88,20 @@ class DremioDriver extends BaseDriver {
8088
getEnv('dbPollMaxInterval', { dataSource })
8189
) * 1000,
8290
};
83-
const protocol = (this.config.ssl === true || this.config.ssl === 'true')
84-
? 'https'
85-
: 'http';
86-
this.config.url =
87-
`${protocol}://${this.config.host}:${this.config.port}`;
91+
92+
if (this.config.dbUrl) {
93+
this.config.url = this.config.dbUrl;
94+
this.config.apiVersion = '';
95+
if (this.config.dremioAuthToken === '') {
96+
throw new Error('dremioAuthToken is blank');
97+
}
98+
} else {
99+
const protocol = (this.config.ssl === true || this.config.ssl === 'true')
100+
? 'https'
101+
: 'http';
102+
this.config.url = `${protocol}://${this.config.host}:${this.config.port}`;
103+
this.config.apiVersion = '/api/v3';
104+
}
88105
}
89106

90107
/**
@@ -103,6 +120,20 @@ class DremioDriver extends BaseDriver {
103120
* @protected
104121
*/
105122
async getToken() {
123+
if (this.config.dremioAuthToken) {
124+
const bearerToken = `Bearer ${this.config.dremioAuthToken}`;
125+
await axios.get(
126+
`${this.config.url}${this.config.apiVersion}/catalog`,
127+
{
128+
headers: {
129+
Authorization: bearerToken
130+
},
131+
},
132+
);
133+
134+
return bearerToken;
135+
}
136+
106137
if (this.authToken && this.authToken.expires > new Date().getTime()) {
107138
return `_dremio${this.authToken.token}`;
108139
}
@@ -129,7 +160,7 @@ class DremioDriver extends BaseDriver {
129160

130161
return axios.request({
131162
method,
132-
url: `${this.config.url}${url}`,
163+
url: `${this.config.url}${this.config.apiVersion}${url}`,
133164
headers: {
134165
Authorization: token
135166
},
@@ -141,7 +172,7 @@ class DremioDriver extends BaseDriver {
141172
* @protected
142173
*/
143174
async getJobStatus(jobId) {
144-
const { data } = await this.restDremioQuery('get', `/api/v3/job/${jobId}`);
175+
const { data } = await this.restDremioQuery('get', `/job/${jobId}`);
145176

146177
if (data.jobState === 'FAILED') {
147178
throw new Error(data.errorMessage);
@@ -162,7 +193,7 @@ class DremioDriver extends BaseDriver {
162193
* @protected
163194
*/
164195
async getJobResults(jobId, limit = 500, offset = 0) {
165-
return this.restDremioQuery('get', `/api/v3/job/${jobId}/results?offset=${offset}&limit=${limit}`);
196+
return this.restDremioQuery('get', `/job/${jobId}/results?offset=${offset}&limit=${limit}`);
166197
}
167198

168199
/**
@@ -171,7 +202,7 @@ class DremioDriver extends BaseDriver {
171202
* @return {Promise<*>}
172203
*/
173204
async executeQuery(sql) {
174-
const { data } = await this.restDremioQuery('post', '/api/v3/sql', { sql });
205+
const { data } = await this.restDremioQuery('post', '/sql', { sql });
175206
return data.id;
176207
}
177208

@@ -216,7 +247,7 @@ class DremioDriver extends BaseDriver {
216247
}
217248

218249
async refreshTablesSchema(path) {
219-
const { data } = await this.restDremioQuery('get', `/api/v3/catalog/by-path/${path}`);
250+
const { data } = await this.restDremioQuery('get', `/catalog/by-path/${path}`);
220251
if (!data || !data.children) {
221252
return true;
222253
}

0 commit comments

Comments
 (0)