Skip to content

Commit 11437c2

Browse files
feat: Add Dremio Cloud Support
- Adds support to cubejs-dremio-driver for Dremio Cloud - Adds support for personal access tokens for Dremio Server
1 parent 5593a2a commit 11437c2

File tree

2 files changed

+55
-12
lines changed

2 files changed

+55
-12
lines changed

packages/cubejs-dremio-driver/README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,24 @@
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_PASS | Bearer ${PERSONAL_ACCESS_TOKEN} |
22+
23+
> It's important to note that "Bearer" is required for using personal access tokens.
24+
1225
## Support
1326

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

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.
29+
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.
1730

1831
## License
1932

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

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

5151
this.config = {
52+
dbUrl:
53+
config.dbUrl ||
54+
getEnv('dbUrl', { dataSource }) ||
55+
'',
5256
host:
5357
config.host ||
5458
getEnv('dbHost', { dataSource }) ||
@@ -80,11 +84,24 @@ class DremioDriver extends BaseDriver {
8084
getEnv('dbPollMaxInterval', { dataSource })
8185
) * 1000,
8286
};
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}`;
87+
88+
if (this.config.dbUrl) {
89+
this.config.url = this.config.dbUrl;
90+
this.config.apiVersion = '';
91+
this.config.auth = 'PAT';
92+
} else {
93+
const protocol = (this.config.ssl === true || this.config.ssl === 'true')
94+
? 'https'
95+
: 'http';
96+
this.config.url = `${protocol}://${this.config.host}:${this.config.port}`;
97+
this.config.apiVersion = '/api/v3';
98+
}
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+
}
88105
}
89106

90107
/**
@@ -103,6 +120,19 @@ class DremioDriver extends BaseDriver {
103120
* @protected
104121
*/
105122
async getToken() {
123+
if (this.config.auth === 'PAT') {
124+
await axios.get(
125+
`${this.config.url}${this.config.apiVersion}/catalog`,
126+
{
127+
headers: {
128+
Authorization: this.config.password
129+
},
130+
},
131+
);
132+
133+
return this.config.password;
134+
}
135+
106136
if (this.authToken && this.authToken.expires > new Date().getTime()) {
107137
return `_dremio${this.authToken.token}`;
108138
}
@@ -129,7 +159,7 @@ class DremioDriver extends BaseDriver {
129159

130160
return axios.request({
131161
method,
132-
url: `${this.config.url}${url}`,
162+
url: `${this.config.url}${this.config.apiVersion}${url}`,
133163
headers: {
134164
Authorization: token
135165
},
@@ -141,7 +171,7 @@ class DremioDriver extends BaseDriver {
141171
* @protected
142172
*/
143173
async getJobStatus(jobId) {
144-
const { data } = await this.restDremioQuery('get', `/api/v3/job/${jobId}`);
174+
const { data } = await this.restDremioQuery('get', `/job/${jobId}`);
145175

146176
if (data.jobState === 'FAILED') {
147177
throw new Error(data.errorMessage);
@@ -162,7 +192,7 @@ class DremioDriver extends BaseDriver {
162192
* @protected
163193
*/
164194
async getJobResults(jobId, limit = 500, offset = 0) {
165-
return this.restDremioQuery('get', `/api/v3/job/${jobId}/results?offset=${offset}&limit=${limit}`);
195+
return this.restDremioQuery('get', `/job/${jobId}/results?offset=${offset}&limit=${limit}`);
166196
}
167197

168198
/**
@@ -171,7 +201,7 @@ class DremioDriver extends BaseDriver {
171201
* @return {Promise<*>}
172202
*/
173203
async executeQuery(sql) {
174-
const { data } = await this.restDremioQuery('post', '/api/v3/sql', { sql });
204+
const { data } = await this.restDremioQuery('post', '/sql', { sql });
175205
return data.id;
176206
}
177207

@@ -216,7 +246,7 @@ class DremioDriver extends BaseDriver {
216246
}
217247

218248
async refreshTablesSchema(path) {
219-
const { data } = await this.restDremioQuery('get', `/api/v3/catalog/by-path/${path}`);
249+
const { data } = await this.restDremioQuery('get', `/catalog/by-path/${path}`);
220250
if (!data || !data.children) {
221251
return true;
222252
}

0 commit comments

Comments
 (0)