public InternalConfiguration Create(FileConfiguration fileConfiguration, List <Route> routes)
        {
            var serviceProviderConfiguration = _serviceProviderConfigCreator.Create(fileConfiguration.GlobalConfiguration);

            var lbOptions = _loadBalancerOptionsCreator.Create(fileConfiguration.GlobalConfiguration.LoadBalancerOptions);

            var qosOptions = _qosOptionsCreator.Create(fileConfiguration.GlobalConfiguration.QoSOptions);

            var httpHandlerOptions = _httpHandlerOptionsCreator.Create(fileConfiguration.GlobalConfiguration.HttpHandlerOptions);

            var adminPath = _adminPath != null ? _adminPath.Path : null;

            var version = _versionCreator.Create(fileConfiguration.GlobalConfiguration.DownstreamHttpVersion);

            return(new InternalConfiguration(routes,
                                             adminPath,
                                             serviceProviderConfiguration,
                                             fileConfiguration.GlobalConfiguration.RequestIdKey,
                                             lbOptions,
                                             fileConfiguration.GlobalConfiguration.DownstreamScheme,
                                             qosOptions,
                                             httpHandlerOptions,
                                             version
                                             ));
        }
        private async Task <Response <IInternalConfiguration> > SetUpConfiguration(FileConfiguration fileConfiguration)
        {
            var response = await _configurationValidator.IsValid(fileConfiguration);

            if (response.Data.IsError)
            {
                return(new ErrorResponse <IInternalConfiguration>(response.Data.Errors));
            }

            var reRoutes = new List <ReRoute>();

            foreach (var reRoute in fileConfiguration.ReRoutes)
            {
                var downstreamReRoute = SetUpDownstreamReRoute(reRoute, fileConfiguration.GlobalConfiguration);

                var ocelotReRoute = SetUpReRoute(reRoute, downstreamReRoute);

                reRoutes.Add(ocelotReRoute);
            }

            foreach (var aggregate in fileConfiguration.Aggregates)
            {
                var ocelotReRoute = SetUpAggregateReRoute(reRoutes, aggregate, fileConfiguration.GlobalConfiguration);
                reRoutes.Add(ocelotReRoute);
            }

            var serviceProviderConfiguration = _serviceProviderConfigCreator.Create(fileConfiguration.GlobalConfiguration);

            var lbOptions = CreateLoadBalancerOptions(fileConfiguration.GlobalConfiguration.LoadBalancerOptions);

            var qosOptions = _qosOptionsCreator.Create(fileConfiguration.GlobalConfiguration.QoSOptions);

            var httpHandlerOptions = _httpHandlerOptionsCreator.Create(fileConfiguration.GlobalConfiguration.HttpHandlerOptions);

            var config = new InternalConfiguration(reRoutes,
                                                   _adminPath.Path,
                                                   serviceProviderConfiguration,
                                                   fileConfiguration.GlobalConfiguration.RequestIdKey,
                                                   lbOptions,
                                                   fileConfiguration.GlobalConfiguration.DownstreamScheme,
                                                   qosOptions,
                                                   httpHandlerOptions
                                                   );

            return(new OkResponse <IInternalConfiguration>(config));
        }
        private ReRoute SetUpReRoute(FileReRoute fileReRoute, FileGlobalConfiguration globalConfiguration)
        {
            var fileReRouteOptions = _fileReRouteOptionsCreator.Create(fileReRoute);

            var requestIdKey = _requestIdKeyCreator.Create(fileReRoute, globalConfiguration);

            var reRouteKey = CreateReRouteKey(fileReRoute);

            var upstreamTemplatePattern = _upstreamTemplatePatternCreator.Create(fileReRoute);

            var authOptionsForRoute = _authOptionsCreator.Create(fileReRoute);

            var claimsToHeaders = _claimsToThingCreator.Create(fileReRoute.AddHeadersToRequest);

            var claimsToClaims = _claimsToThingCreator.Create(fileReRoute.AddClaimsToRequest);

            var claimsToQueries = _claimsToThingCreator.Create(fileReRoute.AddQueriesToRequest);

            var qosOptions = _qosOptionsCreator.Create(fileReRoute);

            var rateLimitOption = _rateLimitOptionsCreator.Create(fileReRoute, globalConfiguration, fileReRouteOptions.EnableRateLimiting);

            var region = _regionCreator.Create(fileReRoute);

            var httpHandlerOptions = _httpHandlerOptionsCreator.Create(fileReRoute);

            var reRoute = new ReRouteBuilder()
                          .WithDownstreamPathTemplate(fileReRoute.DownstreamPathTemplate)
                          .WithUpstreamPathTemplate(fileReRoute.UpstreamPathTemplate)
                          .WithUpstreamHttpMethod(fileReRoute.UpstreamHttpMethod)
                          .WithUpstreamTemplatePattern(upstreamTemplatePattern)
                          .WithIsAuthenticated(fileReRouteOptions.IsAuthenticated)
                          .WithAuthenticationOptions(authOptionsForRoute)
                          .WithClaimsToHeaders(claimsToHeaders)
                          .WithClaimsToClaims(claimsToClaims)
                          .WithRouteClaimsRequirement(fileReRoute.RouteClaimsRequirement)
                          .WithIsAuthorised(fileReRouteOptions.IsAuthorised)
                          .WithClaimsToQueries(claimsToQueries)
                          .WithRequestIdKey(requestIdKey)
                          .WithIsCached(fileReRouteOptions.IsCached)
                          .WithCacheOptions(new CacheOptions(fileReRoute.FileCacheOptions.TtlSeconds, region))
                          .WithDownstreamScheme(fileReRoute.DownstreamScheme)
                          .WithLoadBalancer(fileReRoute.LoadBalancer)
                          .WithDownstreamHost(fileReRoute.DownstreamHost)
                          .WithDownstreamPort(fileReRoute.DownstreamPort)
                          .WithReRouteKey(reRouteKey)
                          .WithIsQos(fileReRouteOptions.IsQos)
                          .WithQosOptions(qosOptions)
                          .WithEnableRateLimiting(fileReRouteOptions.EnableRateLimiting)
                          .WithRateLimitOptions(rateLimitOption)
                          .WithHttpHandlerOptions(httpHandlerOptions)
                          .WithServiceName(fileReRoute.ServiceName)
                          .WithUseServiceDiscovery(fileReRoute.UseServiceDiscovery)
                          .Build();

            return(reRoute);
        }
 private void WhenICreateHttpHandlerOptions()
 {
     _httpHandlerOptions = _httpHandlerOptionsCreator.Create(_fileReRoute);
 }
