function wrapClient()

in lib/keyVaultConfigurationResolver.js [115:161]


function wrapClient(keyVaultClient) {
  keyVaultClient.getObjectSecrets = async function resolveSecrets(object) {
    let paths = null;
    try {
      paths = identifyKeyVaultValuePaths(object);
    } catch(parseError) {
      throw parseError;
    }

    // Build a unique list of secrets, fetch them at once
    const uniqueUris = new Set();
    const properties = new Map();
    for (const path in paths) {
      const value = paths[path];
      const tag = value.auth;
      value.protocol = httpsProtocol;
      value.auth = null;
      const uri = url.format(value);
      properties.set(path, [uri, tag]);
      uniqueUris.add(uri);
    }
    const secretStash = new Map();
    const uniques = Array.from(uniqueUris.values());
    for (const uniqueSecretId of uniques) {
      try {
        await getSecretAsPromise(keyVaultClient, secretStash, uniqueSecretId);
      } catch (resolveSecretError) {
        console.log(`Error resolving secret with ID ${uniqueSecretId}: ${resolveSecretError}`);
        throw resolveSecretError;
      }
    }
    for (const path in paths) {
      const [uri, tag] = properties.get(path);
      const secretResponse = secretStash.get(uri);

      let value = undefined;
      if (tag === null) {
        value = secretResponse.value;
      } else if (secretResponse.tags) {
        value = secretResponse.tags[tag];
      }

      objectPath.set(object, path, value);
    }
  };
  return keyVaultClient;
}