2022-10-10 12:50:21 +00:00
|
|
|
import { readYamlPage } from "./yaml_page.ts";
|
2022-07-15 12:59:47 +00:00
|
|
|
|
|
|
|
// Read SECRETS page and retrieve specific set of secret keys
|
|
|
|
// Note: in this implementation there's no encryption employed at all so it's just a matter
|
|
|
|
// of not decising this SECRETS page to other places
|
|
|
|
export async function readSecrets(keys: string[]): Promise<any[]> {
|
|
|
|
try {
|
|
|
|
let allSecrets = await readYamlPage("SECRETS", ["yaml", "secrets"]);
|
|
|
|
let collectedSecrets: any[] = [];
|
|
|
|
for (let key of keys) {
|
|
|
|
let secret = allSecrets[key];
|
|
|
|
if (secret) {
|
|
|
|
collectedSecrets.push(secret);
|
|
|
|
} else {
|
|
|
|
throw new Error(`No such secret: ${key}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return collectedSecrets;
|
|
|
|
} catch (e: any) {
|
2023-05-23 18:53:53 +00:00
|
|
|
if (e.message === "Not found") {
|
2022-07-15 12:59:47 +00:00
|
|
|
throw new Error(`No such secret: ${keys[0]}`);
|
|
|
|
}
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
2022-12-16 15:35:23 +00:00
|
|
|
|
|
|
|
// Read SECRETS page and retrieve a specific secret
|
|
|
|
export async function readSecret(key: string): Promise<any> {
|
|
|
|
try {
|
|
|
|
const allSecrets = await readYamlPage("SECRETS", ["yaml", "secrets"]);
|
|
|
|
const val = allSecrets[key];
|
|
|
|
if (val === undefined) {
|
|
|
|
throw new Error(`No such secret: ${key}`);
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
} catch (e: any) {
|
2023-05-23 18:53:53 +00:00
|
|
|
if (e.message === "Not found") {
|
2022-12-16 15:35:23 +00:00
|
|
|
throw new Error(`No such secret: ${key}`);
|
|
|
|
}
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|