Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
gjsjohnmurray committed Apr 15, 2021
1 parent d2d06e6 commit 1c5b2e0
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 54 deletions.
16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,28 +226,29 @@
},
{
"command": "intersystems-community.servermanager.addToStarred",
"category": "InterSystems Server Manager",
"title": "Add to Starred",
"icon": "$(star-full)"
},
{
"command": "intersystems-community.servermanager.removeFromStarred",
"category": "InterSystems Server Manager",
"title": "Remove from Starred",
"icon": "$(star-empty)"
},
{
"command": "intersystems-community.servermanager.openPortalExternal",
"category": "InterSystems Server Manager",
"title": "Open Management Portal in External Browser",
"icon": "$(link-external)"
},
{
"command": "intersystems-community.servermanager.openPortalTab",
"category": "InterSystems Server Manager",
"title": "Open Management Portal in Tab",
"icon": "$(tools)"
},
{
"command": "intersystems-community.servermanager.retryServer",
"title": "Reconnect",
"icon": "$(refresh)"
},
{
"command": "intersystems-community.servermanager.editSettings",
"category": "InterSystems Server Manager",
Expand All @@ -268,7 +269,7 @@
{
"command": "intersystems-community.servermanager.importServers",
"category": "InterSystems Server Manager",
"title": "Import Servers from Registry"
"title": "Import Servers from Windows Registry"
},
{
"command": "intersystems-community.servermanager.setIconRed",
Expand Down Expand Up @@ -401,6 +402,11 @@
"when": "view == intersystems-community_servermanager && viewItem == starred.server.starred",
"group": "inline@10"
},
{
"command": "intersystems-community.servermanager.retryServer",
"when": "view == intersystems-community_servermanager && viewItem =~ /offline$/",
"group": "inline@10"
},
{
"command": "intersystems-community.servermanager.editNamespace",
"when": "view == intersystems-community_servermanager && viewItem =~ /namespace$/",
Expand Down
43 changes: 33 additions & 10 deletions src/api/getServerSpec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as vscode from 'vscode';
import { filePassword } from '../commands/managePasswords';
import { ServerSpec } from '../extension';
import { Keychain } from '../keychain';

Expand Down Expand Up @@ -82,16 +83,38 @@ export async function getServerSpec(name: string, scope?: vscode.ConfigurationSc

}
if (server.username && !server.password) {
await vscode.window
.showInputBox({
password: true,
placeHolder: `Password for user '${server.username}' on InterSystems server '${name}'`,
validateInput: (value => {
return value.length > 0 ? '' : 'Mandatory field';
}),
ignoreFocusOut: true,
})
.then((password) => {
const doInputBox = async (): Promise<string | undefined> => {
return await new Promise<string | undefined>((resolve, reject) => {
const inputBox = vscode.window.createInputBox();
inputBox.password = true,
inputBox.title = `Password for InterSystems server '${name}'`,
inputBox.placeholder = `Password for user '${server?.username}' on '${name}'`,
inputBox.prompt = 'To store your password securely, submit it using the $(key) button',
inputBox.ignoreFocusOut = true,
inputBox.buttons = [{ iconPath: new vscode.ThemeIcon('key'), tooltip: 'Store Password in Keychain' }]

async function done(store: boolean) {
// File the password and return it
if (store) {
await filePassword(name, inputBox.value)
}
// Resolve the promise and tidy up
resolve(inputBox.value);
inputBox.hide();
inputBox.dispose();
}

inputBox.onDidTriggerButton((button) => {
// We only added one button
done(true);
});
inputBox.onDidAccept(() => {
done(false);
});
inputBox.show();
})
};
await doInputBox().then((password) => {
if (password && server) {
server.password = password;
credentialCache[name] = {username: server.username, password: password};
Expand Down
8 changes: 6 additions & 2 deletions src/commands/managePasswords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ export async function storePassword(treeItem?: ServerTreeItem): Promise<string>
})
.then((password) => {
if (password) {
credentialCache[name] = undefined;
new Keychain(name).setPassword(password).then(() => {
filePassword(name, password).then(() => {
vscode.window.showInformationMessage(`Password for '${name}' stored in keychain.`);
});
reply = name;
Expand All @@ -35,6 +34,11 @@ export async function storePassword(treeItem?: ServerTreeItem): Promise<string>
return reply;
}

export async function filePassword(serverName: string, password: string): Promise<boolean> {
credentialCache[serverName] = undefined;
return new Keychain(serverName).setPassword(password).then(() => true, () => false);
}

export async function clearPassword(treeItem?: ServerTreeItem): Promise<string> {
if (treeItem && !getServerNames().some((value) => value.name === treeItem?.label)) {
treeItem = undefined;
Expand Down
6 changes: 6 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ export function activate(context: vscode.ExtensionContext) {
})
);

context.subscriptions.push(
vscode.commands.registerCommand(`${extensionId}.retryServer`, () => {
view.refreshTree();
})
);

const addWorkspaceFolderAsync = async (readonly: boolean, namespaceTreeItem?: ServerTreeItem) => {
if (namespaceTreeItem) {
const pathParts = namespaceTreeItem.id?.split(':');
Expand Down
Loading

0 comments on commit 1c5b2e0

Please sign in to comment.