Пример #1
0
        /// <summary>
        /// Add configuration from Azure KeyVault. Providers configured prior to
        /// this one will be used to get Azure KeyVault connection details.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="allowInteractiveLogon"></param>
        /// <param name="singleton"></param>
        /// <param name="keyVaultUrlVarName"></param>
        /// <param name="providerPriority"> Determines where in the configuration
        /// providers chain current provider should be added. Default to lowest
        /// </param>
        /// <returns></returns>
        public static IConfigurationBuilder AddFromKeyVault(this IConfigurationBuilder builder,
                                                            ConfigurationProviderPriority providerPriority = ConfigurationProviderPriority.Lowest,
                                                            bool allowInteractiveLogon = false, bool singleton = true, string keyVaultUrlVarName = null)
        {
            var configuration = builder.Build();
            var provider      = KeyVaultConfigurationProvider.CreateInstanceAsync(
                allowInteractiveLogon, singleton, configuration, keyVaultUrlVarName).Result;

            if (provider != null)
            {
                switch (providerPriority)
                {
                case ConfigurationProviderPriority.Highest:
                    builder.Add(provider);
                    break;

                case ConfigurationProviderPriority.Lowest:
                    builder.Sources.Insert(0, provider);
                    break;

                default:
                    throw new ArgumentException(
                              $"Unknown ConfigurationProviderPriority value: {providerPriority}");
                }
            }
            return(builder);
        }
        /// <summary>
        /// Add configuration from Azure KeyVault. Providers configured prior to
        /// this one will be used to get Azure KeyVault connection details.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="allowInteractiveLogon"></param>
        /// <param name="singleton"></param>
        /// <param name="keyVaultUrlVarName"></param>
        /// <param name="providerPriority"> Determines where in the configuration
        /// providers chain current provider should be added. Default to lowest
        /// </param>
        /// <returns></returns>
        public static IConfigurationBuilder AddFromKeyVault(this IConfigurationBuilder builder,
                                                            ConfigurationProviderPriority providerPriority = ConfigurationProviderPriority.Lowest,
                                                            bool allowInteractiveLogon = false, bool singleton = true, string keyVaultUrlVarName = null)
        {
            var configuration = builder.Build();

            // Check if configuration should be loaded from KeyVault, default to true.
            var keyVaultConfigEnabled = configuration.GetValue(PcsVariable.PCS_KEYVAULT_CONFIG_ENABLED, true);

            if (!keyVaultConfigEnabled)
            {
                return(builder);
            }

            var provider = KeyVaultConfigurationProvider.CreateInstanceAsync(
                allowInteractiveLogon, singleton, configuration, keyVaultUrlVarName).Result;

            if (provider != null)
            {
                switch (providerPriority)
                {
                case ConfigurationProviderPriority.Highest:
                    builder.Add(provider);
                    break;

                case ConfigurationProviderPriority.Lowest:
                    builder.Sources.Insert(0, provider);
                    break;

                default:
                    throw new ArgumentException(
                              $"Unknown ConfigurationProviderPriority value: {providerPriority}");
                }
            }
            return(builder);
        }