public static void Initialize(string configPrefix, ConfigServerClientSettingsBase settings, IHostingEnvironment environment, ConfigurationRoot root) { if (configPrefix == null) { throw new ArgumentNullException(nameof(configPrefix)); } if (settings == null) { throw new ArgumentNullException(nameof(settings)); } if (environment == null) { throw new ArgumentNullException(nameof(environment)); } if (root == null) { throw new ArgumentNullException(nameof(root)); } var clientConfigsection = root.GetSection(configPrefix); settings.Name = ResovlePlaceholders(GetApplicationName(clientConfigsection, root), root); settings.Environment = ResovlePlaceholders(GetEnvironment(clientConfigsection, environment), root); settings.Label = ResovlePlaceholders(GetLabel(clientConfigsection), root); settings.Username = ResovlePlaceholders(GetUsername(clientConfigsection), root); settings.Password = ResovlePlaceholders(GetPassword(clientConfigsection), root); settings.Uri = ResovlePlaceholders(GetUri(clientConfigsection, root, settings.Uri), root); settings.Enabled = GetEnabled(clientConfigsection, root, settings.Enabled); settings.FailFast = GetFailFast(clientConfigsection, root, settings.FailFast); settings.ValidateCertificates = GetCertificateValidation(clientConfigsection, root, settings.ValidateCertificates); }
/// <summary> /// Initializes a new instance of <see cref="ConfigServerConfigurationProvider"/>. /// </summary> /// <param name="settings">the configuration settings the provider uses when /// accessing the server.</param> /// <param name="httpClient">a HttpClient the provider uses to make requests of /// the server.</param> /// <param name="logFactory">optional logging factory</param> /// </summary> internal protected ConfigServerConfigurationProviderBase(ConfigServerClientSettingsBase settings, HttpClient httpClient, ILoggerFactory logFactory = null) { if (settings == null) { throw new ArgumentNullException(nameof(settings)); } if (httpClient == null) { throw new ArgumentNullException(nameof(httpClient)); } _logger = logFactory?.CreateLogger<ConfigServerConfigurationProviderBase>(); _settings = settings; _client = httpClient; }
/// <summary> /// Initializes a new instance of <see cref="ConfigServerConfigurationProvider"/>. /// </summary> /// <param name="settings">the configuration settings the provider uses when /// accessing the server.</param> /// <param name="logFactory">optional logging factory</param> /// </summary> internal protected ConfigServerConfigurationProviderBase(ConfigServerClientSettingsBase settings, ILoggerFactory logFactory = null) : this(settings, GetHttpClient(settings), logFactory) { _client.Timeout = DEFAULT_TIMEOUT; }
/// <summary> /// Creates an appropriatly configured HttpClient that will be used in communicating with the /// Spring Cloud Configuration Server /// </summary> /// <param name="settings">the settings used in configuring the HttpClient</param> /// <returns>The HttpClient used by the provider</returns> protected static HttpClient GetHttpClient(ConfigServerClientSettingsBase settings) { #if NET451 return new HttpClient(); #else // TODO: For coreclr, disabling certificate validation only works on windows // https://github.com/dotnet/corefx/issues/4476 if (settings != null && !settings.ValidateCertificates) { var handler = new WinHttpHandler(); handler.ServerCertificateValidationCallback = (sender, cert, chain, sslPolicyErrors) => true; return new HttpClient(handler); } else { return new HttpClient(); } #endif }