Skip to content

Commit

Permalink
Merge pull request #2316 from posit-dev/dotnomad/remove-secret-cmd
Browse files Browse the repository at this point in the history
Add ability to remove a Secret name in the UI
  • Loading branch information
dotNomad authored Sep 26, 2024
2 parents b081f49 + 9631a4e commit 4209d39
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
14 changes: 14 additions & 0 deletions extensions/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
"icon": "$(refresh)",
"category": "Posit Publisher"
},
{
"command": "posit.publisher.homeView.removeSecret",
"title": "Remove Secret from Configuration",
"icon": "$(trash)",
"category": "Posit Publisher"
},
{
"command": "posit.publisher.files.refresh",
"title": "Refresh Deployment Files",
Expand Down Expand Up @@ -247,6 +253,10 @@
"command": "posit.publisher.homeView.refreshCredentials",
"when": "posit.publish.state == 'initialized'"
},
{
"command": "posit.publisher.homeView.removeSecret",
"when": "false"
},
{
"command": "posit.publisher.files.refresh",
"when": "posit.publish.state == 'initialized'"
Expand Down Expand Up @@ -346,6 +356,10 @@
{
"command": "posit.publisher.homeView.deleteCredential",
"when": "webviewId == 'posit.publisher.homeView' && webviewSection == 'credentials-tree-item'"
},
{
"command": "posit.publisher.homeView.removeSecret",
"when": "webviewId == 'posit.publisher.homeView' && webviewSection == 'secrets-tree-item'"
}
]
},
Expand Down
1 change: 1 addition & 0 deletions extensions/vscode/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const homeViewCommands = {
AddCredential: "posit.publisher.homeView.addCredential",
DeleteCredential: "posit.publisher.homeView.deleteCredential",
RefreshCredentials: "posit.publisher.homeView.refreshCredentials",
RemoveSecret: "posit.publisher.homeView.removeSecret",
EditCurrentConfiguration: "posit.publisher.homeView.edit.Configuration",
// Added automatically by VSCode with view registration
Focus: "posit.publisher.homeView.focus",
Expand Down
31 changes: 31 additions & 0 deletions extensions/vscode/src/views/homeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,30 @@ export class HomeViewProvider implements WebviewViewProvider, Disposable {
}
}

public removeSecret = async (context: { name: string }) => {
const activeConfig = await this.state.getSelectedConfiguration();
if (activeConfig === undefined) {
console.error("homeView::removeSecret: No active configuration.");
return;
}

try {
await showProgress("Removing Secret", Views.HomeView, async () => {
const api = await useApi();
await api.secrets.remove(
activeConfig.configurationName,
context.name,
activeConfig.projectDir,
);
});
} catch (error: unknown) {
const summary = getSummaryStringFromError("removeSecret", error);
window.showInformationMessage(
`Failed to remove secret from configuration. ${summary}`,
);
}
};

private async showNewCredential() {
return await commands.executeCommand(Commands.HomeView.AddCredential);
}
Expand Down Expand Up @@ -1789,6 +1813,13 @@ export class HomeViewProvider implements WebviewViewProvider, Disposable {
}),
);

this.context.subscriptions.push(
commands.registerCommand(
Commands.HomeView.RemoveSecret,
this.removeSecret,
),
);

this.context.subscriptions.push(
commands.registerCommand(Commands.HomeView.RefreshCredentials, () =>
useBus().trigger("refreshCredentials", undefined),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:list-style="secretValue || isEditing ? 'default' : 'deemphasized'"
:tooltip="tooltip"
align-icon-with-twisty
:data-vscode-context="vscodeContext"
>
<template #description>
<SidebarInput
Expand Down Expand Up @@ -91,4 +92,12 @@ const actions = computed<ActionButton[]>(() => {
return result;
});
const vscodeContext = computed(() => {
return JSON.stringify({
name: props.name,
webviewSection: "secrets-tree-item",
preventDefaultContextMenuItems: true,
});
});
</script>

0 comments on commit 4209d39

Please sign in to comment.