Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"node-cmd": "^6.0.1"
},
"devDependencies": {
"@intersystems-community/intersystems-servermanager": "^3.14.1",
"@intersystems-community/intersystems-servermanager": "3.15.0-beta.1",
"@types/glob": "^7.1.1",
"@types/mocha": "^9.0.0",
"@types/node": "^20.14.0",
Expand Down
4 changes: 2 additions & 2 deletions src/api/addServer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IJSONServerSpec } from "@intersystems-community/intersystems-servermanager";
import * as vscode from "vscode";
import { promptOAuth2Authority, promptOAuth2ClientId } from "../oauth2Prompts";
import { IServerSetting } from "../serverSetting";
import { getServerNames } from "./getServerNames";

export async function addServer(
Expand Down Expand Up @@ -107,7 +107,7 @@ export async function addServer(
{ ignoreFocusOut: true, title: "Select the authentication method" },
))?.label;
if (authMethod === undefined) { return; }
let authDetails: Pick<IServerSetting, "username" | "oauth2">;
let authDetails: Pick<IJSONServerSpec, "username" | "oauth2">;
if (authMethod === "OAuth2") {
const authority = (await promptOAuth2Authority(name))?.trim();
if (!authority) { return; }
Expand Down
14 changes: 5 additions & 9 deletions src/api/getServerSpec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { IServerSpec, Authorization, VSCodeObjectScriptAPI } from "@intersystems-community/intersystems-servermanager";
import { IServerSpec, Authorization, VSCodeObjectScriptAPI, IJSONServerSpec } from "@intersystems-community/intersystems-servermanager";
import * as vscode from "vscode";
import { OAuth2Authorization, OBJECTSCRIPT_EXTENSIONID, BasicAuthorization } from "../commonActivate";
import { IServerSetting } from "../serverSetting";

/**
* Get a server specification.
Expand All @@ -15,7 +14,7 @@ export async function getServerSpec(
scope?: vscode.ConfigurationScope,
): Promise<IServerSpec & { auth: Authorization } | undefined> {
// To avoid breaking existing users, continue to return a default server definition even after we dropped that feature
const setting = vscode.workspace.getConfiguration("intersystems.servers", scope).get(name) as IServerSetting | undefined || legacyEmbeddedServer(name);
const setting = vscode.workspace.getConfiguration("intersystems.servers", scope).get(name) as IJSONServerSpec | undefined || legacyEmbeddedServer(name);
// Unknown server
if (!setting) {
const folder = vscode.workspace.workspaceFolders?.find((f) => f.name === name);
Expand Down Expand Up @@ -52,8 +51,8 @@ export async function getServerSpec(
};
} else {
// Found a setting
const { username, password, oauth2, ...spec } = setting;
spec.name = name;
const { username, password, oauth2, ...kept } = setting;
const spec = { ...kept, name };
spec.description = spec.description || "";
spec.webServer.scheme = spec.webServer.scheme || "http";
spec.webServer.port = spec.webServer.port || (spec.webServer.scheme === "https" ? 443 : 80);
Expand Down Expand Up @@ -81,10 +80,9 @@ export async function getServerSpec(
* @param name The name.
* @returns Server specification or undefined.
*/
export function legacyEmbeddedServer(name: string): IServerSetting | undefined {
export function legacyEmbeddedServer(name: string): IJSONServerSpec | undefined {
return {
"default~iris": {
name: "default~iris",
webServer: {
scheme: "http",
host: "127.0.0.1",
Expand All @@ -93,7 +91,6 @@ export function legacyEmbeddedServer(name: string): IServerSetting | undefined {
description: "Connection to local InterSystems IRIS™ installed with default settings.",
},
"default~cache": {
name: "default~cache",
webServer: {
scheme: "http",
host: "127.0.0.1",
Expand All @@ -102,7 +99,6 @@ export function legacyEmbeddedServer(name: string): IServerSetting | undefined {
description: "Connection to local InterSystems Caché installed with default settings.",
},
"default~ensemble": {
name: "default~ensemble",
webServer: {
scheme: "http",
host: "127.0.0.1",
Expand Down
7 changes: 3 additions & 4 deletions src/api/getServerSummary.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { IServerName } from "@intersystems-community/intersystems-servermanager";
import { IServerName, IJSONServerSpec } from "@intersystems-community/intersystems-servermanager";
import * as vscode from "vscode";
import { IServerSetting } from "../serverSetting";
import { legacyEmbeddedServer } from "./getServerSpec";

export function getServerSummary(name: string, scope?: vscode.ConfigurationScope): IServerName | undefined {
// To avoid breaking existing users, continue to return a default server definition even after we dropped that feature
const server = vscode.workspace.getConfiguration("intersystems.servers", scope).get(name) as IServerSetting | undefined || legacyEmbeddedServer(name);
const server = vscode.workspace.getConfiguration("intersystems.servers", scope).get<IJSONServerSpec>(name) || legacyEmbeddedServer(name);
if (!server) {
return undefined;
}
return { name, description: server.description || "", detail: serverDetail(server), scope };
}

export function serverDetail(connSpec: IServerSetting): string {
export function serverDetail(connSpec: IJSONServerSpec): string {
return `${connSpec.webServer.scheme || "http"}://${connSpec.webServer.host}:${connSpec.webServer.port}${connSpec.webServer.pathPrefix || ""}/`;
}
17 changes: 10 additions & 7 deletions src/commonActivate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Authorization, IServerName, IServerSpec, ResolvedAuthorization, ServerManagerAPI } from "@intersystems-community/intersystems-servermanager";
import { Authorization, IOAuth2Spec, IServerName, IServerSpec, ResolvedAuthorization, ServerManagerAPI } from "@intersystems-community/intersystems-servermanager";
import * as vscode from "vscode";
import { addServer } from "./api/addServer";
import { getPortalUri } from "./api/getPortalUri";
Expand All @@ -9,7 +9,6 @@ import { pickServer } from "./api/pickServer";
import { AUTHENTICATION_PROVIDER, ServerManagerAuthenticationProvider } from "./authenticationProvider";
import { initLogger } from "./logger";
import { logout, serverSessions } from "./makeRESTRequest";
import { OAuth2Config } from "./serverSetting";
import { NamespaceTreeItem, ProjectTreeItem, ServerManagerView, ServerTreeItem, SMTreeItem, WebAppTreeItem } from "./ui/serverManagerView";

export const extensionId = "intersystems-community.servermanager";
Expand Down Expand Up @@ -75,10 +74,14 @@ export class BasicAuthorization implements Authorization {
}
}

interface ResolvedOAuth2Authorization extends ResolvedAuthorization {
get httpAuthorizationHeader(): string;
}

export class OAuth2Authorization implements Authorization {
#username?: string;
#bearer?: string;
constructor(public readonly oauth2: OAuth2Config, bearer?: string) {
constructor(public readonly oauth2: IOAuth2Spec, bearer?: string) {
this.#bearer = bearer;
}

Expand All @@ -88,11 +91,11 @@ export class OAuth2Authorization implements Authorization {
}
}

public resolved(): this is ResolvedAuthorization {
public resolved(): this is ResolvedOAuth2Authorization {
return this.#bearer ? true : false;
}

public resolve({ accessToken, username }): this is ResolvedAuthorization {
public resolve({ accessToken, username }): this is ResolvedOAuth2Authorization {
// empty accessTokens are ignored.
if (accessToken) {
this.#bearer = accessToken;
Expand Down Expand Up @@ -151,8 +154,8 @@ export function commonActivate(context: vscode.ExtensionContext, view: ServerMan
if (pathParts && pathParts.length === 4) {
const serverName = pathParts[1];
const namespace = pathParts[3];
const serverSetting = await getServerSpec(serverName);
if (serverSetting) {
const server = await getServerSpec(serverName);
if (server) {
const isfsExtension = vscode.extensions.getExtension(OBJECTSCRIPT_EXTENSIONID);
if (isfsExtension) {
if (!isfsExtension.isActive) {
Expand Down
5 changes: 2 additions & 3 deletions src/oauth2Flow.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { IOAuth2Spec } from "@intersystems-community/intersystems-servermanager";
import axios from "axios";
import * as vscode from "vscode";
import { logger } from "./logger";

export interface IOAuth2Config {
authority: string;
clientId: string;
export interface IOAuth2Config extends IOAuth2Spec {
audience: string;
}

Expand Down
13 changes: 0 additions & 13 deletions src/serverSetting.ts

This file was deleted.

34 changes: 21 additions & 13 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,26 @@ export interface ISuperServerSpec {
port: number;
}

export interface IOAuth2Spec {
authority: string;
clientId: string;
}

/** One entry of the 'intersystems.servers' setting; the server name is the key. */
export interface IJSONServerSpec {
webServer: IWebServerSpec;
superServer?: ISuperServerSpec;
username?: string;
password?: string;
oauth2?: IOAuth2Spec;
description?: string;
}

/**
* Processed `IJSONServerSpec`: `name` added, `oauth2` folded into `auth`, and `username`/`password` deprecated in favour of `auth`.
*/
export interface IServerSpec extends Omit<IJSONServerSpec, "oauth2"> {
name: string;
/**
* @deprecated Use `auth.username` instead. Get credentials from the `auth` property.
*/
Expand All @@ -33,16 +50,7 @@ export interface IJSONServerSpec {
* @deprecated Use `auth.password` instead. Get credentials from the `auth` property.
*/
password?: string;
auth?: Authorization;
description?: string;
}

export interface IServerSpec extends IJSONServerSpec {
name: string;
}

/** IServerSpec with `auth` guaranteed to be present. */
export interface IServerSpecWithAuth extends IServerSpec {
/** Always present in current Server Manager versions; optional for compatibility with older ones. */
auth?: Authorization;
}

Expand All @@ -68,7 +76,7 @@ export interface ServerManagerAPI {
scope?: vscode.ConfigurationScope,
flushCredentialCache?: boolean,
options?: { hideFromRecents?: boolean, /* Obsolete */ noCredentials?: boolean },
): Promise<IServerSpecWithAuth | undefined>;
): Promise<IServerSpec | undefined>;

getAccount(
serverSpec: Pick<IServerSpec, "name" | "username">,
Expand Down Expand Up @@ -106,10 +114,10 @@ export interface Authorization {
get credentials(): undefined | { auth?: { username: string; password: string }; headers?: Record<string, string> };
}

/** Narrowed `Authorization` known to hold usable credentials, per `resolved()`. */
/** Narrowed `Authorization` known to hold usable credentials, per `resolved()`. `httpAuthorizationHeader` stays optional because UnknownUser has nothing to send. */
export interface ResolvedAuthorization extends Authorization {
/** Empty for UnknownUser, since unauthenticated access has no credential. */
get accessToken(): string;
get httpAuthorizationHeader(): string;
get credentials(): { auth?: { username: string; password: string }; headers?: Record<string, string> };
}

Expand Down
2 changes: 1 addition & 1 deletion types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@intersystems-community/intersystems-servermanager",
"version": "3.14.1",
"version": "3.15.0-beta.1",
"description": "InterSystems Server Manager VS Code extension API interfaces and constants",
"types": "index.d.ts",
"main": "index.js",
Expand Down
Loading