Example #1
0
 /// <summary>
 /// Adds the secrets configuration provider to the <paramref name="configurationBuilder"/>.
 /// </summary>
 /// <param name="configurationBuilder">The <see cref="IConfigurationBuilder"/> to add to.</param>
 /// <param name="secretsProvider">
 /// The implementation of <see cref="ISecretsProvider"/> that provides the secrets that are mapped
 /// to configuration settings.
 /// </param>
 /// <returns>The <see cref="IConfigurationBuilder"/></returns>
 public static IConfigurationBuilder AddRockLibSecrets(this IConfigurationBuilder configurationBuilder,
                                                       ISecretsProvider secretsProvider) =>
 configurationBuilder.Add(new SecretsConfigurationSource(secretsProvider));
 /// <summary>
 /// Adds a INI configuration source to <paramref name="builder"/>.
 /// </summary>
 /// <param name="builder">The <see cref="IConfigurationBuilder"/> to add to.</param>
 /// <param name="configureSource">Configures the source.</param>
 /// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
 public static IConfigurationBuilder AddIniFile(this IConfigurationBuilder builder, Action <IniConfigurationSource> configureSource)
 => builder.Add(configureSource);
Example #3
0
        public void AsEnumerateStripsKeyFromChildren()
        {
            // Arrange
            var dic1 = new Dictionary <string, string>()
            {
                { "Mem1", "Value1" },
                { "Mem1:", "NoKeyValue1" },
                { "Mem1:KeyInMem1", "ValueInMem1" },
                { "Mem1:KeyInMem1:Deep1", "ValueDeep1" }
            };
            var dic2 = new Dictionary <string, string>()
            {
                { "Mem2", "Value2" },
                { "Mem2:", "NoKeyValue2" },
                { "Mem2:KeyInMem2", "ValueInMem2" },
                { "Mem2:KeyInMem2:Deep2", "ValueDeep2" }
            };
            var dic3 = new Dictionary <string, string>()
            {
                { "Mem3", "Value3" },
                { "Mem3:", "NoKeyValue3" },
                { "Mem3:KeyInMem3", "ValueInMem3" },
                { "Mem3:KeyInMem4", "ValueInMem4" },
                { "Mem3:KeyInMem3:Deep3", "ValueDeep3" },
                { "Mem3:KeyInMem3:Deep4", "ValueDeep4" }
            };
            var memConfigSrc1 = new MemoryConfigurationSource {
                InitialData = dic1
            };
            var memConfigSrc2 = new MemoryConfigurationSource {
                InitialData = dic2
            };
            var memConfigSrc3 = new MemoryConfigurationSource {
                InitialData = dic3
            };

            var config = new ConfigurationManager();
            IConfigurationBuilder configurationBuilder = config;

            // Act
            configurationBuilder.Add(memConfigSrc1);
            configurationBuilder.Add(memConfigSrc2);
            configurationBuilder.Add(memConfigSrc3);

            var dict = config.GetSection("Mem1").AsEnumerable(makePathsRelative: true).ToDictionary(k => k.Key, v => v.Value);

            Assert.Equal(3, dict.Count);
            Assert.Equal("NoKeyValue1", dict[""]);
            Assert.Equal("ValueInMem1", dict["KeyInMem1"]);
            Assert.Equal("ValueDeep1", dict["KeyInMem1:Deep1"]);

            var dict2 = config.GetSection("Mem2").AsEnumerable(makePathsRelative: true).ToDictionary(k => k.Key, v => v.Value);

            Assert.Equal(3, dict2.Count);
            Assert.Equal("NoKeyValue2", dict2[""]);
            Assert.Equal("ValueInMem2", dict2["KeyInMem2"]);
            Assert.Equal("ValueDeep2", dict2["KeyInMem2:Deep2"]);

            var dict3 = config.GetSection("Mem3").AsEnumerable(makePathsRelative: true).ToDictionary(k => k.Key, v => v.Value);

            Assert.Equal(5, dict3.Count);
            Assert.Equal("NoKeyValue3", dict3[""]);
            Assert.Equal("ValueInMem3", dict3["KeyInMem3"]);
            Assert.Equal("ValueInMem4", dict3["KeyInMem4"]);
            Assert.Equal("ValueDeep3", dict3["KeyInMem3:Deep3"]);
            Assert.Equal("ValueDeep4", dict3["KeyInMem3:Deep4"]);
        }
 public static IConfigurationBuilder AddEntityFrameworkConfig(
     this IConfigurationBuilder builder, Action <DbContextOptionsBuilder> setup)
 {
     return(builder.Add(new EFConfigSource(setup)));
 }
