Skip to content

Commit ddc4dff

Browse files
vladi-devpaveltiunov
authored andcommitted
fix(mongobi-driver): fix ssl configuration (#78)
* fix(mongobi-driver): fix ssl configuration * fix(mongobi-driver): revert renaming CUBEJS_DB_SSL for backward compat
1 parent c4f12ee commit ddc4dff

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

docs/Cube.js-Backend/Connecting-to-the-Database.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ The table below shows which environment variables are used for different databas
3737

3838
| Database | Credentials |
3939
| -------------------- |--------------- |
40-
| PostgreSQL, MySQL, MongoDB, AWS Redshift | `CUBEJS_DB_TYPE`, `CUBEJS_DB_HOST`, `CUBEJS_DB_NAME`, `CUBEJS_DB_USER`, `CUBEJS_DB_PASS` |
41-
| AWS Athena | `CUBEJS_DB_TYPE`, `CUBEJS_AWS_KEY`, `CUBEJS_AWS_SECRET`, `CUBEJS_AWS_REGION`, `CUBEJS_AWS_S3_OUTPUT_LOCATION` |
42-
| Google Bigquery | `CUBEJS_DB_BQ_PROJECT_ID`, `CUBEJS_DB_BQ_KEY_FILE or CUBEJS_DB_BQ_CREDENTIALS` |
40+
| PostgreSQL, MySQL, AWS Redshift | `CUBEJS_DB_HOST`, `CUBEJS_DB_NAME`, `CUBEJS_DB_USER`, `CUBEJS_DB_PASS` |
41+
| AWS Athena | `CUBEJS_AWS_KEY`, `CUBEJS_AWS_SECRET`, `CUBEJS_AWS_REGION`, `CUBEJS_AWS_S3_OUTPUT_LOCATION` |
42+
| Google Bigquery | `CUBEJS_DB_BQ_PROJECT_ID`, `CUBEJS_DB_BQ_KEY_FILE or CUBEJS_DB_BQ_CREDENTIALS` |
43+
| MongoDB | `CUBEJS_DB_HOST`, `CUBEJS_DB_NAME`, `CUBEJS_DB_PORT`, `CUBEJS_DB_USER`, `CUBEJS_DB_PASS`, `CUBEJS_DB_SSL`, `CUBEJS_DB_SSL_CA`, `CUBEJS_DB_SSL_CERT`, `CUBEJS_DB_SSL_CIPHERS`, `CUBEJS_DB_SSL_PASSPHRASE` |
4344

4445
## Notes
4546

packages/cubejs-mongobi-driver/driver/MongoBIDriver.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,40 @@ const BaseDriver = require('@cubejs-backend/query-orchestrator/driver/BaseDriver
66
class MongoBIDriver extends BaseDriver {
77
constructor(config) {
88
super();
9+
10+
let ssl = {};
11+
12+
if (process.env.CUBEJS_DB_SSL) {
13+
ssl = process.env.CUBEJS_DB_SSL;
14+
} else {
15+
const sslOptions = [
16+
{ name: 'ca', value: 'CUBEJS_DB_SSL_CA' },
17+
{ name: 'cert', value: 'CUBEJS_DB_SSL_CERT' },
18+
{ name: 'ciphers', value: 'CUBEJS_DB_SSL_CIPHERS' },
19+
{ name: 'passphrase', value: 'CUBEJS_DB_SSL_PASSPHRASE' },
20+
];
21+
22+
ssl = sslOptions.reduce(
23+
(agg, { name, value }) => ({
24+
...agg,
25+
...(process.env[value] ? { [name]: process.env[value] } : {}),
26+
}),
27+
{}
28+
);
29+
30+
if (process.env.CUBEJS_DB_SSL_REJECT_UNAUTHORIZED) {
31+
ssl.rejectUnauthorized =
32+
process.env.CUBEJS_DB_SSL_REJECT_UNAUTHORIZED.toLowerCase() === 'true';
33+
}
34+
}
35+
936
this.config = {
1037
host: process.env.CUBEJS_DB_HOST,
1138
database: process.env.CUBEJS_DB_NAME,
1239
port: process.env.CUBEJS_DB_PORT,
1340
user: process.env.CUBEJS_DB_USER,
1441
password: process.env.CUBEJS_DB_PASS,
15-
ssl: process.env.CUBEJS_DB_SSL && {
16-
ssl: process.env.CUBEJS_DB_SSL
17-
},
42+
ssl,
1843
authSwitchHandler: (data, cb) => {
1944
const buffer = Buffer.from((process.env.CUBEJS_DB_PASS || '').concat('\0'));
2045
cb(null, buffer);

0 commit comments

Comments
 (0)