-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add frontend Secrets API client resource
- Loading branch information
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |