Skip to content

Commit 65f5904

Browse files
Merge pull request #329 from gjsjohnmurray/fix-328
fix #328 resolve the server spec fully, including credentials
2 parents 483acb1 + d869065 commit 65f5904

File tree

2 files changed

+39
-18
lines changed

2 files changed

+39
-18
lines changed

src/commands/addServerNamespaceToWorkspace.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from "vscode";
22
import { AtelierAPI } from "../api";
3-
import { panel } from "../extension";
3+
import { panel, resolveConnectionSpec } from "../extension";
44

55
export async function addServerNamespaceToWorkspace(): Promise<void> {
66
const serverManagerApi = await getServerManagerApi();
@@ -18,18 +18,30 @@ export async function addServerNamespaceToWorkspace(): Promise<void> {
1818
}
1919
// Get its namespace list
2020
let uri = vscode.Uri.parse(`isfs://${serverName}/?ns=%SYS`);
21+
await resolveConnectionSpec(serverName);
22+
// Prepare a displayable form of its connection spec as a hint to the user
23+
const connSpec = await serverManagerApi.getServerSpec(serverName);
24+
const connDisplayString = `${connSpec.webServer.scheme}://${connSpec.webServer.host}:${connSpec.webServer.port}/${connSpec.webServer.pathPrefix}`;
25+
// Connect and fetch namespaces
2126
const api = new AtelierAPI(uri);
22-
const allNamespaces: string[] = await api
27+
const allNamespaces: string[] | undefined = await api
2328
.serverInfo()
2429
.then((data) => data.result.content.namespaces)
25-
.catch(() => []);
26-
// Clear the panel entry this created
30+
.catch((reason) => {
31+
// Notify user about serverInfo failure
32+
vscode.window.showErrorMessage(
33+
reason.message || `Failed to fetch namespace list from server at ${connDisplayString}`
34+
);
35+
return undefined;
36+
});
37+
// Clear the panel entry created by the connection
2738
panel.text = "";
2839
panel.tooltip = "";
29-
// Prepare a displayable form of its connection spec as a hint to the user
30-
const connSpec = await serverManagerApi.getServerSpec(serverName);
31-
const connDisplayString = `${connSpec.webServer.scheme}://${connSpec.webServer.host}:${connSpec.webServer.port}/${connSpec.webServer.pathPrefix}`;
32-
// Handle serveInfo having failed or returned no namespaces
40+
// Handle serverInfo failure
41+
if (!allNamespaces) {
42+
return;
43+
}
44+
// Handle serverInfo having returned no namespaces
3345
if (!allNamespaces.length) {
3446
vscode.window.showErrorMessage(`No namespace list returned by server at ${connDisplayString}`);
3547
return;

src/extension.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,23 @@ let serverManagerApi: any;
163163
// Map of the intersystems.server connection specs we have resolved via the API to that extension
164164
const resolvedConnSpecs = new Map<string, any>();
165165

166-
// Accessor for the connection specs
166+
/**
167+
* If servermanager extension is available, fetch the connection spec unless already cached.
168+
* Prompt for credentials if necessary.
169+
* @param serverName authority element of an isfs uri, or `objectscript.conn.server` property
170+
*/
171+
export async function resolveConnectionSpec(serverName: string): Promise<void> {
172+
if (serverManagerApi && serverManagerApi.getServerSpec) {
173+
if (serverName && serverName !== "" && !resolvedConnSpecs.has(serverName)) {
174+
const connSpec = await serverManagerApi.getServerSpec(serverName);
175+
if (connSpec) {
176+
resolvedConnSpecs.set(serverName, connSpec);
177+
}
178+
}
179+
}
180+
}
181+
182+
// Accessor for the cache of resolved connection specs
167183
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
168184
export function getResolvedConnectionSpec(key: string, dflt: any): any {
169185
return resolvedConnSpecs.has(key) ? resolvedConnSpecs.get(key) : dflt;
@@ -418,15 +434,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
418434
toCheck.set(configName, uri);
419435
});
420436
toCheck.forEach(async function (uri, configName) {
421-
if (serverManagerApi && serverManagerApi.getServerSpec) {
422-
const serverName = uri.scheme === "file" ? config("conn", configName).server : configName;
423-
if (serverName && serverName !== "" && !resolvedConnSpecs.has(serverName)) {
424-
const connSpec = await serverManagerApi.getServerSpec(serverName);
425-
if (connSpec) {
426-
resolvedConnSpecs.set(serverName, connSpec);
427-
}
428-
}
429-
}
437+
const serverName = uri.scheme === "file" ? config("conn", configName).server : configName;
438+
await resolveConnectionSpec(serverName);
430439
checkConnection(true, uri);
431440
});
432441

0 commit comments

Comments
 (0)