-
Notifications
You must be signed in to change notification settings - Fork 0
/
KeyVault.js
47 lines (34 loc) · 1.18 KB
/
KeyVault.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const { ClientSecretCredential } = require("@azure/identity");
const { SecretClient } = require("@azure/keyvault-secrets");
class KeyVault {
client;
constructor(kv) {
const keyVaultURL = `https://${kv.kvName}.vault.azure.net`;
const credential = new ClientSecretCredential(
kv.ati,
kv.aci,
kv.acs
);
this.client = new SecretClient(keyVaultURL, credential);
}
async getSecretNames() {
const names = [];
for await (let page of this.client.listPropertiesOfSecrets().byPage({ maxPageSize: 25 })) {
names.push(...page.map(item => item.name));
}
return names;
}
async getSecretContent(secretName) {
const secret = await this.client.getSecret(secretName);
return secret.value;
}
async setSecretContent(secretName, content) {
await this.client.setSecret(secretName, content);
}
async deleteSecret(secretName) {
const deletingProcess = await this.client.beginDeleteSecret(secretName);
await deletingProcess.pollUntilDone();
await this.client.purgeDeletedSecret(secretName);
}
}
module.exports = KeyVault;