Skip to content

Commit

Permalink
Add frontend Secrets API client resource
Browse files Browse the repository at this point in the history
  • Loading branch information
dotNomad committed Sep 26, 2024
1 parent 02e6eb0 commit eab4e5f
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 eab4e5f

Please sign in to comment.