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);
        }
 public SwaggerMiddleware(RequestDelegate next, IDictionary <string, SwaggerBuilder> declaredSwaggerBuilders,
                          IInternalConfigurationRepository ocelotConfigurationsRepository)
 {
     _next = next;
     _declaredSwaggerBuilders        = declaredSwaggerBuilders;
     _ocelotConfigurationsRepository = ocelotConfigurationsRepository;
 }
Beispiel #3
0
        public ConsulFileConfigurationRepository(
            Cache.IOcelotCache <FileConfiguration> cache,
            IInternalConfigurationRepository repo,
            IConsulClientFactory factory,
            IOcelotLoggerFactory loggerFactory)
        {
            _logger = loggerFactory.CreateLogger <ConsulFileConfigurationRepository>();
            _cache  = cache;

            var internalConfig = repo.Get();

            var    consulHost = "localhost";
            var    consulPort = 8500;
            string token      = null;

            if (!internalConfig.IsError)
            {
                consulHost = string.IsNullOrEmpty(internalConfig.Data.ServiceProviderConfiguration?.Host) ? consulHost : internalConfig.Data.ServiceProviderConfiguration?.Host;
                consulPort = internalConfig.Data.ServiceProviderConfiguration?.Port ?? consulPort;
                token      = internalConfig.Data.ServiceProviderConfiguration?.Token;
            }

            var config = new ConsulRegistryConfiguration(consulHost, consulPort, OcelotConfiguration, token);

            _consul = factory.Get(config);
        }
Beispiel #4
0
 public InternalConfigurationSetter(
     IInternalConfigurationRepository configRepo,
     IInternalConfigurationCreator configCreator)
 {
     _internalConfigRepo = configRepo;
     _configCreator      = configCreator;
     _logger             = LogManager.GetCurrentClassLogger();
 }
Beispiel #5
0
 public FileAndInternalConfigurationSetter(
     IInternalConfigurationRepository configRepo,
     IInternalConfigurationCreator configCreator,
     IFileConfigurationRepository repo)
 {
     internalConfigRepo = configRepo;
     _configCreator     = configCreator;
     _repo = repo;
 }
Beispiel #6
0
 public ConfigurationController(
     IFileConfigurationRepository configDbRepo,
     IInternalConfigurationRepository configUsingRepo,
     IFileConfigurationSetter setter)
 {
     _logger          = LogManager.GetLogger("apigatewayadmin");
     _setter          = setter;
     _configRepo      = configDbRepo;
     _configUsingRepo = configUsingRepo;
 }
        private static IInternalConfiguration GetOcelotConfigAndReturn(IInternalConfigurationRepository provider)
        {
            var ocelotConfiguration = provider.Get();

            if (ocelotConfiguration?.Data == null || ocelotConfiguration.IsError)
            {
                ThrowToStopOcelotStarting(ocelotConfiguration);
            }
            return(ocelotConfiguration.Data);
        }
 public ExceptionHandlerMiddleware(OcelotRequestDelegate next,
                                   IOcelotLoggerFactory loggerFactory,
                                   IInternalConfigurationRepository configRepo,
                                   IRequestScopedDataRepository repo)
     : base(loggerFactory.CreateLogger <ExceptionHandlerMiddleware>())
 {
     _configRepo = configRepo;
     _repo       = repo;
     _next       = next;
 }
        private static IInternalConfiguration GetOcelotConfigAndReturn(IInternalConfigurationRepository provider)
        {
            Response <IInternalConfiguration> response = provider.Get();

            if (response?.Data == null || response.IsError)
            {
                ThrowToStopOcelotStarting(response);
            }
            return(response.Data);
        }
Beispiel #10
0
 public OcelotSwaggerMiddleware(
     RequestDelegate next,
     IOptionsMonitor <OcelotSwaggerOptions> optionsAccessor,
     IInternalConfigurationRepository internalConfiguration,
     IDistributedCache cache)
 {
     this._next    = next;
     this._options = optionsAccessor.CurrentValue;
     this._internalConfiguration = internalConfiguration;
     this._cache = cache;
 }
