Skip to content

Commit

Permalink
Improve profiles loading
Browse files Browse the repository at this point in the history
Currently we show error notification during login process if cfg file doesn't exist.
  • Loading branch information
ilia-db committed Oct 21, 2024
1 parent c1c4a43 commit c0d4936
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions packages/databricks-vscode/src/configuration/LoginWizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ import {
ProfileAuthProvider,
} from "./auth/AuthProvider";
import {FileUtils, UrlUtils} from "../utils";
import {
loadConfigFile,
AuthType as SdkAuthType,
} from "@databricks/databricks-sdk";
import {AuthType as SdkAuthType} from "@databricks/databricks-sdk";
import {randomUUID} from "crypto";
import ini from "ini";
import {appendFile, copyFile} from "fs/promises";
import path from "path";
import os from "os";
import {createFile} from "fs-extra";
import {getDatabricksConfigFilePath} from "../utils/fileUtils";
import {stat} from "node:fs/promises";

interface AuthTypeQuickPickItem extends QuickPickItem {
authType?: SdkAuthType;
Expand Down Expand Up @@ -388,7 +386,7 @@ export async function saveNewProfile(
const configFilePath: string = getDatabricksConfigFilePath().fsPath;
let shouldBackup = true;
try {
await loadConfigFile(configFilePath);
await stat(configFilePath);
} catch (e) {
shouldBackup = false;
await createFile(configFilePath);
Expand Down Expand Up @@ -450,19 +448,21 @@ export async function listProfiles(cliWrapper: CliWrapper) {
title: "Loading Databricks profiles",
},
async () => {
const profiles = (
await cliWrapper.listProfiles(
FileUtils.getDatabricksConfigFilePath().fsPath
)
).filter((profile) => {
const cfgPath = FileUtils.getDatabricksConfigFilePath().fsPath;
try {
await stat(cfgPath);
} catch (e) {
return [];
}
const allProfiles = await cliWrapper.listProfiles(cfgPath);
const profiles = allProfiles.filter((profile) => {
try {
UrlUtils.normalizeHost(profile.host!.toString());
return true;
} catch (e) {
return false;
}
});

return profiles;
}
);
Expand Down

0 comments on commit c0d4936

Please sign in to comment.