Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create profile wizard for Azure-Cli and OAuth (U2M) auth types #990

Merged
merged 16 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 1 addition & 39 deletions packages/databricks-vscode/src/cli/CliWrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,6 @@ describe(__filename, () => {
assert.equal([command, ...args].join(" "), syncCommand);
});

it("should create an 'add profile' command", () => {
const cli = createCliWrapper();

const {command, args} = cli.getAddProfileCommand(
"DEFAULT",
new URL("https://databricks.com")
);

assert.equal(
[command, ...args].join(" "),
`${cliPath} configure --no-interactive --profile DEFAULT --host https://databricks.com/ --token`
);
});

it("should list profiles when no config file exists", async () => {
const logFilePath = getTempLogFilePath();
const cli = createCliWrapper(logFilePath);
Expand Down Expand Up @@ -171,29 +157,9 @@ host = https://cloud.databricks.com/
[missing-host-token]
nothing = true

[typo-host]
host = example.com
`
);

const logs: {level: string; msg?: string; meta: any}[] = [];
const profiles = await cli.listProfiles(
path,
new Context({
logger: logging.NamedLogger.getOrCreate(
"cli-profile-format-test",
{
factory: () => {
return {
log: (level, msg, meta) => {
logs.push({level, msg, meta});
},
};
},
}
),
})
);
const profiles = await cli.listProfiles(path);
assert.equal(profiles.length, 2);

assert.equal(profiles[0].name, "correct");
Expand All @@ -203,10 +169,6 @@ host = example.com
assert.equal(profiles[1].name, "no-token");
assert.equal(profiles[1].host, "https://cloud.databricks.com/");
assert.equal(profiles[1].authType, "");

const typoLog = logs.find((log) => log.msg?.includes("typo-host"));
assert.ok(typoLog !== undefined);
assert.ok(typoLog.level === "error");
});
});

Expand Down
47 changes: 3 additions & 44 deletions packages/databricks-vscode/src/cli/CliWrapper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {execFile as execFileCb, spawn} from "child_process";
import {execFile as execFileCb} from "child_process";
import {ExtensionContext, window, commands, Uri} from "vscode";
import {SyncDestinationMapper} from "../sync/SyncDestination";
import {workspaceConfigs} from "../vscode-objs/WorkspaceConfigs";
Expand All @@ -7,8 +7,8 @@ import {logging} from "@databricks/databricks-sdk";
import {Loggers} from "../logger";
import {Context, context} from "@databricks/databricks-sdk/dist/context";
import {Cloud} from "../utils/constants";
import {EnvVarGenerators, UrlUtils} from "../utils";
import {AuthProvider} from "../configuration/auth/AuthProvider";
import {EnvVarGenerators} from "../utils";

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

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

function getValidHost(host: string) {
if (host.match(/^(?:(?:https?):\/\/)?(.(?!:\/\/))+$/) !== null) {
return new URL(host);
} else {
throw new TypeError("Invalid type for host");
}
}
/**
* Entrypoint for all wrapped CLI commands
*
Expand Down Expand Up @@ -137,7 +130,7 @@ export class CliWrapper {
try {
result.push({
name: profile.name,
host: getValidHost(profile.host),
host: UrlUtils.normalizeHost(profile.host),
accountId: profile.account_id,
cloud: profile.cloud,
authType: profile.auth_type,
Expand Down Expand Up @@ -176,40 +169,6 @@ export class CliWrapper {
return stdout;
}

getAddProfileCommand(profile: string, host: URL): Command {
return {
command: this.cliPath,
args: [
"configure",
"--no-interactive",
"--profile",
profile,
"--host",
host.href,
"--token",
],
};
}

async addProfile(
name: string,
host: URL,
token: string
): Promise<{stdout: string; stderr: string}> {
return new Promise((resolve, reject) => {
const {command, args} = this.getAddProfileCommand(name, host);
const child = spawn(command, args, {
stdio: ["pipe", 0, 0],
});

child.stdin!.write(`${token}\n`);
child.stdin!.end();

child.on("error", reject);
child.on("exit", resolve);
});
}

async bundleValidate(
target: string,
authProvider: AuthProvider,
Expand Down
Loading
Loading