mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-23 00:32:50 +08:00
started messing around with admin area
This commit is contained in:
parent
0b830d9891
commit
95fc687e93
@ -85,7 +85,7 @@ namespace Ocelot.Configuration.Creator
|
||||
reRoutes.Add(ocelotReRoute);
|
||||
}
|
||||
|
||||
return new OcelotConfiguration(reRoutes);
|
||||
return new OcelotConfiguration(reRoutes, _options.Value.GlobalConfiguration.AdministrationPath);
|
||||
}
|
||||
|
||||
private async Task<ReRoute> SetUpReRoute(FileReRoute fileReRoute, FileGlobalConfiguration globalConfiguration)
|
||||
|
@ -8,5 +8,6 @@
|
||||
}
|
||||
public string RequestIdKey { get; set; }
|
||||
public FileServiceDiscoveryProvider ServiceDiscoveryProvider {get;set;}
|
||||
public string AdministrationPath {get;set;}
|
||||
}
|
||||
}
|
||||
|
@ -5,5 +5,6 @@ namespace Ocelot.Configuration
|
||||
public interface IOcelotConfiguration
|
||||
{
|
||||
List<ReRoute> ReRoutes { get; }
|
||||
string AdministrationPath {get;}
|
||||
}
|
||||
}
|
@ -4,11 +4,13 @@ namespace Ocelot.Configuration
|
||||
{
|
||||
public class OcelotConfiguration : IOcelotConfiguration
|
||||
{
|
||||
public OcelotConfiguration(List<ReRoute> reRoutes)
|
||||
public OcelotConfiguration(List<ReRoute> reRoutes, string administrationPath)
|
||||
{
|
||||
ReRoutes = reRoutes;
|
||||
AdministrationPath = administrationPath;
|
||||
}
|
||||
|
||||
public List<ReRoute> ReRoutes { get; }
|
||||
public string AdministrationPath {get;}
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@ namespace Ocelot.Middleware
|
||||
using System.Threading.Tasks;
|
||||
using Authorisation.Middleware;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Configuration.Provider;
|
||||
using Ocelot.LoadBalancer.Middleware;
|
||||
|
||||
@ -30,9 +31,9 @@ namespace Ocelot.Middleware
|
||||
/// <returns></returns>
|
||||
public static IApplicationBuilder UseOcelot(this IApplicationBuilder builder)
|
||||
{
|
||||
CreateConfiguration(builder);
|
||||
var configuration = CreateConfiguration(builder).Result;
|
||||
|
||||
builder.Map("/admin", x =>
|
||||
builder.Map(configuration.AdministrationPath, x =>
|
||||
{
|
||||
x.UseMvc();
|
||||
});
|
||||
@ -131,16 +132,19 @@ namespace Ocelot.Middleware
|
||||
return builder;
|
||||
}
|
||||
|
||||
private static void CreateConfiguration(IApplicationBuilder builder)
|
||||
private static async Task<IOcelotConfiguration> CreateConfiguration(IApplicationBuilder builder)
|
||||
{
|
||||
var configProvider = (IOcelotConfigurationProvider)builder.ApplicationServices.GetService(typeof(IOcelotConfigurationProvider));
|
||||
|
||||
var config = configProvider.Get();
|
||||
var config = await configProvider.Get();
|
||||
|
||||
if(config == null)
|
||||
//todo move this to config validators
|
||||
if(config == null || config.Data == null || config.IsError)
|
||||
{
|
||||
throw new Exception("Unable to start Ocelot: configuration was null");
|
||||
throw new Exception("Unable to start Ocelot: configuration was invalid");
|
||||
}
|
||||
|
||||
return config.Data;
|
||||
}
|
||||
|
||||
private static void UseIfNotNull(this IApplicationBuilder builder, Func<HttpContext, Func<Task>, Task> middleware)
|
||||
|
@ -300,6 +300,7 @@
|
||||
],
|
||||
|
||||
"GlobalConfiguration": {
|
||||
"RequestIdKey": "OcRequestId"
|
||||
"RequestIdKey": "OcRequestId",
|
||||
"AdministrationPath": "/admin"
|
||||
}
|
||||
}
|
@ -29,9 +29,9 @@ namespace Ocelot.UnitTests.Configuration
|
||||
[Fact]
|
||||
public void should_get_config()
|
||||
{
|
||||
this.Given(x => x.GivenTheRepoReturns(new OkResponse<IOcelotConfiguration>(new OcelotConfiguration(new List<ReRoute>()))))
|
||||
this.Given(x => x.GivenTheRepoReturns(new OkResponse<IOcelotConfiguration>(new OcelotConfiguration(new List<ReRoute>(), string.Empty))))
|
||||
.When(x => x.WhenIGetTheConfig())
|
||||
.Then(x => x.TheFollowingIsReturned(new OkResponse<IOcelotConfiguration>(new OcelotConfiguration(new List<ReRoute>()))))
|
||||
.Then(x => x.TheFollowingIsReturned(new OkResponse<IOcelotConfiguration>(new OcelotConfiguration(new List<ReRoute>(), string.Empty))))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -39,9 +39,9 @@ namespace Ocelot.UnitTests.Configuration
|
||||
public void should_create_config_if_it_doesnt_exist()
|
||||
{
|
||||
this.Given(x => x.GivenTheRepoReturns(new OkResponse<IOcelotConfiguration>(null)))
|
||||
.And(x => x.GivenTheCreatorReturns(new OkResponse<IOcelotConfiguration>(new OcelotConfiguration(new List<ReRoute>()))))
|
||||
.And(x => x.GivenTheCreatorReturns(new OkResponse<IOcelotConfiguration>(new OcelotConfiguration(new List<ReRoute>(), string.Empty))))
|
||||
.When(x => x.WhenIGetTheConfig())
|
||||
.Then(x => x.TheFollowingIsReturned(new OkResponse<IOcelotConfiguration>(new OcelotConfiguration(new List<ReRoute>()))))
|
||||
.Then(x => x.TheFollowingIsReturned(new OkResponse<IOcelotConfiguration>(new OcelotConfiguration(new List<ReRoute>(), string.Empty))))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
|
@ -82,6 +82,14 @@ namespace Ocelot.UnitTests.Configuration
|
||||
_downstreamTemplatePath = downstreamTemplatePath;
|
||||
}
|
||||
|
||||
public string AdministrationPath
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public List<ReRoute> ReRoutes => new List<ReRoute>
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
|
@ -48,7 +48,8 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.WithUpstreamHttpMethod("Get")
|
||||
.WithUpstreamTemplatePattern("someUpstreamPath")
|
||||
.Build()
|
||||
}))
|
||||
}, string.Empty
|
||||
))
|
||||
.And(x => x.GivenTheUrlMatcherReturns(new OkResponse<UrlMatch>(new UrlMatch(true))))
|
||||
.And(x => x.GivenTheUpstreamHttpMethodIs("Get"))
|
||||
.When(x => x.WhenICallTheFinder())
|
||||
@ -80,7 +81,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.WithUpstreamHttpMethod("Get")
|
||||
.WithUpstreamTemplatePattern("someUpstreamPath")
|
||||
.Build()
|
||||
}
|
||||
}, string.Empty
|
||||
))
|
||||
.And(x => x.GivenTheUrlMatcherReturns(new OkResponse<UrlMatch>(new UrlMatch(true))))
|
||||
.And(x => x.GivenTheUpstreamHttpMethodIs("Get"))
|
||||
@ -118,7 +119,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.WithUpstreamHttpMethod("Post")
|
||||
.WithUpstreamTemplatePattern("")
|
||||
.Build()
|
||||
}
|
||||
}, string.Empty
|
||||
))
|
||||
.And(x => x.GivenTheUrlMatcherReturns(new OkResponse<UrlMatch>(new UrlMatch(true))))
|
||||
.And(x => x.GivenTheUpstreamHttpMethodIs("Post"))
|
||||
@ -145,7 +146,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.WithUpstreamHttpMethod("Get")
|
||||
.WithUpstreamTemplatePattern("somePath")
|
||||
.Build(),
|
||||
}
|
||||
}, string.Empty
|
||||
))
|
||||
.And(x => x.GivenTheUrlMatcherReturns(new OkResponse<UrlMatch>(new UrlMatch(false))))
|
||||
.And(x => x.GivenTheUpstreamHttpMethodIs("Get"))
|
||||
@ -193,12 +194,12 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.Returns(_match);
|
||||
}
|
||||
|
||||
private void GivenTheConfigurationIs(List<ReRoute> reRoutesConfig)
|
||||
private void GivenTheConfigurationIs(List<ReRoute> reRoutesConfig, string adminPath)
|
||||
{
|
||||
_reRoutesConfig = reRoutesConfig;
|
||||
_mockConfig
|
||||
.Setup(x => x.Get())
|
||||
.ReturnsAsync(new OkResponse<IOcelotConfiguration>(new OcelotConfiguration(_reRoutesConfig)));
|
||||
.ReturnsAsync(new OkResponse<IOcelotConfiguration>(new OcelotConfiguration(_reRoutesConfig, adminPath)));
|
||||
}
|
||||
|
||||
private void GivenThereIsAnUpstreamUrlPath(string upstreamUrlPath)
|
||||
|
Loading…
x
Reference in New Issue
Block a user