Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
gjsjohnmurray committed Apr 12, 2021
1 parent 7c4b697 commit 9d121fa
Show file tree
Hide file tree
Showing 9 changed files with 4,952 additions and 2,194 deletions.
6,870 changes: 4,733 additions & 2,137 deletions package-lock.json

Large diffs are not rendered by default.

75 changes: 58 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "servermanager",
"displayName": "InterSystems Server Manager",
"version": "1.0.6-SNAPSHOT",
"version": "2.0.0-SNAPSHOT",
"publisher": "intersystems-community",
"description": "Helper extension for defining connections to InterSystems servers.",
"repository": {
Expand Down Expand Up @@ -40,7 +40,7 @@
"lint-fix": "tslint --project tsconfig.json -t verbose --fix"
},
"dependencies": {
"@types/vscode": "^1.43.0",
"@types/vscode": "^1.55.0",
"node-cmd": "^4.0.0"
},
"devDependencies": {
Expand All @@ -49,7 +49,7 @@
"@types/mocha": "^8.0.4",
"@types/node": "^8.10.60",
"glob": "^7.1.6",
"mocha": "^8.2.1",
"mocha": "^8.3.2",
"ovsx": "latest",
"ts-loader": "^6.2.2",
"tslint": "^5.20.1",
Expand All @@ -66,15 +66,15 @@
"onCommand:intersystems-community.servermanager.importServers"
],
"contributes": {
"viewsContainers": {
"activitybar": [
{
"id": "intersystems-community_servermanager",
"title": "InterSystems Tools",
"icon": "images/toolsContainer.svg"
}
]
},
"viewsContainers": {
"activitybar": [
{
"id": "intersystems-community_servermanager",
"title": "InterSystems Tools",
"icon": "images/toolsContainer.svg"
}
]
},
"views": {
"intersystems-community_servermanager": [
{
Expand Down Expand Up @@ -208,12 +208,30 @@
}
},
"commands": [
{
"command": "intersystems-community.servermanager.refreshTree",
"category": "InterSystems Server Manager",
"title": "Refresh",
"icon": "$(refresh)"
},
{
"command": "intersystems-community.servermanager.addServer",
"category": "InterSystems Server Manager",
"title": "Add Server",
"icon": "$(add)"
},
{
"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.openManagementPortalExternal",
"category": "InterSystems Server Manager",
Expand Down Expand Up @@ -248,6 +266,14 @@
"command": "intersystems-community.servermanager.importServers",
"when": "isWindows"
},
{
"command": "intersystems-community.servermanager.addToStarred",
"when": "false"
},
{
"command": "intersystems-community.servermanager.removeFromStarred",
"when": "false"
},
{
"command": "intersystems-community.servermanager.openManagementPortalExternal",
"when": "false"
Expand All @@ -258,30 +284,45 @@
}
],
"view/title": [
{
"command": "intersystems-community.servermanager.refreshTree",
"when": "view == intersystems-community_servermanager",
"group": "navigation@10"
},
{
"command": "intersystems-community.servermanager.addServer",
"when": "view == intersystems-community_servermanager",
"group": "navigation"
"group": "navigation@20"
},
{
"command": "intersystems-community.servermanager.importServers",
"when": "view == intersystems-community_servermanager && isWindows"
}
],
"view/item/context": [
{
"command": "intersystems-community.servermanager.addToStarred",
"when": "view == intersystems-community_servermanager && viewItem =~ /\\.server\\.$/",
"group": "inline@10"
},
{
"command": "intersystems-community.servermanager.removeFromStarred",
"when": "view == intersystems-community_servermanager && viewItem == starred.server.starred",
"group": "inline@10"
},
{
"command": "intersystems-community.servermanager.openManagementPortalExternal",
"when": "view == intersystems-community_servermanager && viewItem == server",
"group": "inline"
"when": "view == intersystems-community_servermanager && viewItem =~ /\\.server\\./",
"group": "inline@90"
},
{
"command": "intersystems-community.servermanager.storePassword",
"when": "view == intersystems-community_servermanager && viewItem == server",
"when": "view == intersystems-community_servermanager && viewItem =~ /\\.server\\./",
"group": "password@10"
},
{
"command": "intersystems-community.servermanager.clearPassword",
"when": "view == intersystems-community_servermanager && viewItem == server",
"when": "view == intersystems-community_servermanager && viewItem =~ /\\.server\\./",
"group": "password@20"
}
]
Expand Down
4 changes: 2 additions & 2 deletions src/api/getPortalUriWithCredentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export async function getPortalUriWithCredentials(name: string, scope?: vscode.C
queryString += `&CacheUsername=${usernameEncoded}&IRISUsername=${usernameEncoded}`;
}

// Push the credentials offscreen
queryString = '_=' + ' '.padStart(500,' ') + queryString;
// Add a dummy cache-buster and push the actual credentials offscreen
queryString = '_=' + new Date().getTime().toString().padEnd(480,' ') + queryString;

return vscode.Uri.parse(`${webServer.scheme}://${webServer.host}:${webServer.port}${webServer.pathPrefix}/csp/sys/UtilHome.csp?${queryString}`, true);
}
Expand Down
9 changes: 3 additions & 6 deletions src/api/getServerNames.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as vscode from 'vscode';
import { ServerName, ServerSpec } from '../extension';
import { ServerName } from '../extension';
import { serverDetail } from './getServerSummary';

export function getServerNames(scope?: vscode.ConfigurationScope): ServerName[] {
let names: ServerName[] = [];
Expand All @@ -19,7 +20,7 @@ export function getServerNames(scope?: vscode.ConfigurationScope): ServerName[]
if (myDefault.length > 0 && servers[myDefault]) {
names.push({
name: myDefault,
description: `${servers[myDefault].description || ''} (default)`,
description: `${servers[myDefault].description || ''} (default)`.trim(),
detail: serverDetail(servers[myDefault])
});
}
Expand Down Expand Up @@ -53,7 +54,3 @@ export function getServerNames(scope?: vscode.ConfigurationScope): ServerName[]
}
return names;
}

