Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 33 additions & 34 deletions packages/cubejs-base-driver/src/BaseDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/

import * as stream from 'stream';
import type { ConnectionOptions as TLSConnectionOptions } from 'tls';

import {
getEnv,
keyByDataSource,
Expand Down Expand Up @@ -149,43 +151,38 @@ export abstract class BaseDriver implements DriverInterface {
`;
}

/**
* Returns SSL options.
*/
protected getSslOptions(dataSource: string) {
let ssl;

const sslOptions = [{
name: 'ca',
canBeFile: true,
envKey: keyByDataSource('CUBEJS_DB_SSL_CA', dataSource),
validate: isSslCert,
}, {
name: 'cert',
canBeFile: true,
envKey: keyByDataSource('CUBEJS_DB_SSL_CERT', dataSource),
validate: isSslCert,
}, {
name: 'key',
canBeFile: true,
envKey: keyByDataSource('CUBEJS_DB_SSL_KEY', dataSource),
validate: isSslKey,
}, {
name: 'ciphers',
envKey: keyByDataSource('CUBEJS_DB_SSL_CIPHERS', dataSource),
}, {
name: 'passphrase',
envKey: keyByDataSource('CUBEJS_DB_SSL_PASSPHRASE', dataSource),
}, {
name: 'servername',
envKey: keyByDataSource('CUBEJS_DB_SSL_SERVERNAME', dataSource),
}];

protected getSslOptions(dataSource: string): TLSConnectionOptions | undefined {
if (
getEnv('dbSsl', { dataSource }) ||
getEnv('dbSslRejectUnauthorized', { dataSource })
) {
ssl = sslOptions.reduce(
const sslOptions = [{
name: 'ca',
canBeFile: true,
envKey: keyByDataSource('CUBEJS_DB_SSL_CA', dataSource),
validate: isSslCert,
}, {
name: 'cert',
canBeFile: true,
envKey: keyByDataSource('CUBEJS_DB_SSL_CERT', dataSource),
validate: isSslCert,
}, {
name: 'key',
canBeFile: true,
envKey: keyByDataSource('CUBEJS_DB_SSL_KEY', dataSource),
validate: isSslKey,
}, {
name: 'ciphers',
envKey: keyByDataSource('CUBEJS_DB_SSL_CIPHERS', dataSource),
}, {
name: 'passphrase',
envKey: keyByDataSource('CUBEJS_DB_SSL_PASSPHRASE', dataSource),
}, {
name: 'servername',
envKey: keyByDataSource('CUBEJS_DB_SSL_SERVERNAME', dataSource),
}];

const ssl: TLSConnectionOptions = sslOptions.reduce(
(agg, { name, envKey, canBeFile, validate }) => {
const value = process.env[envKey];
if (value) {
Expand Down Expand Up @@ -227,9 +224,11 @@ export abstract class BaseDriver implements DriverInterface {
);

ssl.rejectUnauthorized = getEnv('dbSslRejectUnauthorized', { dataSource });

return ssl;
}

return ssl;
return undefined;
}

abstract testConnection(): Promise<void>;
Expand Down
2 changes: 1 addition & 1 deletion packages/cubejs-mongobi-driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@types/node": "^14",
"generic-pool": "^3.6.0",
"moment": "^2.29.1",
"mysql2": "^2.2.5"
"mysql2": "^2.3.3"
},
"license": "Apache-2.0",
"publishConfig": {
Expand Down
4 changes: 3 additions & 1 deletion packages/cubejs-mongobi-driver/src/MongoBIDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export class MongoBIDriver extends BaseDriver implements DriverInterface {
port: getEnv('dbPort', { dataSource }),
user: getEnv('dbUser', { dataSource }),
password: getEnv('dbPass', { dataSource }),
ssl: this.getSslOptions(dataSource),
// mysql2 uses own typings for ssl property, which is not correct
// Types of property 'pfx' are incompatible. Skipping validation with any cast
ssl: this.getSslOptions(dataSource) as any,
authPlugins: {
mysql_clear_password: () => async () => {
const password =
Expand Down
5 changes: 4 additions & 1 deletion packages/cubejs-prestodb-driver/src/PrestoDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import {
getEnv,
assertDataSource,
} from '@cubejs-backend/shared';

import { Transform, TransformCallback } from 'stream';
import type { ConnectionOptions as TLSConnectionOptions } from 'tls';

import {
map, zipObj, prop, concat
} from 'ramda';
Expand All @@ -32,7 +35,7 @@ export type PrestoDriverConfiguration = {
user?: string;
// eslint-disable-next-line camelcase
basic_auth?: { user: string, password: string };
ssl?: string;
ssl?: string | TLSConnectionOptions;
dataSource?: string;
};

Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -20143,7 +20143,7 @@ mute-stream@0.0.8, mute-stream@~0.0.4:
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d"
integrity sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==

mysql2@^2.2.5, mysql2@^2.3.3:
mysql2@^2.3.3:
version "2.3.3"
resolved "https://registry.yarnpkg.com/mysql2/-/mysql2-2.3.3.tgz#944f3deca4b16629052ff8614fbf89d5552545a0"
integrity sha512-wxJUev6LgMSgACDkb/InIFxDprRa6T95+VEoR+xPvtngtccNH2dGjEB/fVZ8yg1gWv1510c9CvXuJHi5zUm0ZA==
Expand Down