Пример #1
0
 public async Task <IActionResult> Global(GlobalConfigurationDto configurationDto)
 {
     if (configurationDto.ItemId == 0)
     {
         await _globalConfigurationAppService.CreateAsync(configurationDto);
     }
     else
     {
         await _globalConfigurationAppService.UpdateAsync(configurationDto);
     }
     return(RedirectToAction(nameof(Global)));
 }
        public async Task <GlobalConfigurationDto> CreateAsync(GlobalConfigurationDto configurationDto)
        {
            await CheckPolicyAsync();

            var globalConfiguration = new GlobalConfiguration(_snowflakeIdGenerator.NextId(), configurationDto.BaseUrl);

            globalConfiguration.RequestIdKey     = configurationDto.RequestIdKey;
            globalConfiguration.DownstreamScheme = configurationDto.DownstreamScheme;

            ApplyGlobalConfigurationOptions(globalConfiguration, configurationDto);

            globalConfiguration = await _globalConfigRepository.InsertAsync(globalConfiguration, true);

            await _eventPublisher.PublishAsync(ApiGatewayDomainConsts.Events_OcelotConfigChanged, Clock.Now);

            return(ObjectMapper.Map <GlobalConfiguration, GlobalConfigurationDto>(globalConfiguration));
        }
        public async Task <GlobalConfigurationDto> UpdateAsync(GlobalConfigurationDto configurationDto)
        {
            await CheckPolicyAsync();

            var globalConfiguration = await _globalConfigRepository.GetByItemIdAsync(configurationDto.ItemId);

            globalConfiguration.BaseUrl          = configurationDto.BaseUrl;
            globalConfiguration.RequestIdKey     = configurationDto.RequestIdKey;
            globalConfiguration.DownstreamScheme = configurationDto.DownstreamScheme;

            ApplyGlobalConfigurationOptions(globalConfiguration, configurationDto);

            globalConfiguration = await _globalConfigRepository.UpdateAsync(globalConfiguration, true);

            await _eventPublisher.PublishAsync(ApiGatewayDomainConsts.Events_OcelotConfigChanged, Clock.Now);

            return(ObjectMapper.Map <GlobalConfiguration, GlobalConfigurationDto>(globalConfiguration));
        }
Пример #4
0
        private void ApplyGlobalConfigurationOptions(GlobalConfiguration globalConfiguration, GlobalConfigurationDto configurationDto)
        {
            globalConfiguration.ServiceDiscoveryProvider.Type = configurationDto.ServiceDiscoveryProvider.Type;
            globalConfiguration.ServiceDiscoveryProvider
            .BindServiceRegister(configurationDto.ServiceDiscoveryProvider.Host, configurationDto.ServiceDiscoveryProvider.Port);

            globalConfiguration.HttpHandlerOptions.ApplyAllowAutoRedirect(configurationDto.HttpHandlerOptions.AllowAutoRedirect);
            globalConfiguration.HttpHandlerOptions.ApplyCookieContainer(configurationDto.HttpHandlerOptions.UseCookieContainer);
            globalConfiguration.HttpHandlerOptions.ApplyHttpProxy(configurationDto.HttpHandlerOptions.UseProxy);
            globalConfiguration.HttpHandlerOptions.ApplyHttpTracing(configurationDto.HttpHandlerOptions.UseTracing);

            globalConfiguration.QoSOptions.ApplyQosOptions(configurationDto.QoSOptions.ExceptionsAllowedBeforeBreaking, configurationDto.QoSOptions.DurationOfBreak,
                                                           configurationDto.QoSOptions.TimeoutValue);

            if (!configurationDto.RateLimitOptions.DisableRateLimitHeaders)
            {
                globalConfiguration.RateLimitOptions.ApplyRateLimitOptions(configurationDto.RateLimitOptions.ClientIdHeader, configurationDto.RateLimitOptions.QuotaExceededMessage,
                                                                           configurationDto.RateLimitOptions.HttpStatusCode);
            }

            globalConfiguration.LoadBalancerOptions.ApplyLoadBalancerOptions(configurationDto.LoadBalancerOptions.Type, configurationDto.LoadBalancerOptions.Key,
                                                                             configurationDto.LoadBalancerOptions.Expiry);
        }