Example #5
0
 public static IConfigurationBuilder AddMongoDBConfigProvider <TSettingsObject>(this IConfigurationBuilder builder, SharpSettingsMongoDataStore <TSettingsObject> store, string settingsId, bool reloadOnChange = true) where TSettingsObject : WatchableSettings <string>
 {
     return(builder.Add(new MongoDBConfigurationSource <TSettingsObject>(store, settingsId, reloadOnChange)));
 }
 /// <summary>
 /// Adds a Environment Json configuration source to <paramref name="builder"/>.
 /// </summary>
 /// <param name="builder">The <see cref="IConfigurationBuilder"/> to add to.</param>
 /// <param name="configureSource">Configures the source.</param>
 /// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
 public static IConfigurationBuilder AddEnvironmentConfigJson(this IConfigurationBuilder builder, Action <EnvironmentConfigJsonConfigurationSource> configureSource)
 => builder.Add(configureSource);
Example #7
0
 public static IConfigurationBuilder AddAzureTableStorageConfiguration(this IConfigurationBuilder builder, string connection, string appName, string environment, string version)
 {
     return(builder.Add(new AzureTableStorageConfigurationSource(connection, appName, environment, version)));
 }
        /// <summary>
        /// Adds a XML configuration source to <paramref name="builder"/>.
        /// </summary>
        /// <param name="builder">The <see cref="IConfigurationBuilder"/> to add to.</param>
        /// <param name="stream">The <see cref="Stream"/> to read the XML configuration data from.</param>
        /// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
        public static IConfigurationBuilder AddXmlStream(this IConfigurationBuilder builder, Stream stream)
        {
            ThrowHelper.ThrowIfNull(builder);

            return(builder.Add <XmlStreamConfigurationSource>(s => s.Stream = stream));
        }
Example #9
0
 private void AddEnvironmentVariables()
 {
     _configBuilder.Add(new EnvironmentVariablesConfigurationSource());
 }
 public static IConfigurationBuilder AddDoltTree(this IConfigurationBuilder builder, Action <DoltTreeConfigurationSource> configureSource)
 => builder.Add(configureSource);
 /// <summary>
 /// Adds a XML configuration source to <paramref name="builder"/>.
 /// </summary>
 /// <param name="builder">The <see cref="IConfigurationBuilder"/> to add to.</param>
 /// <param name="configureSource">Configures the source.</param>
 /// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
 public static IConfigurationBuilder AddXmlFile(this IConfigurationBuilder builder, Action <XmlConfigurationSource>?configureSource)
 => builder.Add(configureSource);
Example #12
0
 public static IConfigurationBuilder AddConsulBuilder(this IConfigurationBuilder configurationBuilder, Uri consulUrl, List <string> consulPaths)
 {
     configurationBuilder.Add(new ConsulConfigurationSource(consulUrl, consulPaths));
     return(configurationBuilder);
 }
 public static IConfigurationBuilder AddVault(this IConfigurationBuilder configurationBuilder, string serviceName, string address, string token, bool optional)
 {
     return(configurationBuilder.Add(new VaultConfigurationSource(serviceName, address, token, optional)));
 }
