From b28fc6694ef0c092dd715b93c8d0a80597023361 Mon Sep 17 00:00:00 2001 From: Tom Gardham-Pallister Date: Sun, 29 Oct 2017 16:35:12 +0000 Subject: [PATCH] tidy up and no longer hard code admin area...still one int test failing before we start looking at rebuilding auth stuff --- .../ServiceCollectionExtensions.cs | 8 ++++---- src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs | 11 +++++------ test/Ocelot.AcceptanceTests/Steps.cs | 6 +----- test/Ocelot.IntegrationTests/AdministrationTests.cs | 2 +- .../Ocelot.IntegrationTests.csproj | 2 +- test/Ocelot.ManualTest/Startup.cs | 4 +--- 6 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/Ocelot/DependencyInjection/ServiceCollectionExtensions.cs b/src/Ocelot/DependencyInjection/ServiceCollectionExtensions.cs index 13452678..e6940d86 100644 --- a/src/Ocelot/DependencyInjection/ServiceCollectionExtensions.cs +++ b/src/Ocelot/DependencyInjection/ServiceCollectionExtensions.cs @@ -147,13 +147,13 @@ namespace Ocelot.DependencyInjection if (identityServerConfiguration != null) { - services.AddIdentityServer(identityServerConfiguration); + services.AddIdentityServer(identityServerConfiguration, configurationRoot); } return services; } - private static void AddIdentityServer(this IServiceCollection services, IIdentityServerConfiguration identityServerConfiguration) + private static void AddIdentityServer(this IServiceCollection services, IIdentityServerConfiguration identityServerConfiguration, IConfigurationRoot configurationRoot) { services.TryAddSingleton(identityServerConfiguration); services.TryAddSingleton(); @@ -172,8 +172,8 @@ namespace Ocelot.DependencyInjection services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme) .AddIdentityServerAuthentication(o => { - //todo - this needs to come from the config so have to get it in here... - o.Authority = baseSchemeUrlAndPort + "/administration"; + var adminPath = configurationRoot.GetValue("GlobalConfiguration:AdministrationPath", string.Empty); + o.Authority = baseSchemeUrlAndPort + adminPath; o.ApiName = identityServerConfiguration.ApiName; o.RequireHttpsMetadata = identityServerConfiguration.RequireHttps; o.SupportedTokens = SupportedTokens.Both; diff --git a/src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs b/src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs index 57c9d3f4..cef4307b 100644 --- a/src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs +++ b/src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs @@ -41,9 +41,9 @@ namespace Ocelot.Middleware /// /// /// - public static async Task UseOcelot(this IApplicationBuilder builder, IServiceCollection services) + public static async Task UseOcelot(this IApplicationBuilder builder) { - await builder.UseOcelot(new OcelotMiddlewareConfiguration(), services); + await builder.UseOcelot(new OcelotMiddlewareConfiguration()); return builder; } @@ -54,9 +54,9 @@ namespace Ocelot.Middleware /// /// /// - public static async Task UseOcelot(this IApplicationBuilder builder, OcelotMiddlewareConfiguration middlewareConfiguration, IServiceCollection services) + public static async Task UseOcelot(this IApplicationBuilder builder, OcelotMiddlewareConfiguration middlewareConfiguration) { - await CreateAdministrationArea(builder, services); + await CreateAdministrationArea(builder); ConfigureDiagnosticListener(builder); @@ -173,7 +173,7 @@ namespace Ocelot.Middleware return ocelotConfiguration.Data; } - private static async Task CreateAdministrationArea(IApplicationBuilder builder, IServiceCollection services) + private static async Task CreateAdministrationArea(IApplicationBuilder builder) { var configuration = await CreateConfiguration(builder); @@ -183,7 +183,6 @@ namespace Ocelot.Middleware { builder.Map(configuration.AdministrationPath, app => { - Console.WriteLine("SETTING UP ADMIN AREA"); app.UseIdentityServer(); app.UseAuthentication(); app.UseMvc(); diff --git a/test/Ocelot.AcceptanceTests/Steps.cs b/test/Ocelot.AcceptanceTests/Steps.cs index b482c00a..44bdf8f4 100644 --- a/test/Ocelot.AcceptanceTests/Steps.cs +++ b/test/Ocelot.AcceptanceTests/Steps.cs @@ -134,11 +134,8 @@ namespace Ocelot.AcceptanceTests .AddJsonFile("configuration.json") .AddEnvironmentVariables(); - IServiceCollection serviceCollection = new ServiceCollection(); var configuration = builder.Build(); - _webHostBuilder = new WebHostBuilder(); - _webHostBuilder.ConfigureServices(s => { s.AddSingleton(_webHostBuilder); @@ -158,7 +155,6 @@ namespace Ocelot.AcceptanceTests }; s.AddOcelot(configuration, settings); - serviceCollection = s; }) .ConfigureLogging(l => { @@ -167,7 +163,7 @@ namespace Ocelot.AcceptanceTests }) .Configure(a => { - a.UseOcelot(ocelotMiddlewareConfig, serviceCollection).Wait(); + a.UseOcelot(ocelotMiddlewareConfig).Wait(); })); _ocelotClient = _ocelotServer.CreateClient(); diff --git a/test/Ocelot.IntegrationTests/AdministrationTests.cs b/test/Ocelot.IntegrationTests/AdministrationTests.cs index 39721df6..e6fbcb0f 100644 --- a/test/Ocelot.IntegrationTests/AdministrationTests.cs +++ b/test/Ocelot.IntegrationTests/AdministrationTests.cs @@ -59,7 +59,7 @@ namespace Ocelot.IntegrationTests public void should_return_response_200_with_call_re_routes_controller() { var configuration = new FileConfiguration - { + { GlobalConfiguration = new FileGlobalConfiguration { AdministrationPath = "/administration" diff --git a/test/Ocelot.IntegrationTests/Ocelot.IntegrationTests.csproj b/test/Ocelot.IntegrationTests/Ocelot.IntegrationTests.csproj index ffabc693..73097d57 100644 --- a/test/Ocelot.IntegrationTests/Ocelot.IntegrationTests.csproj +++ b/test/Ocelot.IntegrationTests/Ocelot.IntegrationTests.csproj @@ -42,7 +42,7 @@ - + diff --git a/test/Ocelot.ManualTest/Startup.cs b/test/Ocelot.ManualTest/Startup.cs index e48f3cb7..1ecda12e 100644 --- a/test/Ocelot.ManualTest/Startup.cs +++ b/test/Ocelot.ManualTest/Startup.cs @@ -26,7 +26,6 @@ namespace Ocelot.ManualTest } public IConfigurationRoot Configuration { get; } - public IServiceCollection Services { get; private set; } public void ConfigureServices(IServiceCollection services) { @@ -40,14 +39,13 @@ namespace Ocelot.ManualTest }; services.AddOcelot(Configuration, settings); - Services = services; } public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); - app.UseOcelot(Services).Wait(); + app.UseOcelot().Wait(); } } }