Skip to content

Commit ecebdc5

Browse files
committed
remove UID and PWD from URL
1 parent 014bf1d commit ecebdc5

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

packages/cubejs-databricks-jdbc-driver/src/DatabricksDriver.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ import {
1818
} from '@cubejs-backend/base-driver';
1919
import { JDBCDriver, JDBCDriverConfiguration, } from '@cubejs-backend/jdbc-driver';
2020
import { DatabricksQuery } from './DatabricksQuery';
21-
import { extractUidFromJdbcUrl, resolveJDBCDriver } from './helpers';
21+
import {
22+
extractAndRemoveUidPwdFromJdbcUrl,
23+
resolveJDBCDriver
24+
} from './helpers';
2225

2326
const SUPPORTED_BUCKET_TYPES = ['s3', 'gcs', 'azure'];
2427

@@ -187,20 +190,20 @@ export class DatabricksDriver extends JDBCDriver {
187190
url = url.replace('jdbc:spark://', 'jdbc:databricks://');
188191
}
189192

193+
const [uid, pwd, cleanedUrl] = extractAndRemoveUidPwdFromJdbcUrl(url);
194+
190195
const config: DatabricksDriverConfiguration = {
191196
...conf,
192-
url,
197+
url: cleanedUrl,
193198
dbType: 'databricks',
194199
drivername: 'com.databricks.client.jdbc.Driver',
195200
customClassPath: undefined,
196201
properties: {
197-
UID: extractUidFromJdbcUrl(url),
198-
// PWD-parameter passed to the connection string has higher priority,
199-
// so we can set this one to an empty string to avoid a Java error.
202+
UID: uid,
200203
PWD:
201204
conf?.token ||
202205
getEnv('databrickToken', { dataSource }) ||
203-
'',
206+
pwd,
204207
UserAgentEntry: 'CubeDev_Cube',
205208
},
206209
catalog:

packages/cubejs-databricks-jdbc-driver/src/helpers.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,20 @@ export async function resolveJDBCDriver(): Promise<string> {
3232
);
3333
}
3434

35-
export function extractUidFromJdbcUrl(jdbcUrl: string): string {
36-
const { pathname } = new URL(jdbcUrl);
37-
const [_, ...params] = pathname.split(';');
38-
const searchParams = new URLSearchParams(params.join('&'));
39-
return searchParams.get('UID') || 'token';
35+
/**
36+
* Extract if exist UID and PWD from URL and return UID, PWD and URL without these params
37+
* @param jdbcUrl
38+
*/
39+
export function extractAndRemoveUidPwdFromJdbcUrl(jdbcUrl: string): [string, string, string] {
40+
const uidMatch = jdbcUrl.match(/UID=([^;]*)/);
41+
const pwdMatch = jdbcUrl.match(/PWD=([^;]*)/);
42+
43+
const uid = uidMatch?.[1] || 'token';
44+
const pwd = pwdMatch?.[1] || '';
45+
46+
const cleanedUrl = jdbcUrl
47+
.replace(/;?UID=[^;]*/i, '')
48+
.replace(/;?PWD=[^;]*/i, '');
49+
50+
return [uid, pwd, cleanedUrl];
4051
}

0 commit comments

Comments
 (0)