Beispiel #11
0
 public OcelotConfigurationChangedEventHandler(
     IFileConfigurationRepository fileConfigRepo,
     IInternalConfigurationRepository internalConfigRepo,
     IInternalConfigurationCreator internalConfigCreator,
     ILogger <OcelotConfigurationChangedEventHandler> logger)
 {
     _fileConfigRepo        = fileConfigRepo;
     _internalConfigRepo    = internalConfigRepo;
     _internalConfigCreator = internalConfigCreator;
     _logger = logger;
 }
 public DBConfigurationPoller(IOcelotLoggerFactory ocelotLoggerFactory,
                              IFileConfigurationRepository fileConfigurationRepository,
                              IInternalConfigurationRepository internalConfigurationRepository,
                              IInternalConfigurationCreator internalConfigurationCreator,
                              GatewayConfiguration gatewayConfiguration)
 {
     _internalConfigRepo    = internalConfigurationRepository;
     _internalConfigCreator = internalConfigurationCreator;
     _logger = ocelotLoggerFactory.CreateLogger <DBConfigurationPoller>();
     _repo   = fileConfigurationRepository;
     _option = gatewayConfiguration;
 }
Beispiel #13
0
 public DownstreamRouteFinderMiddleware(OcelotRequestDelegate next,
                                        IOcelotLoggerFactory loggerFactory,
                                        IDownstreamRouteFinder downstreamRouteFinder,
                                        IInternalConfigurationRepository repo,
                                        IMultiplexer multiplexer)
     : base(loggerFactory.CreateLogger <DownstreamRouteFinderMiddleware>())
 {
     _repo                  = repo;
     _multiplexer           = multiplexer;
     _next                  = next;
     _downstreamRouteFinder = downstreamRouteFinder;
 }
Beispiel #14
0
 public DbConfigurationPoller(IOcelotLoggerFactory factory,
                              IFileConfigurationRepository repo,
                              IInternalConfigurationRepository internalConfigRepo,
                              IInternalConfigurationCreator internalConfigCreator,
                              AhphOcelotConfiguration option)
 {
     _internalConfigRepo    = internalConfigRepo;
     _internalConfigCreator = internalConfigCreator;
     _logger = factory.CreateLogger <DbConfigurationPoller>();
     _repo   = repo;
     _option = option;
 }
Beispiel #15
0
 public UpdateFileConfigurationEventHandler(ConfigCacheOptions option,
                                            IFileConfigurationRepository fileConfigurationRepository,
                                            IAbpFileConfigurationRepository abpFileConfigurationRepository,
                                            IInternalConfigurationRepository internalConfigRepo,
                                            IInternalConfigurationCreator internalConfigCreator,
                                            ILogger <UpdateFileConfigurationEventHandler> logger)
 {
     _option = option;
     _fileConfigurationRepository    = fileConfigurationRepository;
     _abpFileConfigurationRepository = abpFileConfigurationRepository;
     _internalConfigRepo             = internalConfigRepo;
     _internalConfigCreator          = internalConfigCreator;
     _logger = logger;
 }
Beispiel #16
0
        public ApigatewayConfigChangeEventHandler(
            IOptions <ApiGatewayOptions> options,
            IFileConfigurationRepository fileConfigRepo,
            IInternalConfigurationRepository internalConfigRepo,
            IInternalConfigurationCreator internalConfigCreator,
            ILogger <ApigatewayConfigChangeEventHandler> logger)
        {
            _fileConfigRepo        = fileConfigRepo;
            _internalConfigRepo    = internalConfigRepo;
            _internalConfigCreator = internalConfigCreator;
            _logger = logger;

            Options = options.Value;
        }
 public FileConfigurationPoller(
     IOcelotLoggerFactory factory,
     IFileConfigurationRepository repo,
     IFileConfigurationPollerOptions options,
     IInternalConfigurationRepository internalConfigRepo,
     IInternalConfigurationCreator internalConfigCreator)
 {
     _internalConfigRepo    = internalConfigRepo;
     _internalConfigCreator = internalConfigCreator;
     _options        = options;
     _logger         = factory.CreateLogger <FileConfigurationPoller>();
     _repo           = repo;
     _previousAsJson = "";
 }
