/* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * http://aws.amazon.com/apache2.0 * * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ using System; using Amazon.Extensions.Configuration.SystemsManager; using Amazon.Extensions.Configuration.SystemsManager.AppConfig; using Amazon.Extensions.Configuration.SystemsManager.Internal; using Amazon.Extensions.NETCore.Setup; // ReSharper disable once CheckNamespace namespace Microsoft.Extensions.Configuration { /// /// Extension methods for registering with . /// public static class AppConfigExtensions { /// /// Adds an that reads configuration values from AWS Systems Manager AppConfig. /// /// The to add to. /// The AppConfig application id. /// The AppConfig environment id. /// The AppConfig configuration profile id. /// used to create an AWS Systems Manager AppConfig Client connection /// Whether the AWS Systems Manager AppConfig is optional. /// Initiate reload after TimeSpan /// cannot be null /// cannot be null /// cannot be null /// cannot be null /// The . public static IConfigurationBuilder AddAppConfig(this IConfigurationBuilder builder, string applicationId, string environmentId, string configProfileId, AWSOptions awsOptions, bool optional, TimeSpan? reloadAfter) { if (applicationId == null) throw new ArgumentNullException(nameof(applicationId)); if (environmentId == null) throw new ArgumentNullException(nameof(environmentId)); if (configProfileId == null) throw new ArgumentNullException(nameof(configProfileId)); if (awsOptions == null) throw new ArgumentNullException(nameof(awsOptions)); return builder.AddAppConfig(ConfigureSource(applicationId, environmentId, configProfileId, awsOptions, optional, reloadAfter)); } /// /// Adds an that reads configuration values from AWS Systems Manager AppConfig. /// /// The to add to. /// The AppConfig application id. /// The AppConfig environment id. /// The AppConfig configuration profile id. /// used to create an AWS Systems Manager AppConfig Client connection /// Whether the AWS Systems Manager AppConfig is optional. /// cannot be null /// cannot be null /// cannot be null /// cannot be null /// The . public static IConfigurationBuilder AddAppConfig(this IConfigurationBuilder builder, string applicationId, string environmentId, string configProfileId, AWSOptions awsOptions, bool optional) { if (applicationId == null) throw new ArgumentNullException(nameof(applicationId)); if (environmentId == null) throw new ArgumentNullException(nameof(environmentId)); if (configProfileId == null) throw new ArgumentNullException(nameof(configProfileId)); if (awsOptions == null) throw new ArgumentNullException(nameof(awsOptions)); return builder.AddAppConfig(ConfigureSource(applicationId, environmentId, configProfileId, awsOptions, optional)); } /// /// Adds an that reads configuration values from AWS Systems Manager AppConfig. /// /// The to add to. /// The AppConfig application id. /// The AppConfig environment id. /// The AppConfig configuration profile id. /// used to create an AWS Systems Manager AppConfig Client connection /// Initiate reload after TimeSpan /// cannot be null /// cannot be null /// cannot be null /// cannot be null /// The . public static IConfigurationBuilder AddAppConfig(this IConfigurationBuilder builder, string applicationId, string environmentId, string configProfileId, AWSOptions awsOptions, TimeSpan? reloadAfter) { if (applicationId == null) throw new ArgumentNullException(nameof(applicationId)); if (environmentId == null) throw new ArgumentNullException(nameof(environmentId)); if (configProfileId == null) throw new ArgumentNullException(nameof(configProfileId)); if (awsOptions == null) throw new ArgumentNullException(nameof(awsOptions)); return builder.AddAppConfig(ConfigureSource(applicationId, environmentId, configProfileId, awsOptions, reloadAfter: reloadAfter)); } /// /// Adds an that reads configuration values from AWS Systems Manager AppConfig. /// /// The to add to. /// The AppConfig application id. /// The AppConfig environment id. /// The AppConfig configuration profile id. /// used to create an AWS Systems Manager AppConfig Client connection /// cannot be null /// cannot be null /// cannot be null /// cannot be null /// The . public static IConfigurationBuilder AddAppConfig(this IConfigurationBuilder builder, string applicationId, string environmentId, string configProfileId, AWSOptions awsOptions) { if (applicationId == null) throw new ArgumentNullException(nameof(applicationId)); if (environmentId == null) throw new ArgumentNullException(nameof(environmentId)); if (configProfileId == null) throw new ArgumentNullException(nameof(configProfileId)); if (awsOptions == null) throw new ArgumentNullException(nameof(awsOptions)); return builder.AddAppConfig(ConfigureSource(applicationId, environmentId, configProfileId, awsOptions)); } /// /// Adds an that reads configuration values from AWS Systems Manager AppConfig. /// /// The to add to. /// The AppConfig application id. /// The AppConfig environment id. /// The AppConfig configuration profile id. /// Whether the AWS Systems Manager AppConfig is optional. /// Initiate reload after TimeSpan /// cannot be null /// cannot be null /// cannot be null /// The . public static IConfigurationBuilder AddAppConfig(this IConfigurationBuilder builder, string applicationId, string environmentId, string configProfileId, bool optional, TimeSpan? reloadAfter) { if (applicationId == null) throw new ArgumentNullException(nameof(applicationId)); if (environmentId == null) throw new ArgumentNullException(nameof(environmentId)); if (configProfileId == null) throw new ArgumentNullException(nameof(configProfileId)); return builder.AddAppConfig(ConfigureSource(applicationId, environmentId, configProfileId, optional: optional, reloadAfter: reloadAfter)); } /// /// Adds an that reads configuration values from AWS Systems Manager AppConfig. /// /// The to add to. /// The AppConfig application id. /// The AppConfig environment id. /// The AppConfig configuration profile id. /// Initiate reload after TimeSpan /// cannot be null /// cannot be null /// cannot be null /// The . public static IConfigurationBuilder AddAppConfig(this IConfigurationBuilder builder, string applicationId, string environmentId, string configProfileId, TimeSpan? reloadAfter) { if (applicationId == null) throw new ArgumentNullException(nameof(applicationId)); if (environmentId == null) throw new ArgumentNullException(nameof(environmentId)); if (configProfileId == null) throw new ArgumentNullException(nameof(configProfileId)); return builder.AddAppConfig(ConfigureSource(applicationId, environmentId, configProfileId, reloadAfter: reloadAfter)); } /// /// Adds an that reads configuration values from AWS Systems Manager AppConfig. /// /// The to add to. /// The AppConfig application id. /// The AppConfig environment id. /// The AppConfig configuration profile id. /// Whether the AWS Systems Manager AppConfig is optional. /// cannot be null /// cannot be null /// cannot be null /// The . public static IConfigurationBuilder AddAppConfig(this IConfigurationBuilder builder, string applicationId, string environmentId, string configProfileId, bool optional) { if (applicationId == null) throw new ArgumentNullException(nameof(applicationId)); if (environmentId == null) throw new ArgumentNullException(nameof(environmentId)); if (configProfileId == null) throw new ArgumentNullException(nameof(configProfileId)); return builder.AddAppConfig(ConfigureSource(applicationId, environmentId, configProfileId, optional: optional)); } /// /// Adds an that reads configuration values from AWS Systems Manager AppConfig. /// /// The to add to. /// The AppConfig application id. /// The AppConfig environment id. /// The AppConfig configuration profile id. /// cannot be null /// cannot be null /// cannot be null /// The . public static IConfigurationBuilder AddAppConfig(this IConfigurationBuilder builder, string applicationId, string environmentId, string configProfileId) { if (applicationId == null) throw new ArgumentNullException(nameof(applicationId)); if (environmentId == null) throw new ArgumentNullException(nameof(environmentId)); if (configProfileId == null) throw new ArgumentNullException(nameof(configProfileId)); return builder.AddAppConfig(ConfigureSource(applicationId, environmentId, configProfileId)); } /// /// Adds an that reads configuration values from AWS Systems Manager AppConfig. /// /// The to add to. /// Configuration source. /// cannot be null /// . cannot be null /// . cannot be null /// . cannot be null /// The . public static IConfigurationBuilder AddAppConfig(this IConfigurationBuilder builder, AppConfigConfigurationSource source) { if (source == null) throw new ArgumentNullException(nameof(source)); if (source.ApplicationId == null) throw new ArgumentNullException(nameof(source.ApplicationId)); if (source.EnvironmentId == null) throw new ArgumentNullException(nameof(source.EnvironmentId)); if (source.ConfigProfileId == null) throw new ArgumentNullException(nameof(source.ConfigProfileId)); if (source.AwsOptions == null) { source.AwsOptions = AwsOptionsProvider.GetAwsOptions(builder); } return builder.Add(source); } private static AppConfigConfigurationSource ConfigureSource( string applicationId, string environmentId, string configProfileId, AWSOptions awsOptions = null, bool optional = false, TimeSpan? reloadAfter = null ) { return new AppConfigConfigurationSource { ApplicationId = applicationId, EnvironmentId = environmentId, ConfigProfileId = configProfileId, AwsOptions = awsOptions, Optional = optional, ReloadAfter = reloadAfter }; } } }