示例#1
0
        public void TestPreferredNetworksListIsEmpty()
        {
            InetOptions properties = new InetOptions();

            InetUtils utils = new InetUtils(properties);

            Assert.True(utils.IsPreferredAddress(IPAddress.Parse("192.168.0.1")));
            Assert.True(utils.IsPreferredAddress(IPAddress.Parse("5.5.8.1")));
            Assert.True(utils.IsPreferredAddress(IPAddress.Parse("10.255.10.1")));
            Assert.True(utils.IsPreferredAddress(IPAddress.Parse("10.0.10.1")));
        }
示例#2
0
        public void TestSiteLocalAddresses()
        {
            InetOptions properties = new InetOptions()
            {
                UseOnlySiteLocalInterfaces = true
            };

            InetUtils utils = new InetUtils(properties);

            Assert.True(utils.IsPreferredAddress(IPAddress.Parse("192.168.0.1")));
            Assert.False(utils.IsPreferredAddress(IPAddress.Parse("5.5.8.1")));
        }
示例#3
0
        public void TestIgnoreInterface()
        {
            InetOptions properties = new InetOptions()
            {
                IgnoredInterfaces = "docker0,veth.*"
            };

            InetUtils inetUtils = new InetUtils(properties);

            Assert.True(inetUtils.IgnoreInterface("docker0"));
            Assert.True(inetUtils.IgnoreInterface("vethAQI2QT"));
            Assert.False(inetUtils.IgnoreInterface("docker1"));
        }
示例#4
0
        public void TestPreferredNetworksRegex()
        {
            InetOptions properties = new InetOptions()
            {
                PreferredNetworks = "192.168.*,10.0.*"
            };

            InetUtils utils = new InetUtils(properties);

            Assert.True(utils.IsPreferredAddress(IPAddress.Parse("192.168.0.1")));
            Assert.False(utils.IsPreferredAddress(IPAddress.Parse("5.5.8.1")));
            Assert.True(utils.IsPreferredAddress(IPAddress.Parse("10.0.10.1")));
            Assert.False(utils.IsPreferredAddress(IPAddress.Parse("10.255.10.1")));
        }
示例#5
0
        public void TestPreferredNetworksSimple()
        {
            var properties = new InetOptions()
            {
                PreferredNetworks = "192,10.0"
            };

            var utils = new InetUtils(properties, GetLogger());

            Assert.True(utils.IsPreferredAddress(IPAddress.Parse("192.168.0.1")));
            Assert.False(utils.IsPreferredAddress(IPAddress.Parse("5.5.8.1")));
            Assert.False(utils.IsPreferredAddress(IPAddress.Parse("10.255.10.1")));
            Assert.True(utils.IsPreferredAddress(IPAddress.Parse("10.0.10.1")));
        }
示例#6
0
        private static void ConfigureConsulServices(IServiceCollection services, IConfiguration config, InetOptions netOptions)
        {
            var consulSection = config.GetSection(ConsulOptions.CONSUL_CONFIGURATION_PREFIX);

            services.Configure <ConsulOptions>(consulSection);
            services.PostConfigure <ConsulOptions>(options => ConsulPostConfigurer.ValidateConsulOptions(options));
            var consulDiscoverySection = config.GetSection(ConsulDiscoveryOptions.CONSUL_DISCOVERY_CONFIGURATION_PREFIX);

            services.Configure <ConsulDiscoveryOptions>(consulDiscoverySection);
            services.PostConfigure <ConsulDiscoveryOptions>(options => ConsulPostConfigurer.UpdateDiscoveryOptions(config, options, netOptions));
            services.TryAddSingleton(serviceProvider =>
            {
                var clientOptions = serviceProvider.GetRequiredService <IOptions <ConsulDiscoveryOptions> >();
                return(new DistributedCacheEntryOptions {
                    AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(clientOptions.Value.CacheTTL)
                });
            });
        }
        private static void ConfigureEurekaServices(IServiceCollection services, IConfiguration config, IServiceInfo info, InetOptions netOptions)
        {
            var einfo         = info as EurekaServiceInfo;
            var clientSection = config.GetSection(EurekaClientOptions.EUREKA_CLIENT_CONFIGURATION_PREFIX);

            services.Configure <EurekaClientOptions>(clientSection);
            services.PostConfigure <EurekaClientOptions>((options) =>
            {
                EurekaPostConfigurer.UpdateConfiguration(config, einfo, options);
            });

            var instSection = config.GetSection(EurekaInstanceOptions.EUREKA_INSTANCE_CONFIGURATION_PREFIX);

            services.Configure <EurekaInstanceOptions>(instSection);
            services.PostConfigure <EurekaInstanceOptions>((options) =>
            {
                IApplicationInstanceInfo appInfo = null;
                if (einfo?.ApplicationInfo == null)
                {
                    appInfo = services.GetApplicationInstanceInfo();
                }

                options.NetUtils = new InetUtils(netOptions);
                options.ApplyNetUtils();
                EurekaPostConfigurer.UpdateConfiguration(config, einfo, options, einfo?.ApplicationInfo ?? appInfo);
            });
        }
        private static void ConfigureConsulServices(IServiceCollection services, IConfiguration config, IServiceInfo info, InetOptions netOptions)
        {
            var consulSection = config.GetSection(ConsulOptions.CONSUL_CONFIGURATION_PREFIX);

            services.Configure <ConsulOptions>(consulSection);
            var consulDiscoverySection = config.GetSection(ConsulDiscoveryOptions.CONSUL_DISCOVERY_CONFIGURATION_PREFIX);

            services.Configure <ConsulDiscoveryOptions>(consulDiscoverySection);
            services.PostConfigure <ConsulDiscoveryOptions>(options =>
            {
                options.NetUtils = new InetUtils(netOptions);
                options.ApplyNetUtils();
            });
        }