Beispiel #5
0
        private DownstreamReRoute SetUpDownstreamReRoute(FileReRoute fileReRoute, FileGlobalConfiguration globalConfiguration)
        {
            var fileReRouteOptions = _fileReRouteOptionsCreator.Create(fileReRoute);

            var requestIdKey = _requestIdKeyCreator.Create(fileReRoute, globalConfiguration);

            var reRouteKey = _reRouteKeyCreator.Create(fileReRoute);

            var upstreamTemplatePattern = _upstreamTemplatePatternCreator.Create(fileReRoute);

            var authOptionsForRoute = _authOptionsCreator.Create(fileReRoute);

            var claimsToHeaders = _claimsToThingCreator.Create(fileReRoute.AddHeadersToRequest);

            var claimsToClaims = _claimsToThingCreator.Create(fileReRoute.AddClaimsToRequest);

            var claimsToQueries = _claimsToThingCreator.Create(fileReRoute.AddQueriesToRequest);

            var qosOptions = _qosOptionsCreator.Create(fileReRoute.QoSOptions, fileReRoute.UpstreamPathTemplate, fileReRoute.UpstreamHttpMethod);

            var rateLimitOption = _rateLimitOptionsCreator.Create(fileReRoute.RateLimitOptions, globalConfiguration);

            var region = _regionCreator.Create(fileReRoute);

            var httpHandlerOptions = _httpHandlerOptionsCreator.Create(fileReRoute.HttpHandlerOptions);

            var hAndRs = _headerFAndRCreator.Create(fileReRoute);

            var downstreamAddresses = _downstreamAddressesCreator.Create(fileReRoute);

            var lbOptions = _loadBalancerOptionsCreator.Create(fileReRoute.LoadBalancerOptions);

            var securityOptions = _securityOptionsCreator.Create(fileReRoute.SecurityOptions);

            var reRoute = new DownstreamReRouteBuilder()
                          .WithKey(fileReRoute.Key)
                          .WithDownstreamPathTemplate(fileReRoute.DownstreamPathTemplate)
                          .WithUpstreamHttpMethod(fileReRoute.UpstreamHttpMethod)
                          .WithUpstreamPathTemplate(upstreamTemplatePattern)
                          .WithIsAuthenticated(fileReRouteOptions.IsAuthenticated)
                          .WithAuthenticationOptions(authOptionsForRoute)
                          .WithClaimsToHeaders(claimsToHeaders)
                          .WithClaimsToClaims(claimsToClaims)
                          .WithRouteClaimsRequirement(fileReRoute.RouteClaimsRequirement)
                          .WithIsAuthorised(fileReRouteOptions.IsAuthorised)
                          .WithClaimsToQueries(claimsToQueries)
                          .WithRequestIdKey(requestIdKey)
                          .WithIsCached(fileReRouteOptions.IsCached)
                          .WithCacheOptions(new CacheOptions(fileReRoute.FileCacheOptions.TtlSeconds, region))
                          .WithDownstreamScheme(fileReRoute.DownstreamScheme)
                          .WithLoadBalancerOptions(lbOptions)
                          .WithDownstreamAddresses(downstreamAddresses)
                          .WithLoadBalancerKey(reRouteKey)
                          .WithQosOptions(qosOptions)
                          .WithEnableRateLimiting(fileReRouteOptions.EnableRateLimiting)
                          .WithRateLimitOptions(rateLimitOption)
                          .WithHttpHandlerOptions(httpHandlerOptions)
                          .WithServiceName(fileReRoute.ServiceName)
                          .WithUseServiceDiscovery(fileReRouteOptions.UseServiceDiscovery)
                          .WithUpstreamHeaderFindAndReplace(hAndRs.Upstream)
                          .WithDownstreamHeaderFindAndReplace(hAndRs.Downstream)
                          .WithDelegatingHandlers(fileReRoute.DelegatingHandlers)
                          .WithAddHeadersToDownstream(hAndRs.AddHeadersToDownstream)
                          .WithAddHeadersToUpstream(hAndRs.AddHeadersToUpstream)
                          .WithDangerousAcceptAnyServerCertificateValidator(fileReRoute.DangerousAcceptAnyServerCertificateValidator)
                          .WithSecurityOptions(securityOptions)
                          .Build();

            return(reRoute);
        }