Skip to content

Commit 89aadbe

Browse files
authored
Handle missing ~/.databrickscfg (#383)
1 parent 169dfbf commit 89aadbe

File tree

5 files changed

+22
-99
lines changed

5 files changed

+22
-99
lines changed

packages/databricks-vscode/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@
517517
"scripts": {
518518
"vscode:prepublish": "rm -rf out && yarn run package:compile && yarn run package:copy-webview-toolkit",
519519
"package": "vsce package",
520-
"package:cli:fetch": "BRICKS_VERSION=v0.0.15 && bash ./scripts/fetch-bricks-cli.sh ${BRICKS_VERSION} ${BRICKS_ARCH:-}",
520+
"package:cli:fetch": "BRICKS_VERSION=v0.0.17 && bash ./scripts/fetch-bricks-cli.sh ${BRICKS_VERSION} ${BRICKS_ARCH:-}",
521521
"package:cli:link": "rm -f ./bin/bricks && ln -s ../../../../bricks/bricks bin",
522522
"package:compile": "yarn run esbuild:base",
523523
"package:copy-webview-toolkit": "cp ./node_modules/@vscode/webview-ui-toolkit/dist/toolkit.js ./out/toolkit.js",
@@ -604,4 +604,4 @@
604604
],
605605
"report-dir": "coverage"
606606
}
607-
}
607+
}