示例#9
0
 /// <summary>
 /// Perform post-configuration on ConsulDiscoveryOptions
 /// </summary>
 /// <param name="config">Application Configuration</param>
 /// <param name="options">ConsulDiscoveryOptions to configure</param>
 /// <param name="netOptions">Optional InetOptions</param>
 public static void UpdateDiscoveryOptions(IConfiguration config, ConsulDiscoveryOptions options, InetOptions netOptions)
 {
     options.NetUtils = new InetUtils(netOptions);
     options.ApplyNetUtils();
     options.ApplyConfigUrls(config.GetAspNetCoreUrls(), ConfigurationUrlHelpers.WILDCARD_HOST);
 }
示例#10
0
        private static void ConfigureConsulServices(IServiceCollection services, IConfiguration config, InetOptions netOptions)
        {
            var consulSection = config.GetSection(ConsulOptions.CONSUL_CONFIGURATION_PREFIX);

            services.Configure <ConsulOptions>(consulSection);
            var consulDiscoverySection = config.GetSection(ConsulDiscoveryOptions.CONSUL_DISCOVERY_CONFIGURATION_PREFIX);

            services.Configure <ConsulDiscoveryOptions>(consulDiscoverySection);
            services.PostConfigure <ConsulDiscoveryOptions>(options =>
            {
                options.NetUtils = new InetUtils(netOptions);
                options.ApplyNetUtils();
                options.ApplyConfigUrls(config.GetAspNetCoreUrls(), ConfigurationUrlHelpers.WILDCARD_HOST);
            });
            services.TryAddSingleton(serviceProvider =>
            {
                var clientOptions = serviceProvider.GetRequiredService <IOptions <ConsulDiscoveryOptions> >();
                return(new DistributedCacheEntryOptions {
                    AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(clientOptions.Value.CacheTTL)
                });
            });
        }
示例#11
0
        private static void ConfigureEurekaServices(IServiceCollection services, IConfiguration config, IServiceInfo info, InetOptions netOptions)
        {
            var einfo         = info as EurekaServiceInfo;
            var clientSection = config.GetSection(EurekaClientOptions.EUREKA_CLIENT_CONFIGURATION_PREFIX);

            services.Configure <EurekaClientOptions>(clientSection);
            services.PostConfigure <EurekaClientOptions>((options) =>
            {
                EurekaPostConfigurer.UpdateConfiguration(config, einfo, options);
            });

            var instSection = config.GetSection(EurekaInstanceOptions.EUREKA_INSTANCE_CONFIGURATION_PREFIX);

            services.Configure <EurekaInstanceOptions>(instSection);
            services.PostConfigure <EurekaInstanceOptions>((options) =>
            {
                IApplicationInstanceInfo appInfo = null;
                if (einfo?.ApplicationInfo == null)
                {
                    appInfo = services.GetApplicationInstanceInfo();
                }

                options.NetUtils = new InetUtils(netOptions);
                options.ApplyNetUtils();
                EurekaPostConfigurer.UpdateConfiguration(config, einfo, options, einfo?.ApplicationInfo ?? appInfo);
            });
            services.TryAddSingleton(serviceProvider =>
            {
                var clientOptions = serviceProvider.GetRequiredService <IOptions <EurekaClientOptions> >();
                return(new DistributedCacheEntryOptions {
                    AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(clientOptions.Value.CacheTTL)
                });
            });
        }