8000 #593 instanciate upstream path template when dynamic routing for logging by TomPallister · Pull Request #594 · ThreeMammals/Ocelot · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

#593 instanciate upstream path template when dynamic routing for logging #594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8000
Merged
merged 1 commit into from
Sep 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public DownstreamReRouteBuilder WithDownstreamPathTemplate(string input)
return this;
}

public DownstreamReRouteBuilder WithUpstreamTemplatePattern(UpstreamPathTemplate input)
public DownstreamReRouteBuilder WithUpstreamPathTemplate(UpstreamPathTemplate input)
{
_upstreamTemplatePattern = input;
return this;
Expand Down
2 changes: 1 addition & 1 deletion src/Ocelot/Configuration/Builder/ReRouteBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public ReRouteBuilder WithUpstreamHost(string upstreamAddresses)
return this;
}

public ReRouteBuilder WithUpstreamTemplatePattern(UpstreamPathTemplate input)
public ReRouteBuilder WithUpstreamPathTemplate(UpstreamPathTemplate input)
{
_upstreamTemplatePattern = input;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private ReRoute SetUpAggregateReRoute(List<ReRoute> reRoutes, FileAggregateReRou

var reRoute = new ReRouteBuilder()
.WithUpstreamHttpMethod(aggregateReRoute.UpstreamHttpMethod)
.WithUpstreamTemplatePattern(upstreamTemplatePattern)
.WithUpstreamPathTemplate(upstreamTemplatePattern)
.WithDownstreamReRoutes(applicableReRoutes)
.WithUpstreamHost(aggregateReRoute.UpstreamHost)
.WithAggregator(aggregateReRoute.Aggregator)
Expand All @@ -182,7 +182,7 @@ private ReRoute SetUpReRoute(FileReRoute fileReRoute, DownstreamReRoute downstre

var reRoute = new ReRouteBuilder()
.WithUpstreamHttpMethod(fileReRoute.UpstreamHttpMethod)
.WithUpstreamTemplatePattern(upstreamTemplatePattern)
.WithUpstreamPathTemplate(upstreamTemplatePattern)
.WithDownstreamReRoute(downstreamReRoutes)
.WithUpstreamHost(fileReRoute.UpstreamHost)
.Build();
Expand Down Expand Up @@ -228,7 +228,7 @@ private DownstreamReRoute SetUpDownstreamReRoute(FileReRoute fileReRoute, FileGl
.WithKey(fileReRoute.Key)
.WithDownstreamPathTemplate(fileReRoute.DownstreamPathTemplate)
.WithUpstreamHttpMethod(fileReRoute.UpstreamHttpMethod)
.WithUpstreamTemplatePattern(upstreamTemplatePattern)
.WithUpstreamPathTemplate(upstreamTemplatePattern)
.WithIsAuthenticated(fileReRouteOptions.IsAuthenticated)
.WithAuthenticationOptions(authOptionsForRoute)
.WithClaimsToHeaders(claimsToHeaders)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public Response<DownstreamRoute> Get(string upstreamUrlPath, string upstreamQuer

var qosOptions = _qoSOptionsCreator.Create(configuration.QoSOptions, downstreamPathForKeys, new []{ upstreamHttpMethod });

var upstreamPathTemplate = new UpstreamPathTemplateBuilder().WithOriginalValue(upstreamUrlPath).Build();

var downstreamReRouteBuilder = new DownstreamReRouteBuilder()
.WithServiceName(serviceName)
.WithLoadBalancerKey(loadBalancerKey)
Expand All @@ -52,7 +54,8 @@ public Response<DownstreamRoute> Get(string upstreamUrlPath, string upstreamQuer
.WithHttpHandlerOptions(configuration.HttpHandlerOptions)
.WithQosOptions(qosOptions)
.WithDownstreamScheme(configuration.DownstreamScheme)
.WithLoadBalancerOptions(configuration.LoadBalancerOptions);
.WithLoadBalancerOptions(configuration.LoadBalancerOptions)
.WithUpstreamPathTemplate(upstreamPathTemplate);

var rateLimitOptions = configuration.ReRoutes != null
? configuration.ReRoutes
Expand All @@ -72,6 +75,7 @@ public Response<DownstreamRoute> Get(string upstreamUrlPath, string upstreamQuer
var reRoute = new ReRouteBuilder()
.WithDownstreamReRoute(downstreamReRoute)
.WithUpstreamHttpMethod(new List<string>(){ upstreamHttpMethod })
.WithUpstreamPathTemplate(upstreamPathTemplate)
.Build();

downstreamRoute = new OkResponse<DownstreamRoute>(new DownstreamRoute(new List<PlaceholderNameAndValue>(), reRoute));
Expand Down
8000
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void should_call_authorisation_service()
{
this.Given(x => x.GivenTheDownStreamRouteIs(new List<PlaceholderNameAndValue>(),
new DownstreamReRouteBuilder()
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().Build())
.WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().Build())
.WithIsAuthorised(true)
.WithUpstreamHttpMethod(new List<string> { "Get" })
.Build()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void should_set_up_sticky_sessions_config()
.Build();

var downstreamReRoute = new DownstreamReRouteBuilder()
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
6855 .WithDownstreamAddresses(new List<DownstreamHostAndPort>() { new DownstreamHostAndPort("127.0.0.1", 80) })
.WithDownstreamPathTemplate("/products/{productId}")
.WithUpstreamHttpMethod(new List<string> { "Get" })
Expand Down Expand Up @@ -124,7 +124,7 @@ public void should_set_up_sticky_sessions_config()
{
new ReRouteBuilder()
.WithDownstreamReRoute(downstreamReRoute)
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamHttpMethod(new List<string> { "Get" })
.Build()
}))
Expand Down Expand Up @@ -206,7 +206,7 @@ public void should_set_up_aggregate_re_route()
var lauraReRoute = new ReRouteBuilder()
.WithUpstreamHttpMethod(new List<string>() { "Get" })
.WithUpstreamHost("localhost")
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/laura").Build())
.WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/laura").Build())
.WithDownstreamReRoute(lauraDownstreamReRoute)
.Build();

Expand All @@ -225,14 +225,14 @@ public void should_set_up_aggregate_re_route()
var tomReRoute = new ReRouteBuilder()
.WithUpstreamHttpMethod(new List<string>() { "Get" })
.WithUpstreamHost("localhost")
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/tom").Build())
.WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/tom").Build())
.WithDownstreamReRoute(tomDownstreamReRoute)
.Build();

expected.Add(tomReRoute);

var aggregateReReRoute = new ReRouteBuilder()
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/").Build())
.WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/").Build())
.WithUpstreamHost("localhost")
.WithDownstreamReRoute(lauraDownstreamReRoute)
.WithDownstreamReRoute(tomDownstreamReRoute)
Expand Down Expand Up @@ -417,7 +417,7 @@ public void should_use_downstream_host()
.Build();

var downstreamReRoute = new DownstreamReRouteBuilder()
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithDownstreamAddresses(new List<DownstreamHostAndPort>() {new DownstreamHostAndPort("127.0.0.1", 80)})
.WithDownstreamPathTemplate("/products/{productId}")
.WithUpstreamHttpMethod(new List<string> {"Get"})
Expand Down Expand Up @@ -453,7 +453,7 @@ public void should_use_downstream_host()
{
new ReRouteBuilder()
.WithDownstreamReRoute(downstreamReRoute)
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamHttpMethod(new List<string> { "Get" })
.Build()
}))
Expand All @@ -471,7 +471,7 @@ public void should_use_downstream_scheme()
var downstreamReRoute = new DownstreamReRouteBuilder()
.WithDownstreamScheme("https")
.WithDownstreamPathTemplate("/products/{productId}")
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamHttpMethod(new List<string> {"Get"})
.WithDelegatingHandlers(handlers)
.WithLoadBalancerKey("/api/products/{productId}|Get|")
Expand Down Expand Up @@ -501,7 +501,7 @@ public void should_use_downstream_scheme()
{
new ReRouteBuilder()
.WithDownstreamReRoute(downstreamReRoute)
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamHttpMethod(new List<string> { "Get" })
.Build()
}))
Expand All @@ -516,7 +516,7 @@ public void should_use_service_discovery_for_downstream_service_host()

var downstreamReRoute = new DownstreamReRouteBuilder()
.WithDownstreamPathTemplate("/products/{productId}")
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamHttpMethod(new List<string> {"Get"})
.WithUseServiceDiscovery(true)
.WithServiceName("ProductService")
Expand Down Expand Up @@ -554,7 +554,7 @@ public void should_use_service_discovery_for_downstream_service_host()
{
new ReRouteBuilder()
.WithDownstreamReRoute(downstreamReRoute)
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamHttpMethod(new List<string> { "Get" })
.Build()
}))
Expand All @@ -569,7 +569,7 @@ public void should_not_use_service_discovery_for_downstream_host_url_when_no_ser