packages/databricks-vscode/scripts/fetch-bricks-cli.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,5 @@ popd
1919
mkdir -p bin
2020
cd ./bin
2121
rm -rf bricks
22-
BRICKS_BINARY=$(cd $BRICKS_DIR && ls bricks*)
23-
# strip the version from the binary name but keep exe on Windows
24-
BRICKS_TARGET_NAME=$(echo $BRICKS_BINARY | sed -E 's/(.*)_v[0-9]+\.[0-9]+\.[0-9]+(\.exe)?/\1\2/g')
25-
mv $BRICKS_DIR/$BRICKS_BINARY $BRICKS_TARGET_NAME
22+
mv $BRICKS_DIR/bricks .
2623
rm -rf $BRICKS_DIR

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {Cluster, Repo} from "@databricks/databricks-sdk";
22
import {homedir} from "node:os";
33
import {
44
Disposable,
5+
FileSystemError,
56
QuickPickItem,
67
QuickPickItemKind,
78
ThemeIcon,
@@ -70,9 +71,19 @@ export class ConnectionCommands implements Disposable {
7071

7172
openDatabricksConfigFileCommand() {
7273
return async () => {
73-
const doc = await workspace.openTextDocument(
74-
Uri.joinPath(Uri.file(homedir()), ".databrickscfg")
75-
);
74+
const uri = Uri.joinPath(Uri.file(homedir()), ".databrickscfg");
75+
76+
try {
77+
await workspace.fs.stat(uri);
78+
} catch (e) {
79+
if (e instanceof FileSystemError && e.code === "FileNotFound") {
80+
await workspace.fs.writeFile(uri, Buffer.from(""));
81+
} else {
82+
throw e;
83+
}
84+
}
85+
86+
const doc = await workspace.openTextDocument(uri);
7687
await window.showTextDocument(doc);
7788
};
7889
}

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

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@ const extensionVersion = require("../../../package.json")
1212

1313
import {AzureCliCheck} from "../AzureCliCheck";
1414

15-
export type AuthType =
16-
| "azure-cli"
17-
| "google-id"
18-
| "oauth-u2m"
19-
| "profile"
20-
| "pat";
15+
export type AuthType = "azure-cli" | "google-id" | "oauth-u2m" | "profile";
2116

2217
export abstract class AuthProvider {
2318
constructor(
@@ -79,53 +74,12 @@ export abstract class AuthProvider {
7974
}
8075
return new ProfileAuthProvider(host, json.profile);
8176

82-
case "pat":
83-
if (!json.token) {
84-
throw new Error("Missing token");
85-
}
86-
return new TokenAuthProvider(host, json.token);
87-
8877
default:
8978
throw new Error(`Unknown auth type: ${json.authType}`);
9079
}
9180
}
9281
}
9382

94-
export class TokenAuthProvider extends AuthProvider {
95-
constructor(host: URL, private readonly token: string) {
96-
super(host, "pat");
97-
}
98-
99-
describe(): string {
100-
return "Personal Access Token";
101-
}
102-
103-
toJSON(): Record<string, unknown> {
104-
return {
105-
host: this.host.toString(),
106-
authType: this.authType,
107-
token: this.token,
108-
};
109-
}
110-
111-
getEnvVars(): Record<string, string | undefined> {
112-
return {
113-
DATABRICKS_HOST: this.host.toString(),
114-
DATABRICKS_AUTH_TYPE: this.authType,
115-
DATABRICKS_TOKEN: this.token,
116-
};
117-
}
118-
119-
getSdkConfig(): Config {
120-
return new Config({
121-
authType: "pat",
122-
token: this.token,
123-
host: this.host.toString(),
124-
env: {},
125-
});
126-
}
127-
}
128-
12983
export class ProfileAuthProvider extends AuthProvider {
13084
constructor(host: URL, private readonly profile: string) {
13185
super(host, "profile");

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

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,6 @@ export async function configureWorkspaceWizard(
7070
});
7171
break;
7272

73-
// Disabled PAT until we can figure out how we want to deal with the secret on disk
74-
// case "pat":
75-
// items.push({
76-
// label: "PAT",
77-
// kind: QuickPickItemKind.Separator,
78-
// authType: "none",
79-
// });
80-
81-
// items.push({
82-
// label: "Personal Access Token",
83-
// detail: "Authenticate using a personal access token",
84-
// authType: "pat",
85-
// });
86-
// break;
87-
8873
case "profile":
8974
items.push({
9075
label: "Databricks CLI Profiles",
@@ -154,10 +139,6 @@ export async function configureWorkspaceWizard(
154139
state.authType = pick.authType;
155140
break;
156141

157-
case "pat":
158-
state.authType = pick.authType;
159-
return (input: MultiStepInput) => inputToken(input, state);
160-
161142
case "profile":
162143
state.authType = pick.authType;
163144
state.profile = pick.profile;
@@ -170,26 +151,6 @@ export async function configureWorkspaceWizard(
170151
}
171152
}
172153

173-
async function inputToken(input: MultiStepInput, state: Partial<State>) {
174-
state.token = await input.showInputBox({
175-
title,
176-
step: 4,
177-
totalSteps: 4,
178-
value: typeof state.token === "string" ? state.token : "",
179-
prompt: "Databricks personal access token (PAT)",
180-
validate: async (s) => {
181-
if (!s.length) {
182-
return "Invalid access token";
183-
}
184-
},
185-
shouldResume: shouldResume,
186-
});
187-
}
188-
async function shouldResume(): Promise<boolean> {
189-
// Could show a notification with the option to resume.
190-
return true;
191-
}
192-
193154
const state = await collectInputs();
194155
if (!state.host || !state.authType) {
195156
return;
@@ -212,16 +173,16 @@ async function validateDatabricksHost(
212173

213174
function authMethodsForHostname(host: URL): Array<AuthType> {
214175
if (host.hostname.endsWith(".azuredatabricks.net")) {
215-
return ["azure-cli", "pat", "profile"];
176+
return ["azure-cli", "profile"];
216177
}
217178

218179
if (host.hostname.endsWith(".gcp.databricks.com")) {
219-
return ["google-id", "pat", "profile"];
180+
return ["google-id", "profile"];
220181
}
221182

222183
if (host.hostname.endsWith(".cloud.databricks.com")) {
223-
return ["oauth-u2m", "pat", "profile"];
184+
return ["oauth-u2m", "profile"];
224185
}
225186

226-
return ["pat", "profile"];
187+
return ["profile"];
227188
}

0 commit comments

Comments
 (0)