new readSetting() and readSecret() APIs

This commit is contained in:
Zef Hemel
2022-12-16 16:35:23 +01:00
parent ef4f6ad171
commit 3af82495d1
2 changed files with 34 additions and 0 deletions
+17
View File
@@ -23,3 +23,20 @@ export async function readSecrets(keys: string[]): Promise<any[]> {
throw e;
}
}
// 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) {
if (e.message === "Page not found") {
throw new Error(`No such secret: ${key}`);
}
throw e;
}
}