var downstreamReRoute = new DownstreamReRouteBuilder()
.WithDownstreamPathTemplate("/products/{productId}")
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamHttpMethod(new List<string> {"Get"})
.WithUseServiceDiscovery(false)
.WithLoadBalancerKey("/api/products/{productId}|Get|")
Expand Down Expand Up @@ -598,7 +598,7 @@ public void should_not_use_service_discovery_for_downstream_host_url_when_no_ser
{
new ReRouteBuilder()
.WithDownstreamReRoute(downstreamReRoute)
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamHttpMethod(new List<string> { "Get" })
.Build()
}))
Expand All @@ -613,9 +613,9 @@ public void should_call_template_pattern_creator_correctly()

var downstreamReRoute = new DownstreamReRouteBuilder()
.WithDownstreamPathTemplate("/products/{productId}")
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamHttpMethod(new List<string> {"Get"})
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("(?i)/api/products/.*/$", 1, false, "/api/products/{productId}"))
.WithUpstreamPathTemplate(new UpstreamPathTemplate("(?i)/api/products/.*/$", 1, false, "/api/products/{productId}"))
.WithLoadBalancerKey("/api/products/{productId}|Get|")
.Build();

Expand All @@ -642,9 +642,9 @@ public void should_call_template_pattern_creator_correctly()
{
new ReRouteBuilder()
.WithDownstreamReRoute(downstreamReRoute)
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamHttpMethod(new List<string> { "Get" })
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("(?i)/api/products/.*/$", 1, false, "/api/products/{productId}"))
.WithUpstreamPathTemplate(new UpstreamPathTemplate("(?i)/api/products/.*/$", 1, false, "/api/products/{productId}"))
.Build()
}))
.BDDfy();
Expand All @@ -658,7 +658,7 @@ public void should_call_request_id_creator()

