auth options builders

This commit is contained in:
Tom Gardham-Pallister 2017-02-07 20:30:26 +00:00
parent 33ce162693
commit 7fffc9827a
27 changed files with 222 additions and 167 deletions

View File

@ -122,7 +122,7 @@ Ocelot's primary functionality is to take incomeing http requests and forward th
to a downstream service. At the moment in the form of another http request (in the future
this could be any transport mechanism.).
Ocelot always adds a trailing slash to an UpstreamTemplate.
Ocelot always adds a trailing slash to an UpstreamPathTemplate.
Ocelot's describes the routing of one request to another as a ReRoute. In order to get
anything working in Ocelot you need to set up a ReRoute in the configuration.
@ -140,16 +140,16 @@ the following.
"DownstreamScheme": "https",
"DownstreamPort": 80,
"DownstreamHost" "localhost"
"UpstreamTemplate": "/posts/{postId}",
"UpstreamPathTemplate": "/posts/{postId}",
"UpstreamHttpMethod": "Put"
}
The DownstreamPathTemplate,Scheme, Port and Host make the URL that this request will be forwarded to.
The UpstreamTemplate is the URL that Ocelot will use to identity which
The UpstreamPathTemplate is the URL that Ocelot will use to identity which
DownstreamPathTemplate to use for a given request. Finally the UpstreamHttpMethod is used so
Ocelot can distinguish between requests to the same URL and is obviously needed to work :)
In Ocelot you can add placeholders for variables to your Templates in the form of {something}.
The placeholder needs to be in both the DownstreamPathTemplate and UpstreamTemplate. If it is
The placeholder needs to be in both the DownstreamPathTemplate and UpstreamPathTemplate. If it is
Ocelot will attempt to replace the placeholder with the correct variable value from the
Upstream URL when the request comes in.
@ -190,7 +190,7 @@ and LeastConnection algorithm you can use. If no load balancer is specified Ocel
{
"DownstreamPathTemplate": "/api/posts/{postId}",
"DownstreamScheme": "https",
"UpstreamTemplate": "/posts/{postId}",
"UpstreamPathTemplate": "/posts/{postId}",
"UpstreamHttpMethod": "Put",
"ServiceName": "product"
"LoadBalancer": "LeastConnection"

View File

@ -15,7 +15,7 @@
# The path template we are listening on for this re route, Ocelot will add a trailing
# slash to this property. Then when a request is made Ocelot makes sure a trailing
# slash is added, so everything matches
"UpstreamTemplate": "/identityserverexample",
"UpstreamPathTemplate": "/identityserverexample",
# The method we are listening for on this re route
"UpstreamHttpMethod": "Get",
# Only support identity server at the moment

View File

@ -61,7 +61,7 @@ namespace Ocelot.Authorisation.Middleware
SetPipelineError(new List<Error>
{
new UnauthorisedError(
$"{context.User.Identity.Name} unable to access {DownstreamRoute.ReRoute.UpstreamTemplate}")
$"{context.User.Identity.Name} unable to access {DownstreamRoute.ReRoute.UpstreamPathTemplate.Value}")
});
}
}

View File

@ -0,0 +1,56 @@
using System.Collections.Generic;
namespace Ocelot.Configuration.Builder
{
public class AuthenticationOptionsBuilder
{
private string _provider;
private string _providerRootUrl;
private string _scopeName;
private string _scopeSecret;
private bool _requireHttps;
private List<string> _additionalScopes;
public AuthenticationOptionsBuilder WithProvider(string provider)
{
_provider = provider;
return this;
}
public AuthenticationOptionsBuilder WithProviderRootUrl(string providerRootUrl)
{
_providerRootUrl = providerRootUrl;
return this;
}
public AuthenticationOptionsBuilder WithScopeName(string scopeName)
{
_scopeName = scopeName;
return this;
}
public AuthenticationOptionsBuilder WithScopeSecret(string scopeSecret)
{
_scopeSecret = scopeSecret;
return this;
}
public AuthenticationOptionsBuilder WithRequireHttps(bool requireHttps)
{
_requireHttps = requireHttps;
return this;
}
public AuthenticationOptionsBuilder WithAdditionalScopes(List<string> additionalScopes)
{
_additionalScopes = additionalScopes;
return this;
}
public AuthenticationOptions Build()
{
return new AuthenticationOptions(_provider, _providerRootUrl, _scopeName, _requireHttps, _additionalScopes, _scopeSecret);
}
}
}

View File

