Skip to content

Commit 263f731

Browse files
Create profile wizard for Azure-Cli and OAuth (U2M) auth types (#990)
## Changes * Show a wizard to create a profile after user selects the auth type. * Select auth type * Enter profile name (default is target name + uuid (optional in case target name itself is not unique)) * Run through setup loop of the selected auth type. * If successful write a profile (and create a backup of the existing .databrickscfg). * If not successful prompt user to select another auth type. ## Tests * manual
1 parent 007c096 commit 263f731

File tree

7 files changed

+569
-384
lines changed

7 files changed

+569
-384
lines changed

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

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,6 @@ describe(__filename, () => {
9797
assert.equal([command, ...args].join(" "), syncCommand);
9898
});
9999

100-
it("should create an 'add profile' command", () => {
101-
const cli = createCliWrapper();
102-
103-
const {command, args} = cli.getAddProfileCommand(
104-
"DEFAULT",
105-
new URL("https://databricks.com")
106-
);
107-
108-
assert.equal(
109-
[command, ...args].join(" "),
110-
`${cliPath} configure --no-interactive --profile DEFAULT --host https://databricks.com/ --token`
111-
);
112-
});
113-
114100
it("should list profiles when no config file exists", async () => {
115101
const logFilePath = getTempLogFilePath();
116102
const cli = createCliWrapper(logFilePath);
@@ -171,29 +157,9 @@ host = https://cloud.databricks.com/
171157
[missing-host-token]
172158
nothing = true
173159
174-
[typo-host]
175-
host = example.com
176160
`
177161
);
178-
179-
const logs: {level: string; msg?: string; meta: any}[] = [];
180-
const profiles = await cli.listProfiles(
181-
path,
182-
new Context({
183-
logger: logging.NamedLogger.getOrCreate(
184-
"cli-profile-format-test",
185-
{
186-
factory: () => {
187-
return {
188-
log: (level, msg, meta) => {
189-
logs.push({level, msg, meta});
190-
},
191-
};
192-
},
193-
}
194-
),
195-
})
196-
);
162+
const profiles = await cli.listProfiles(path);
197163
assert.equal(profiles.length, 2);
198164

199165
assert.equal(profiles[0].name, "correct");
@@ -203,10 +169,6 @@ host = example.com
203169
assert.equal(profiles[1].name, "no-token");
204170
assert.equal(profiles[1].host, "https://cloud.databricks.com/");
205171
assert.equal(profiles[1].authType, "");
206-
207-
const typoLog = logs.find((log) => log.msg?.includes("typo-host"));
208-
assert.ok(typoLog !== undefined);
209-
assert.ok(typoLog.level === "error");
210172
});
211173
});
212174

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

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {execFile as execFileCb, spawn} from "child_process";
1+
import {execFile as execFileCb} from "child_process";
22
import {ExtensionContext, window, commands, Uri} from "vscode";
33
import {SyncDestinationMapper} from "../sync/SyncDestination";
44
import {workspaceConfigs} from "../vscode-objs/WorkspaceConfigs";
@@ -7,8 +7,8 @@ import {logging} from "@databricks/databricks-sdk";
77
import {Loggers} from "../logger";
88
import {Context, context} from "@databricks/databricks-sdk/dist/context";
99
import {Cloud} from "../utils/constants";
10+
import {EnvVarGenerators, UrlUtils} from "../utils";
1011
import {AuthProvider} from "../configuration/auth/AuthProvider";
11-
import {EnvVarGenerators} from "../utils";
1212

1313
const withLogContext = logging.withLogContext;
1414
const execFile = promisify(execFileCb);
@@ -29,13 +29,6 @@ export interface ConfigEntry {
2929

3030
export type SyncType = "full" | "incremental";
3131

32-
function getValidHost(host: string) {
33-
if (host.match(/^(?:(?:https?):\/\/)?(.(?!:\/\/))+$/) !== null) {
34-
return new URL(host);
35-
} else {
36-
throw new TypeError("Invalid type for host");
37-
}
38-
}
3932
/**
4033
* Entrypoint for all wrapped CLI commands
4134
*
@@ -137,7 +130,7 @@ export class CliWrapper {
137130
try {
138131
result.push({
139132
name: profile.name,
140-
host: getValidHost(profile.host),
133+
host: UrlUtils.normalizeHost(profile.host),
141134
accountId: profile.account_id,
142135
cloud: profile.cloud,
143136
authType: profile.auth_type,
@@ -176,40 +169,6 @@ export class CliWrapper {
176169
return stdout;
177170
}
178171

179-
getAddProfileCommand(profile: string, host: URL): Command {
180-
return {
181-
command: this.cliPath,
182-
args: [
183-
"configure",
184-
"--no-interactive",
185-
"--profile",
186-
profile,
187-
"--host",
188-
host.href,
189-
"--token",
190-
],
191-
};
192-
}
193-
194-
async addProfile(
195-
name: string,
196-
host: URL,
197-
token: string
198-
): Promise<{stdout: string; stderr: string}> {
199-
return new Promise((resolve, reject) => {
200-
const {command, args} = this.getAddProfileCommand(name, host);
201-
const child = spawn(command, args, {
202-
stdio: ["pipe", 0, 0],
203-
});
204-
205-
child.stdin!.write(`${token}\n`);
206-
child.stdin!.end();
207-
208-
child.on("error", reject);
209-
child.on("exit", resolve);
210-
});
211-
}
212-
213172
async bundleValidate(
214173
target: string,
215174
authProvider: AuthProvider,

0 commit comments

Comments
 (0)