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);
        }
Example #2
0
        public ShellSettings(
            string name, TenantState tenantState)
        {
            RootConfiguration = new ConfigurationRoot(new[] { new InternalConfigurationProvider() });

            Name = name;
            State = tenantState;
        }
Example #3
0
        public ShellSettings(ShellSettings settings)
        {
            RootConfiguration = new ConfigurationRoot(new[] { new InternalConfigurationProvider() });

            Name = settings.Name;
            RequestUrlHost = settings.RequestUrlHost;
            RequestUrlPrefix = settings.RequestUrlPrefix;
            State = settings.State;
        }
Example #4
0
        public ShellSettings(ShellSettings settings)
        {
            RootConfiguration = new ConfigurationRoot(new[] { new InternalConfigurationProvider() });

            Name = settings.Name;
            RequestUrlHost = settings.RequestUrlHost;
            RequestUrlPrefix = settings.RequestUrlPrefix;
            State = settings.State;
            DatabaseProvider = settings.DatabaseProvider;
            ConnectionString = settings.ConnectionString;
            TablePrefix = settings.TablePrefix;
        }
 private static bool GetCertificateValidation(IConfigurationSection configServerSection, ConfigurationRoot root, bool def)
 {
     var accept = configServerSection["validate_certificates"];
     if (!string.IsNullOrEmpty(accept))
     {
         bool result;
         string resolved = ResovlePlaceholders(accept, root);
         if (Boolean.TryParse(resolved, out result))
             return result;
     }
     return def;
 }
 private static bool GetEnabled(IConfigurationSection configServerSection, ConfigurationRoot root, bool def)
 {
     var enabled = configServerSection["enabled"];
     if (!string.IsNullOrEmpty(enabled))
     {
         bool result;
         string resolved = ResovlePlaceholders(enabled, root);
         if (Boolean.TryParse(resolved, out result))
             return result;
     }
     return def;
 }
        public void Initialize_WithDefaultSettings()
        {
            // Arrange
            string prefix = "spring:cloud:config";
            ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase();
            HostingEnvironment env = new HostingEnvironment();
            env.EnvironmentName = null;
            ConfigurationRoot root = new ConfigurationRoot(new List<IConfigurationProvider>());

            // Act and Assert
            ConfigServerConfigurationSettingsHelper.Initialize(prefix, settings, env, root);
            ConfigServerTestHelpers.VerifyDefaults(settings);
        }
        private static ConfigServerClientSettings CreateSettings(IHostingEnvironment environment, IEnumerable<IConfigurationProvider> providers, ILoggerFactory logFactory)
        {
            ConfigServerClientSettings settings = new ConfigServerClientSettings();

            if (providers != null)
            {
                ConfigurationRoot existing = new ConfigurationRoot(new List<IConfigurationProvider>(providers));
                Initialize(settings, environment, existing);
            }
   
            return settings;

        }
Example #9
0
        public ConfigurationSection(ConfigurationRoot root, string path)
        {
            if (root == null)
            {
                throw new ArgumentNullException(nameof(root));
            }

            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            _root = root;
            _path = path;
        }
        public ConfigurationSection(ConfigurationRoot root, string path)
        {
            if (root == null)
            {
                throw new ArgumentNullException(nameof(root));
            }

            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            _root = root;
            _path = path;
        }
Example #11
0
        public void Contact()
        {
            // Arrange
            var config = new ConfigurationRoot(new List<IConfigurationProvider> {new MemoryConfigurationProvider(new MemoryConfigurationSource())});
            config["kEY1"] = "keyValue1";
            config["key2"] = "keyValue2";
            config["USERNAME"] = "******";
            var otherSettings = new OtherSettings { Numbers = new int[] { 234, 567 } };
            var options = new OptionsWrapper<OtherSettings>(otherSettings);
            var loggerFactory = new LoggerFactory();
            var logger = loggerFactory.CreateLogger<HomeController>();
            IMemoryCache cache = new MemoryCache(new MemoryCacheOptions());

            HomeController controller = new HomeController(config, options, logger, cache);

            // Act
            ViewResult result = controller.Contact() as ViewResult;

            // Assert
            Assert.Equal("keyValue1 SNeagu 234, 567", result.ViewBag.Message);
        }
Example #12
0
 public ShellSettings()
 {
     RootConfiguration = new ConfigurationRoot(new[] { new InternalConfigurationProvider() });
     State = TenantState.Invalid;
 }
        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;
        }
 private static bool GetFailFast(IConfigurationSection configServerSection, ConfigurationRoot root, bool def)
 {
     var failFast = configServerSection["failFast"];
     if (!string.IsNullOrEmpty(failFast))
     {
         bool result;
         string resolved = ResovlePlaceholders(failFast, root);
         if (Boolean.TryParse(resolved, out result))
             return result;
     }
     return def;
 }
 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);
 }
        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 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 GetUri(IConfigurationSection configServerSection, ConfigurationRoot root, string def)
        {
            // First check for spring:cloud:config:uri
            var uri = configServerSection["uri"];
            if (!string.IsNullOrEmpty(uri))
            {
                return uri;
            }

            // Take default if none of above
            return def;
        }
        private static bool GetCertificateValidation(IConfigurationSection configServerSection, ConfigurationRoot root)
        {
            var accept = configServerSection["validate_certificates"];
            if (!string.IsNullOrEmpty(accept))
            {
                bool result;
                string resolved = ResovlePlaceholders(accept, root);
                if (Boolean.TryParse(resolved, out result))
                    return result;
            }
            return ConfigServerClientSettings.DEFAULT_CERTIFICATE_VALIDATION;

        }
        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 bool GetEnabled(IConfigurationSection configServerSection, ConfigurationRoot root)
        {
            var enabled = configServerSection["enabled"];
            if (!string.IsNullOrEmpty(enabled))
            {
                bool result;
                string resolved = ResovlePlaceholders(enabled, root);
                if (Boolean.TryParse(resolved, out result))
                    return result;
            }
            return ConfigServerClientSettings.DEFAULT_PROVIDER_ENABLED; ;

        }