var downstreamReRoute = new DownstreamReRouteBuilder()
.WithDownstreamPathTemplate("/products/{productId}")
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamHttpMethod(new List<string> {"Get"})
.WithRequestIdKey("blahhhh")
.WithLoadBalancerKey("/api/products/{productId}|Get|")
Expand Down Expand Up @@ -692,7 +692,7 @@ public void should_call_request_id_creator()
{
new ReRouteBuilder()
.WithDownstreamReRoute(downstreamReRoute)
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamHttpMethod(new List<string> { "Get" })
.Build()
}))
Expand Down Expand Up @@ -750,7 +750,7 @@ public void should_create_with_headers_to_extract(FileConfiguration fileConfig)

var downstreamReRoute = new DownstreamReRouteBuilder()
.WithDownstreamPathTemplate("/products/{productId}")
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamHttpMethod(new List<string> {"Get"})
.WithAuthenticationOptions(authenticationOptions)
.WithClaimsToHeaders(new List<ClaimToThing>
Expand All @@ -764,7 +764,7 @@ public void should_create_with_headers_to_extract(FileConfiguration fileConfig)
{
new ReRouteBuilder()
.WithDownstreamReRoute(downstreamReRoute)
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamHttpMethod(new List<string> { "Get" })
.Build()
};
Expand Down Expand Up @@ -798,7 +798,7 @@ public void should_create_with_authentication_properties(FileConfiguration fileC

var downstreamReRoute = new DownstreamReRouteBuilder()
.WithDownstreamPathTemplate("/products/{productId}")
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamHttpMethod(new List<string> {"Get"})
.WithAuthenticationOptions(authenticationOptions)
.WithLoadBalancerKey("/api/products/{productId}|Get|")
Expand All @@ -808,7 +808,7 @@ public void should_create_with_authentication_properties(FileConfiguration fileC
{
new ReRouteBuilder()
.WithDownstreamReRoute(downstreamReRoute)
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
.WithUpstreamHttpMethod(new List<string> { "Get" })
.Build()
};
Expand Down
Loading
0