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);
        }
 private static string GetApplicationName(IConfigurationSection configServerSection, ConfigurationRoot root)
 {
     // TODO: Figure out a sensible "default" app name (e.g apps assembly name?)
     var appSection = root.GetSection(SPRING_APPLICATION_PREFIX);
     return GetSetting("name", configServerSection, appSection, null);
 }
예제 #3
0
 public IConfigurationSection GetSection(string key) => _root.GetSection(Path + Constants.KeyDelimiter + key);
예제 #4
0
 /// <summary>
 /// Gets a configuration sub-section with the specified key.
 /// </summary>
 /// <param name="key">The key of the configuration section.</param>
 /// <returns>The <see cref="IConfigurationSection"/>.</returns>
 /// <remarks>
 ///     This method will never return <c>null</c>. If no matching sub-section is found with the specified key,
 ///     an empty <see cref="IConfigurationSection"/> will be returned.
 /// </remarks>
 public IConfigurationSection GetSection(string key) => _root.GetSection(ConfigurationPath.Combine(Path, key));
        private static void Initialize(ConfigServerClientSettings settings, IHostingEnvironment environment, ConfigurationRoot root)
        {

            var clientConfigsection = root.GetSection(PREFIX);

            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), root);
            settings.AccessTokenUri = ResovlePlaceholders(GetAccessTokenUri(clientConfigsection, root), root);
            settings.ClientId = ResovlePlaceholders(GetClientId(clientConfigsection, root), root);
            settings.ClientSecret = ResovlePlaceholders(GetClientSecret(clientConfigsection, root), root);
            settings.Enabled = GetEnabled(clientConfigsection, root);
            settings.FailFast = GetFailFast(clientConfigsection, root);
            settings.ValidateCertificates = GetCertificateValidation(clientConfigsection, root);

    }
        private static string GetAccessTokenUri(IConfigurationSection configServerSection, ConfigurationRoot root)
        {
            var vcapConfigServerSection = root.GetSection(VCAP_SERVICES_CONFIGSERVER_PREFIX);
            return GetSetting("credentials:access_token_uri", configServerSection, vcapConfigServerSection, 
                ConfigServerClientSettings.DEFAULT_ACCESS_TOKEN_URI);

        }
        private static string GetClientId(IConfigurationSection configServerSection, ConfigurationRoot root)
        {
            var vcapConfigServerSection = root.GetSection(VCAP_SERVICES_CONFIGSERVER_PREFIX);
            return GetSetting("credentials:client_id", configServerSection, vcapConfigServerSection,
                ConfigServerClientSettings.DEFAULT_CLIENT_ID);

        }
        private static string GetUri(IConfigurationSection configServerSection, ConfigurationRoot root)
        {
        
            // First check for spring:cloud:config:uri
            var uri = configServerSection["uri"];
            if (!string.IsNullOrEmpty(uri))
            {
                return uri;
            }

            // Next check for cloudfoundry binding vcap:services:p-config-server:0:credentials:uri
            var vcapConfigServerSection = root.GetSection(VCAP_SERVICES_CONFIGSERVER_PREFIX);
            uri = vcapConfigServerSection["credentials:uri"];
            if (!string.IsNullOrEmpty(uri))
            {
                return uri;
            }

            // Take default if none of above
            return ConfigServerClientSettings.DEFAULT_URI;
        }