Skip to content

Commit

Permalink
Merge pull request #2317 from posit-dev/dotnomad/add-secret-btn
Browse files Browse the repository at this point in the history
Add button to add a Secret to the config
  • Loading branch information
dotNomad authored Sep 26, 2024
2 parents 4209d39 + 8f3b977 commit 80beb95
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
6 changes: 6 additions & 0 deletions extensions/vscode/src/types/messages/webviewToHostMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export enum WebviewToHostMessageType {
REQUEST_FILES_LISTS = "requestFilesLists",
REQUEST_CREDENTIALS = "requestCredentials",
VSCODE_OPEN_RELATIVE = "VSCodeOpenRelativeMsg",
ADD_SECRET = "addSecret",
REFRESH_PYTHON_PACKAGES = "RefreshPythonPackagesMsg",
SCAN_PYTHON_PACKAGE_REQUIREMENTS = "ScanPythonPackageRequirementsMsg",
REFRESH_R_PACKAGES = "RefreshRPackagesMsg",
Expand Down Expand Up @@ -50,6 +51,7 @@ export type WebviewToHostMessage =
| ExcludeFileMsg
| RequestFilesListsMsg
| RequestCredentialsMsg
| AddSecretMsg
| RefreshPythonPackagesMsg
| VSCodeOpenRelativeMsg
| ScanPythonPackageRequirementsMsg
Expand All @@ -75,6 +77,7 @@ export function isWebviewToHostMessage(msg: any): msg is WebviewToHostMessage {
msg.kind === WebviewToHostMessageType.EXCLUDE_FILE ||
msg.kind === WebviewToHostMessageType.REQUEST_FILES_LISTS ||
msg.kind === WebviewToHostMessageType.REQUEST_CREDENTIALS ||
msg.kind === WebviewToHostMessageType.ADD_SECRET ||
msg.kind === WebviewToHostMessageType.REFRESH_PYTHON_PACKAGES ||
msg.kind === WebviewToHostMessageType.VSCODE_OPEN_RELATIVE ||
msg.kind === WebviewToHostMessageType.SCAN_PYTHON_PACKAGE_REQUIREMENTS ||
Expand Down Expand Up @@ -154,6 +157,9 @@ export type RequestFilesListsMsg =
export type RequestCredentialsMsg =
AnyWebviewToHostMessage<WebviewToHostMessageType.REQUEST_CREDENTIALS>;

export type AddSecretMsg =
AnyWebviewToHostMessage<WebviewToHostMessageType.ADD_SECRET>;

export type RefreshPythonPackagesMsg =
AnyWebviewToHostMessage<WebviewToHostMessageType.REFRESH_PYTHON_PACKAGES>;

Expand Down
46 changes: 46 additions & 0 deletions extensions/vscode/src/views/homeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ export class HomeViewProvider implements WebviewViewProvider, Disposable {
return await this.debounceRefreshPythonPackages();
case WebviewToHostMessageType.REFRESH_R_PACKAGES:
return await this.debounceRefreshRPackages();
case WebviewToHostMessageType.ADD_SECRET:
return await this.addSecret();
case WebviewToHostMessageType.VSCODE_OPEN_RELATIVE:
return await this.onRelativeOpenVSCode(msg);
case WebviewToHostMessageType.SCAN_PYTHON_PACKAGE_REQUIREMENTS:
Expand Down Expand Up @@ -936,6 +938,50 @@ export class HomeViewProvider implements WebviewViewProvider, Disposable {
}
}

private inputSecretName = async () => {
return await window.showInputBox({
title: "Add a Secret",
prompt: "Enter the name of the secret.",
ignoreFocusOut: true,
validateInput: (value: string) => {
if (value.length === 0) {
return "Secret names cannot be empty.";
}
return;
},
});
};

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

const name = await this.inputSecretName();
if (name === undefined) {
// Cancelled by the user
return;
}

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

public removeSecret = async (context: { name: string }) => {
const activeConfig = await this.state.getSelectedConfiguration();
if (activeConfig === undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,25 @@ import TreeSection from "src/components/tree/TreeSection.vue";
import WelcomeView from "src/components/WelcomeView.vue";
import { useHomeStore } from "src/stores/home";
import Secret from "src/components/views/secrets/Secret.vue";
import { useHostConduitService } from "src/HostConduitService";
import { WebviewToHostMessageType } from "../../../../../../src/types/messages/webviewToHostMessages";
const home = useHomeStore();
const { sendMsg } = useHostConduitService();
const sectionActions = computed<ActionButton[]>(() => {
const result: ActionButton[] = [];
const result: ActionButton[] = [
{
label: "Add Secret",
codicon: "codicon-add",
fn: () => {
sendMsg({
kind: WebviewToHostMessageType.ADD_SECRET,
});
},
},
];
if (home.secretsWithValueCount > 0) {
result.push({
Expand Down

0 comments on commit 80beb95

Please sign in to comment.