mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 04:48:17 +08:00
looking at #135 validation
This commit is contained in:
@ -0,0 +1,12 @@
|
||||
using Ocelot.Errors;
|
||||
|
||||
namespace Ocelot.Configuration.Validator
|
||||
{
|
||||
public class PathTemplateDoesntStartWithForwardSlash : Error
|
||||
{
|
||||
public PathTemplateDoesntStartWithForwardSlash(string message)
|
||||
: base(message, OcelotErrorCode.PathTemplateDoesntStartWithForwardSlash)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -26,6 +26,20 @@ namespace Ocelot.Configuration.Validator
|
||||
return new OkResponse<ConfigurationValidationResult>(result);
|
||||
}
|
||||
|
||||
result = CheckDownstreamTemplatePathBeingsWithForwardSlash(configuration);
|
||||
|
||||
if (result.IsError)
|
||||
{
|
||||
return new OkResponse<ConfigurationValidationResult>(result);
|
||||
}
|
||||
|
||||
result = CheckUpstreamTemplatePathBeingsWithForwardSlash(configuration);
|
||||
|
||||
if (result.IsError)
|
||||
{
|
||||
return new OkResponse<ConfigurationValidationResult>(result);
|
||||
}
|
||||
|
||||
result = await CheckForUnsupportedAuthenticationProviders(configuration);
|
||||
|
||||
if (result.IsError)
|
||||
@ -49,6 +63,46 @@ namespace Ocelot.Configuration.Validator
|
||||
return new OkResponse<ConfigurationValidationResult>(result);
|
||||
}
|
||||
|
||||
private ConfigurationValidationResult CheckDownstreamTemplatePathBeingsWithForwardSlash(FileConfiguration configuration)
|
||||
{
|
||||
var errors = new List<Error>();
|
||||
|
||||
foreach(var reRoute in configuration.ReRoutes)
|
||||
{
|
||||
if(!reRoute.DownstreamPathTemplate.StartsWith("/"))
|
||||
{
|
||||
errors.Add(new PathTemplateDoesntStartWithForwardSlash($"{reRoute.DownstreamPathTemplate} doesnt start with forward slash"));
|
||||
}
|
||||
}
|
||||
|
||||
if(errors.Any())
|
||||
{
|
||||
return new ConfigurationValidationResult(true, errors);
|
||||
}
|
||||
|
||||
return new ConfigurationValidationResult(false, errors);
|
||||
}
|
||||
|
||||
private ConfigurationValidationResult CheckUpstreamTemplatePathBeingsWithForwardSlash(FileConfiguration configuration)
|
||||
{
|
||||
var errors = new List<Error>();
|
||||
|
||||
foreach(var reRoute in configuration.ReRoutes)
|
||||
{
|
||||
if(!reRoute.UpstreamPathTemplate.StartsWith("/"))
|
||||
{
|
||||
errors.Add(new PathTemplateDoesntStartWithForwardSlash($"{reRoute.DownstreamPathTemplate} doesnt start with forward slash"));
|
||||
}
|
||||
}
|
||||
|
||||
if(errors.Any())
|
||||
{
|
||||
return new ConfigurationValidationResult(true, errors);
|
||||
}
|
||||
|
||||
return new ConfigurationValidationResult(false, errors);
|
||||
}
|
||||
|
||||
private async Task<ConfigurationValidationResult> CheckForUnsupportedAuthenticationProviders(FileConfiguration configuration)
|
||||
{
|
||||
var errors = new List<Error>();
|
||||
|
@ -31,6 +31,7 @@
|
||||
UnableToFindQoSProviderError,
|
||||
UnableToSetConfigInConsulError,
|
||||
UnmappableRequestError,
|
||||
RateLimitOptionsError
|
||||
RateLimitOptionsError,
|
||||
PathTemplateDoesntStartWithForwardSlash
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user