diff --git a/extensions/vscode/src/api/client.ts b/extensions/vscode/src/api/client.ts index fe42d07fd..05cdcbbe1 100644 --- a/extensions/vscode/src/api/client.ts +++ b/extensions/vscode/src/api/client.ts @@ -7,6 +7,7 @@ import { ContentRecords } from "./resources/ContentRecords"; import { Configurations } from "./resources/Configurations"; import { Files } from "./resources/Files"; import { Packages } from "./resources/Packages"; +import { Secrets } from "./resources/Secrets"; import { EntryPoints } from "./resources/Entrypoints"; import * as Entities from "entities"; @@ -18,6 +19,7 @@ class PublishingClientApi { contentRecords: ContentRecords; files: Files; packages: Packages; + secrets: Secrets; apiServiceIsUp: Promise; entrypoints: EntryPoints; @@ -51,6 +53,7 @@ class PublishingClientApi { this.contentRecords = new ContentRecords(this.client); this.files = new Files(this.client); this.packages = new Packages(this.client); + this.secrets = new Secrets(this.client); this.entrypoints = new EntryPoints(this.client); } diff --git a/extensions/vscode/src/api/resources/Secrets.ts b/extensions/vscode/src/api/resources/Secrets.ts new file mode 100644 index 000000000..e3c8944bf --- /dev/null +++ b/extensions/vscode/src/api/resources/Secrets.ts @@ -0,0 +1,57 @@ +// Copyright (C) 2024 by Posit Software, PBC. + +import { AxiosInstance, AxiosResponse } from "axios"; + +import { Configuration } from "../types/configurations"; +import { PostSecretBody, SecretAction } from "../types/secrets"; + +export class Secrets { + private client: AxiosInstance; + + constructor(client: AxiosInstance) { + this.client = client; + } + + // Returns: + // 200 - success + // 400 - bad request + // 404 - not found + // 500 - internal server error + get(configName: string, dir: string) { + const encodedName = encodeURIComponent(configName); + return this.client.get(`/configurations/${encodedName}/secrets`, { + params: { dir }, + }); + } + + add(configName: string, secretName: string, dir: string) { + return this.update(configName, SecretAction.ADD, secretName, dir); + } + + remove(configName: string, secretName: string, dir: string) { + return this.update(configName, SecretAction.REMOVE, secretName, dir); + } + + // Returns: + // 200 - success + // 400 - bad request + // 404 - not found + // 500 - internal server error + update( + configName: string, + action: SecretAction, + secretName: string, + dir: string, + ) { + const encodedName = encodeURIComponent(configName); + const body = { + action, + secret: secretName, + }; + return this.client.post< + Configuration, + AxiosResponse, + PostSecretBody + >(`/configurations/${encodedName}/secrets`, body, { params: { dir } }); + } +} diff --git a/extensions/vscode/src/api/types/secrets.ts b/extensions/vscode/src/api/types/secrets.ts new file mode 100644 index 000000000..a346b8b65 --- /dev/null +++ b/extensions/vscode/src/api/types/secrets.ts @@ -0,0 +1,11 @@ +// Copyright (C) 2024 by Posit Software, PBC. + +export enum SecretAction { + ADD = "add", + REMOVE = "remove", +} + +export type PostSecretBody = { + action: SecretAction; + secret: string; +};