Beispiel #18
0
 public SwaggerMiddleware(RequestDelegate next,
                          IMemoryCache cache,
                          IOptions <SwaggerOptions> options,
                          Func <Dictionary <string, string> > servicesFactory,
                          SwaggerBuilder builder,
                          IHttpClientFactory httpClientFactory,
                          IInternalConfigurationRepository configRepository)
 {
     _next              = next;
     _cache             = cache;
     _options           = options.Value;
     _servicesFactory   = servicesFactory;
     _builder           = builder;
     _httpClientFactory = httpClientFactory;
     _configRepository  = configRepository;
 }
        private static async Task <IInternalConfiguration> CreateConfiguration(IApplicationBuilder builder)
        {
            var fileConfigRepo = builder.ApplicationServices.GetRequiredService <IFileConfigurationRepository>();
            var fileConfig     = await fileConfigRepo.Get();

            // IOptionsMonitor<FileConfiguration> fileConfig = builder.ApplicationServices.GetService<IOptionsMonitor<FileConfiguration>>();
            IInternalConfigurationCreator     internalConfigCreator = builder.ApplicationServices.GetService <IInternalConfigurationCreator>();
            Response <IInternalConfiguration> response = await internalConfigCreator.Create(fileConfig.Data);

            if (response.IsError)
            {
                ThrowToStopOcelotStarting(response);
            }
            IInternalConfigurationRepository internalConfigRepo = builder.ApplicationServices.GetService <IInternalConfigurationRepository>();

            internalConfigRepo.AddOrReplace(response.Data);
            return(GetOcelotConfigAndReturn(internalConfigRepo));
        }
Beispiel #20
0
        public FilePeersProvider(IOptions <FilePeers> options, IBaseUrlFinder finder, IInternalConfigurationRepository repo, IIdentityServerConfiguration identityServerConfig)
        {
            _identityServerConfig = identityServerConfig;
            _repo    = repo;
            _finder  = finder;
            _options = options;
            _peers   = new List <IPeer>();

            var config = _repo.Get();

            foreach (var item in _options.Value.Peers)
            {
                var httpClient = new HttpClient();

                //todo what if this errors?
                var httpPeer = new HttpPeer(item.HostAndPort, httpClient, _finder, config.Data, _identityServerConfig);
                _peers.Add(httpPeer);
            }
        }
        public MySqlFileConfigurationRepository(
            Cache.IOcelotCache <FileConfiguration> cache,
            IInternalConfigurationRepository repo,
            IOcelotLoggerFactory loggerFactory,
            OcelotConfigDbDal configDbDal)
        {
            _logger      = loggerFactory.CreateLogger <MySqlFileConfigurationRepository>();
            _cache       = cache;
            _configDbDal = configDbDal;

            var internalConfig = repo.Get();

            _configurationKey = "InternalConfiguration";
            if (!internalConfig.IsError)
            {
                _configurationKey = !string.IsNullOrEmpty(internalConfig.Data.ServiceProviderConfiguration.ConfigurationKey) ?
                                    internalConfig.Data.ServiceProviderConfiguration.ConfigurationKey : _configurationKey;
            }
        }
