public Response ChangeDownstreamPath(List <ClaimToThing> claimsToThings, IEnumerable <Claim> claims,
                                             DownstreamPathTemplate downstreamPathTemplate, List <PlaceholderNameAndValue> placeholders)
        {
            foreach (var config in claimsToThings)
            {
                var value = _claimsParser.GetValue(claims, config.NewKey, config.Delimiter, config.Index);

                if (value.IsError)
                {
                    return(new ErrorResponse(value.Errors));
                }

                var placeholderName = $"{{{config.ExistingKey}}}";

                if (!downstreamPathTemplate.Value.Contains(placeholderName))
                {
                    return(new ErrorResponse(new CouldNotFindPlaceholderError(placeholderName)));
                }

                if (placeholders.Any(ph => ph.Name == placeholderName))
                {
                    placeholders.RemoveAll(ph => ph.Name == placeholderName);
                }

                placeholders.Add(new PlaceholderNameAndValue(placeholderName, value.Data));
            }

            return(new OkResponse());
        }
Пример #2
0
        public Response <DownstreamPath> Replace(DownstreamPathTemplate downstreamDownstreamPathTemplate, List <PlaceholderNameAndValue> urlPathPlaceholderNameAndValues)
        {
            var downstreamPath = new StringBuilder();

            downstreamPath.Append(downstreamDownstreamPathTemplate.Value);

            foreach (var placeholderVariableAndValue in urlPathPlaceholderNameAndValues)
            {
                downstreamPath.Replace(placeholderVariableAndValue.Name, placeholderVariableAndValue.Value);
            }

            return(new OkResponse <DownstreamPath>(new DownstreamPath(downstreamPath.ToString())));
        }
Пример #3
0
 public ReRoute(DownstreamPathTemplate downstreamPathTemplate,
                string upstreamTemplate, string upstreamHttpMethod,
                string upstreamTemplatePattern,
                bool isAuthenticated, AuthenticationOptions authenticationOptions,
                List <ClaimToThing> configurationHeaderExtractorProperties,
                List <ClaimToThing> claimsToClaims,
                Dictionary <string, string> routeClaimsRequirement, bool isAuthorised,
                List <ClaimToThing> claimsToQueries,
                string requestIdKey, bool isCached, CacheOptions fileCacheOptions,
                string downstreamScheme, string loadBalancer, string downstreamHost,
                int downstreamPort, string loadBalancerKey, ServiceProviderConfiguraion serviceProviderConfiguraion)
 {
     LoadBalancerKey             = loadBalancerKey;
     ServiceProviderConfiguraion = serviceProviderConfiguraion;
     LoadBalancer            = loadBalancer;
     DownstreamHost          = downstreamHost;
     DownstreamPort          = downstreamPort;
     DownstreamPathTemplate  = downstreamPathTemplate;
     UpstreamTemplate        = upstreamTemplate;
     UpstreamHttpMethod      = upstreamHttpMethod;
     UpstreamTemplatePattern = upstreamTemplatePattern;
     IsAuthenticated         = isAuthenticated;
     AuthenticationOptions   = authenticationOptions;
     RouteClaimsRequirement  = routeClaimsRequirement;
     IsAuthorised            = isAuthorised;
     RequestIdKey            = requestIdKey;
     IsCached         = isCached;
     FileCacheOptions = fileCacheOptions;
     ClaimsToQueries  = claimsToQueries
                        ?? new List <ClaimToThing>();
     ClaimsToClaims = claimsToClaims
                      ?? new List <ClaimToThing>();
     ClaimsToHeaders = configurationHeaderExtractorProperties
                       ?? new List <ClaimToThing>();
     DownstreamScheme = downstreamScheme;
 }
Пример #4
0
 public DownstreamReRoute(
     string key,
     UpstreamPathTemplate upstreamPathTemplate,
     List <HeaderFindAndReplace> upstreamHeadersFindAndReplace,
     List <HeaderFindAndReplace> downstreamHeadersFindAndReplace,
     List <DownstreamHostAndPort> downstreamAddresses,
     string serviceName,
     HttpHandlerOptions httpHandlerOptions,
     bool useServiceDiscovery,
     bool enableEndpointEndpointRateLimiting,
     QoSOptions qosOptions,
     string downstreamScheme,
     string requestIdKey,
     bool isCached,
     CacheOptions cacheOptions,
     LoadBalancerOptions loadBalancerOptions,
     RateLimitOptions rateLimitOptions,
     Dictionary <string, string> routeClaimsRequirement,
     List <ClaimToThing> claimsToQueries,
     List <ClaimToThing> claimsToHeaders,
     List <ClaimToThing> claimsToClaims,
     bool isAuthenticated,
     bool isAuthorised,
     AuthenticationOptions authenticationOptions,
     DownstreamPathTemplate downstreamPathTemplate,
     string loadBalancerKey,
     List <string> delegatingHandlers,
     List <AddHeader> addHeadersToDownstream,
     List <AddHeader> addHeadersToUpstream,
     bool dangerousAcceptAnyServerCertificateValidator,
     SecurityOptions securityOptions)
 {
     DangerousAcceptAnyServerCertificateValidator = dangerousAcceptAnyServerCertificateValidator;
     AddHeadersToDownstream = addHeadersToDownstream;
     DelegatingHandlers     = delegatingHandlers;
     Key = key;
     UpstreamPathTemplate            = upstreamPathTemplate;
     UpstreamHeadersFindAndReplace   = upstreamHeadersFindAndReplace ?? new List <HeaderFindAndReplace>();
     DownstreamHeadersFindAndReplace = downstreamHeadersFindAndReplace ?? new List <HeaderFindAndReplace>();
     DownstreamAddresses             = downstreamAddresses ?? new List <DownstreamHostAndPort>();
     ServiceName         = serviceName;
     HttpHandlerOptions  = httpHandlerOptions;
     UseServiceDiscovery = useServiceDiscovery;
     EnableEndpointEndpointRateLimiting = enableEndpointEndpointRateLimiting;
     QosOptions             = qosOptions;
     DownstreamScheme       = downstreamScheme;
     RequestIdKey           = requestIdKey;
     IsCached               = isCached;
     CacheOptions           = cacheOptions;
     LoadBalancerOptions    = loadBalancerOptions;
     RateLimitOptions       = rateLimitOptions;
     RouteClaimsRequirement = routeClaimsRequirement;
     ClaimsToQueries        = claimsToQueries ?? new List <ClaimToThing>();
     ClaimsToHeaders        = claimsToHeaders ?? new List <ClaimToThing>();
     ClaimsToClaims         = claimsToClaims ?? new List <ClaimToThing>();
     IsAuthenticated        = isAuthenticated;
     IsAuthorised           = isAuthorised;
     AuthenticationOptions  = authenticationOptions;
     DownstreamPathTemplate = downstreamPathTemplate;
     LoadBalancerKey        = loadBalancerKey;
     AddHeadersToUpstream   = addHeadersToUpstream;
     SecurityOptions        = securityOptions;
 }
 private void GivenDownstreamPathTemplate(string template)
 {
     _downstreamPathTemplate = new DownstreamPathTemplate(template);
 }