Skip to content

Commit bb90491

Browse files
committed
Show extension display name when denied
Signed-off-by: Seb Julliand <[email protected]>
1 parent b6e30b5 commit bb90491

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/instantiate.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { VariablesUI } from "./webviews/variables";
2121

2222
export let instance: Instance;
2323

24-
const passwordAttempts: {[extensionId: string]: number} = {}
24+
const passwordAttempts: { [extensionId: string]: number } = {}
2525

2626
const CLEAR_RECENT = `$(trash) Clear recently opened`;
2727
const CLEAR_CACHED = `$(trash) Clear cached`;
@@ -627,26 +627,24 @@ export async function loadAllofExtension(context: vscode.ExtensionContext) {
627627
const extension = vscode.extensions.getExtension(extensionId);
628628
const isValid = (extension && extension.isActive);
629629
if (isValid) {
630-
631630
const connection = instance.getConnection();
632-
if (connection) {
631+
const storage = instance.getStorage();
632+
if (connection && storage) {
633+
const displayName = extension.packageJSON.displayName || extensionId;
633634

634635
// Some logic to stop spam from extensions.
635636
passwordAttempts[extensionId] = passwordAttempts[extensionId] || 0;
636637
if (passwordAttempts[extensionId] > 1) {
637-
throw new Error(`Password request denied.`);
638+
throw new Error(`Password request denied for extension ${displayName}.`);
638639
}
639640

640641
const connectionKey = `${instance.getConnection()!.currentConnectionName}_password`;
641642
const storedPassword = await context.secrets.get(connectionKey);
642643

643644
if (storedPassword) {
644-
645-
const storage = instance.getStorage()!;
646645
let isAuthed = storage.isExtensionAuthorised(extensionId);
647646

648647
if (!isAuthed) {
649-
const displayName = extension.packageJSON.displayName || extensionId;
650648
const detail = `The ${displayName} extension is requesting access to your password for this connection. ${reason ? `\n\nReason: ${reason}` : `The extension did not provide a reason for password access.`}`;
651649
let done = false;
652650
let modal = true;
@@ -659,13 +657,13 @@ export async function loadAllofExtension(context: vscode.ExtensionContext) {
659657
} else {
660658
options.push(`Deny`);
661659
}
662-
660+
663661
const result = await vscode.window.showWarningMessage(
664-
modal ? `Password Request` : detail,
662+
modal ? `Password Request` : detail,
665663
{
666664
modal,
667665
detail,
668-
},
666+
},
669667
...options
670668
);
671669

0 commit comments

Comments
 (0)