Skip to content

Commit 25f964f

Browse files
authored
Improve login wizard (#1045)
Ensure we can let users select host manually when they want to setup new auth for bundle init
1 parent 0f85446 commit 25f964f

File tree

5 files changed

+25
-24
lines changed

5 files changed

+25
-24
lines changed

packages/databricks-vscode/src/bundle/BundleInitWizard.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {Loggers} from "../logger";
1111
import {AuthProvider} from "../configuration/auth/AuthProvider";
1212
import {LoginWizard} from "../configuration/LoginWizard";
1313
import {CliWrapper} from "../cli/CliWrapper";
14-
import {ConfigModel} from "../configuration/models/ConfigModel";
1514
import {getSubProjects} from "./BundleFileSet";
1615
import {tmpdir} from "os";
1716

@@ -47,13 +46,10 @@ export class BundleInitWizard {
4746

4847
public async initNewProject(
4948
workspaceUri?: Uri,
50-
existingAuthProvider?: AuthProvider,
51-
configModel?: ConfigModel
49+
existingAuthProvider?: AuthProvider
5250
) {
53-
const authProvider = await this.configureAuthForBundleInit(
54-
existingAuthProvider,
55-
configModel
56-
);
51+
const authProvider =
52+
await this.configureAuthForBundleInit(existingAuthProvider);
5753
if (!authProvider) {
5854
this.logger.debug(
5955
"No valid auth providers, can't proceed with bundle init wizard"
@@ -91,8 +87,7 @@ export class BundleInitWizard {
9187
}
9288

9389
private async configureAuthForBundleInit(
94-
authProvider?: AuthProvider,
95-
configModel?: ConfigModel
90+
authProvider?: AuthProvider
9691
): Promise<AuthProvider | undefined> {
9792
if (authProvider) {
9893
const response = await this.promptToUseExistingAuth(authProvider);
@@ -103,7 +98,7 @@ export class BundleInitWizard {
10398
}
10499
}
105100
if (!authProvider) {
106-
authProvider = await LoginWizard.run(this.cli, configModel);
101+
authProvider = await LoginWizard.run(this.cli);
107102
}
108103
if (authProvider && (await authProvider.check())) {
109104
return authProvider;
@@ -147,6 +142,9 @@ export class BundleInitWizard {
147142
isTransient: true,
148143
location: TerminalLocation.Editor,
149144
env: this.cli.getBundleInitEnvVars(authProvider),
145+
// Without strict env we will inherit our environmentVariableCollection
146+
// which will override auth env vars we provide in this call.
147+
strictEnv: true,
150148
// Setting CWD avoids a possibility of the CLI picking up unrelated bundle configuration
151149
// in the current workspace root or while traversing up the folder structure.
152150
cwd: tmpdir(),

packages/databricks-vscode/src/bundle/BundleProjectManager.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ export class BundleProjectManager {
217217
},
218218
})
219219
public async startManualMigration() {
220-
const authProvider = await LoginWizard.run(this.cli, this.configModel);
220+
const authProvider = await LoginWizard.run(this.cli);
221221
if (
222222
authProvider instanceof ProfileAuthProvider &&
223223
(await authProvider.check())
@@ -275,8 +275,7 @@ export class BundleProjectManager {
275275
this.connectionManager.databricksWorkspace?.authProvider;
276276
const parentFolder = await bundleInitWizard.initNewProject(
277277
this.workspaceUri,
278-
authProvider,
279-
this.configModel
278+
authProvider
280279
);
281280
if (parentFolder) {
282281
await this.isBundleProjectCache.refresh();

packages/databricks-vscode/src/cli/CliWrapper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ export class CliWrapper {
303303
}
304304

305305
getBundleInitEnvVars(authProvider: AuthProvider) {
306-
return {
306+
return removeUndefinedKeys({
307307
...EnvVarGenerators.getEnvVarsForCli(
308308
workspaceConfigs.databrickscfgLocation
309309
),
@@ -312,7 +312,7 @@ export class CliWrapper {
312312
...authProvider.toEnv(),
313313
// eslint-disable-next-line @typescript-eslint/naming-convention
314314
DATABRICKS_OUTPUT_FORMAT: "text",
315-
};
315+
});
316316
}
317317

318318
async bundleInit(

packages/databricks-vscode/src/configuration/ConnectionManager.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,11 @@ export class ConnectionManager implements Disposable {
286286
popup: {prefix: "Can't configure workspace. "},
287287
})
288288
async configureLogin() {
289-
const authProvider = await LoginWizard.run(this.cli, this.configModel);
289+
const authProvider = await LoginWizard.run(
290+
this.cli,
291+
this.configModel.target,
292+
await this.configModel.get("host")
293+
);
290294
if (!authProvider) {
291295
return;
292296
}

packages/databricks-vscode/src/configuration/LoginWizard.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
loadConfigFile,
2727
AuthType as SdkAuthType,
2828
} from "@databricks/databricks-sdk";
29-
import {ConfigModel} from "./models/ConfigModel";
3029
import {randomUUID} from "crypto";
3130
import ini from "ini";
3231
import {copyFile, writeFile} from "fs/promises";
@@ -55,7 +54,7 @@ export class LoginWizard {
5554
}
5655
constructor(
5756
private readonly cliWrapper: CliWrapper,
58-
private readonly configModel?: ConfigModel
57+
private readonly target?: string
5958
) {}
6059

6160
private async inputHost(input: MultiStepInput) {
@@ -253,13 +252,13 @@ export class LoginWizard {
253252
input: MultiStepInput,
254253
pick: AuthTypeQuickPickItem
255254
) {
256-
let initialValue = this.configModel?.target ?? "";
255+
let initialValue = this.target ?? "";
257256

258257
// If the initialValue profile already exists, then create a unique name.
259258
const profiles = await this.getProfiles();
260259
if (profiles.find((profile) => profile.name === initialValue)) {
261260
const suffix = randomUUID().slice(0, 8);
262-
initialValue = `${this.configModel?.target ?? "dev"}-${suffix}`;
261+
initialValue = `${this.target ?? "dev"}-${suffix}`;
263262
}
264263

265264
const profileName = await input.showInputBox({
@@ -342,11 +341,12 @@ export class LoginWizard {
342341

343342
static async run(
344343
cliWrapper: CliWrapper,
345-
configModel?: ConfigModel
344+
target?: string,
345+
host?: URL
346346
): Promise<AuthProvider | undefined> {
347-
const wizard = new LoginWizard(cliWrapper, configModel);
348-
if (configModel) {
349-
wizard.state.host = await configModel.get("host");
347+
const wizard = new LoginWizard(cliWrapper, target);
348+
if (host) {
349+
wizard.state.host = host;
350350
}
351351
await MultiStepInput.run(wizard.inputHost.bind(wizard));
352352
if (!wizard.state.host || !wizard.state.authProvider) {

0 commit comments

Comments
 (0)