@ -1,23 +1,19 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using Ocelot.Values;
namespace Ocelot.Configuration.Builder
{
public class ReRouteBuilder
{
private AuthenticationOptions _authenticationOptions;
private string _loadBalancerKey;
private string _downstreamPathTemplate;
private string _upstreamTemplate;
private string _upstreamTemplatePattern;
private string _upstreamHttpMethod;
private bool _isAuthenticated;
private string _authenticationProvider;
private string _authenticationProviderUrl;
private string _scopeName;
private List<string> _additionalScopes;
private bool _requireHttps;
private string _scopeSecret;
private List<ClaimToThing> _configHeaderExtractorProperties;
private List<ClaimToThing> _claimToClaims;
private Dictionary<string, string> _routeClaimRequirement;
@ -33,11 +29,6 @@ namespace Ocelot.Configuration.Builder
private string _loadBalancer;
private ServiceProviderConfiguraion _serviceProviderConfiguraion;
public ReRouteBuilder()
{
_additionalScopes = new List<string>();
}
public ReRouteBuilder WithLoadBalancer(string loadBalancer)
{
_loadBalancer = loadBalancer;
@ -68,7 +59,7 @@ namespace Ocelot.Configuration.Builder
return this;
}
public ReRouteBuilder WithUpstreamTemplate(string input)
public ReRouteBuilder WithUpstreamPathTemplate(string input)
{
_upstreamTemplate = input;
return this;
@ -96,42 +87,6 @@ namespace Ocelot.Configuration.Builder
return this;
}
public ReRouteBuilder WithAuthenticationProvider(string input)
{
_authenticationProvider = input;
return this;
}
public ReRouteBuilder WithAuthenticationProviderUrl(string input)
{
_authenticationProviderUrl = input;
return this;
}
public ReRouteBuilder WithAuthenticationProviderScopeName(string input)
{
_scopeName = input;
return this;
}
public ReRouteBuilder WithAuthenticationProviderAdditionalScopes(List<string> input)
{
_additionalScopes = input;
return this;
}
public ReRouteBuilder WithRequireHttps(bool input)
{
_requireHttps = input;
return this;
}
public ReRouteBuilder WithScopeSecret(string input)
{
_scopeSecret = input;
return this;
}
public ReRouteBuilder WithRequestIdKey(string input)
{
_requestIdHeaderKey = input;
@ -192,13 +147,35 @@ namespace Ocelot.Configuration.Builder
return this;
}
public ReRouteBuilder WithAuthenticationOptions(AuthenticationOptions authenticationOptions)
{
_authenticationOptions = authenticationOptions;
return this;
}
public ReRoute Build()
{
return new ReRoute(new PathTemplate(_downstreamPathTemplate), new PathTemplate(_upstreamTemplate), _upstreamHttpMethod, _upstreamTemplatePattern,
_isAuthenticated, new AuthenticationOptions(_authenticationProvider, _authenticationProviderUrl, _scopeName,
_requireHttps, _additionalScopes, _scopeSecret), _configHeaderExtractorProperties, _claimToClaims, _routeClaimRequirement,
_isAuthorised, _claimToQueries, _requestIdHeaderKey, _isCached, _fileCacheOptions, _downstreamScheme, _loadBalancer,
_downstreamHost, _downstreamPort, _loadBalancerKey, _serviceProviderConfiguraion);
return new ReRoute(
new PathTemplate(_downstreamPathTemplate),
new PathTemplate(_upstreamTemplate),
new HttpMethod(_upstreamHttpMethod),
_upstreamTemplatePattern,
_isAuthenticated,
_authenticationOptions,
_configHeaderExtractorProperties,
_claimToClaims,
_routeClaimRequirement,
_isAuthorised,
_claimToQueries,
_requestIdHeaderKey,
_isCached,
_fileCacheOptions,
_downstreamScheme,
_loadBalancer,
_downstreamHost,
_downstreamPort,
_loadBalancerKey,
_serviceProviderConfiguraion);
}
}
}

View File

