Skip to content

Commit fc83973

Browse files
Prevent overprompting for permission and account (#1456)
* `npm audit fix` * Require VS Code 1.93, matching what Server Manager 3.8 needs * Fix some FileSystemProvider type errors Not sure why they didn't show up previously * Prevent overprompting for permission and account Requires Server Manager 3.8.0
1 parent b161728 commit fc83973

File tree

4 files changed

+92
-64
lines changed

4 files changed

+92
-64
lines changed

package-lock.json

+69-47
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
}
4949
],
5050
"engines": {
51-
"vscode": "^1.91.0"
51+
"vscode": "^1.93.0"
5252
},
5353
"enabledApiProposals": [
5454
"fileSearchProvider",
@@ -1815,16 +1815,17 @@
18151815
"test": "node ./out/test/runTest.js",
18161816
"lint": "eslint src/**",
18171817
"lint-fix": "eslint --fix src/**",
1818-
"download-api": "dts dev 1.91.0",
1818+
"download-api": "dts dev 1.93.0",
18191819
"postinstall": "npm run download-api"
18201820
},
18211821
"devDependencies": {
1822+
"@intersystems-community/intersystems-servermanager": "^3.8.0",
18221823
"@types/istextorbinary": "2.3.1",
18231824
"@types/minimatch": "5.1.2",
18241825
"@types/mocha": "^7.0.2",
18251826
"@types/node": "20.16.5",
18261827
"@types/semver": "7.5.4",
1827-
"@types/vscode": "1.91.0",
1828+
"@types/vscode": "1.93.0",
18281829
"@types/ws": "8.5.4",
18291830
"@types/xmldom": "^0.1.29",
18301831
"@typescript-eslint/eslint-plugin": "^4.32.0",

src/extension.ts

+15-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export const smExtensionId = "intersystems-community.servermanager";
44

55
import vscode = require("vscode");
66
import * as semver from "semver";
7+
import * as serverManager from "@intersystems-community/intersystems-servermanager";
78

89
import { AtelierJob, Content, Response, ServerInfo } from "./api/atelier";
910
export const OBJECTSCRIPT_FILE_SCHEMA = "objectscript";
@@ -198,7 +199,7 @@ let reporter: TelemetryReporter = null;
198199

199200
export let checkingConnection = false;
200201

201-
let serverManagerApi: any;
202+
let serverManagerApi: serverManager.ServerManagerAPI;
202203

203204
// Map of the intersystems.server connection specs we have resolved via the API to that extension
204205
const resolvedConnSpecs = new Map<string, any>();
@@ -222,18 +223,26 @@ export async function resolveConnectionSpec(serverName: string): Promise<void> {
222223

223224
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
224225
export async function resolvePassword(serverSpec, ignoreUnauthenticated = false): Promise<void> {
225-
const AUTHENTICATION_PROVIDER = "intersystems-server-credentials";
226-
// This arises if setting says to use authentication provider
227226
if (
228227
// Connection isn't unauthenticated
229228
(!isUnauthenticated(serverSpec.username) || ignoreUnauthenticated) &&
230229
// A password is missing
231230
typeof serverSpec.password == "undefined"
232231
) {
233232
const scopes = [serverSpec.name, serverSpec.username || ""];
234-
let session = await vscode.authentication.getSession(AUTHENTICATION_PROVIDER, scopes, { silent: true });
233+
234+
// Handle Server Manager extension version < 3.8.0
235+
const account = serverManagerApi.getAccount ? serverManagerApi.getAccount(serverSpec) : undefined;
236+
237+
let session = await vscode.authentication.getSession(serverManager.AUTHENTICATION_PROVIDER, scopes, {
238+
silent: true,
239+
account,
240+
});
235241
if (!session) {
236-
session = await vscode.authentication.getSession(AUTHENTICATION_PROVIDER, scopes, { createIfNone: true });
242+
session = await vscode.authentication.getSession(serverManager.AUTHENTICATION_PROVIDER, scopes, {
243+
createIfNone: true,
244+
account,
245+
});
237246
}
238247
if (session) {
239248
// If original spec lacked username use the one obtained by the authprovider
@@ -1164,7 +1173,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
11641173
}
11651174
const fileName = filePathNoWorkspaceArr.join(".");
11661175
// Generate the new content
1167-
const newContent = generateFileContent(uri, fileName, Buffer.from(await vscode.workspace.fs.readFile(uri)));
1176+
const newContent = generateFileContent(uri, fileName, await vscode.workspace.fs.readFile(uri));
11681177
// Write the new content to the file
11691178
return vscode.workspace.fs.writeFile(uri, new TextEncoder().encode(newContent.content.join("\n")));
11701179
})

src/providers/FileSystemProvider/FileSystemProvider.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export type Entry = File | Directory;
3030
export function generateFileContent(
3131
uri: vscode.Uri,
3232
fileName: string,
33-
sourceContent: Buffer
33+
sourceContent: Uint8Array
3434
): { content: string[]; enc: boolean } {
3535
const sourceLines = sourceContent.length ? new TextDecoder().decode(sourceContent).split("\n") : [];
3636
const fileExt = fileName.split(".").pop().toLowerCase();
@@ -104,7 +104,7 @@ export function generateFileContent(
104104
}
105105
}
106106
return {
107-
content: [sourceContent.toString("base64")],
107+
content: [Buffer.from(sourceContent).toString("base64")],
108108
enc: true,
109109
};
110110
}
@@ -396,7 +396,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
396396

397397
public writeFile(
398398
uri: vscode.Uri,
399-
content: Buffer,
399+
content: Uint8Array,
400400
options: {
401401
create: boolean;
402402
overwrite: boolean;
@@ -659,11 +659,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
659659
const newCsp = newParams.has("csp") && ["", "1"].includes(newParams.get("csp"));
660660
const newFileName = newCsp ? newUri.path : newUri.path.slice(1).replace(/\//g, ".");
661661
// Generate content for the new file
662-
const newContent = generateFileContent(
663-
newUri,
664-
newFileName,
665-
Buffer.from(await vscode.workspace.fs.readFile(oldUri))
666-
);
662+
const newContent = generateFileContent(newUri, newFileName, await vscode.workspace.fs.readFile(oldUri));
667663
if (newFileStat) {
668664
// We're overwriting an existing file so prompt the user to check it out
669665
await fireOtherStudioAction(OtherStudioAction.AttemptedEdit, newUri);

0 commit comments

Comments
 (0)