-
Notifications
You must be signed in to change notification settings - Fork 589
/
keyvault.js
34 lines (25 loc) · 915 Bytes
/
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
const { DefaultAzureCredential } = require("@azure/identity");
const { SecretClient } = require("@azure/keyvault-secrets");
const getSecret = async (secretName, keyVaultName) => {
if (!secretName || !keyVaultName) {
throw Error("getSecret: Required params missing")
}
const credential = new DefaultAzureCredential();
// Build the URL to reach your key vault
const url = `https://${keyVaultName}.vault.azure.net`;
try {
// Create client to connect to service
const client = new SecretClient(url, credential);
// Get secret Obj
const latestSecret = await client.getSecret(secretName);
console.log(`Secret (${secretName}=${latestSecret.value})`)
// Return value
return latestSecret.value;
} catch (ex) {
console.log(ex)
throw ex;
}
}
module.exports = {
getSecret
}