29 lines
777 B
TypeScript
29 lines
777 B
TypeScript
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();
|