summaryrefslogtreecommitdiff
path: root/utils/secret.ts
diff options
context:
space:
mode:
authorElizabeth Alexander Hunt <me@liz.coffee>2025-05-12 09:40:12 -0700
committerElizabeth <me@liz.coffee>2025-05-26 14:15:42 -0700
commitd51c9d74857aca3c2f172609297266968bc7f809 (patch)
tree64327f9cc4219729aa11af32d7d4c70cddfc2292 /utils/secret.ts
parent30729a0cf707d9022bae0a7baaba77379dc31fd5 (diff)
downloadci-d51c9d74857aca3c2f172609297266968bc7f809.tar.gz
ci-d51c9d74857aca3c2f172609297266968bc7f809.zip
The big refactor TM
Diffstat (limited to 'utils/secret.ts')
-rw-r--r--utils/secret.ts66
1 files changed, 0 insertions, 66 deletions
diff --git a/utils/secret.ts b/utils/secret.ts
deleted file mode 100644
index eb2054b..0000000
--- a/utils/secret.ts
+++ /dev/null
@@ -1,66 +0,0 @@
-import { getRequiredEnv, getStdout, loggerWithPrefix } from "./mod.ts";
-
-const logger = loggerWithPrefix(() =>
- `[${new Date().toISOString()}] [BitwardenSession]`
-);
-export class BitwardenSession {
- private readonly sessionInitializer: Promise<string>;
-
- constructor(server = getRequiredEnv("BW_SERVER")) {
- ["BW_CLIENTID", "BW_CLIENTSECRET"].forEach(getRequiredEnv);
-
- this.sessionInitializer = getStdout(
- `bw config server ${server} --quiet`,
- )
- .then(() => {
- logger.log("Logging in via API");
- return getStdout(`bw login --apikey --quiet`);
- })
- .then(() => {
- logger.log("Unlocking vault in session");
- return getStdout(`bw unlock --passwordenv BW_PASSWORD --raw`);
- })
- .then((session) => {
- logger.log(`Session ${session}`);
- return session.trim();
- });
- }
-
- public async getItem<T extends LoginItem | SecureNote>(
- secretName: string,
- ): Promise<T> {
- logger.log(`Finding secret ${secretName}`);
- return await this.sessionInitializer.then((session) =>
- getStdout(`bw list items`, {
- env: {
- BW_SESSION: session,
- },
- })
- ).then((items) => JSON.parse(items)).then((items) =>
- items.find(({ name }: { name: string }) => name === secretName)
- ).then((item) => {
- if (!item) throw new Error("Could not find bitwarden item " + secretName);
- logger.log(`Found secret: ${secretName}`);
- return item;
- });
- }
-
- async close(): Promise<void> {
- return await this.sessionInitializer.then((session) =>
- getStdout(`bw lock`, { env: { BW_SESSION: session } })
- ).then(() => {
- logger.log("Locked session");
- });
- }
-}
-
-export type LoginItem = {
- login: {
- username: string;
- password: string;
- };
-};
-
-export type SecureNote = {
- notes: string;
-};