@ -1,4 +1,4 @@
namespace Ocelot.Configuration
namespace Ocelot.Configuration.Builder
{
public class ServiceProviderConfiguraionBuilder
{

View File

@ -1,9 +1,11 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Ocelot.Configuration.Builder;
using Ocelot.Configuration.File;
using Ocelot.Configuration.Parser;
using Ocelot.Configuration.Validator;
@ -88,7 +90,7 @@ namespace Ocelot.Configuration.Creator
{
var globalRequestIdConfiguration = !string.IsNullOrEmpty(globalConfiguration?.RequestIdKey);
var upstreamTemplate = BuildUpstreamTemplate(fileReRoute);
var upstreamTemplatePattern = BuildUpstreamTemplate(fileReRoute);
var isAuthenticated = !string.IsNullOrEmpty(fileReRoute.AuthenticationOptions?.Provider);
@ -104,7 +106,7 @@ namespace Ocelot.Configuration.Creator
&& !string.IsNullOrEmpty(globalConfiguration?.ServiceDiscoveryProvider?.Provider);
//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.UpstreamTemplate}{fileReRoute.UpstreamHttpMethod}";
var loadBalancerKey = $"{fileReRoute.UpstreamPathTemplate}{fileReRoute.UpstreamHttpMethod}";
ReRoute reRoute;
@ -132,20 +134,29 @@ namespace Ocelot.Configuration.Creator
var claimsToQueries = GetAddThingsToRequest(fileReRoute.AddQueriesToRequest);
reRoute = new ReRoute(new PathTemplate(fileReRoute.DownstreamPathTemplate),
new PathTemplate(fileReRoute.UpstreamTemplate),
fileReRoute.UpstreamHttpMethod, upstreamTemplate, isAuthenticated,
new PathTemplate(fileReRoute.UpstreamPathTemplate),
new HttpMethod(fileReRoute.UpstreamHttpMethod), upstreamTemplatePattern, isAuthenticated,
authOptionsForRoute, claimsToHeaders, claimsToClaims,
fileReRoute.RouteClaimsRequirement, isAuthorised, claimsToQueries,
requestIdKey, isCached, new CacheOptions(fileReRoute.FileCacheOptions.TtlSeconds)
, fileReRoute.DownstreamScheme,
fileReRoute.LoadBalancer, fileReRoute.DownstreamHost, fileReRoute.DownstreamPort, loadBalancerKey,
serviceProviderConfiguration);
//reRoute = new ReRouteBuilder()
// .WithDownstreamPathTemplate(fileReRoute.DownstreamPathTemplate)
// .WithUpstreamPathTemplate(fileReRoute.UpstreamPathTemplate)
// .WithUpstreamHttpMethod(fileReRoute.UpstreamHttpMethod)
// .WithUpstreamTemplatePattern(upstreamTemplatePattern)
// .WithIsAuthenticated(isAuthenticated)
//.Build();
}
else
{
reRoute = new ReRoute(new PathTemplate(fileReRoute.DownstreamPathTemplate),
new PathTemplate(fileReRoute.UpstreamTemplate),
fileReRoute.UpstreamHttpMethod, upstreamTemplate, isAuthenticated,
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),
@ -161,7 +172,7 @@ namespace Ocelot.Configuration.Creator
private string BuildUpstreamTemplate(FileReRoute reRoute)
{
var upstreamTemplate = reRoute.UpstreamTemplate;
var upstreamTemplate = reRoute.UpstreamPathTemplate;
upstreamTemplate = upstreamTemplate.SetLastCharacterAs('/');

View File

@ -15,7 +15,7 @@ namespace Ocelot.Configuration.File
}
public string DownstreamPathTemplate { get; set; }
public string UpstreamTemplate { get; set; }
public string UpstreamPathTemplate { get; set; }
public string UpstreamHttpMethod { get; set; }
public FileAuthenticationOptions AuthenticationOptions { get; set; }
public Dictionary<string, string> AddHeadersToRequest { get; set; }

View File

@ -8,7 +8,7 @@ namespace Ocelot.Configuration
public class ReRoute
{
public ReRoute(PathTemplate downstreamPathTemplate,
PathTemplate upstreamTemplate, string upstreamHttpMethod,
PathTemplate upstreamTemplate, HttpMethod upstreamHttpMethod,
string upstreamTemplatePattern,
bool isAuthenticated, AuthenticationOptions authenticationOptions,
List<ClaimToThing> configurationHeaderExtractorProperties,
@ -25,8 +25,8 @@ namespace Ocelot.Configuration
DownstreamHost = downstreamHost;
DownstreamPort = downstreamPort;
DownstreamPathTemplate = downstreamPathTemplate;
UpstreamTemplate = upstreamTemplate;
UpstreamHttpMethod = new HttpMethod(upstreamHttpMethod);
UpstreamPathTemplate = upstreamTemplate;
UpstreamHttpMethod = upstreamHttpMethod;
UpstreamTemplatePattern = upstreamTemplatePattern;
IsAuthenticated = isAuthenticated;
AuthenticationOptions = authenticationOptions;
@ -46,7 +46,7 @@ namespace Ocelot.Configuration
public string LoadBalancerKey {get;private set;}
public PathTemplate DownstreamPathTemplate { get; private set; }
public PathTemplate UpstreamTemplate { get; private set; }
public PathTemplate UpstreamPathTemplate { get; private set; }
public string UpstreamTemplatePattern { get; private set; }
public HttpMethod UpstreamHttpMethod { get; private set; }
public bool IsAuthenticated { get; private set; }

View File

@ -54,7 +54,7 @@ namespace Ocelot.Configuration.Validator
continue;
}
var error = new UnsupportedAuthenticationProviderError($"{reRoute.AuthenticationOptions?.Provider} is unsupported authentication provider, upstream template is {reRoute.UpstreamTemplate}, upstream method is {reRoute.UpstreamHttpMethod}");
var error = new UnsupportedAuthenticationProviderError($"{reRoute.AuthenticationOptions?.Provider} is unsupported authentication provider, upstream template is {reRoute.UpstreamPathTemplate}, upstream method is {reRoute.UpstreamHttpMethod}");
errors.Add(error);
}
@ -94,18 +94,18 @@ namespace Ocelot.Configuration.Validator
private ConfigurationValidationResult CheckForDupliateReRoutes(FileConfiguration configuration)
{
var hasDupes = configuration.ReRoutes
.GroupBy(x => new { x.UpstreamTemplate, x.UpstreamHttpMethod }).Any(x => x.Skip(1).Any());
.GroupBy(x => new { x.UpstreamPathTemplate, x.UpstreamHttpMethod }).Any(x => x.Skip(1).Any());
if (!hasDupes)
{
return new ConfigurationValidationResult(false);
}
var dupes = configuration.ReRoutes.GroupBy(x => new { x.UpstreamTemplate, x.UpstreamHttpMethod })
var dupes = configuration.ReRoutes.GroupBy(x => new { x.UpstreamPathTemplate, x.UpstreamHttpMethod })
.Where(x => x.Skip(1).Any());
var errors = dupes
.Select(d => new DownstreamPathTemplateAlreadyUsedError(string.Format("Duplicate DownstreamPath: {0}", d.Key.UpstreamTemplate)))
.Select(d => new DownstreamPathTemplateAlreadyUsedError(string.Format("Duplicate DownstreamPath: {0}", d.Key.UpstreamPathTemplate)))
.Cast<Error>()
.ToList();

View File

@ -34,7 +34,7 @@ namespace Ocelot.DownstreamRouteFinder.Finder
if (urlMatch.Data.Match)
{
var templateVariableNameAndValues = _urlPathPlaceholderNameAndValueFinder.Find(upstreamUrlPath, reRoute.UpstreamTemplate.Value);
var templateVariableNameAndValues = _urlPathPlaceholderNameAndValueFinder.Find(upstreamUrlPath, reRoute.UpstreamPathTemplate.Value);
return new OkResponse<DownstreamRoute>(new DownstreamRoute(templateVariableNameAndValues.Data, reRoute));
}

View File

@ -47,7 +47,7 @@ namespace Ocelot.AcceptanceTests
DownstreamPort = _downstreamServicePort,
DownstreamHost = _downstreamServiceHost,
DownstreamScheme = _downstreamServiceScheme,
UpstreamTemplate = "/",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = "Post",
AuthenticationOptions = new FileAuthenticationOptions
{
@ -85,7 +85,7 @@ namespace Ocelot.AcceptanceTests
DownstreamPort = _downstreamServicePort,
DownstreamHost = _downstreamServiceHost,
DownstreamScheme = _downstreamServiceScheme,
UpstreamTemplate = "/",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = "Post",
AuthenticationOptions = new FileAuthenticationOptions
{
@ -123,7 +123,7 @@ namespace Ocelot.AcceptanceTests
DownstreamPort = _downstreamServicePort,
DownstreamHost = _downstreamServiceHost,
DownstreamScheme = _downstreamServiceScheme,
UpstreamTemplate = "/",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = "Get",
AuthenticationOptions = new FileAuthenticationOptions
{
@ -163,7 +163,7 @@ namespace Ocelot.AcceptanceTests
DownstreamPort = _downstreamServicePort,
DownstreamHost = _downstreamServiceHost,
DownstreamScheme = _downstreamServiceScheme,
UpstreamTemplate = "/",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = "Post",
AuthenticationOptions = new FileAuthenticationOptions
{
@ -203,7 +203,7 @@ namespace Ocelot.AcceptanceTests
DownstreamPort = _downstreamServicePort,
DownstreamHost = _downstreamServiceHost,
DownstreamScheme = _downstreamServiceScheme,
UpstreamTemplate = "/",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = "Post",
AuthenticationOptions = new FileAuthenticationOptions
{

View File

@ -41,7 +41,7 @@ namespace Ocelot.AcceptanceTests
DownstreamPort = 51876,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = "Get",
AuthenticationOptions = new FileAuthenticationOptions
{
@ -98,7 +98,7 @@ namespace Ocelot.AcceptanceTests
DownstreamPort = 51876,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = "Get",
AuthenticationOptions = new FileAuthenticationOptions
{

View File

@ -35,7 +35,7 @@ namespace Ocelot.AcceptanceTests
DownstreamPort = 51879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = "Get",
FileCacheOptions = new FileCacheOptions
{
@ -71,7 +71,7 @@ namespace Ocelot.AcceptanceTests
DownstreamPort = 51879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = "Get",
FileCacheOptions = new FileCacheOptions
{

View File

@ -34,7 +34,7 @@ namespace Ocelot.AcceptanceTests
DownstreamPort = 51879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/products/{productId}",
UpstreamPathTemplate = "/products/{productId}",
UpstreamHttpMethod = "Get"
}
}
@ -61,7 +61,7 @@ namespace Ocelot.AcceptanceTests
DownstreamPort = 51879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/products/{productId}",
UpstreamPathTemplate = "/products/{productId}",
UpstreamHttpMethod = "Get",
ReRouteIsCaseSensitive = false
}
@ -89,7 +89,7 @@ namespace Ocelot.AcceptanceTests
DownstreamPort = 51879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/products/{productId}",
UpstreamPathTemplate = "/products/{productId}",
UpstreamHttpMethod = "Get",
ReRouteIsCaseSensitive = true
}
@ -117,7 +117,7 @@ namespace Ocelot.AcceptanceTests
DownstreamPort = 51879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/PRODUCTS/{productId}",
UpstreamPathTemplate = "/PRODUCTS/{productId}",
UpstreamHttpMethod = "Get",
ReRouteIsCaseSensitive = true
}
@ -145,7 +145,7 @@ namespace Ocelot.AcceptanceTests
DownstreamPort = 51879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/products/{productId}",
UpstreamPathTemplate = "/products/{productId}",
UpstreamHttpMethod = "Get",
ReRouteIsCaseSensitive = true
}
@ -173,7 +173,7 @@ namespace Ocelot.AcceptanceTests
DownstreamPort = 51879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/PRODUCTS/{productId}",
UpstreamPathTemplate = "/PRODUCTS/{productId}",
UpstreamHttpMethod = "Get",
ReRouteIsCaseSensitive = true
}

View File

@ -55,7 +55,7 @@ namespace Ocelot.AcceptanceTests
DownstreamPort = 52876,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = "Get",
AuthenticationOptions = new FileAuthenticationOptions
{

View File

@ -55,7 +55,7 @@ namespace Ocelot.AcceptanceTests
DownstreamPort = 57876,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = "Get",
AuthenticationOptions = new FileAuthenticationOptions
{

View File

@ -49,7 +49,7 @@ namespace Ocelot.AcceptanceTests
DownstreamPort = 41879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = "Get",
}
}
@ -86,7 +86,7 @@ namespace Ocelot.AcceptanceTests
DownstreamPort = 41879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = "Get",
}
}
@ -123,7 +123,7 @@ namespace Ocelot.AcceptanceTests
DownstreamPort = 41879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = "Get",
}
}
@ -160,7 +160,7 @@ namespace Ocelot.AcceptanceTests
DownstreamPort = 41879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = "Get",
}
}
@ -197,7 +197,7 @@ namespace Ocelot.AcceptanceTests
DownstreamPort = 41879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = "Get",
}
}
@ -234,7 +234,7 @@ namespace Ocelot.AcceptanceTests
DownstreamPort = 41879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = "Get",
}
}

