< Summary

Class:Microsoft.Extensions.Configuration.AzureKeyVaultConfigurationExtensions
Assembly:Azure.Extensions.AspNetCore.Configuration.Secrets
File(s):C:\Git\azure-sdk-for-net\sdk\extensions\Azure.Extensions.AspNetCore.Configuration.Secrets\src\AzureKeyVaultConfigurationExtensions.cs
Covered lines:0
Uncovered lines:16
Coverable lines:16
Total lines:90
Line coverage:0% (0 of 16)
Covered branches:0
Total branches:0

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
AddAzureKeyVault(...)-0%100%
AddAzureKeyVault(...)-0%100%
AddAzureKeyVault(...)-0%100%
AddAzureKeyVault(...)-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\extensions\Azure.Extensions.AspNetCore.Configuration.Secrets\src\AzureKeyVaultConfigurationExtensions.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using Azure.Core;
 6using Azure.Extensions.AspNetCore.Configuration.Secrets;
 7using Azure.Security.KeyVault.Secrets;
 8
 9#pragma warning disable AZC0001 // Extension methods have to be in the correct namespace to appear in intellisense.
 10namespace Microsoft.Extensions.Configuration
 11#pragma warning restore
 12{
 13    /// <summary>
 14    /// Extension methods for registering <see cref="AzureKeyVaultConfigurationProvider"/> with <see cref="IConfiguratio
 15    /// </summary>
 16    public static class AzureKeyVaultConfigurationExtensions
 17    {
 18        /// <summary>
 19        /// Adds an <see cref="IConfigurationProvider"/> that reads configuration values from the Azure KeyVault.
 20        /// </summary>
 21        /// <param name="configurationBuilder">The <see cref="IConfigurationBuilder"/> to add to.</param>
 22        /// <param name="vaultUri">The Azure Key Vault uri.</param>
 23        /// <param name="credential">The credential to to use for authentication.</param>
 24        /// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
 25        public static IConfigurationBuilder AddAzureKeyVault(
 26            this IConfigurationBuilder configurationBuilder,
 27            Uri vaultUri,
 28            TokenCredential credential)
 29        {
 030            return AddAzureKeyVault(configurationBuilder, vaultUri, credential, KeyVaultSecretManager.Instance);
 31        }
 32
 33        /// <summary>
 34        /// Adds an <see cref="IConfigurationProvider"/> that reads configuration values from the Azure KeyVault.
 35        /// </summary>
 36        /// <param name="configurationBuilder">The <see cref="IConfigurationBuilder"/> to add to.</param>
 37        /// <param name="vaultUri">Azure Key Vault uri.</param>
 38        /// <param name="credential">The credential to to use for authentication.</param>
 39        /// <param name="manager">The <see cref="KeyVaultSecretManager"/> instance used to control secret loading.</para
 40        /// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
 41        public static IConfigurationBuilder AddAzureKeyVault(
 42            this IConfigurationBuilder configurationBuilder,
 43            Uri vaultUri,
 44            TokenCredential credential,
 45            KeyVaultSecretManager manager)
 46        {
 047            return AddAzureKeyVault(configurationBuilder, new AzureKeyVaultConfigurationOptions(vaultUri, credential)
 048            {
 049                Manager = manager
 050            });
 51        }
 52
 53        /// <summary>
 54        /// Adds an <see cref="IConfigurationProvider"/> that reads configuration values from the Azure KeyVault.
 55        /// </summary>
 56        /// <param name="configurationBuilder">The <see cref="IConfigurationBuilder"/> to add to.</param>
 57        /// <param name="client">The <see cref="SecretClient"/> to use for retrieving values.</param>
 58        /// <param name="manager">The <see cref="KeyVaultSecretManager"/> instance used to control secret loading.</para
 59        /// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
 60        public static IConfigurationBuilder AddAzureKeyVault(
 61            this IConfigurationBuilder configurationBuilder,
 62            SecretClient client,
 63            KeyVaultSecretManager manager)
 64        {
 065            return configurationBuilder.Add(new AzureKeyVaultConfigurationSource(new AzureKeyVaultConfigurationOptions()
 066            {
 067                Client = client,
 068                Manager = manager
 069            }));
 70        }
 71
 72        /// <summary>
 73        /// Adds an <see cref="IConfigurationProvider"/> that reads configuration values from the Azure KeyVault.
 74        /// </summary>
 75        /// <param name="configurationBuilder">The <see cref="IConfigurationBuilder"/> to add to.</param>
 76        /// <param name="options">The <see cref="AzureKeyVaultConfigurationOptions"/> to use.</param>
 77        /// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
 78        private static IConfigurationBuilder AddAzureKeyVault(this IConfigurationBuilder configurationBuilder, AzureKeyV
 79        {
 080            Argument.AssertNotNull(configurationBuilder, nameof(configurationBuilder));
 081            Argument.AssertNotNull(options, nameof(configurationBuilder));
 082            Argument.AssertNotNull(options.Client, $"{nameof(options)}.{nameof(options.Client)}");
 083            Argument.AssertNotNull(options.Manager, $"{nameof(options)}.{nameof(options.Manager)}");
 84
 085            configurationBuilder.Add(new AzureKeyVaultConfigurationSource(options));
 86
 087            return configurationBuilder;
 88        }
 89    }
 90}