Skip to content

Commit

Permalink
Deeplink to the PAT creation page in PAT profile creation wizard (#1047)
Browse files Browse the repository at this point in the history
## 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? -->
  • Loading branch information
kartikgupta-db authored Feb 7, 2024
1 parent 25f964f commit fc9d3e7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
29 changes: 25 additions & 4 deletions packages/databricks-vscode/src/configuration/LoginWizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export class LoginWizard {

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

case "pat":
{
const token = await collectTokenForPatAuth(input, 4, 4);
const token = await collectTokenForPatAuth(
this.state.host!,
input,
4,
4
);
if (token === undefined) {
// Token can never be undefined unless the users cancels the whole process.
// Therefore, we can safely return here.
Expand Down Expand Up @@ -375,7 +380,7 @@ export async function saveNewProfile(
// Create a backup for .databrickscfg
const backup = path.join(
path.dirname(configFilePath),
".databrickscfg.bak"
`.databrickscfg.${new Date().toISOString()}.bak`
);
await copyFile(configFilePath, backup);
window.showInformationMessage(
Expand Down Expand Up @@ -472,11 +477,12 @@ function authMethodsForHostname(host: URL): Array<AuthType> {
}

async function collectTokenForPatAuth(
host: URL,
input: MultiStepInput,
step: number,
totalSteps: number
) {
const token = await input.showInputBox({
const token = await input.showQuickAutoComplete({
title: "Enter Personal Access Token",
step,
totalSteps,
Expand All @@ -490,11 +496,26 @@ async function collectTokenForPatAuth(
},
placeholder: "Enter Personal Access Token",
ignoreFocusOut: true,
shouldResume: async () => false,
items: [
{
label: "Create a new Personal Access Token",
detail: "Open the Databricks UI to create a new Personal Access Token",
alwaysShow: true,
},
],
});

if (token === undefined) {
return;
}

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

return token;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {ThemeColor, ThemeIcon} from "vscode";
import {DateUtils} from "../../../utils";

export type SimplifiedRunState =
| "Terminated"
Expand All @@ -16,7 +17,7 @@ export function humaniseDate(timestamp?: number) {
return undefined;
}
const date = new Date(timestamp);
return date.toLocaleString();
return DateUtils.toString(date);
}

export function humaniseDuration(ms?: number) {
Expand Down
15 changes: 15 additions & 0 deletions packages/databricks-vscode/src/utils/DateUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export function toString(date: Date): string {
return toDateString(date) + " " + toTimeString(date);
}

export function toDateString(date: Date): string {
const day = date.getDay();
const month = date.getMonth() + 1;
const year = date.getFullYear();

return `${day}-${month}-${year}`;
}

export function toTimeString(date: Date): string {
return date.toLocaleTimeString();
}
1 change: 1 addition & 0 deletions packages/databricks-vscode/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * as UrlUtils from "./urlUtils";
export * as UtilsCommands from "./UtilsCommands";
export * as PackageJsonUtils from "./packageJsonUtils";
export * as EnvVarGenerators from "./envVarGenerators";
export * as DateUtils from "./DateUtils";

0 comments on commit fc9d3e7

Please sign in to comment.