Added some configuration validation stuff but then realised probablt wont need this for a while

This commit is contained in:
TomPallister
2016-09-07 22:53:39 +01:00
parent 484270edbc
commit 87702141e2
5 changed files with 160 additions and 0 deletions

View File

@ -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
{
}
}

View File

@ -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);
}
}
}

View File

@ -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)
{
}
}
}

View File

@ -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);
}
}