Example #14
0
 /// <summary>
 /// Adds a docker secrets configuration source to <paramref name="builder"/>.
 /// </summary>
 /// <param name="builder">The <see cref="IConfigurationBuilder"/> to add to.</param>
 /// <param name="configureSource">Configures the source.</param>
 /// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
 public static IConfigurationBuilder AddDockerSecrets(this IConfigurationBuilder builder, Action <DockerSecretsConfigurationSource> configureSource)
 => builder.Add(configureSource);
Example #15
0
 public static IConfigurationBuilder AddFile(this IConfigurationBuilder builder,
                                             string fileName,
                                             IConfigurationFormatter formatter)
 => builder.Add(new FileConfigurationSource(fileName), formatter);
Example #16
0
 public static IConfigurationBuilder AddEnvironmentContextConfiguration(this IConfigurationBuilder builder, EnvironmentContext environmentContext)
 {
     return(builder.Add(new EnvironmentContextConfigurationSource(environmentContext)));
 }
 public IConfigurationBuilder Add(IConfigurationSource source) => _builder.Add(source);
Example #18
0
 /// <summary>
 ///     Adds a HOCON configuration source to <paramref name="builder" />.
 /// </summary>
 /// <param name="builder">The <see cref="IConfigurationBuilder" /> to add to.</param>
 /// <param name="configureSource">Configures the source.</param>
 /// <returns>The <see cref="IConfigurationBuilder" />.</returns>
 public static IConfigurationBuilder AddHoconFile(this IConfigurationBuilder builder,
                                                  Action <HoconConfigurationSource> configureSource)
 {
     return(builder.Add(configureSource));
 }
Example #19
0
 public static IConfigurationBuilder AddServiceFabricConfig(this IConfigurationBuilder builder, string packageName)
 {
     return(builder.Add(new ServiceFabricConfigSource(packageName)));
 }
 /// <summary>
 /// Azure functions use a file called local.settings.json to store app settings in.
 /// To run integrationtests we also need to add these settings to the configuration.
 /// <a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local#local-settings-file">See documentation.</a>
 /// </summary>
 public static void AddLocalSettings(this IConfigurationBuilder configurationBuilder,
                                     string solutionDirectoryName, string projectDirectoryName, string localSettingsFileName)
 {
     // Add the local settings source to the configuration builder.
     configurationBuilder.Add(new LocalSettingsSource(solutionDirectoryName, projectDirectoryName, localSettingsFileName));
 }
 public static IConfigurationBuilder AddConsul(this IConfigurationBuilder builder, ConsulConfigurationOptions Options)
 {
     return(builder.Add(new ConsulConfigurationSource(Options)));
 }
 /// <summary>
 /// Adds an <see cref="IConfigurationProvider"/> that reads configuration values from environment variables.
 /// </summary>
 /// <param name="configurationBuilder">The <see cref="IConfigurationBuilder"/> to add to.</param>
 /// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
 public static IConfigurationBuilder AddModifiedEnvironmentVariables(this IConfigurationBuilder configurationBuilder)
 {
     configurationBuilder.Add(new EnvironmentVariablesConfigurationSource());
     return(configurationBuilder);
 }
 public static IConfigurationBuilder AddLocalEnvironmentVariablesConfiguration(this IConfigurationBuilder builder)
 {
     return(builder.Add(new LocalEnvironmentVariablesSource()));
 }
 /// <summary>
 /// Adds an <see cref="IConfigurationProvider"/> that reads configuration values from environment variables.
 /// </summary>
 /// <param name="builder">The <see cref="IConfigurationBuilder"/> to add to.</param>
 /// <param name="configureSource">Configures the source.</param>
 /// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
 public static IConfigurationBuilder AddModifiedEnvironmentVariables(this IConfigurationBuilder builder, Action <EnvironmentVariablesConfigurationSource> configureSource)
 => builder.Add(configureSource);
 public static IConfigurationBuilder AddEFConfiguration(this IConfigurationBuilder builder, Action <DbContextOptionsBuilder> optionsAction)
 {
     return(builder.Add(new EFConfigurationSource(optionsAction)));
 }
 public static IConfigurationBuilder AddGoogleSecretsConfiguration(this IConfigurationBuilder builder)
 {
     return(builder.Add(new GoogleSecretsConfigurationSource()));
 }
