Skip to content

Commit

Permalink
Merge pull request #2313 from posit-dev/dotnomad/ts-secrets-api
Browse files Browse the repository at this point in the history
Add frontend Secrets API client resource
  • Loading branch information
dotNomad authored Sep 26, 2024
2 parents 02e6eb0 + eab4e5f commit b081f49
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
3 changes: 3 additions & 0 deletions extensions/vscode/src/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -18,6 +19,7 @@ class PublishingClientApi {
contentRecords: ContentRecords;
files: Files;
packages: Packages;
secrets: Secrets;
apiServiceIsUp: Promise<boolean>;
entrypoints: EntryPoints;

Expand Down Expand Up @@ -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);
}

Expand Down
57 changes: 57 additions & 0 deletions extensions/vscode/src/api/resources/Secrets.ts
Original file line number Diff line number Diff line change
@@ -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<string[]>(`/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<Configuration>,
PostSecretBody
>(`/configurations/${encodedName}/secrets`, body, { params: { dir } });
}
}
11 changes: 11 additions & 0 deletions extensions/vscode/src/api/types/secrets.ts
Original file line number Diff line number Diff line change
@@ -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;
};

0 comments on commit b081f49

Please sign in to comment.