Skip to content

Commit

Permalink
Prevent overprompting for permission and account
Browse files Browse the repository at this point in the history
Requires Server Manager 3.8.0
  • Loading branch information
gjsjohnmurray committed Nov 12, 2024
1 parent 0623f96 commit b70c748
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const smExtensionId = "intersystems-community.servermanager";

import vscode = require("vscode");
import * as semver from "semver";
import * as serverManager from "@intersystems-community/intersystems-servermanager";

import { AtelierJob, Content, Response, ServerInfo } from "./api/atelier";
export const OBJECTSCRIPT_FILE_SCHEMA = "objectscript";
Expand Down Expand Up @@ -198,7 +199,7 @@ let reporter: TelemetryReporter = null;

export let checkingConnection = false;

let serverManagerApi: any;
let serverManagerApi: serverManager.ServerManagerAPI;

// Map of the intersystems.server connection specs we have resolved via the API to that extension
const resolvedConnSpecs = new Map<string, any>();
Expand All @@ -222,18 +223,26 @@ export async function resolveConnectionSpec(serverName: string): Promise<void> {

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export async function resolvePassword(serverSpec, ignoreUnauthenticated = false): Promise<void> {
const AUTHENTICATION_PROVIDER = "intersystems-server-credentials";
// This arises if setting says to use authentication provider
if (
// Connection isn't unauthenticated
(!isUnauthenticated(serverSpec.username) || ignoreUnauthenticated) &&
// A password is missing
typeof serverSpec.password == "undefined"
) {
const scopes = [serverSpec.name, serverSpec.username || ""];
let session = await vscode.authentication.getSession(AUTHENTICATION_PROVIDER, scopes, { silent: true });

// Handle Server Manager extension version < 3.8.0
const account = serverManagerApi.getAccount ? serverManagerApi.getAccount(serverSpec) : undefined;

let session = await vscode.authentication.getSession(serverManager.AUTHENTICATION_PROVIDER, scopes, {
silent: true,
account,
});
if (!session) {
session = await vscode.authentication.getSession(AUTHENTICATION_PROVIDER, scopes, { createIfNone: true });
session = await vscode.authentication.getSession(serverManager.AUTHENTICATION_PROVIDER, scopes, {
createIfNone: true,
account,
});
}
if (session) {
// If original spec lacked username use the one obtained by the authprovider
Expand Down

0 comments on commit b70c748

Please sign in to comment.