Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent overprompting for permission and account #1456

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 69 additions & 47 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
}
],
"engines": {
"vscode": "^1.91.0"
"vscode": "^1.93.0"
},
"enabledApiProposals": [
"fileSearchProvider",
Expand Down Expand Up @@ -1815,16 +1815,17 @@
"test": "node ./out/test/runTest.js",
"lint": "eslint src/**",
"lint-fix": "eslint --fix src/**",
"download-api": "dts dev 1.91.0",
"download-api": "dts dev 1.93.0",
"postinstall": "npm run download-api"
},
"devDependencies": {
"@intersystems-community/intersystems-servermanager": "^3.8.0",
"@types/istextorbinary": "2.3.1",
"@types/minimatch": "5.1.2",
"@types/mocha": "^7.0.2",
"@types/node": "20.16.5",
"@types/semver": "7.5.4",
"@types/vscode": "1.91.0",
"@types/vscode": "1.93.0",
"@types/ws": "8.5.4",
"@types/xmldom": "^0.1.29",
"@typescript-eslint/eslint-plugin": "^4.32.0",
Expand Down
21 changes: 15 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const smExtensionId = "intersystems-community.servermanager";

import vscode = require("vscode");
import * as semver from "semver";
import * as serverManager from "@intersystems-community/intersystems-servermanager";

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

export let checkingConnection = false;

let serverManagerApi: any;
let serverManagerApi: serverManager.ServerManagerAPI;

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

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export async function resolvePassword(serverSpec, ignoreUnauthenticated = false): Promise<void> {
const AUTHENTICATION_PROVIDER = "intersystems-server-credentials";
// This arises if setting says to use authentication provider
if (
// Connection isn't unauthenticated
(!isUnauthenticated(serverSpec.username) || ignoreUnauthenticated) &&
// A password is missing
typeof serverSpec.password == "undefined"
) {
const scopes = [serverSpec.name, serverSpec.username || ""];
let session = await vscode.authentication.getSession(AUTHENTICATION_PROVIDER, scopes, { silent: true });

// Handle Server Manager extension version < 3.8.0
const account = serverManagerApi.getAccount ? serverManagerApi.getAccount(serverSpec) : undefined;

let session = await vscode.authentication.getSession(serverManager.AUTHENTICATION_PROVIDER, scopes, {
silent: true,
account,
});
if (!session) {
session = await vscode.authentication.getSession(AUTHENTICATION_PROVIDER, scopes, { createIfNone: true });
session = await vscode.authentication.getSession(serverManager.AUTHENTICATION_PROVIDER, scopes, {
createIfNone: true,
account,
});
}
if (session) {
// If original spec lacked username use the one obtained by the authprovider
Expand Down Expand Up @@ -1164,7 +1173,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
}
const fileName = filePathNoWorkspaceArr.join(".");
// Generate the new content
const newContent = generateFileContent(uri, fileName, Buffer.from(await vscode.workspace.fs.readFile(uri)));
const newContent = generateFileContent(uri, fileName, await vscode.workspace.fs.readFile(uri));
// Write the new content to the file
return vscode.workspace.fs.writeFile(uri, new TextEncoder().encode(newContent.content.join("\n")));
})
Expand Down
12 changes: 4 additions & 8 deletions src/providers/FileSystemProvider/FileSystemProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type Entry = File | Directory;
export function generateFileContent(
uri: vscode.Uri,
fileName: string,
sourceContent: Buffer
sourceContent: Uint8Array
): { content: string[]; enc: boolean } {
const sourceLines = sourceContent.length ? new TextDecoder().decode(sourceContent).split("\n") : [];
const fileExt = fileName.split(".").pop().toLowerCase();
Expand Down Expand Up @@ -104,7 +104,7 @@ export function generateFileContent(
}
}
return {
content: [sourceContent.toString("base64")],
content: [Buffer.from(sourceContent).toString("base64")],
enc: true,
};
}
Expand Down Expand Up @@ -396,7 +396,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider {

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