Skip to content

Commit 3f54441

Browse files
authored
fix: Preserve profile name in Databricks CLI auth provider (#1877)
## Changes When the databricks-cli auth type is used with a named profile (e.g. from ~/.databrickscfg), the profile name was not being threaded through to DatabricksCliAuthProvider. As a result `auth login` always used --host, causing issues with new databricks cli when same host exists under multiple profiles. Notes: The process.env["DATABRICKS_CONFIG_PROFILE"] mutation is a workaround and should be revisited once the upstream JS SDK exposes a proper API for this. ## Tests Manually
1 parent 98fabd6 commit 3f54441

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

packages/databricks-vscode/src/configuration/auth/AuthProvider.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ export abstract class AuthProvider {
7878
return true;
7979
}
8080

81+
// TODO: Temporary workaround until the JS SDK supports passing a profile
82+
// directly to auth types. Once supported, remove this env mutation.
83+
const profile = this.toJSON()["profile"];
84+
if (profile !== undefined) {
85+
process.env["DATABRICKS_CONFIG_PROFILE"] = profile;
86+
} else {
87+
delete process.env["DATABRICKS_CONFIG_PROFILE"];
88+
}
89+
8190
const checkFn = async (token?: CancellationToken) => {
8291
this.checked = await this._check(token);
8392
};
@@ -165,7 +174,8 @@ export abstract class AuthProvider {
165174
return new DatabricksCliAuthProvider(
166175
host,
167176
json.databricksPath ?? cli.cliPath,
168-
cli
177+
cli,
178+
json.profile
169179
);
170180

171181
case "profile":
@@ -198,7 +208,8 @@ export abstract class AuthProvider {
198208
return new DatabricksCliAuthProvider(
199209
host,
200210
config.databricksCliPath ?? cli.cliPath,
201-
cli
211+
cli,
212+
config.profile
202213
);
203214

204215
default:
@@ -308,7 +319,8 @@ export class DatabricksCliAuthProvider extends AuthProvider {
308319
constructor(
309320
host: URL,
310321
readonly cliPath: string,
311-
cli: CliWrapper
322+
cli: CliWrapper,
323+
readonly profile?: string
312324
) {
313325
super(host, "databricks-cli", cli);
314326
}
@@ -322,6 +334,7 @@ export class DatabricksCliAuthProvider extends AuthProvider {
322334
host: this.host.toString(),
323335
authType: this.authType,
324336
databricksPath: this.cliPath,
337+
...(this.profile ? {profile: this.profile} : {}),
325338
};
326339
}
327340

@@ -330,14 +343,19 @@ export class DatabricksCliAuthProvider extends AuthProvider {
330343
host: this.host.toString(),
331344
authType: "databricks-cli",
332345
databricksCliPath: this.cliPath,
346+
...(this.profile ? {profile: this.profile} : {}),
333347
});
334348
}
335349

336350
toEnv(): Record<string, string> {
337-
return {
351+
const env: Record<string, string> = {
338352
DATABRICKS_HOST: this.host.toString(),
339353
DATABRICKS_AUTH_TYPE: "databricks-cli",
340354
};
355+
if (this.profile) {
356+
env["DATABRICKS_CONFIG_PROFILE"] = this.profile;
357+
}
358+
return env;
341359
}
342360

343361
toIni() {

packages/databricks-vscode/src/configuration/auth/DatabricksCliCheck.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export class DatabricksCliCheck implements Disposable {
8484
host: this.authProvider.host.toString(),
8585
authType: "databricks-cli",
8686
databricksCliPath: this.authProvider.cliPath,
87+
profile: this.authProvider.profile,
8788
},
8889
{
8990
product: "databricks-vscode",
@@ -105,9 +106,16 @@ export class DatabricksCliCheck implements Disposable {
105106
private async login(cancellationToken?: CancellationToken): Promise<void> {
106107
try {
107108
const host = this.authProvider.host.toString().replace(/\/+$/, "");
109+
const profile = this.authProvider.profile;
110+
const args = ["auth", "login"];
111+
if (profile) {
112+
args.push("--profile", profile);
113+
} else {
114+
args.push("--host", host);
115+
}
108116
await execFile(
109117
this.authProvider.cliPath,
110-
["auth", "login", "--host", host],
118+
args,
111119
{},
112120
cancellationToken
113121
);

0 commit comments

Comments
 (0)