Example #27
0
        public void ChainedAsEnumerateFlattensIntoDictionaryTest(bool removePath)
        {
            // Arrange
            var dic1 = new Dictionary <string, string>()
            {
                { "Mem1", "Value1" },
                { "Mem1:", "NoKeyValue1" },
                { "Mem1:KeyInMem1", "ValueInMem1" },
                { "Mem1:KeyInMem1:Deep1", "ValueDeep1" }
            };
            var dic2 = new Dictionary <string, string>()
            {
                { "Mem2", "Value2" },
                { "Mem2:", "NoKeyValue2" },
                { "Mem2:KeyInMem2", "ValueInMem2" },
                { "Mem2:KeyInMem2:Deep2", "ValueDeep2" }
            };
            var dic3 = new Dictionary <string, string>()
            {
                { "Mem3", "Value3" },
                { "Mem3:", "NoKeyValue3" },
                { "Mem3:KeyInMem3", "ValueInMem3" },
                { "Mem3:KeyInMem3:Deep3", "ValueDeep3" }
            };
            var memConfigSrc1 = new MemoryConfigurationSource {
                InitialData = dic1
            };
            var memConfigSrc2 = new MemoryConfigurationSource {
                InitialData = dic2
            };
            var memConfigSrc3 = new MemoryConfigurationSource {
                InitialData = dic3
            };

            var config1 = new ConfigurationManager();
            IConfigurationBuilder configurationBuilder = config1;

            // Act
            configurationBuilder.Add(memConfigSrc1);
            configurationBuilder.Add(memConfigSrc2);

            var config2 = new ConfigurationManager();

            config2
            .AddConfiguration(config1)
            .Add(memConfigSrc3);

            var dict = config2.AsEnumerable(makePathsRelative: removePath).ToDictionary(k => k.Key, v => v.Value);

            // Assert
            Assert.Equal("Value1", dict["Mem1"]);
            Assert.Equal("NoKeyValue1", dict["Mem1:"]);
            Assert.Equal("ValueDeep1", dict["Mem1:KeyInMem1:Deep1"]);
            Assert.Equal("ValueInMem2", dict["Mem2:KeyInMem2"]);
            Assert.Equal("Value2", dict["Mem2"]);
            Assert.Equal("NoKeyValue2", dict["Mem2:"]);
            Assert.Equal("ValueDeep2", dict["Mem2:KeyInMem2:Deep2"]);
            Assert.Equal("Value3", dict["Mem3"]);
            Assert.Equal("NoKeyValue3", dict["Mem3:"]);
            Assert.Equal("ValueInMem3", dict["Mem3:KeyInMem3"]);
            Assert.Equal("ValueDeep3", dict["Mem3:KeyInMem3:Deep3"]);
        }
Example #28
0
 public static IConfigurationBuilder AddProperties(this IConfigurationBuilder builder, IConfigurationSource source)
 => builder.Add(source, new PropertiesFormatter());
Example #29
0
 public static IConfigurationBuilder AddParameterStoreHandler(this IConfigurationBuilder configurationBuilder, AWSCredentials awsCredentials = null, RegionEndpoint regionEndpoint = null)
 {
     configurationBuilder.Add(new AwsParameterStoreConfigurationSource(awsCredentials, regionEndpoint));
     return(configurationBuilder);
 }
Example #30
0
        /// <summary>
        /// Initializes the Test Logger.
        /// </summary>
        /// <param name="events">Events that can be registered for.</param>
        /// <param name="parameters">Configuration parameters for logger.</param>
        public void Initialize(TestLoggerEvents events, Dictionary <string, string> parameters)
        {
            _configBuilder.Add(new LoggerConfigurationProvider(parameters));

            Initialize(events, parameters.Single(p => p.Key == "TestRunDirectory").Value);
        }