0
votes

Im making use of the following node library azure-keyvault to get retrieve stored secrets from azure keyvault. Ive only found the client.getSecret api exposed to retrieve a secret value. Im searching for a way to retrieve multiple secret values in one call. I hav'nt found one yet. Is there a way to do this that i'm missing or its simply not supported.

3

3 Answers

1
votes

Here is the complete code for getting the multiple client secret at once:

var credentials = new KeyVault.KeyVaultCredentials(authenticator);
var client = new KeyVault.KeyVaultClient(credentials);

client.setSecret(vaultUri, 'mysecret', 'my password', options, function (err, secretBundle) {

  // List all secrets
  var parsedId = KeyVault.parseSecretIdentifier(secretBundle.id);
  client.getSecrets(parsedId.vault, parsedId.name, function (err, result) {
    if (err) throw err;

    var loop = function (nextLink) {
      if (nextLink !== null && nextLink !== undefined) {
        client.getSecretsNext(nextLink, function (err, res) {
          console.log(res);
          loop(res.nextLink);
        });
      }
    };

    console.log(result);
    loop(result.nextLink);
  });
});

You can find the complete reference for azure key vault using node js below:

http://azure.github.io/azure-sdk-for-node/azure-keyvault/latest/KeyVaultClient.html#getSecrets

http://azure.github.io/azure-sdk-for-node/azure-keyvault/latest/

Hope it helps.

1
votes

You can use read-azure-secrets npm package which will return all secrets to you. E.g.

    const secretClient = require('read-azure-secrets');

    async function loadKeyVaultValues() {

        let applicationID = '';
        let applicationSecret = '';
        let vaultURL = 'https://<your-key-vault-name>.vault.azure.net/';
        let secrets = await secretClient.getSecrets(applicationID, applicationSecret, vaultURL);

        secrets.forEach(secret => {
            console.log(secret);
        });

    }

loadKeyVaultValues();
0
votes

You can try using client.getSecrets(..) method exposed by the REST Api.

Kindly go through the following useful blog, in which all methods have been implemented.

LINK: https://www.red-gate.com/simple-talk/cloud/platform-as-a-service/using-azure-keyvault-with-node-js/