Beispiel #22
0
        /// <summary>
        /// 设置存储配置信息
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="fileConfigRepo"></param>
        /// <param name="internalConfigCreator"></param>
        /// <param name="internalConfigRepo"></param>
        /// <returns></returns>
        internal static async Task SetFileConfigInDataBase(
            IFileConfigurationRepository fileConfigRepo,
            IInternalConfigurationCreator internalConfigCreator, IInternalConfigurationRepository internalConfigRepo)
        {
            // 从redis中获取数据
            var fileConfigFromDataBase = await fileConfigRepo.Get().ConfigureAwait(false);

            if (IsError(fileConfigFromDataBase))
            {
                ThrowToStopOcelotStarting(fileConfigFromDataBase);
            }
            else
            {
                //设置存储
                await fileConfigRepo.Set(fileConfigFromDataBase.Data).ConfigureAwait(false);

                // create the internal config from consul data
                var internalConfig = await internalConfigCreator.Create(fileConfigFromDataBase.Data).ConfigureAwait(false);

                if (IsError(internalConfig))
                {
                    ThrowToStopOcelotStarting(internalConfig);
                }
                else
                {
                    //
                    var response = internalConfigRepo.AddOrReplace(internalConfig.Data);

                    if (IsError(response))
                    {
                        ThrowToStopOcelotStarting(response);
                    }
                }

                if (IsError(internalConfig))
                {
                    ThrowToStopOcelotStarting(internalConfig);
                }
            }
        }
        private static async Task <IInternalConfiguration> CreateConfiguration(IApplicationBuilder builder)
        {
            /* 因为ABP框架中,Abp.HttpClient这个模块里面
             * RemoteServiceOptions 是用的IOptionsSnapshot注入的,这里会出现一个异常
             * 每个RemoteService服务必须在一个请求范围内
             * 解决方案为重写DynamicHttpProxyInterceptor类,替换IOptions<RemoteServiceOptions>
             * 网关不需要实现网关后台服务地址的实时更新
             */
            var fileConfigRepo = builder.ApplicationServices.GetRequiredService <IFileConfigurationRepository>();
            var fileConfig     = await fileConfigRepo.Get();

            // IOptionsMonitor<FileConfiguration> fileConfig = builder.ApplicationServices.GetService<IOptionsMonitor<FileConfiguration>>();
            IInternalConfigurationCreator     internalConfigCreator = builder.ApplicationServices.GetService <IInternalConfigurationCreator>();
            Response <IInternalConfiguration> response = await internalConfigCreator.Create(fileConfig.Data);

            if (response.IsError)
            {
                ThrowToStopOcelotStarting(response);
            }
            IInternalConfigurationRepository internalConfigRepo = builder.ApplicationServices.GetService <IInternalConfigurationRepository>();

            internalConfigRepo.AddOrReplace(response.Data);
            return(GetOcelotConfigAndReturn(internalConfigRepo));
        }
