Skip to content

Commit 2d6e248

Browse files
committed
working?
1 parent 4677311 commit 2d6e248

3 files changed

Lines changed: 52 additions & 27 deletions

File tree

src/api/index.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import {
1212
schemas,
1313
checkingConnection,
1414
inactiveServerIds,
15+
serverManagerApi,
1516
} from "../extension";
1617
import { currentWorkspaceFolder, outputChannel, outputConsole } from "../utils";
1718

1819
const DEFAULT_API_VERSION = 1;
1920
const DEFAULT_SERVER_VERSION = "2016.2.0";
2021
import * as Atelier from "./atelier";
2122
import { isfsConfig } from "../utils/FileProviderUtil";
23+
import { IServerSpec } from "@intersystems-community/intersystems-servermanager";
2224

2325
// Map of the authRequest promises for each username@host:port/pathPrefix target to avoid concurrency issues
2426
const authRequestMap = new Map<string, Promise<any>>();
@@ -37,6 +39,7 @@ interface ConnectionSettings {
3739
superserverPort?: number;
3840
pathPrefix: string;
3941
ns: string;
42+
authMethod: "password" | "oauth2";
4043
username: string;
4144
password: string;
4245
docker: boolean;
@@ -59,7 +62,7 @@ export class AtelierAPI {
5962
}
6063

6164
public get config(): ConnectionSettings {
62-
const { serverName, active = false, https = false, pathPrefix = "", username } = this._config;
65+
const { serverName, active = false, https = false, pathPrefix = "", authMethod, username } = this._config;
6366
const ns = this.namespace || this._config.ns;
6467
const wsKey = this.configName.toLowerCase();
6568
const host = this.externalServer ? this._config.host : workspaceState.get(wsKey + ":host", this._config.host);
@@ -83,6 +86,7 @@ export class AtelierAPI {
8386
superserverPort,
8487
pathPrefix,
8588
ns,
89+
authMethod,
8690
username,
8791
password,
8892
docker,
@@ -147,12 +151,14 @@ export class AtelierAPI {
147151
* Manually set the connection spec for this object,
148152
* where `connSpec` is the return value of `getResolvedConnectionSpec()`.
149153
*/
150-
public setConnSpec(serverName: string, connSpec: any): void {
154+
public setConnSpec(serverName: string, connSpec: IServerSpec): void {
151155
const {
152156
webServer: { scheme, host, port, pathPrefix = "" },
157+
authMethod = "password",
153158
username,
154159
password,
155160
} = connSpec;
161+
this._config.authMethod = authMethod;
156162
this._config.username = username;
157163
this._config.password = password;
158164
this._config.https = scheme == "https";
@@ -239,6 +245,7 @@ export class AtelierAPI {
239245
if (serverName !== "") {
240246
const {
241247
webServer: { scheme, host, port, pathPrefix = "" },
248+
authMethod,
242249
username,
243250
password,
244251
superServer,
@@ -253,6 +260,7 @@ export class AtelierAPI {
253260
host,
254261
port,
255262
superserverPort: superServer?.port,
263+
authMethod,
256264
username,
257265
password,
258266
pathPrefix,
@@ -264,6 +272,7 @@ export class AtelierAPI {
264272
if (resolvedSpec) {
265273
const {
266274
webServer: { scheme, host, port, pathPrefix = "" },
275+
authMethod,
267276
username,
268277
password,
269278
superServer,
@@ -278,6 +287,7 @@ export class AtelierAPI {
278287
host,
279288
port,
280289
superserverPort: superServer?.port,
290+
authMethod,
281291
username,
282292
password,
283293
pathPrefix,
@@ -316,7 +326,7 @@ export class AtelierAPI {
316326
headers?: any,
317327
options?: any
318328
): Promise<any> {
319-
const { active, apiVersion, host, port, username, password, https } = this.config;
329+
const { active, apiVersion, host, port, password, https } = this.config;
320330
if (!active || !port || !host) {
321331
return Promise.reject();
322332
}
@@ -370,11 +380,7 @@ export class AtelierAPI {
370380
let authRequest = authRequestMap.get(mapKey);
371381
if (cookies.length || (method === "HEAD" && !originalPath)) {
372382
auth = Promise.resolve(cookies);
373-
374-
// Only send basic authorization if username and password specified (including blank, for unauthenticated access)
375-
if (typeof username === "string" && typeof password === "string") {
376-
headers["Authorization"] = `Basic ${Buffer.from(`${username}:${password}`).toString("base64")}`;
377-
}
383+
headers["Authorization"] = serverManagerApi.getAuthorization(this.config);
378384
} else if (!cookies.length) {
379385
if (!authRequest) {
380386
// Recursion point

src/commands/restDebugPanel.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as httpsModule from "https";
33
import * as vscode from "vscode";
44
import { AtelierAPI } from "../api";
55
import { handleError, webviewCSS } from "../utils";
6-
import { iscIcon } from "../extension";
6+
import { iscIcon, serverManagerApi } from "../extension";
77

88
interface WebviewMessage {
99
/** Whether this message was triggered by the user pressing the 'Start Debugging' button */
@@ -501,8 +501,8 @@ export class RESTDebugPanel {
501501
form.onchange = () => sendData(false);
502502
button.onclick = () => sendData(true);
503503
// Bubble change events up to the form
504-
bodyContent.onchange = headersText.onchange =
505-
paramsText.onchange = path.onchange =
504+
bodyContent.onchange = headersText.onchange =
505+
paramsText.onchange = path.onchange =
506506
() => form.dispatchEvent(new Event("change"));
507507
</script>
508508
</body>
@@ -548,16 +548,7 @@ export class RESTDebugPanel {
548548
.trim();
549549
}
550550
});
551-
if (
552-
headers["authorization"] == undefined &&
553-
typeof api.config.username === "string" &&
554-
typeof api.config.password === "string"
555-
) {
556-
// Use the server connection's auth if the user didn't specify any
557-
headers["authorization"] = `Basic ${Buffer.from(`${api.config.username}:${api.config.password}`).toString(
558-
"base64"
559-
)}`;
560-
}
551+
headers["authorization"] = headers["authorization"] ?? serverManagerApi.getAuthorization(api.config);
561552
const hasBody =
562553
typeof message.bodyContent == "string" && message.bodyContent != "" && message.bodyType != "No Body";
563554
if (hasBody) {

src/extension.ts

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export let checkingConnection = false;
209209
export let serverManagerApi: serverManager.ServerManagerAPI;
210210

211211
/** Map of the intersystems.server connection specs we have resolved via the API to that extension */
212-
const resolvedConnSpecs = new Map<string, any>();
212+
const resolvedConnSpecs = new Map<string, serverManager.IServerSpec>();
213213

214214
/**
215215
* If servermanager extension is available, fetch the connection spec unless already cached.
@@ -364,7 +364,7 @@ export async function checkConnection(
364364
_onDidChangeConnection.fire();
365365
}
366366
let api = new AtelierAPI(apiTarget, false);
367-
const { active, host = "", port = 0, superserverPort = 0, username, ns = "" } = api.config;
367+
const { active, host = "", port = 0, superserverPort = 0, ns = "", username } = api.config;
368368
vscode.commands.executeCommand("setContext", "vscode-objectscript.connectActive", active);
369369
if (!panel.text) {
370370
panel.text = `${PANEL_LABEL}`;
@@ -1945,9 +1945,35 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
19451945
return extensionApi;
19461946
}
19471947

1948+
type HttpsAndScheme =
1949+
| {
1950+
scheme: "https";
1951+
https: true;
1952+
}
1953+
| {
1954+
scheme: "http";
1955+
https?: false;
1956+
};
1957+
1958+
export interface GeneralServerForUri {
1959+
serverName: string;
1960+
active: boolean;
1961+
host: string;
1962+
port: number;
1963+
superserverPort: number;
1964+
pathPrefix: string;
1965+
namespace: string;
1966+
apiVersion: number;
1967+
serverVersion: string;
1968+
}
1969+
1970+
export type ServerForUri = GeneralServerForUri &
1971+
HttpsAndScheme &
1972+
Required<Pick<serverManager.Authorization, "authMethod" | "username" | "password">>;
1973+
19481974
// This function is exported as one of our API functions but is also used internally
19491975
// for example to implement the async variant capable of resolving docker port number.
1950-
function serverForUri(uri: vscode.Uri): any {
1976+
function serverForUri(uri: vscode.Uri): ServerForUri {
19511977
const { apiTarget, configName } = connectionTarget(uri);
19521978
const configNameLower = configName.toLowerCase();
19531979
const api = new AtelierAPI(apiTarget);
@@ -1958,25 +1984,27 @@ function serverForUri(uri: vscode.Uri): any {
19581984
const {
19591985
serverName,
19601986
active,
1961-
host = "",
1987+
host,
19621988
https,
19631989
port,
19641990
superserverPort,
19651991
pathPrefix,
1992+
authMethod,
19661993
username,
19671994
password,
1968-
ns = "",
1995+
ns,
19691996
apiVersion,
19701997
serverVersion,
19711998
} = api.config;
19721999
return {
19732000
serverName,
19742001
active,
1975-
scheme: https ? "https" : "http",
2002+
...(https ? ({ https: true, scheme: "https" } as const) : ({ scheme: "http" } as const)),
19762003
host,
19772004
port,
19782005
superserverPort,
19792006
pathPrefix,
2007+
authMethod,
19802008
username,
19812009
password:
19822010
serverName === ""

0 commit comments

Comments
 (0)