Boilerplate generator and deno tasks for monorepo
This commit is contained in:
28
common/vault.ts
Normal file
28
common/vault.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
class Vault {
|
||||
private secrets: Map<string, string> = new Map();
|
||||
constructor() {
|
||||
const data = JSON.parse(Deno.readTextFileSync('./secrets.json') || '{}');
|
||||
|
||||
for (const key in data) {
|
||||
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
||||
this.secrets.set(key, data[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
public get = (key: string) => this.secrets.get(key);
|
||||
public getf = (key: string, fields: Record<string, string>) => {
|
||||
let secret = this.secrets.get(key);
|
||||
if (!secret) return;
|
||||
|
||||
for (const k in fields) {
|
||||
if (Object.prototype.hasOwnProperty.call(fields, k)) {
|
||||
const element = fields[k];
|
||||
secret = secret.replace(new RegExp(`{{${k}}}`, 'g'), element)
|
||||
}
|
||||
}
|
||||
|
||||
return secret;
|
||||
}
|
||||
}
|
||||
|
||||
export const vault = new Vault();
|
Reference in New Issue
Block a user