Beispiel #24
0
 public OcelotConfigurationMonitor(IInternalConfigurationRepository repo, IOcelotConfigurationChangeTokenSource changeTokenSource)
 {
     _changeTokenSource = changeTokenSource;
     _repo = repo;
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="serv"></param>
        /// <param name="configClient"></param>
        /// <param name="serviceProvider"></param>
        /// <param name="_internalConfigurationRepo"></param>
        /// <param name="_internalConfigurationCreator"></param>
        public OcelotConfigurationTask(INacosNamingService serv, INacosConfigService configClient, IServiceProvider serviceProvider, IInternalConfigurationRepository _internalConfigurationRepo, IInternalConfigurationCreator _internalConfigurationCreator)
        {
            _configClient = configClient;
            _servClient   = serv;
            nacosConfigListener.internalConfigurationRepo    = _internalConfigurationRepo;
            nacosConfigListener.internalConfigurationCreator = _internalConfigurationCreator;
            OcelotConfig      = Appsettings.GetValue("ApiGateWay:OcelotConfig");
            OcelotConfigGroup = Appsettings.GetValue("ApiGateWay:OcelotConfigGroup");
            AppConfig         = Appsettings.GetValue("ApiGateWay:AppConfig");
            AppConfigGroup    = Appsettings.GetValue("ApiGateWay:AppConfigGroup");



            string OcelotCfg = configClient.GetConfig(OcelotConfig, OcelotConfigGroup, 10000).GetAwaiter().GetResult();

            nacosConfigListener.ReceiveConfigInfo(OcelotCfg);
            string AppCfg = configClient.GetConfig(AppConfig, AppConfigGroup, 10000).GetAwaiter().GetResult();

            AppConfigListener.ReceiveConfigInfo(AppCfg);
            //string sss = serv.Cof_NaoceGet("fld-cloud-datax", "DEFAULT_GROUP", "/api/base/deviceList?limit=10&page=1").GetAwaiter().GetResult();
        }
Beispiel #26
0
 public ConfigurationMiddleware(RequestDelegate next, IOcelotLoggerFactory loggerFactory, IInternalConfigurationRepository configRepo)
     : base(loggerFactory.CreateLogger <ExceptionHandlerMiddleware>())
 {
     _next       = next;
     _configRepo = configRepo;
 }
        private static async Task SetFileConfigInZookeeper(IApplicationBuilder builder,
                                                           IFileConfigurationRepository fileConfigRepo, IOptionsMonitor <FileConfiguration> fileConfig,
                                                           IInternalConfigurationCreator internalConfigCreator, IInternalConfigurationRepository internalConfigRepo)
        {
            // get the config from Zookeeper.
            var fileConfigFromZookeeper = await fileConfigRepo.Get();

            if (IsError(fileConfigFromZookeeper))
            {
                ThrowToStopOcelotStarting(fileConfigFromZookeeper);
            }
            else if (ConfigNotStoredInZookeeper(fileConfigFromZookeeper))
            {
                //there was no config in Zookeeper set the file in config in Zookeeper
                await fileConfigRepo.Set(fileConfig.CurrentValue);
            }
            else
            {
                // create the internal config from Zookeeper data
                var internalConfig = await internalConfigCreator.Create(fileConfigFromZookeeper.Data);

                if (IsError(internalConfig))
                {
                    ThrowToStopOcelotStarting(internalConfig);
                }
                else
                {
                    // add the internal config to the internal repo
                    var response = internalConfigRepo.AddOrReplace(internalConfig.Data);

                    if (IsError(response))
                    {
                        ThrowToStopOcelotStarting(response);
                    }
                }

                if (IsError(internalConfig))
                {
                    ThrowToStopOcelotStarting(internalConfig);
                }
            }
        }
Beispiel #28
0
        private static async Task SetFileConfigInConsul(IApplicationBuilder builder,
                                                        IFileConfigurationRepository fileConfigRepo, IOptions <FileConfiguration> fileConfig,
                                                        IInternalConfigurationCreator internalConfigCreator, IInternalConfigurationRepository internalConfigRepo)
        {
            // get the config from consul.
            var fileConfigFromConsul = await fileConfigRepo.Get();

            if (IsError(fileConfigFromConsul))
            {
                ThrowToStopOcelotStarting(fileConfigFromConsul);
            }
            else if (ConfigNotStoredInConsul(fileConfigFromConsul))
            {
                //there was no config in consul set the file in config in consul
                await fileConfigRepo.Set(fileConfig.Value);
            }
            else
            {
                // create the internal config from consul data
                var internalConfig = await internalConfigCreator.Create(fileConfigFromConsul.Data);

                if (IsError(internalConfig))
                {
                    ThrowToStopOcelotStarting(internalConfig);
                }
                else
                {
                    // add the internal config to the internal repo
                    var response = internalConfigRepo.AddOrReplace(internalConfig.Data);

                    if (IsError(response))
                    {
                        ThrowToStopOcelotStarting(response);
                    }
                }

                if (IsError(internalConfig))
                {
                    ThrowToStopOcelotStarting(internalConfig);
                }
            }

            //todo - this starts the poller if it has been registered...please this is so bad.
            var hack = builder.ApplicationServices.GetService(typeof(ConsulFileConfigurationPoller));
        }
        private static async Task SetFileConfigInSqlServer(IApplicationBuilder builder,
                                                           IFileConfigurationRepository fileConfigRepo, IOptionsMonitor <FileConfiguration> fileConfig,
                                                           IInternalConfigurationCreator internalConfigCreator, IInternalConfigurationRepository internalConfigRepo)
        {
            var fileConfigFromSqlServer = await fileConfigRepo.Get();

            if (IsError(fileConfigFromSqlServer))
            {
                ThrowToStopOcelotStarting(fileConfigFromSqlServer);
            }
            else if (ConfigNotStoredInConsul(fileConfigFromSqlServer))
            {
                await fileConfigRepo.Set(fileConfig.CurrentValue);
            }
            else
            {
                var internalConfig = await internalConfigCreator.Create(fileConfigFromSqlServer.Data);

                if (IsError(internalConfig))
                {
                    ThrowToStopOcelotStarting(internalConfig);
                }
                else
                {
                    var response = internalConfigRepo.AddOrReplace(internalConfig.Data);

                    if (IsError(response))
                    {
                        ThrowToStopOcelotStarting(response);
                    }
                }

                if (IsError(internalConfig))
                {
                    ThrowToStopOcelotStarting(internalConfig);
                }
            }
        }
Beispiel #30
0
 public ResolveFabricEndpointsHostedService(IInternalConfigurationRepository internalConfigurationRepository, IServiceFabricEndpointDiscovery serviceFabricEndpointDiscovery)
 {
     _internalConfigurationRepository = internalConfigurationRepository;
     _serviceFabricEndpointDiscovery  = serviceFabricEndpointDiscovery;
 }