public ConsulFileConfigurationRepository(
            Cache.IOcelotCache <FileConfiguration> cache,
            IInternalConfigurationRepository repo,
            IConsulClientFactory factory,
            IOcelotLoggerFactory loggerFactory)
        {
            _logger = loggerFactory.CreateLogger <ConsulFileConfigurationRepository>();
            _cache  = cache;

            var internalConfig = repo.Get();

            _configurationKey = "InternalConfiguration";

            string token = null;

            if (!internalConfig.IsError)
            {
                token             = internalConfig.Data.ServiceProviderConfiguration.Token;
                _configurationKey = !string.IsNullOrEmpty(internalConfig.Data.ServiceProviderConfiguration.ConfigurationKey) ?
                                    internalConfig.Data.ServiceProviderConfiguration.ConfigurationKey : _configurationKey;
            }

            var config = new ConsulRegistryConfiguration(internalConfig.Data.ServiceProviderConfiguration.Host,
                                                         internalConfig.Data.ServiceProviderConfiguration.Port, _configurationKey, token);

            _consul = factory.Get(config);
        }
Esempio n. 2
0
 public Consul(
     ConsulRegistryConfiguration config,
     IOcelotLoggerFactory factory,
     IConsulClientFactory clientFactory,
     RedisCache redisCache)
 {
     _redisCache = redisCache;
     _logger     = factory.CreateLogger <Consul>();
     _config     = config;
     _consul     = clientFactory.Get(_config);
 }
Esempio n. 3
0
        public IConsulClient Get(ConsulRegistryConfiguration config)
        {
            return(new ConsulClient(c =>
            {
                c.Address = new Uri($"{config.Scheme}://{config.Host}:{config.Port}");

                if (!string.IsNullOrEmpty(config?.Token))
                {
                    c.Token = config.Token;
                }
            }));
        }
Esempio n. 4
0
        public ConsulFileConfigurationRepository(
            IOptions <FileConfiguration> fileConfiguration,
            Cache.IOcelotCache <FileConfiguration> cache,
            IConsulClientFactory factory,
            IOcelotLoggerFactory loggerFactory)
        {
            _logger = loggerFactory.CreateLogger <ConsulFileConfigurationRepository>();
            _cache  = cache;

            var serviceDiscoveryProvider = fileConfiguration.Value.GlobalConfiguration.ServiceDiscoveryProvider;

            _configurationKey = string.IsNullOrWhiteSpace(serviceDiscoveryProvider.ConfigurationKey) ? "InternalConfiguration" :
                                serviceDiscoveryProvider.ConfigurationKey;

            var config = new ConsulRegistryConfiguration(serviceDiscoveryProvider.Host,
                                                         serviceDiscoveryProvider.Port, _configurationKey, serviceDiscoveryProvider.Token);

            _consul = factory.Get(config);
        }
Esempio n. 5
0
 public ConsulServiceDiscoveryProvider(ConsulRegistryConfiguration config, IOcelotLoggerFactory factory, IConsulClientFactory clientFactory)
 {
     _logger = factory.CreateLogger <ConsulServiceDiscoveryProvider>();
     _config = config;
     _consul = clientFactory.Get(_config);
 }