function serverDetail(connSpec: ServerSpec): string {
return `${connSpec.webServer.scheme || 'http'}://${connSpec.webServer.host}:${connSpec.webServer.port}/${connSpec.webServer.pathPrefix || ''}`;
}
14 changes: 14 additions & 0 deletions src/api/getServerSummary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as vscode from 'vscode';
import { ServerName, ServerSpec } from '../extension';

export function getServerSummary(name: string, scope?: vscode.ConfigurationScope): ServerName | undefined {
const server: ServerSpec | undefined = vscode.workspace.getConfiguration('intersystems.servers', scope).get(name);
if (!server) {
return undefined
}
return {name, description: server.description || '', detail: serverDetail(server)};
}

export function serverDetail(connSpec: ServerSpec): string {
return `${connSpec.webServer.scheme || 'http'}://${connSpec.webServer.host}:${connSpec.webServer.port}/${connSpec.webServer.pathPrefix || ''}`;
}
18 changes: 16 additions & 2 deletions src/commands/importFromRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export async function importFromRegistry(scope?: vscode.ConfigurationScope) {
const newServerNames = new Array<string>();
const serversMissingUsernames = new Array<string>();

let overwriteCount: number;

regQueryCache.clear();

return vscode.window.withProgress({
Expand All @@ -25,7 +27,7 @@ export async function importFromRegistry(scope?: vscode.ConfigurationScope) {
// This forces the progress bar to actually show before the possibly long-running load of registry data
await new Promise(resolve => setTimeout(resolve,0));

await loadRegistryData(config, serverDefinitions, serversMissingUsernames, newServerNames);
overwriteCount = await loadRegistryData(config, serverDefinitions, serversMissingUsernames, newServerNames);

if (cancellationToken.isCancellationRequested) {
return false;
Expand All @@ -35,6 +37,13 @@ export async function importFromRegistry(scope?: vscode.ConfigurationScope) {
if (!keepGoing) {
return;
}

if (overwriteCount > 0) {
if (await vscode.window.showWarningMessage(`${overwriteCount} existing definition${overwriteCount > 1 ? "s" : ""} will be overwritten. Continue?`, { modal: true }, "Yes") !=="Yes") {
vscode.window.showInformationMessage("Cancelled server import.");
return;
}
}
if (!await promptForUsernames(serverDefinitions, serversMissingUsernames)) {
vscode.window.showInformationMessage("Cancelled server import.");
return;
Expand All @@ -53,10 +62,11 @@ export async function importFromRegistry(scope?: vscode.ConfigurationScope) {
});
}

async function loadRegistryData(config, serverDefinitions, serversMissingUsernames, newServerNames): Promise<void> {
async function loadRegistryData(config, serverDefinitions, serversMissingUsernames, newServerNames): Promise<number> {
const cmd = require("node-cmd");
const hkeyLocalMachine = "HKEY_LOCAL_MACHINE";
preloadRegistryCache(cmd, "HKEY_CURRENT_USER\\Software\\InterSystems\\Cache\\Servers");
let overwriteCount = 0;
for (const folder of ['','\\WOW6432Node']) {
const subFolder = "\\Intersystems\\Cache\\Servers";
const path = hkeyLocalMachine + "\\SOFTWARE" + folder + subFolder;
Expand Down Expand Up @@ -113,8 +123,12 @@ async function loadRegistryData(config, serverDefinitions, serversMissingUsernam
},
}
}
else if (!name.startsWith("/")) {
overwriteCount++;
}
});
}
return overwriteCount;
}

async function promptForUsernames(serverDefinitions: any, serversMissingUsernames: string[]): Promise<boolean> {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/managePasswords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export async function storePassword(treeItem?: ServerTreeItem): Promise<string>
if (treeItem && !getServerNames().some((value) => value.name === treeItem?.label)) {
treeItem = undefined;
}
const name = treeItem?.label || await commonPickServer({matchOnDetail: true});
const name = treeItem?.name || await commonPickServer({matchOnDetail: true});
let reply = '';
if (name) {
await vscode.window
Expand Down Expand Up @@ -40,7 +40,7 @@ export async function clearPassword(treeItem?: ServerTreeItem): Promise<string>
treeItem = undefined;
}
let reply = '';
const name = treeItem?.label || await commonPickServer({matchOnDetail: true});
const name = treeItem?.name || await commonPickServer({matchOnDetail: true});
if (name) {
credentialCache[name] = undefined;
const keychain = new Keychain(name);
Expand Down
50 changes: 39 additions & 11 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { importFromRegistry } from './commands/importFromRegistry';
import { ServerManagerView, ServerTreeItem } from './ui/serverManagerView';
import { addServer } from './api/addServer';
import { getPortalUriWithCredentials } from './api/getPortalUriWithCredentials';
import { getServerSummary } from './api/getServerSummary';

export interface ServerName {
name: string,
Expand Down Expand Up @@ -43,16 +44,41 @@ export function activate(context: vscode.ExtensionContext) {

const _onDidChangePassword = new vscode.EventEmitter<string>();

// Server Manager View
const view = new ServerManagerView(context);

// Register the commands
context.subscriptions.push(
vscode.commands.registerCommand(`${extensionId}.addServer`, () => {
addServer();
vscode.commands.registerCommand(`${extensionId}.refreshTree`, () => {
view.refreshTree();
})
);
context.subscriptions.push(
vscode.commands.registerCommand(`${extensionId}.addServer`, async () => {
await addServer();
view.refreshTree();
})
);
context.subscriptions.push(
vscode.commands.registerCommand(`${extensionId}.addToStarred`, async (server?: ServerTreeItem) => {
if (server?.contextValue?.match(/\.server\./) && server.name) {
await view.addToFavorites(server.name);
view.refreshTree();
}
})
);
context.subscriptions.push(
vscode.commands.registerCommand(`${extensionId}.removeFromStarred`, async (server?: ServerTreeItem) => {
if (server?.contextValue?.endsWith('.starred') && server.name) {
await view.removeFromFavorites(server.name);
view.refreshTree();
}
})
);
context.subscriptions.push(
vscode.commands.registerCommand(`${extensionId}.openManagementPortalExternal`, (server?: ServerTreeItem) => {
if (server?.contextValue === 'server' && server.label) {
getPortalUriWithCredentials(server.label).then((uriWithCredentials) => {
if (server?.contextValue?.match(/\.server\./) && server.name) {
getPortalUriWithCredentials(server.name).then((uriWithCredentials) => {
if (uriWithCredentials) {
vscode.env.openExternal(uriWithCredentials);
}
Expand All @@ -62,8 +88,8 @@ export function activate(context: vscode.ExtensionContext) {
);
context.subscriptions.push(
vscode.commands.registerCommand(`${extensionId}.openManagementPortalInSimpleBrowser`, (server?: ServerTreeItem) => {
if (server?.contextValue === 'server' && server.label) {
getPortalUriWithCredentials(server.label).then((uriWithCredentials) => {
if (server?.contextValue?.match(/\.server\./) && server.name) {
getPortalUriWithCredentials(server.name).then((uriWithCredentials) => {
if (uriWithCredentials) {
//vscode.commands.executeCommand('simpleBrowser.api.open', uriWithCredentials);
//
Expand Down Expand Up @@ -96,14 +122,12 @@ export function activate(context: vscode.ExtensionContext) {
})
);
context.subscriptions.push(
vscode.commands.registerCommand(`${extensionId}.importServers`, () => {
importFromRegistry();
vscode.commands.registerCommand(`${extensionId}.importServers`, async () => {
await importFromRegistry();
view.refreshTree();
})
);

// Server Manager View
new ServerManagerView(context);

let api = {
async pickServer(scope?: vscode.ConfigurationScope, options: vscode.QuickPickOptions = {}): Promise<string | undefined> {
return await pickServer(scope, options);
Expand All @@ -113,6 +137,10 @@ export function activate(context: vscode.ExtensionContext) {
return getServerNames(scope);
},

getServerSummary(name: string, scope?: vscode.ConfigurationScope): ServerName | undefined {
return getServerSummary(name, scope);
},

async getServerSpec(name: string, scope?: vscode.ConfigurationScope, flushCredentialCache: boolean = false): Promise<ServerSpec | undefined> {
return await getServerSpec(name, scope, flushCredentialCache);
},
Expand Down
Loading

0 comments on commit 9d121fa

Please sign in to comment.