Skip to content

Commit 2625fd9

Browse files
committed
remove UID and PWD from URL
1 parent 5416d1f commit 2625fd9

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
export type DatabricksDriverConfiguration = JDBCDriverConfiguration &
2427
{
@@ -180,20 +183,20 @@ export class DatabricksDriver extends JDBCDriver {
180183
url = url.replace('jdbc:spark://', 'jdbc:databricks://');
181184
}
182185

186+
const [uid, pwd, cleanedUrl] = extractAndRemoveUidPwdFromJdbcUrl(url);
187+
183188
const config: DatabricksDriverConfiguration = {
184189
...conf,
185-
url,
190+
url: cleanedUrl,
186191
dbType: 'databricks',
187192
drivername: 'com.databricks.client.jdbc.Driver',
188193
customClassPath: undefined,
189194
properties: {
190-
UID: extractUidFromJdbcUrl(url),
191-
// PWD-parameter passed to the connection string has higher priority,
192-
// so we can set this one to an empty string to avoid a Java error.
195+
UID: uid,
193196
PWD:
194197
conf?.token ||
195198
getEnv('databrickToken', { dataSource }) ||
196-
'',
199+
pwd,
197200
UserAgentEntry: 'CubeDev_Cube',
198201
},
199202
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)