Azure keyvault, request for multiple secrets

只愿长相守 提交于 2021-02-11 12:33:11

问题


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.


回答1:


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.




回答2:


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();



回答3:


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/



来源:https://stackoverflow.com/questions/56628794/azure-keyvault-request-for-multiple-secrets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!