mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-22 06:22:50 +08:00
tidying up configuration creation
This commit is contained in:
parent
7fffc9827a
commit
dbe28d38bc
@ -108,8 +108,6 @@ namespace Ocelot.Configuration.Creator
|
|||||||
//note - not sure if this is the correct key, but this is probably the only unique key i can think of given my poor brain
|
//note - not sure if this is the correct key, but this is probably the only unique key i can think of given my poor brain
|
||||||
var loadBalancerKey = $"{fileReRoute.UpstreamPathTemplate}{fileReRoute.UpstreamHttpMethod}";
|
var loadBalancerKey = $"{fileReRoute.UpstreamPathTemplate}{fileReRoute.UpstreamHttpMethod}";
|
||||||
|
|
||||||
ReRoute reRoute;
|
|
||||||
|
|
||||||
var serviceProviderPort = globalConfiguration?.ServiceDiscoveryProvider?.Port ?? 0;
|
var serviceProviderPort = globalConfiguration?.ServiceDiscoveryProvider?.Port ?? 0;
|
||||||
|
|
||||||
var serviceProviderConfiguration = new ServiceProviderConfiguraionBuilder()
|
var serviceProviderConfiguration = new ServiceProviderConfiguraionBuilder()
|
||||||
@ -122,48 +120,41 @@ namespace Ocelot.Configuration.Creator
|
|||||||
.WithServiceDiscoveryProviderPort(serviceProviderPort)
|
.WithServiceDiscoveryProviderPort(serviceProviderPort)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
if (isAuthenticated)
|
var authOptionsForRoute = new AuthenticationOptionsBuilder()
|
||||||
{
|
.WithProvider(fileReRoute.AuthenticationOptions?.Provider)
|
||||||
var authOptionsForRoute = new AuthenticationOptions(fileReRoute.AuthenticationOptions.Provider,
|
.WithProviderRootUrl(fileReRoute.AuthenticationOptions?.ProviderRootUrl)
|
||||||
fileReRoute.AuthenticationOptions.ProviderRootUrl, fileReRoute.AuthenticationOptions.ScopeName,
|
.WithScopeName(fileReRoute.AuthenticationOptions?.ScopeName)
|
||||||
fileReRoute.AuthenticationOptions.RequireHttps, fileReRoute.AuthenticationOptions.AdditionalScopes,
|
.WithRequireHttps(fileReRoute.AuthenticationOptions.RequireHttps)
|
||||||
fileReRoute.AuthenticationOptions.ScopeSecret);
|
.WithAdditionalScopes(fileReRoute.AuthenticationOptions?.AdditionalScopes)
|
||||||
|
.WithScopeSecret(fileReRoute.AuthenticationOptions?.ScopeSecret)
|
||||||
|
.Build();
|
||||||
|
|
||||||
var claimsToHeaders = GetAddThingsToRequest(fileReRoute.AddHeadersToRequest);
|
var claimsToHeaders = GetAddThingsToRequest(fileReRoute.AddHeadersToRequest);
|
||||||
var claimsToClaims = GetAddThingsToRequest(fileReRoute.AddClaimsToRequest);
|
var claimsToClaims = GetAddThingsToRequest(fileReRoute.AddClaimsToRequest);
|
||||||
var claimsToQueries = GetAddThingsToRequest(fileReRoute.AddQueriesToRequest);
|
var claimsToQueries = GetAddThingsToRequest(fileReRoute.AddQueriesToRequest);
|
||||||
|
|
||||||
reRoute = new ReRoute(new PathTemplate(fileReRoute.DownstreamPathTemplate),
|
var reRoute = new ReRouteBuilder()
|
||||||
new PathTemplate(fileReRoute.UpstreamPathTemplate),
|
.WithDownstreamPathTemplate(fileReRoute.DownstreamPathTemplate)
|
||||||
new HttpMethod(fileReRoute.UpstreamHttpMethod), upstreamTemplatePattern, isAuthenticated,
|
.WithUpstreamPathTemplate(fileReRoute.UpstreamPathTemplate)
|
||||||
authOptionsForRoute, claimsToHeaders, claimsToClaims,
|
.WithUpstreamHttpMethod(fileReRoute.UpstreamHttpMethod)
|
||||||
fileReRoute.RouteClaimsRequirement, isAuthorised, claimsToQueries,
|
.WithUpstreamTemplatePattern(upstreamTemplatePattern)
|
||||||
requestIdKey, isCached, new CacheOptions(fileReRoute.FileCacheOptions.TtlSeconds)
|
.WithIsAuthenticated(isAuthenticated)
|
||||||
, fileReRoute.DownstreamScheme,
|
.WithAuthenticationOptions(authOptionsForRoute)
|
||||||
fileReRoute.LoadBalancer, fileReRoute.DownstreamHost, fileReRoute.DownstreamPort, loadBalancerKey,
|
.WithClaimsToHeaders(claimsToHeaders)
|
||||||
serviceProviderConfiguration);
|
.WithClaimsToClaims(claimsToClaims)
|
||||||
|
.WithRouteClaimsRequirement(fileReRoute.RouteClaimsRequirement)
|
||||||
//reRoute = new ReRouteBuilder()
|
.WithIsAuthorised(isAuthorised)
|
||||||
// .WithDownstreamPathTemplate(fileReRoute.DownstreamPathTemplate)
|
.WithClaimsToQueries(claimsToQueries)
|
||||||
// .WithUpstreamPathTemplate(fileReRoute.UpstreamPathTemplate)
|
.WithRequestIdKey(requestIdKey)
|
||||||
// .WithUpstreamHttpMethod(fileReRoute.UpstreamHttpMethod)
|
.WithIsCached(isCached)
|
||||||
// .WithUpstreamTemplatePattern(upstreamTemplatePattern)
|
.WithCacheOptions(new CacheOptions(fileReRoute.FileCacheOptions.TtlSeconds))
|
||||||
// .WithIsAuthenticated(isAuthenticated)
|
.WithDownstreamScheme(fileReRoute.DownstreamScheme)
|
||||||
//.Build();
|
.WithLoadBalancer(fileReRoute.LoadBalancer)
|
||||||
|
.WithDownstreamHost(fileReRoute.DownstreamHost)
|
||||||
}
|
.WithDownstreamPort(fileReRoute.DownstreamPort)
|
||||||
else
|
.WithLoadBalancerKey(loadBalancerKey)
|
||||||
{
|
.WithServiceProviderConfiguraion(serviceProviderConfiguration)
|
||||||
reRoute = new ReRoute(new PathTemplate(fileReRoute.DownstreamPathTemplate),
|
.Build();
|
||||||
new PathTemplate(fileReRoute.UpstreamPathTemplate),
|
|
||||||
new HttpMethod(fileReRoute.UpstreamHttpMethod), upstreamTemplatePattern, isAuthenticated,
|
|
||||||
null, new List<ClaimToThing>(), new List<ClaimToThing>(),
|
|
||||||
fileReRoute.RouteClaimsRequirement, isAuthorised, new List<ClaimToThing>(),
|
|
||||||
requestIdKey, isCached, new CacheOptions(fileReRoute.FileCacheOptions.TtlSeconds),
|
|
||||||
fileReRoute.DownstreamScheme,
|
|
||||||
fileReRoute.LoadBalancer, fileReRoute.DownstreamHost, fileReRoute.DownstreamPort, loadBalancerKey,
|
|
||||||
serviceProviderConfiguration);
|
|
||||||
}
|
|
||||||
|
|
||||||
var loadBalancer = await _loadBalanceFactory.Get(reRoute);
|
var loadBalancer = await _loadBalanceFactory.Get(reRoute);
|
||||||
_loadBalancerHouse.Add(reRoute.LoadBalancerKey, loadBalancer);
|
_loadBalancerHouse.Add(reRoute.LoadBalancerKey, loadBalancer);
|
||||||
|
@ -6,6 +6,7 @@ using Moq;
|
|||||||
using Ocelot.Authentication.Handler;
|
using Ocelot.Authentication.Handler;
|
||||||
using Ocelot.Authentication.Handler.Creator;
|
using Ocelot.Authentication.Handler.Creator;
|
||||||
using Ocelot.Authentication.Handler.Factory;
|
using Ocelot.Authentication.Handler.Factory;
|
||||||
|
using Ocelot.Configuration.Builder;
|
||||||
using Ocelot.Errors;
|
using Ocelot.Errors;
|
||||||
using Ocelot.Responses;
|
using Ocelot.Responses;
|
||||||
using Shouldly;
|
using Shouldly;
|
||||||
@ -33,7 +34,11 @@ namespace Ocelot.UnitTests.Authentication
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void should_return_identity_server_access_token_handler()
|
public void should_return_identity_server_access_token_handler()
|
||||||
{
|
{
|
||||||
this.Given(x => x.GivenTheAuthenticationOptionsAre(new AuthenticationOptions("IdentityServer", "","",false, new List<string>(), "")))
|
var authenticationOptions = new AuthenticationOptionsBuilder()
|
||||||
|
.WithProvider("IdentityServer")
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
this.Given(x => x.GivenTheAuthenticationOptionsAre(authenticationOptions))
|
||||||
.And(x => x.GivenTheCreatorReturns())
|
.And(x => x.GivenTheCreatorReturns())
|
||||||
.When(x => x.WhenIGetFromTheFactory())
|
.When(x => x.WhenIGetFromTheFactory())
|
||||||
.Then(x => x.ThenTheHandlerIsReturned("IdentityServer"))
|
.Then(x => x.ThenTheHandlerIsReturned("IdentityServer"))
|
||||||
@ -43,7 +48,10 @@ namespace Ocelot.UnitTests.Authentication
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void should_return_error_if_cannot_create_handler()
|
public void should_return_error_if_cannot_create_handler()
|
||||||
{
|
{
|
||||||
this.Given(x => x.GivenTheAuthenticationOptionsAre(new AuthenticationOptions("IdentityServer", "", "", false, new List<string>(), "")))
|
var authenticationOptions = new AuthenticationOptionsBuilder()
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
this.Given(x => x.GivenTheAuthenticationOptionsAre(authenticationOptions))
|
||||||
.And(x => x.GivenTheCreatorReturnsAnError())
|
.And(x => x.GivenTheCreatorReturnsAnError())
|
||||||
.When(x => x.WhenIGetFromTheFactory())
|
.When(x => x.WhenIGetFromTheFactory())
|
||||||
.Then(x => x.ThenAnErrorResponseIsReturned())
|
.Then(x => x.ThenAnErrorResponseIsReturned())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user