|
1 | 1 | # InterSystems® Server Manager |
2 | | -A VS Code helper extension that contributes settings which define connections to InterSystems servers. |
| 2 | +This is a VS Code helper extension that contributes settings which define connections to [InterSystems](https://www.intersystems.com/) servers. |
3 | 3 |
|
4 | 4 | For example: |
5 | 5 | ```json |
6 | | - "intersystems.servers": { |
7 | | - "my-local": { |
8 | | - "webServer": { |
9 | | - "scheme": "http", |
10 | | - "host": "127.0.0.1", |
11 | | - "port": 52773 |
12 | | - }, |
13 | | - "description": "My local IRIS instance" |
| 6 | +"intersystems.servers": { |
| 7 | + "dev": { |
| 8 | + "webServer": { |
| 9 | + "scheme": "https", |
| 10 | + "host": "webhost.local", |
| 11 | + "port": 443, |
| 12 | + "pathPrefix": "iris/dev" |
14 | 13 | }, |
15 | | - "dev": { |
16 | | - "webServer": { |
17 | | - "scheme": "https", |
18 | | - "host": "webhost.local", |
19 | | - "port": 443, |
20 | | - "pathPrefix": "iris/dev" |
21 | | - }, |
22 | | - "username": "alice", |
23 | | - "description": "Development server serviced by central web host over HTTPS" |
| 14 | + "username": "alice", |
| 15 | + "description": "Development server serviced by central web host over HTTPS" |
| 16 | + }, |
| 17 | + "my-local": { |
| 18 | + "webServer": { |
| 19 | + "scheme": "http", |
| 20 | + "host": "127.0.0.1", |
| 21 | + "port": 52773 |
24 | 22 | }, |
25 | | - "/default": "my-local" |
26 | | - } |
| 23 | + "description": "My local IRIS instance" |
| 24 | + }, |
| 25 | + "/default": "my-local" |
| 26 | +} |
27 | 27 | ``` |
28 | 28 |
|
29 | | -An extension XYZ needing to connect to InterSystems servers defines this extension as a dependency in its `package.json` |
| 29 | +This extension helps users add server definitions to their [user or workspace settings](https://code.visualstudio.com/docs/getstarted/settings) by editing JSON files. |
| 30 | + |
| 31 | +It adds the command `InterSystems Server Manager: Store Password in Keychain` to the Command Palette, which offers a quickpick of defined servers, then prompts for a password to store. This facility should be used instead of the plaintext `password` property of a server's definition, which has been deprecated. |
| 32 | + |
| 33 | +A command `InterSystems Server Manager: Clear Password from Keychain` removes a stored password. |
| 34 | + |
| 35 | +## Use By Other Extensions |
| 36 | + |
| 37 | +An extension XYZ needing to connect to InterSystems servers can define this extension as a dependency in its `package.json` |
30 | 38 |
|
31 | 39 | ```json |
32 | 40 | "extensionDependencies": [ |
33 | 41 | "intersystems-community.servermanager" |
34 | 42 | ], |
35 | 43 | ``` |
36 | 44 |
|
37 | | -This helps users add server definitions to their [user or workspace settings](https://code.visualstudio.com/docs/getstarted/settings). |
| 45 | +Alternatively the `activate` method of XYZ can detect if the extension is already available, then offer to install it if necessary: |
| 46 | + |
| 47 | +```ts |
| 48 | + const extId = "intersystems-community.servermanager"; |
| 49 | + let extension = vscode.extensions.getExtension(extId); |
| 50 | + if (!extension) { |
| 51 | + // Optionally ask user for permission |
| 52 | + // ... |
| 53 | + |
| 54 | + await vscode.commands.executeCommand("workbench.extensions.installExtension", extId); |
| 55 | + extension = vscode.extensions.getExtension(extId); |
| 56 | + } |
| 57 | + if (!extension.isActive) { |
| 58 | + await extension.activate(); |
| 59 | + } |
| 60 | +``` |
38 | 61 |
|
39 | | -Extension XYZ then gets the `intersystems.servers` object and uses it as needed, for example: |
| 62 | +XYZ can then use the extension's API to obtain the properties of a named server definition, including the password from the keychain if present: |
40 | 63 |
|
41 | 64 | ```ts |
42 | | -const allServers = vscode.workspace.getConfiguration('intersystems').get('servers'); |
43 | | -const mine = allServers['my-server']; |
44 | | -const webHost = mine.webServer.host; |
| 65 | + const serverManagerApi = extension.exports; |
| 66 | + if (serverManagerApi && serverManagerApi.getServerSpec) { // defensive coding |
| 67 | + const serverSpec = await serverManagerApi.getServerSpec(serverName); |
| 68 | + } |
45 | 69 | ``` |
| 70 | + |
| 71 | +If the `username` property is absent it will be prompted for. If no `password` is stored in the keychain or in the JSON definition the user will be asked to provide this the first time in any session that `getServerSpec` is called for a given server. |
| 72 | + |
| 73 | +To offer the user a quickpick of servers: |
| 74 | + |
| 75 | +```ts |
| 76 | + const serverName = await serverManagerApi.pickServer(); |
| 77 | +``` |
| 78 | + |
| 79 | +To obtain an array of server names: |
| 80 | + |
| 81 | +```ts |
| 82 | + const allServerNames = await serverManagerApi.getServerNames(); |
| 83 | +``` |
| 84 | + |
| 85 | +Servers are usually listed in the order they are defined. The exception is that if a server name is set as the value of the `/default` property (see example above) it will be shown first in the list. |
| 86 | + |
| 87 | +For details of the API, including result types and available parameters, review the source code of the extension's `activate` method [here](https://github.com/intersystems-community/intersystems-servermanager/blob/master/src/extension.ts). |
0 commit comments