/// <summary> /// Extension method to populate an AzureKeyVaultConfigurationProvider from passing in the connection string parts or environment variable names to retrieve the parts /// and the secret names /// </summary> /// <param name="builder">IConnfigurationBuilder this method extends</param> /// <param name="vaultNameOrEnvVarName">The name of the Azure Key Vault or the Environment varialbe name to retrieve it from</param> /// <param name="clientIdOrEnvVarName">The name of the ClientId or the Environment variable name to retrieve it from</param> /// <param name="clientSecretOrEnvVarName">The name of the ClientSecret or the Environment variable name to retrieve it from</param> /// <param name="secretNames">The secrets to load from the Azure Key Vault</param> /// <returns>Populated IConfigurationBuilder</returns> public static IConfigurationBuilder AddAzureKeyVault(this IConfigurationBuilder builder, string vaultNameOrEnvVarName, string clientIdOrEnvVarName, string clientSecretOrEnvVarName, IEnumerable <string> secretNames) { var vaultName = GetSetting(vaultNameOrEnvVarName); var clientId = GetSetting(clientIdOrEnvVarName); var clientSecret = GetSetting(clientSecretOrEnvVarName); var connectionInfo = new AzureKeyVaultConnectionInfo(vaultName, clientId, clientSecret); builder.Add(new AzureKeyVaultConfigurationProvider(connectionInfo, secretNames)); return(builder); }
/// <summary> /// Extension method to populate an AzureKeyVaultConfigurationProvider from passing in the connection string parts or environment variable names to retrieve the parts /// and the secret names /// </summary> /// <param name="builder">IConnfigurationBuilder this method extends</param> /// <param name="vaultNameOrEnvVarName">The name of the Azure Key Vault or the Environment varialbe name to retrieve it from</param> /// <param name="clientIdOrEnvVarName">The name of the ClientId or the Environment variable name to retrieve it from</param> /// <param name="clientSecretOrEnvVarName">The name of the ClientSecret or the Environment variable name to retrieve it from</param> /// <param name="secretNames">The secrets to load from the Azure Key Vault</param> /// <returns>Populated IConfigurationBuilder</returns> public static IConfigurationBuilder AddAzureKeyVault(this IConfigurationBuilder builder, string vaultNameOrEnvVarName, string clientIdOrEnvVarName, string clientSecretOrEnvVarName, IEnumerable<string> secretNames) { var vaultName = GetSetting(vaultNameOrEnvVarName); var clientId = GetSetting(clientIdOrEnvVarName); var clientSecret = GetSetting(clientSecretOrEnvVarName); var connectionInfo = new AzureKeyVaultConnectionInfo(vaultName, clientId, clientSecret); builder.Add(new AzureKeyVaultConfigurationProvider(connectionInfo, secretNames)); return builder; }
/// <summary> /// Constructor used when all the connection informaiton is provided seperately /// </summary> /// <param name="connectionInfo">A valid AzureKeyVaultConnectionInfo object</param> /// <param name="secretNames">The names of the secrets to retrieve from the AzureKeyVault</param> public AzureKeyVaultConfigurationProvider(AzureKeyVaultConnectionInfo connectionInfo, IEnumerable<string> secretNames) { if (connectionInfo == null) { throw new ArgumentNullException(nameof(connectionInfo)); } if (secretNames == null) { throw new ArgumentNullException(nameof(secretNames)); } ConnectionInfo = connectionInfo; SecretNames = secretNames; }
/// <summary> /// Constructor used when all the connection informaiton is provided seperately /// </summary> /// <param name="connectionInfo">A valid AzureKeyVaultConnectionInfo object</param> /// <param name="secretNames">The names of the secrets to retrieve from the AzureKeyVault</param> public AzureKeyVaultConfigurationProvider(AzureKeyVaultConnectionInfo connectionInfo, IEnumerable <string> secretNames) { if (connectionInfo == null) { throw new ArgumentNullException(nameof(connectionInfo)); } if (secretNames == null) { throw new ArgumentNullException(nameof(secretNames)); } ConnectionInfo = connectionInfo; SecretNames = secretNames; }