Skip to content

Reinstate password prompting, and leverage servermanager for password storage in keychain #211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 24, 2020
Merged
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
41 changes: 27 additions & 14 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as url from "url";
import * as vscode from "vscode";
import * as Cache from "vscode-cache";
import {
getResolvedConnectionSpec,
config,
extensionContext,
FILESYSTEM_SCHEMA,
Expand Down Expand Up @@ -39,6 +40,9 @@ export class AtelierAPI {
// when FileSystemProvider used
public externalServer = false;

// record of the constructor argument
public readonly wsOrFile?: string | vscode.Uri;

public get ns(): string {
return this.namespace || this._config.ns;
}
Expand Down Expand Up @@ -81,9 +85,12 @@ export class AtelierAPI {
return filename;
}

public constructor(wsOrFile?: string | vscode.Uri) {
public constructor(wsOrFile?: string | vscode.Uri, retryAfter401 = true) {
if (retryAfter401) {
this.wsOrFile = wsOrFile;
}
let workspaceFolderName = "";
let namespace;
let namespace = "";
if (wsOrFile) {
if (wsOrFile instanceof vscode.Uri) {
if (wsOrFile.scheme === FILESYSTEM_SCHEMA || wsOrFile.scheme === FILESYSTEM_READONLY_SCHEMA) {
Expand Down Expand Up @@ -147,24 +154,23 @@ export class AtelierAPI {
}

private setConnection(workspaceFolderName: string, namespace?: string): void {
let serverName;
this.configName = workspaceFolderName;
if (config("intersystems.servers").has(workspaceFolderName.toLowerCase())) {
this.externalServer = true;
serverName = workspaceFolderName.toLowerCase();
workspaceFolderName = currentWorkspaceFolder();
}
const conn = config("conn", workspaceFolderName);
if (!serverName && conn.server) {
let serverName = workspaceFolderName.toLowerCase();
if (config("intersystems.servers").has(serverName)) {
this.externalServer = true;
} else if (conn.server) {
serverName = conn.server;
} else {
serverName = "";
}

if (serverName && serverName.length) {
const {
webServer: { scheme, host, port, pathPrefix = "" },
username,
password,
} = config("intersystems.servers", workspaceFolderName).get(serverName);
} = getResolvedConnectionSpec(serverName, config("intersystems.servers", workspaceFolderName).get(serverName));
this._config = {
active: this.externalServer || conn.active,
apiVersion: 1,
Expand All @@ -176,6 +182,13 @@ export class AtelierAPI {
password,
pathPrefix,
};

// Report server as inactive when no namespace has been determined,
// otherwise output channel reports the issue.
// This arises when a server-only workspace is editing the user's settings.json, or the .code-workspace file.
if (this._config.ns === "" && this.externalServer) {
this._config.active = false;
}
} else {
this._config = conn;
}
Expand All @@ -201,10 +214,6 @@ export class AtelierAPI {
if (!active) {
return Promise.reject();
}
if (!username || !username.length || !password || !password.length) {
outputChannel.appendLine("username and password fields in settings are mandatory.");
return Promise.reject();
}
if (minVersion > apiVersion) {
return Promise.reject(`${path} not supported by API version ${apiVersion}`);
}
Expand Down Expand Up @@ -318,6 +327,10 @@ export class AtelierAPI {
workspaceState.update(this.configName + ":host", undefined);
workspaceState.update(this.configName + ":port", undefined);
setTimeout(checkConnection, 30000);
} else if (error.statusCode === 401 && this.wsOrFile) {
setTimeout(() => {
checkConnection(true, typeof this.wsOrFile === "object" ? this.wsOrFile : undefined);
}, 1000);
}
console.error(error);
throw error;
Expand Down
6 changes: 3 additions & 3 deletions src/commands/serverActions.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as vscode from "vscode";
import { config, workspaceState, checkConnection, FILESYSTEM_SCHEMA, FILESYSTEM_READONLY_SCHEMA } from "../extension";
import { currentWorkspaceFolder, terminalWithDocker, currentFile } from "../utils";
import { connectionTarget, terminalWithDocker, currentFile } from "../utils";
import { mainCommandMenu, mainSourceControlMenu } from "./studio";
import { AtelierAPI } from "../api";

export async function serverActions(): Promise<void> {
const workspaceFolder = currentWorkspaceFolder();
const api = new AtelierAPI(workspaceFolder);
const { apiTarget, configName: workspaceFolder } = connectionTarget();
const api = new AtelierAPI(apiTarget);
const { active, host = "", ns = "", https, port = 0, username, password } = api.config;
const { links } = config("conn");
const nsEncoded = encodeURIComponent(ns);
Expand Down
Loading