View File

@ -37,7 +37,7 @@ namespace Ocelot.AcceptanceTests
DownstreamPort = 51879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = "Get",
RequestIdKey = _steps.RequestIdKey
}
@ -65,7 +65,7 @@ namespace Ocelot.AcceptanceTests
DownstreamPort = 51879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = "Get",
RequestIdKey = _steps.RequestIdKey
}
@ -95,7 +95,7 @@ namespace Ocelot.AcceptanceTests
DownstreamPort = 51879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = "Get",
}
},

View File

@ -30,7 +30,7 @@ namespace Ocelot.AcceptanceTests
new FileReRoute
{
DownstreamPathTemplate = "http://localhost:53876/",
UpstreamTemplate = "/",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = "Get"
}
}

View File

@ -44,7 +44,7 @@ namespace Ocelot.AcceptanceTests
DownstreamScheme = "http",
DownstreamHost = "localhost",
DownstreamPort = 51879,
UpstreamTemplate = "/",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = "Get",
}
}
@ -72,7 +72,7 @@ namespace Ocelot.AcceptanceTests
DownstreamScheme = "http",
DownstreamHost = "localhost",
DownstreamPort = 51879,
UpstreamTemplate = "/",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = "Get",
}
}
@ -100,7 +100,7 @@ namespace Ocelot.AcceptanceTests
DownstreamScheme = "http",
DownstreamHost = "localhost/",
DownstreamPort = 51879,
UpstreamTemplate = "/",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = "Get",
}
}
@ -128,7 +128,7 @@ namespace Ocelot.AcceptanceTests
DownstreamScheme = "http",
DownstreamHost = "localhost",
DownstreamPort = 51879,
UpstreamTemplate = "/products/",
UpstreamPathTemplate = "/products/",
UpstreamHttpMethod = "Get",
}
}
@ -156,7 +156,7 @@ namespace Ocelot.AcceptanceTests
DownstreamScheme = "http",
DownstreamHost = "localhost",
DownstreamPort = 51879,
UpstreamTemplate = "/products",
UpstreamPathTemplate = "/products",
UpstreamHttpMethod = "Get",
}
}
@ -184,7 +184,7 @@ namespace Ocelot.AcceptanceTests
DownstreamScheme = "http",
DownstreamHost = "localhost",
DownstreamPort = 51879,
UpstreamTemplate = "/products/{productId}",
UpstreamPathTemplate = "/products/{productId}",
UpstreamHttpMethod = "Get",
}
}
@ -211,7 +211,7 @@ namespace Ocelot.AcceptanceTests
DownstreamScheme = "http",
DownstreamHost = "localhost",
DownstreamPort = 51879,
UpstreamTemplate = "/products/{productId}",
UpstreamPathTemplate = "/products/{productId}",
UpstreamHttpMethod = "Get"
}
}
@ -239,7 +239,7 @@ namespace Ocelot.AcceptanceTests
DownstreamHost = "localhost",
DownstreamPort = 51879,
DownstreamScheme = "http",
UpstreamTemplate = "/",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = "Post"
}
}
@ -264,7 +264,7 @@ namespace Ocelot.AcceptanceTests
new FileReRoute
{
DownstreamPathTemplate = "/newThing",
UpstreamTemplate = "/newThing",
UpstreamPathTemplate = "/newThing",
DownstreamScheme = "http",
DownstreamHost = "localhost",
DownstreamPort = 51879,

View File

@ -68,7 +68,7 @@ namespace Ocelot.AcceptanceTests
{
DownstreamPathTemplate = "/",
DownstreamScheme = "http",
UpstreamTemplate = "/",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = "Get",
ServiceName = serviceName,
LoadBalancer = "LeastConnection",

View File

@ -1 +1 @@
{"ReRoutes":[{"DownstreamPathTemplate":"41879/","UpstreamTemplate":"/","UpstreamHttpMethod":"Get","AuthenticationOptions":{"Provider":null,"ProviderRootUrl":null,"ScopeName":null,"RequireHttps":false,"AdditionalScopes":[],"ScopeSecret":null},"AddHeadersToRequest":{},"AddClaimsToRequest":{},"RouteClaimsRequirement":{},"AddQueriesToRequest":{},"RequestIdKey":null,"FileCacheOptions":{"TtlSeconds":0},"ReRouteIsCaseSensitive":false,"ServiceName":null,"DownstreamScheme":"http","DownstreamHost":"localhost","DownstreamPort":41879,"LoadBalancer":null}],"GlobalConfiguration":{"RequestIdKey":null,"ServiceDiscoveryProvider":{"Provider":null,"Host":null,"Port":0}}}
{"ReRoutes":[{"DownstreamPathTemplate":"41879/","UpstreamPathTemplate":"/","UpstreamHttpMethod":"Get","AuthenticationOptions":{"Provider":null,"ProviderRootUrl":null,"ScopeName":null,"RequireHttps":false,"AdditionalScopes":[],"ScopeSecret":null},"AddHeadersToRequest":{},"AddClaimsToRequest":{},"RouteClaimsRequirement":{},"AddQueriesToRequest":{},"RequestIdKey":null,"FileCacheOptions":{"TtlSeconds":0},"ReRouteIsCaseSensitive":false,"ServiceName":null,"DownstreamScheme":"http","DownstreamHost":"localhost","DownstreamPort":41879,"LoadBalancer":null}],"GlobalConfiguration":{"RequestIdKey":null,"ServiceDiscoveryProvider":{"Provider":null,"Host":null,"Port":0}}}

View File

@ -29,7 +29,7 @@ namespace Ocelot.UnitTests.Configuration
new FileReRoute
{
DownstreamPathTemplate = "http://www.bbc.co.uk/api/products/{productId}",
UpstreamTemplate = "http://asdf.com"
UpstreamPathTemplate = "http://asdf.com"
}
}
}))
@ -48,7 +48,7 @@ namespace Ocelot.UnitTests.Configuration
new FileReRoute
{
DownstreamPathTemplate = "/api/products/",
UpstreamTemplate = "http://asdf.com"
UpstreamPathTemplate = "http://asdf.com"
}
}
}))
@ -67,7 +67,7 @@ namespace Ocelot.UnitTests.Configuration
new FileReRoute
{
DownstreamPathTemplate = "/api/products/",
UpstreamTemplate = "http://asdf.com",
UpstreamPathTemplate = "http://asdf.com",
AuthenticationOptions = new FileAuthenticationOptions
{
Provider = "IdentityServer"
@ -90,7 +90,7 @@ namespace Ocelot.UnitTests.Configuration
new FileReRoute
{
DownstreamPathTemplate = "/api/products/",
UpstreamTemplate = "http://asdf.com",
UpstreamPathTemplate = "http://asdf.com",
AuthenticationOptions = new FileAuthenticationOptions
{
Provider = "BootyBootyBottyRockinEverywhere"
@ -114,12 +114,12 @@ namespace Ocelot.UnitTests.Configuration
new FileReRoute
{
DownstreamPathTemplate = "/api/products/",
UpstreamTemplate = "http://asdf.com"
UpstreamPathTemplate = "http://asdf.com"
},
new FileReRoute
{
DownstreamPathTemplate = "http://www.bbc.co.uk",
UpstreamTemplate = "http://asdf.com"
UpstreamPathTemplate = "http://asdf.com"
}
}
}))

