Skip to content

Commit 3f812e2

Browse files
committed
draft (still buggy)
1 parent 8d61380 commit 3f812e2

9 files changed

Lines changed: 39 additions & 39 deletions

File tree

src/api/index.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export interface ConnectionSettings {
3838
superserverPort?: number;
3939
pathPrefix: string;
4040
ns: string;
41-
authorization: Authorization;
41+
auth: Authorization;
4242
docker: boolean;
4343
dockerService?: string;
4444
}
@@ -59,7 +59,7 @@ export class AtelierAPI {
5959
}
6060

6161
public get config(): ConnectionSettings {
62-
const { serverName, active = false, https = false, pathPrefix = "", authorization } = this._config;
62+
const { serverName, active = false, https = false, pathPrefix = "", auth: authorization } = this._config;
6363
const ns = this.namespace || this._config.ns;
6464
const wsKey = this.configName.toLowerCase();
6565
const host = this.externalServer ? this._config.host : workspaceState.get(wsKey + ":host", this._config.host);
@@ -86,7 +86,7 @@ export class AtelierAPI {
8686
superserverPort,
8787
pathPrefix,
8888
ns,
89-
authorization,
89+
auth: authorization,
9090
docker,
9191
dockerService,
9292
};
@@ -152,9 +152,9 @@ export class AtelierAPI {
152152
public setConnSpec(serverName: string, connSpec: IServerSpec): void {
153153
const {
154154
webServer: { scheme, host, port, pathPrefix = "" },
155-
authorization,
155+
auth,
156156
} = connSpec;
157-
this._config.authorization = authorization;
157+
this._config.auth = auth;
158158
this._config.https = scheme == "https";
159159
this._config.host = host;
160160
this._config.port = port;
@@ -209,7 +209,7 @@ export class AtelierAPI {
209209

210210
/** Return the key for getting values from connection-specific Maps for this connection */
211211
private mapKey(): string {
212-
const { host, port, authorization } = this.config;
212+
const { host, port, auth: authorization } = this.config;
213213
let pathPrefix = this._config.pathPrefix || "";
214214
if (pathPrefix.length && !pathPrefix.startsWith("/")) {
215215
pathPrefix = "/" + pathPrefix;
@@ -252,7 +252,7 @@ export class AtelierAPI {
252252
host,
253253
port,
254254
superserverPort: superServer?.port,
255-
authorization,
255+
auth: authorization,
256256
pathPrefix,
257257
docker: false,
258258
};
@@ -275,7 +275,7 @@ export class AtelierAPI {
275275
host,
276276
port,
277277
superserverPort: superServer?.port,
278-
authorization,
278+
auth: authorization,
279279
pathPrefix,
280280
docker: true,
281281
dockerService: conn["docker-compose"].service,
@@ -312,7 +312,7 @@ export class AtelierAPI {
312312
headers?: any,
313313
options?: any
314314
): Promise<any> {
315-
const { active, apiVersion, host, port, authorization, https } = this.config;
315+
const { active, apiVersion, host, port, auth: authorization, https } = this.config;
316316
if (!active || !port || !host) {
317317
return Promise.reject();
318318
}
@@ -366,9 +366,7 @@ export class AtelierAPI {
366366
let authRequest = authRequestMap.get(mapKey);
367367
if (cookies.length || (method === "HEAD" && !originalPath)) {
368368
auth = Promise.resolve(cookies);
369-
headers["Authorization"] = this.config.authorization.resolved()
370-
? this.config.authorization.httpAuthorizationHeader
371-
: "";
369+
headers["Authorization"] = this.config.auth.resolved() ? this.config.auth.httpAuthorizationHeader : "";
372370
} else if (!cookies.length) {
373371
if (!authRequest) {
374372
// Recursion point

src/commands/connectFolderToServerNamespace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export async function connectFolderToServerNamespace(): Promise<void> {
8080
.serverInfo(false)
8181
.then((data) => data.result.content.namespaces)
8282
.catch(async (error) => {
83-
if (error?.statusCode == 401 && !api.config.authorization.resolved()) {
83+
if (error?.statusCode == 401 && !api.config.auth.resolved()) {
8484
// Attempt to resolve username and password and try again
8585
const newSpec = await resolveUsernameAndPassword(api.config.serverName, connSpec);
8686
if (newSpec) {

src/commands/restDebugPanel.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,7 @@ export class RESTDebugPanel {
549549
}
550550
});
551551
headers["authorization"] =
552-
headers["authorization"] ??
553-
(api.config.authorization.resolved() ? api.config.authorization.httpAuthorizationHeader : "");
552+
headers["authorization"] ?? (api.config.auth.resolved() ? api.config.auth.httpAuthorizationHeader : "");
554553
const hasBody =
555554
typeof message.bodyContent == "string" && message.bodyContent != "" && message.bodyType != "No Body";
556555
if (hasBody) {

src/commands/serverActions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type ServerAction = { detail: string; id: string; label: string; rawLink?: strin
2525
export async function serverActions(): Promise<void> {
2626
const { apiTarget, configName: workspaceFolder } = connectionTarget();
2727
const api = new AtelierAPI(apiTarget);
28-
const { active, host = "", ns = "", https, port = 0, pathPrefix, authorization, docker } = api.config;
28+
const { active, host = "", ns = "", https, port = 0, pathPrefix, auth: authorization, docker } = api.config;
2929
const explorerCount = (await explorerProvider.getChildren()).length;
3030
if (!explorerCount && (!docker || host === "")) {
3131
await vscode.commands.executeCommand("ObjectScriptExplorer.focus");

src/commands/webSocketTerminal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class WebSocketTerminal implements vscode.Pseudoterminal {
225225
this._hideCursorWrite("\x1b]633;P;HasRichCommandDetection=True\x07");
226226
// Print the opening message
227227
this._hideCursorWrite(
228-
`\x1b[32mConnected to \x1b[0m\x1b[4m${api.config.host}:${api.config.port}${api.config.pathPrefix}\x1b[0m\x1b[32m as \x1b[0m\x1b[3m${api.config.authorization.username}\x1b[0m\r\n`
228+
`\x1b[32mConnected to \x1b[0m\x1b[4m${api.config.host}:${api.config.port}${api.config.pathPrefix}\x1b[0m\x1b[32m as \x1b[0m\x1b[3m${api.config.auth.username}\x1b[0m\r\n`
229229
);
230230
// Add event handlers to the socket
231231
this._socket

src/extension.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ export async function resolveConnectionSpec(
254254
superServer: {
255255
port: serverForUri.superserverPort,
256256
},
257-
authorization: serverForUri.authorization.clone(),
257+
auth: serverForUri.auth.clone(),
258258
description: `Server for workspace folder '${serverName}'`,
259259
};
260260
}
@@ -268,11 +268,11 @@ export async function resolveConnectionSpec(
268268
}
269269

270270
async function resolvePassword(
271-
serverSpec: Pick<serverManager.IServerSpec, "name" | "authorization">,
271+
serverSpec: Pick<serverManager.IServerSpec, "name" | "auth">,
272272
ignoreUnauthenticated = false
273273
): Promise<string | undefined> {
274-
if (!(serverSpec.authorization.resolved() || ignoreUnauthenticated)) {
275-
const scopes = [serverSpec.name, serverSpec.authorization.username || ""];
274+
if (!(serverSpec.auth.resolved() || ignoreUnauthenticated)) {
275+
const scopes = [serverSpec.name, serverSpec.auth.username || ""];
276276

277277
// Handle Server Manager extension version < 3.8.0
278278
const account = serverManagerApi.getAccount ? serverManagerApi.getAccount(serverSpec) : undefined;
@@ -289,7 +289,10 @@ async function resolvePassword(
289289
}
290290
if (session) {
291291
// If original spec lacked username use the one obtained from the user by the authprovider (exact case)
292-
serverSpec.authorization.resolve(session.accessToken, session.scopes[1]);
292+
serverSpec.auth.resolve({
293+
username: session.scopes[1],
294+
accessToken: session.accessToken,
295+
});
293296
return session.accessToken;
294297
}
295298
}
@@ -300,16 +303,16 @@ export async function resolveUsernameAndPassword(
300303
serverName: string,
301304
oldSpec: serverManager.IServerSpec
302305
): Promise<(serverManager.IServerSpec & { accessToken?: string }) | undefined> {
303-
const { authorization: _authorization, ...newSpec } = oldSpec;
306+
const { auth: _auth, ...newSpec } = oldSpec;
304307
newSpec.name = serverName;
305-
const authorization = _authorization.clone();
308+
const auth = _auth.clone();
306309

307-
const accessToken = await resolvePassword({ ...newSpec, authorization }, true);
308-
if (authorization.resolved()) {
310+
const accessToken = await resolvePassword({ ...newSpec, auth }, true);
311+
if (auth.resolved()) {
309312
// Update the connection spec
310313
resolvedConnSpecs.set(serverName, {
311314
...oldSpec,
312-
authorization,
315+
auth,
313316
accessToken,
314317
});
315318
return resolvedConnSpecs.get(serverName);
@@ -363,7 +366,7 @@ export async function checkConnection(
363366
_onDidChangeConnection.fire();
364367
}
365368
let api = new AtelierAPI(apiTarget, false);
366-
const { active, host = "", port = 0, superserverPort = 0, ns = "", authorization } = api.config;
369+
const { active, host = "", port = 0, superserverPort = 0, ns = "", auth: authorization } = api.config;
367370
vscode.commands.executeCommand("setContext", "vscode-objectscript.connectActive", active);
368371
if (!panel.text) {
369372
panel.text = `${PANEL_LABEL}`;
@@ -471,7 +474,7 @@ export async function checkConnection(
471474
let success = false;
472475
message = "Not Authorized.";
473476
errorMessage = `Authorization error: Check your credentials in Settings, and that you have sufficient privileges on the /api/atelier web application on ${connInfo}`;
474-
if (!api.config.authorization.resolved()) {
477+
if (!api.config.auth.resolved()) {
475478
vscode.window.showErrorMessage(
476479
`Unauthenticated access rejected by '${api.serverId}'.${
477480
!api.config.serverName ? " Connection has been disabled." : ""
@@ -515,7 +518,7 @@ export async function checkConnection(
515518
vscode.window
516519
.showInputBox({
517520
password: true,
518-
title: `Not Authorized. Enter password to connect as user '${api.config.authorization.username}' to ${connInfo}`,
521+
title: `Not Authorized. Enter password to connect as user '${api.config.auth.username}' to ${connInfo}`,
519522
prompt: !api.externalServer ? "If no password is entered the connection will be disabled." : "",
520523
ignoreFocusOut: true,
521524
})
@@ -1978,7 +1981,7 @@ function serverForUri(uri: vscode.Uri): ServerForUri {
19781981
port,
19791982
superserverPort,
19801983
pathPrefix,
1981-
authorization,
1984+
auth: authorization,
19821985
ns,
19831986
apiVersion,
19841987
serverVersion,
@@ -1997,7 +2000,7 @@ function serverForUri(uri: vscode.Uri): ServerForUri {
19972000
)
19982001
.get("password") as string | undefined;
19992002
if (password !== undefined) {
2000-
authorization.resolve(password);
2003+
authorization.resolve({ accessToken: password });
20012004
}
20022005
}
20032006
return {
@@ -2008,7 +2011,7 @@ function serverForUri(uri: vscode.Uri): ServerForUri {
20082011
port,
20092012
superserverPort,
20102013
pathPrefix,
2011-
authorization,
2014+
auth: authorization,
20122015
namespace: ns,
20132016
apiVersion: active ? apiVersion : undefined,
20142017
serverVersion: active ? serverVersion : undefined,

src/providers/FileSystemProvider/FileSystemProvider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,10 +476,10 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
476476
.catch((error) => {
477477
if (error) {
478478
if (error.errorText.includes(" #5540:")) {
479-
const message = `User '${api.config.authorization.username}' cannot list ${
479+
const message = `User '${api.config.auth.username}' cannot list ${
480480
csp ? `web application '${uri.path}'` : "namespace"
481481
} contents. If they do not have READ permission on the default code database of the ${api.config.ns.toUpperCase()} namespace then grant it and retry. If the problem remains then execute the following SQL in that namespace:\n\t GRANT EXECUTE ON %Library.RoutineMgr_StudioOpenDialog TO ${
482-
api.config.authorization.username
482+
api.config.auth.username
483483
}`;
484484
handleError(message);
485485
}
@@ -1006,7 +1006,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
10061006
private async _lookup(uri: vscode.Uri, fillInPath?: boolean): Promise<Entry> {
10071007
const api = new AtelierAPI(uri);
10081008
const config = api.config;
1009-
const rootName = `${config.authorization.username}@${config.host}:${config.port}${config.pathPrefix}/${config.ns.toUpperCase()}`;
1009+
const rootName = `${config.auth.username}@${config.host}:${config.port}${config.pathPrefix}/${config.ns.toUpperCase()}`;
10101010
let entry: Entry = this.superRoot.entries.get(rootName);
10111011
if (!entry) {
10121012
entry = new Directory(rootName, "");

src/providers/LowCodeEditorProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ export class LowCodeEditorProvider implements vscode.CustomTextEditorProvider {
212212
webviewPanel.webview.postMessage({
213213
direction: "editor",
214214
type: "auth",
215-
username: api.config.authorization.username,
216-
password: api.config.authorization.password,
215+
username: api.config.auth.username,
216+
password: api.config.auth.password,
217217
});
218218
}
219219
return;

src/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ export async function getWsServerConnection(minVersion?: string): Promise<vscode
923923
if (minVersion && lt(config.serverVersion, minVersion)) continue;
924924
const conn = {
925925
label: api.connInfo,
926-
description: !config.authorization.resolved() ? "Unauthenticated" : config.authorization.username,
926+
description: !config.auth.resolved() ? "Unauthenticated" : config.auth.username,
927927
detail: `http${config.https ? "s" : ""}://${config.host}:${config.port}${config.pathPrefix}`,
928928
uri: wsFolder.uri,
929929
ns: api.ns,

0 commit comments

Comments
 (0)