mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 14:28:16 +08:00
Added some configuration validation stuff but then realised probablt wont need this for a while
This commit is contained in:
@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Configuration
|
||||
{
|
||||
public class ConfigurationValidationResult
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Configuration
|
||||
{
|
||||
public class ConfigurationValidator : IConfigurationValidator
|
||||
{
|
||||
public Response<ConfigurationValidationResult> IsValid(Configuration configuration)
|
||||
{
|
||||
var duplicateUpstreamTemplates = configuration.ReRoutes
|
||||
.Select(r => r.DownstreamTemplate)
|
||||
.GroupBy(r => r)
|
||||
.Where(r => r.Count() > 1)
|
||||
.Select(r => r.Key)
|
||||
.ToList();
|
||||
|
||||
if (duplicateUpstreamTemplates.Count <= 0)
|
||||
{
|
||||
return new OkResponse<ConfigurationValidationResult>(new ConfigurationValidationResult());
|
||||
}
|
||||
|
||||
var errors = new List<Error>();
|
||||
|
||||
foreach (var duplicateUpstreamTemplate in duplicateUpstreamTemplates)
|
||||
{
|
||||
var error = new DownstreamTemplateAlreadyUsedError(string.Format("Duplicate DownstreamTemplate: {0}",
|
||||
duplicateUpstreamTemplate));
|
||||
errors.Add(error);
|
||||
}
|
||||
|
||||
return new ErrorResponse<ConfigurationValidationResult>(errors);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Configuration
|
||||
{
|
||||
public class DownstreamTemplateAlreadyUsedError : Error
|
||||
{
|
||||
public DownstreamTemplateAlreadyUsedError(string message) : base(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Configuration
|
||||
{
|
||||
public interface IConfigurationValidator
|
||||
{
|
||||
Response<ConfigurationValidationResult> IsValid(Configuration configuration);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user