View File

@ -53,7 +53,7 @@ namespace Ocelot.UnitTests.Configuration
new FileReRoute
{
DownstreamHost = "127.0.0.1",
UpstreamTemplate = "/api/products/{productId}",
UpstreamPathTemplate = "/api/products/{productId}",
DownstreamPathTemplate = "/products/{productId}",
UpstreamHttpMethod = "Get",
}
@ -78,7 +78,7 @@ namespace Ocelot.UnitTests.Configuration
new FileReRoute
{
DownstreamHost = "127.0.0.1",
UpstreamTemplate = "/api/products/{productId}",
UpstreamPathTemplate = "/api/products/{productId}",
DownstreamPathTemplate = "/products/{productId}",
UpstreamHttpMethod = "Get",
}
@ -91,7 +91,7 @@ namespace Ocelot.UnitTests.Configuration
new ReRouteBuilder()
.WithDownstreamHost("127.0.0.1")
.WithDownstreamPathTemplate("/products/{productId}")
.WithUpstreamTemplate("/api/products/{productId}")
.WithUpstreamPathTemplate("/api/products/{productId}")
.WithUpstreamHttpMethod("Get")
.WithUpstreamTemplatePattern("(?i)/api/products/.*/$")
.Build()
@ -109,7 +109,7 @@ namespace Ocelot.UnitTests.Configuration
new FileReRoute
{
DownstreamScheme = "https",
UpstreamTemplate = "/api/products/{productId}",
UpstreamPathTemplate = "/api/products/{productId}",
DownstreamPathTemplate = "/products/{productId}",
UpstreamHttpMethod = "Get",
}
@ -122,7 +122,7 @@ namespace Ocelot.UnitTests.Configuration
new ReRouteBuilder()
.WithDownstreamScheme("https")
.WithDownstreamPathTemplate("/products/{productId}")
.WithUpstreamTemplate("/api/products/{productId}")
.WithUpstreamPathTemplate("/api/products/{productId}")
.WithUpstreamHttpMethod("Get")
.WithUpstreamTemplatePattern("(?i)/api/products/.*/$")
.Build()
@ -139,7 +139,7 @@ namespace Ocelot.UnitTests.Configuration
{
new FileReRoute
{
UpstreamTemplate = "/api/products/{productId}",
UpstreamPathTemplate = "/api/products/{productId}",
DownstreamPathTemplate = "/products/{productId}",
UpstreamHttpMethod = "Get",
ReRouteIsCaseSensitive = false,
@ -161,7 +161,7 @@ namespace Ocelot.UnitTests.Configuration
{
new ReRouteBuilder()
.WithDownstreamPathTemplate("/products/{productId}")
.WithUpstreamTemplate("/api/products/{productId}")
.WithUpstreamPathTemplate("/api/products/{productId}")
.WithUpstreamHttpMethod("Get")
.WithUpstreamTemplatePattern("(?i)/api/products/.*/$")
.WithServiceName("ProductService")
@ -184,7 +184,7 @@ namespace Ocelot.UnitTests.Configuration
{
new FileReRoute
{
UpstreamTemplate = "/api/products/{productId}",
UpstreamPathTemplate = "/api/products/{productId}",
DownstreamPathTemplate = "/products/{productId}",
UpstreamHttpMethod = "Get",
ReRouteIsCaseSensitive = false,
@ -197,7 +197,7 @@ namespace Ocelot.UnitTests.Configuration
{
new ReRouteBuilder()
.WithDownstreamPathTemplate("/products/{productId}")
.WithUpstreamTemplate("/api/products/{productId}")
.WithUpstreamPathTemplate("/api/products/{productId}")
.WithUpstreamHttpMethod("Get")
.WithUpstreamTemplatePattern("(?i)/api/products/.*/$")
.WithServiceProviderConfiguraion(new ServiceProviderConfiguraionBuilder()
@ -217,7 +217,7 @@ namespace Ocelot.UnitTests.Configuration
{
new FileReRoute
{
UpstreamTemplate = "/api/products/{productId}",
UpstreamPathTemplate = "/api/products/{productId}",
DownstreamPathTemplate = "/products/{productId}",
UpstreamHttpMethod = "Get",
ReRouteIsCaseSensitive = false
@ -230,7 +230,7 @@ namespace Ocelot.UnitTests.Configuration
{
new ReRouteBuilder()
.WithDownstreamPathTemplate("/products/{productId}")
.WithUpstreamTemplate("/api/products/{productId}")
.WithUpstreamPathTemplate("/api/products/{productId}")
.WithUpstreamHttpMethod("Get")
.WithUpstreamTemplatePattern("(?i)/api/products/.*/$")
.Build()
@ -247,7 +247,7 @@ namespace Ocelot.UnitTests.Configuration
{
new FileReRoute
{
UpstreamTemplate = "/api/products/{productId}",
UpstreamPathTemplate = "/api/products/{productId}",
DownstreamPathTemplate = "/products/{productId}",
UpstreamHttpMethod = "Get"
}
@ -259,7 +259,7 @@ namespace Ocelot.UnitTests.Configuration
{
new ReRouteBuilder()
.WithDownstreamPathTemplate("/products/{productId}")
.WithUpstreamTemplate("/api/products/{productId}")
.WithUpstreamPathTemplate("/api/products/{productId}")
.WithUpstreamHttpMethod("Get")
.WithUpstreamTemplatePattern("(?i)/api/products/.*/$")
.Build()
@ -276,7 +276,7 @@ namespace Ocelot.UnitTests.Configuration
{
new FileReRoute
{
UpstreamTemplate = "/api/products/{productId}",
UpstreamPathTemplate = "/api/products/{productId}",
DownstreamPathTemplate = "/products/{productId}",
UpstreamHttpMethod = "Get",
ReRouteIsCaseSensitive = true
@ -289,7 +289,7 @@ namespace Ocelot.UnitTests.Configuration
{
new ReRouteBuilder()
.WithDownstreamPathTemplate("/products/{productId}")
.WithUpstreamTemplate("/api/products/{productId}")
.WithUpstreamPathTemplate("/api/products/{productId}")
.WithUpstreamHttpMethod("Get")
.WithUpstreamTemplatePattern("/api/products/.*/$")
.Build()
@ -306,7 +306,7 @@ namespace Ocelot.UnitTests.Configuration
{
new FileReRoute
{
UpstreamTemplate = "/api/products/{productId}",
UpstreamPathTemplate = "/api/products/{productId}",
DownstreamPathTemplate = "/products/{productId}",
UpstreamHttpMethod = "Get",
ReRouteIsCaseSensitive = true
@ -323,7 +323,7 @@ namespace Ocelot.UnitTests.Configuration
{
new ReRouteBuilder()
.WithDownstreamPathTemplate("/products/{productId}")
.WithUpstreamTemplate("/api/products/{productId}")
.WithUpstreamPathTemplate("/api/products/{productId}")
.WithUpstreamHttpMethod("Get")
.WithUpstreamTemplatePattern("/api/products/.*/$")
.WithRequestIdKey("blahhhh")
@ -341,7 +341,7 @@ namespace Ocelot.UnitTests.Configuration
{
new FileReRoute
{
UpstreamTemplate = "/api/products/{productId}",
UpstreamPathTemplate = "/api/products/{productId}",
DownstreamPathTemplate = "/products/{productId}",
UpstreamHttpMethod = "Get",
ReRouteIsCaseSensitive = true
@ -354,7 +354,7 @@ namespace Ocelot.UnitTests.Configuration
{
new ReRouteBuilder()
.WithDownstreamPathTemplate("/products/{productId}")
.WithUpstreamTemplate("/api/products/{productId}")
.WithUpstreamPathTemplate("/api/products/{productId}")
.WithUpstreamHttpMethod("Get")
.WithUpstreamTemplatePattern("/api/products/.*/$")
.Build()
@ -365,18 +365,23 @@ namespace Ocelot.UnitTests.Configuration
[Fact]
public void should_create_with_headers_to_extract()
{
var authenticationOptions = new AuthenticationOptionsBuilder()
.WithProvider("IdentityServer")
.WithProviderRootUrl("http://localhost:51888")
.WithRequireHttps(false)
.WithScopeSecret("secret")
.WithScopeName("api")
.WithAdditionalScopes(new List<string>())
.Build();
var expected = new List<ReRoute>
{
new ReRouteBuilder()
.WithDownstreamPathTemplate("/products/{productId}")
.WithUpstreamTemplate("/api/products/{productId}")
.WithUpstreamPathTemplate("/api/products/{productId}")
.WithUpstreamHttpMethod("Get")
.WithUpstreamTemplatePattern("/api/products/.*/$")
.WithAuthenticationProvider("IdentityServer")
.WithAuthenticationProviderUrl("http://localhost:51888")
.WithRequireHttps(false)
.WithScopeSecret("secret")
.WithAuthenticationProviderScopeName("api")
.WithAuthenticationOptions(authenticationOptions)
.WithClaimsToHeaders(new List<ClaimToThing>
{
new ClaimToThing("CustomerId", "CustomerId", "", 0),
@ -390,7 +395,7 @@ namespace Ocelot.UnitTests.Configuration
{
new FileReRoute
{
UpstreamTemplate = "/api/products/{productId}",
UpstreamPathTemplate = "/api/products/{productId}",
DownstreamPathTemplate = "/products/{productId}",
UpstreamHttpMethod = "Get",
ReRouteIsCaseSensitive = true,
@ -429,18 +434,23 @@ namespace Ocelot.UnitTests.Configuration
[Fact]
public void should_create_with_authentication_properties()
{
var authenticationOptions = new AuthenticationOptionsBuilder()
.WithProvider("IdentityServer")
.WithProviderRootUrl("http://localhost:51888")
.WithRequireHttps(false)
.WithScopeSecret("secret")
.WithScopeName("api")
.WithAdditionalScopes(new List<string>())
.Build();
var expected = new List<ReRoute>
{
new ReRouteBuilder()
.WithDownstreamPathTemplate("/products/{productId}")
.WithUpstreamTemplate("/api/products/{productId}")
.WithUpstreamPathTemplate("/api/products/{productId}")
.WithUpstreamHttpMethod("Get")
.WithUpstreamTemplatePattern("/api/products/.*/$")
.WithAuthenticationProvider("IdentityServer")
.WithAuthenticationProviderUrl("http://localhost:51888")
.WithRequireHttps(false)
.WithScopeSecret("secret")
.WithAuthenticationProviderScopeName("api")
.WithAuthenticationOptions(authenticationOptions)
.Build()
};
@ -450,7 +460,7 @@ namespace Ocelot.UnitTests.Configuration
{
new FileReRoute
{
UpstreamTemplate = "/api/products/{productId}",
UpstreamPathTemplate = "/api/products/{productId}",
DownstreamPathTemplate = "/products/{productId}",
UpstreamHttpMethod = "Get",
ReRouteIsCaseSensitive = true,
@ -483,7 +493,7 @@ namespace Ocelot.UnitTests.Configuration
{
new FileReRoute
{
UpstreamTemplate = "/api/products/{productId}/variants/{variantId}",
UpstreamPathTemplate = "/api/products/{productId}/variants/{variantId}",
DownstreamPathTemplate = "/products/{productId}",
UpstreamHttpMethod = "Get",
ReRouteIsCaseSensitive = true
@ -496,7 +506,7 @@ namespace Ocelot.UnitTests.Configuration
{
new ReRouteBuilder()
.WithDownstreamPathTemplate("/products/{productId}")
.WithUpstreamTemplate("/api/products/{productId}/variants/{variantId}")
.WithUpstreamPathTemplate("/api/products/{productId}/variants/{variantId}")
.WithUpstreamHttpMethod("Get")
.WithUpstreamTemplatePattern("/api/products/.*/variants/.*/$")
.Build()
@ -513,7 +523,7 @@ namespace Ocelot.UnitTests.Configuration
{
new FileReRoute
{
UpstreamTemplate = "/api/products/{productId}/variants/{variantId}/",
UpstreamPathTemplate = "/api/products/{productId}/variants/{variantId}/",
DownstreamPathTemplate = "/products/{productId}",
UpstreamHttpMethod = "Get",
ReRouteIsCaseSensitive = true
@ -526,7 +536,7 @@ namespace Ocelot.UnitTests.Configuration
{
new ReRouteBuilder()
.WithDownstreamPathTemplate("/products/{productId}")
.WithUpstreamTemplate("/api/products/{productId}/variants/{variantId}/")
.WithUpstreamPathTemplate("/api/products/{productId}/variants/{variantId}/")
.WithUpstreamHttpMethod("Get")
.WithUpstreamTemplatePattern("/api/products/.*/variants/.*/$")
.Build()
@ -543,7 +553,7 @@ namespace Ocelot.UnitTests.Configuration
{
new FileReRoute
{
UpstreamTemplate = "/",
UpstreamPathTemplate = "/",
DownstreamPathTemplate = "/api/products/",
UpstreamHttpMethod = "Get",
ReRouteIsCaseSensitive = true
@ -556,7 +566,7 @@ namespace Ocelot.UnitTests.Configuration
{
new ReRouteBuilder()
.WithDownstreamPathTemplate("/api/products/")
.WithUpstreamTemplate("/")
.WithUpstreamPathTemplate("/")
.WithUpstreamHttpMethod("Get")
.WithUpstreamTemplatePattern("/$")
.Build()
@ -593,7 +603,7 @@ namespace Ocelot.UnitTests.Configuration
result.DownstreamPathTemplate.Value.ShouldBe(expected.DownstreamPathTemplate.Value);
result.UpstreamHttpMethod.ShouldBe(expected.UpstreamHttpMethod);
result.UpstreamTemplate.Value.ShouldBe(expected.UpstreamTemplate.Value);
result.UpstreamPathTemplate.Value.ShouldBe(expected.UpstreamPathTemplate.Value);
result.UpstreamTemplatePattern.ShouldBe(expected.UpstreamTemplatePattern);
}
}

View File

@ -45,7 +45,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
{
new ReRouteBuilder()
.WithDownstreamPathTemplate("someDownstreamPath")
.WithUpstreamTemplate("someUpstreamPath")
.WithUpstreamPathTemplate("someUpstreamPath")
.WithUpstreamHttpMethod("Get")
.WithUpstreamTemplatePattern("someUpstreamPath")
.Build()
@ -77,13 +77,13 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
{
new ReRouteBuilder()
.WithDownstreamPathTemplate("someDownstreamPath")
.WithUpstreamTemplate("someUpstreamPath")
.WithUpstreamPathTemplate("someUpstreamPath")
.WithUpstreamHttpMethod("Get")
.WithUpstreamTemplatePattern("")
.Build(),
new ReRouteBuilder()
.WithDownstreamPathTemplate("someDownstreamPathForAPost")
.WithUpstreamTemplate("someUpstreamPath")
.WithUpstreamPathTemplate("someUpstreamPath")
.WithUpstreamHttpMethod("Post")
.WithUpstreamTemplatePattern("")
.Build()
@ -110,7 +110,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
{
new ReRouteBuilder()
.WithDownstreamPathTemplate("somPath")
.WithUpstreamTemplate("somePath")
.WithUpstreamPathTemplate("somePath")
.WithUpstreamHttpMethod("Get")
.WithUpstreamTemplatePattern("somePath")
.Build(),
@ -145,7 +145,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
private void ThenTheUrlMatcherIsCalledCorrectly()
{
_mockMatcher
.Verify(x => x.Match(_upstreamUrlPath, _reRoutesConfig[0].UpstreamTemplate.Value), Times.Once);
.Verify(x => x.Match(_upstreamUrlPath, _reRoutesConfig[0].UpstreamPathTemplate.Value), Times.Once);
}
private void GivenTheUrlMatcherReturns(Response<UrlMatch> match)

View File

@ -1,4 +1,5 @@
using Ocelot.Configuration;
using Ocelot.Configuration.Builder;
using Ocelot.ServiceDiscovery;
using Shouldly;
using TestStack.BDDfy;