Skip to content

Commit fc9d3e7

Browse files
Deeplink to the PAT creation page in PAT profile creation wizard (#1047)
## Changes * Also prevent overwritting old .databrickscfg.bak by adding timestamp to the name. * Standardise date format in bundle resource explorer. ## Tests <!-- How is this tested? -->
1 parent 25f964f commit fc9d3e7

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export class LoginWizard {
175175

176176
items.push({
177177
label: "Personal Access Token",
178-
detail: "Create a new profile and authenticate using the 'databricks' command line tool",
178+
detail: "Create a profile and authenticate using a Personal Access Token",
179179
authType: "pat",
180180
});
181181
if (profiles.length !== 0) {
@@ -306,7 +306,12 @@ export class LoginWizard {
306306

307307
case "pat":
308308
{
309-
const token = await collectTokenForPatAuth(input, 4, 4);
309+
const token = await collectTokenForPatAuth(
310+
this.state.host!,
311+
input,
312+
4,
313+
4
314+
);
310315
if (token === undefined) {
311316
// Token can never be undefined unless the users cancels the whole process.
312317
// Therefore, we can safely return here.
@@ -375,7 +380,7 @@ export async function saveNewProfile(
375380
// Create a backup for .databrickscfg
376381
const backup = path.join(
377382
path.dirname(configFilePath),
378-
".databrickscfg.bak"
383+
`.databrickscfg.${new Date().toISOString()}.bak`
379384
);
380385
await copyFile(configFilePath, backup);
381386
window.showInformationMessage(
@@ -472,11 +477,12 @@ function authMethodsForHostname(host: URL): Array<AuthType> {
472477
}
473478

474479
async function collectTokenForPatAuth(
480+
host: URL,
475481
input: MultiStepInput,
476482
step: number,
477483
totalSteps: number
478484
) {
479-
const token = await input.showInputBox({
485+
const token = await input.showQuickAutoComplete({
480486
title: "Enter Personal Access Token",
481487
step,
482488
totalSteps,
@@ -490,11 +496,26 @@ async function collectTokenForPatAuth(
490496
},
491497
placeholder: "Enter Personal Access Token",
492498
ignoreFocusOut: true,
499+
shouldResume: async () => false,
500+
items: [
501+
{
502+
label: "Create a new Personal Access Token",
503+
detail: "Open the Databricks UI to create a new Personal Access Token",
504+
alwaysShow: true,
505+
},
506+
],
493507
});
494508

495509
if (token === undefined) {
496510
return;
497511
}
498512

513+
if (token === "Create a new Personal Access Token") {
514+
commands.executeCommand("databricks.utils.openExternal", {
515+
url: `${host.toString()}settings/user/developer/access-tokens`,
516+
});
517+
return collectTokenForPatAuth(host, input, step, totalSteps);
518+
}
519+
499520
return token;
500521
}

packages/databricks-vscode/src/ui/bundle-resource-explorer/utils/RunStateUtils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {ThemeColor, ThemeIcon} from "vscode";
2+
import {DateUtils} from "../../../utils";
23

34
export type SimplifiedRunState =
45
| "Terminated"
@@ -16,7 +17,7 @@ export function humaniseDate(timestamp?: number) {
1617
return undefined;
1718
}
1819
const date = new Date(timestamp);
19-
return date.toLocaleString();
20+
return DateUtils.toString(date);
2021
}
2122

2223
export function humaniseDuration(ms?: number) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export function toString(date: Date): string {
2+
return toDateString(date) + " " + toTimeString(date);
3+
}
4+
5+
export function toDateString(date: Date): string {
6+
const day = date.getDay();
7+
const month = date.getMonth() + 1;
8+
const year = date.getFullYear();
9+
10+
return `${day}-${month}-${year}`;
11+
}
12+
13+
export function toTimeString(date: Date): string {
14+
return date.toLocaleTimeString();
15+
}

packages/databricks-vscode/src/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * as UrlUtils from "./urlUtils";
33
export * as UtilsCommands from "./UtilsCommands";
44
export * as PackageJsonUtils from "./packageJsonUtils";
55
export * as EnvVarGenerators from "./envVarGenerators";
6+
export * as DateUtils from "./DateUtils";

0 commit comments

Comments
 (0)