Browse Source

update startups

features/migration-dotnet3
Erik Pique 5 years ago
parent
commit
49cc39d731
9 changed files with 122 additions and 149 deletions
  1. +11
    -8
      src/ApiGateways/ApiGw-Base/Startup.cs
  2. +14
    -12
      src/ApiGateways/Mobile.Bff.Shopping/aggregator/Startup.cs
  3. +14
    -12
      src/ApiGateways/Web.Bff.Shopping/aggregator/Startup.cs
  4. +14
    -11
      src/Services/Webhooks/Webhooks.API/Infrastructure/AuthorizeCheckOperationFilter.cs
  5. +37
    -49
      src/Services/Webhooks/Webhooks.API/Startup.cs
  6. +6
    -3
      src/Services/Webhooks/Webhooks.API/Webhooks.API.csproj
  7. +17
    -50
      src/Web/WebMVC/Startup.cs
  8. +7
    -3
      src/Web/WebhookClient/Startup.cs
  9. +2
    -1
      src/Web/WebhookClient/WebhookClient.csproj

+ 11
- 8
src/ApiGateways/ApiGw-Base/Startup.cs View File

@ -89,15 +89,18 @@ namespace OcelotApiGw
app.UseDeveloperExceptionPage();
}
app.UseHealthChecks("/hc", new HealthCheckOptions()
app.UseRouting();
app.UseEndpoints(endpoints =>
{
Predicate = _ => true,
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});
app.UseHealthChecks("/liveness", new HealthCheckOptions
{
Predicate = r => r.Name.Contains("self")
endpoints.MapHealthChecks("/hc", new HealthCheckOptions()
{
Predicate = _ => true,
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});
endpoints.MapHealthChecks("/liveness", new HealthCheckOptions
{
Predicate = r => r.Name.Contains("self")
});
});
app.UseCors("CorsPolicy");


+ 14
- 12
src/ApiGateways/Mobile.Bff.Shopping/aggregator/Startup.cs View File

@ -62,17 +62,6 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator
app.UsePathBase(pathBase);
}
app.UseHealthChecks("/hc", new HealthCheckOptions()
{
Predicate = _ => true,
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});
app.UseHealthChecks("/liveness", new HealthCheckOptions
{
Predicate = r => r.Name.Contains("self")
});
app.UseCors("CorsPolicy");
if (env.IsDevelopment())
@ -87,7 +76,20 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator
app.UseAuthentication();
app.UseHttpsRedirection();
app.UseMvc();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapHealthChecks("/hc", new HealthCheckOptions()
{
Predicate = _ => true,
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});
endpoints.MapHealthChecks("/liveness", new HealthCheckOptions
{
Predicate = r => r.Name.Contains("self")
});
endpoints.MapDefaultControllerRoute();
});
app.UseSwagger().UseSwaggerUI(c =>
{


+ 14
- 12
src/ApiGateways/Web.Bff.Shopping/aggregator/Startup.cs View File

@ -61,17 +61,6 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
app.UsePathBase(pathBase);
}
app.UseHealthChecks("/hc", new HealthCheckOptions()
{
Predicate = _ => true,
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});
app.UseHealthChecks("/liveness", new HealthCheckOptions
{
Predicate = r => r.Name.Contains("self")
});
app.UseCors("CorsPolicy");
if (env.IsDevelopment())
@ -86,7 +75,20 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
app.UseAuthentication();
app.UseHttpsRedirection();
app.UseMvc();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapHealthChecks("/hc", new HealthCheckOptions()
{
Predicate = _ => true,
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});
endpoints.MapHealthChecks("/liveness", new HealthCheckOptions
{
Predicate = r => r.Name.Contains("self")
});
endpoints.MapDefaultControllerRoute();
});
app.UseSwagger()
.UseSwaggerUI(c =>


+ 14
- 11
src/Services/Webhooks/Webhooks.API/Infrastructure/AuthorizeCheckOperationFilter.cs View File

@ -1,16 +1,14 @@
using Microsoft.AspNetCore.Authorization;
using Swashbuckle.AspNetCore.Swagger;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Webhooks.API.Infrastructure
{
public class AuthorizeCheckOperationFilter : IOperationFilter
{
public void Apply(Operation operation, OperationFilterContext context)
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
// Check for authorize attribute
var hasAuthorize = context.MethodInfo.DeclaringType.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any() ||
@ -18,16 +16,21 @@ namespace Webhooks.API.Infrastructure
if (!hasAuthorize) return;
operation.Responses.TryAdd("401", new Response { Description = "Unauthorized" });
operation.Responses.TryAdd("403", new Response { Description = "Forbidden" });
operation.Responses.TryAdd("401", new OpenApiResponse { Description = "Unauthorized" });
operation.Responses.TryAdd("403", new OpenApiResponse { Description = "Forbidden" });
operation.Security = new List<IDictionary<string, IEnumerable<string>>>
var oAuthScheme = new OpenApiSecurityScheme
{
new Dictionary<string, IEnumerable<string>>
{
{ "oauth2", new [] { "webhooksapi" } }
}
Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "oauth2" }
};
operation.Security = new List<OpenApiSecurityRequirement>
{
new OpenApiSecurityRequirement
{
[ oAuthScheme ] = new [] { "webhooksapi" }
}
};
}
}
}

+ 37
- 49
src/Services/Webhooks/Webhooks.API/Startup.cs View File

@ -1,21 +1,10 @@
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Autofac;
using Autofac;
using Autofac.Extensions.DependencyInjection;
using Devspaces.Support;
using HealthChecks.UI.Client;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.ServiceFabric;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.ServiceBus;
@ -31,7 +20,12 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Logging;
using RabbitMQ.Client;
using Swashbuckle.AspNetCore.Swagger;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.IdentityModel.Tokens.Jwt;
using System.Reflection;
using System.Threading;
using Webhooks.API.Infrastructure;
using Webhooks.API.IntegrationEvents;
using Webhooks.API.Services;
@ -84,22 +78,25 @@ namespace Webhooks.API
app.UsePathBase(pathBase);
}
app.UseHealthChecks("/hc", new HealthCheckOptions()
{
Predicate = _ => true,
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});
app.UseHealthChecks("/liveness", new HealthCheckOptions
{
Predicate = r => r.Name.Contains("self")
});
app.UseCors("CorsPolicy");
ConfigureAuth(app);
app.UseMvcWithDefaultRoute();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapHealthChecks("/hc", new HealthCheckOptions()
{
Predicate = _ => true,
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});
endpoints.MapHealthChecks("/liveness", new HealthCheckOptions
{
Predicate = r => r.Name.Contains("self")
});
endpoints.MapDefaultControllerRoute();
});
app.UseSwagger()
.UseSwaggerUI(c =>
@ -138,19 +135,7 @@ namespace Webhooks.API
public static IServiceCollection AddAppInsight(this IServiceCollection services, IConfiguration configuration)
{
services.AddApplicationInsightsTelemetry(configuration);
var orchestratorType = configuration.GetValue<string>("OrchestratorType");
if (orchestratorType?.ToUpper() == "K8S")
{
// Enable K8s telemetry initializer
services.AddApplicationInsightsKubernetesEnricher();
}
if (orchestratorType?.ToUpper() == "SF")
{
// Enable SF telemetry initializer
services.AddSingleton<ITelemetryInitializer>((serviceProvider) =>
new FabricTelemetryInitializer());
}
services.AddApplicationInsightsKubernetesEnricher();
return services;
}
@ -161,7 +146,7 @@ namespace Webhooks.API
{
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
})
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
.AddControllersAsServices();
services.AddCors(options =>
@ -203,23 +188,26 @@ namespace Webhooks.API
services.AddSwaggerGen(options =>
{
options.DescribeAllEnumsAsStrings();
options.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info
options.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo
{
Title = "eShopOnContainers - Webhooks HTTP API",
Version = "v1",
Description = "The Webhooks Microservice HTTP API. This is a simple webhooks CRUD registration entrypoint",
TermsOfService = "Terms Of Service"
Description = "The Webhooks Microservice HTTP API. This is a simple webhooks CRUD registration entrypoint"
});
options.AddSecurityDefinition("oauth2", new OAuth2Scheme
options.AddSecurityDefinition("oauth2", new Microsoft.OpenApi.Models.OpenApiSecurityScheme
{
Type = "oauth2",
Flow = "implicit",
AuthorizationUrl = $"{configuration.GetValue<string>("IdentityUrlExternal")}/connect/authorize",
TokenUrl = $"{configuration.GetValue<string>("IdentityUrlExternal")}/connect/token",
Scopes = new Dictionary<string, string>()
Flows = new Microsoft.OpenApi.Models.OpenApiOAuthFlows()
{
{ "webhooks", "Webhooks API" }
Implicit = new Microsoft.OpenApi.Models.OpenApiOAuthFlow()
{
AuthorizationUrl = new Uri($"{configuration.GetValue<string>("IdentityUrlExternal")}/connect/authorize"),
TokenUrl = new Uri($"{configuration.GetValue<string>("IdentityUrlExternal")}/connect/token"),
Scopes = new Dictionary<string, string>()
{
{ "marketing", "Marketing API" }
}
}
}
});


+ 6
- 3
src/Services/Webhooks/Webhooks.API/Webhooks.API.csproj View File

@ -4,21 +4,24 @@
<TargetFramework>$(NetCoreTargetVersion)</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.0.2105168" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="$(Microsoft_AspNetCore_Razor_Design)" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="$(Microsoft_VisualStudio_Azure_Containers_Tools_Targets)" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="$(Autofac_Extensions_DependencyInjection)" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="$(Microsoft_ApplicationInsights_AspNetCore)" />
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="$(Microsoft_ApplicationInsights_DependencyCollector)" />
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="$(Microsoft_ApplicationInsights_Kubernetes)" />
<PackageReference Include="Microsoft.ApplicationInsights.ServiceFabric" Version="2.2.2" />
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="$(Microsoft_Extensions_Logging_AzureAppServices)" />
<PackageReference Include="Microsoft.AspNetCore.HealthChecks" Version="$(Microsoft_AspNetCore_HealthChecks)" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="$(AspNetCore_HealthChecks_UI_Client)" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="$(Swashbuckle_AspNetCore)" />
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="$(AspNetCore_HealthChecks_SqlServer)" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="$(Microsoft_AspNetCore_Authentication_JwtBearer)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\BuildingBlocks\Devspaces.Support\Devspaces.Support.csproj" />


+ 17
- 50
src/Web/WebMVC/Startup.cs View File

@ -108,13 +108,7 @@ namespace Microsoft.eShopOnContainers.WebMVC
public static IServiceCollection AddAppInsight(this IServiceCollection services, IConfiguration configuration)
{
services.AddApplicationInsightsTelemetry(configuration);
var orchestratorType = configuration.GetValue<string>("OrchestratorType");
if (orchestratorType?.ToUpper() == "K8S")
{
// Enable K8s telemetry initializer
services.AddApplicationInsightsKubernetesEnricher();
}
services.AddApplicationInsightsKubernetesEnricher();
return services;
}
@ -232,52 +226,25 @@ namespace Microsoft.eShopOnContainers.WebMVC
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddCookie(setup => setup.ExpireTimeSpan = TimeSpan.FromMinutes(sessionCookieLifetime))
.AddJwtBearer(options =>
.AddOpenIdConnect(options =>
{
//options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
//options.Authority = identityUrl.ToString();
//options.SignedOutRedirectUri = callBackUrl.ToString();
//options.ClientId = useLoadTest ? "mvctest" : "mvc";
//options.ClientSecret = "secret";
//options.ResponseType = useLoadTest ? "code id_token token" : "code id_token";
//options.SaveTokens = true;
//options.GetClaimsFromUserInfoEndpoint = true;
//options.RequireHttpsMetadata = false;
//options.Scope.Add("openid");
//options.Scope.Add("profile");
//options.Scope.Add("orders");
//options.Scope.Add("basket");
//options.Scope.Add("marketing");
//options.Scope.Add("locations");
//options.Scope.Add("webshoppingagg");
//options.Scope.Add("orders.signalrhub");
//options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.Authority = identityUrl.ToString();
options.ForwardSignOut = callBackUrl.ToString();
//options.ClientId = useLoadTest ? "mvctest" : "mvc";
//options.ClientSecret = "secret";
if (useLoadTest)
{
options.Configuration.ResponseTypesSupported.Add("code id_token token");
}
else
{
options.Configuration.ResponseTypesSupported.Add("code id_token");
}
options.SaveToken = true;
//options.GetClaimsFromUserInfoEndpoint = true;
options.SignedOutRedirectUri = callBackUrl.ToString();
options.ClientId = useLoadTest ? "mvctest" : "mvc";
options.ClientSecret = "secret";
options.ResponseType = useLoadTest ? "code id_token token" : "code id_token";
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true;
options.RequireHttpsMetadata = false;
options.Configuration.ScopesSupported.Add("openid");
options.Configuration.ScopesSupported.Add("profile");
options.Configuration.ScopesSupported.Add("orders");
options.Configuration.ScopesSupported.Add("basket");
options.Configuration.ScopesSupported.Add("marketing");
options.Configuration.ScopesSupported.Add("locations");
options.Configuration.ScopesSupported.Add("webshoppingagg");
options.Configuration.ScopesSupported.Add("orders.signalrhub");
options.Scope.Add("openid");
options.Scope.Add("profile");
options.Scope.Add("orders");
options.Scope.Add("basket");
options.Scope.Add("marketing");
options.Scope.Add("locations");
options.Scope.Add("webshoppingagg");
options.Scope.Add("orders.signalrhub");
});
return services;


+ 7
- 3
src/Web/WebhookClient/Startup.cs View File

@ -36,7 +36,7 @@ namespace WebhookClient
.AddCustomAuthentication(Configuration)
.AddTransient<IWebhooksClient, WebhooksClient>()
.AddSingleton<IHooksRepository, InMemoryHooksRepository>()
.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@ -69,7 +69,7 @@ namespace WebhookClient
var header = context.Request.Headers[HeaderNames.WebHookCheckHeader];
var value = header.FirstOrDefault();
var tokenToValidate = Configuration["Token"];
if (!validateToken || value == tokenToValidate)
if (!validateToken || value == tokenToValidate)
{
if (!string.IsNullOrWhiteSpace(tokenToValidate))
{
@ -91,7 +91,11 @@ namespace WebhookClient
});
app.UseStaticFiles();
app.UseSession();
app.UseMvcWithDefaultRoute();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
});
}
}


+ 2
- 1
src/Web/WebhookClient/WebhookClient.csproj View File

@ -5,12 +5,13 @@
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<UserSecretsId>36215d41-f31a-4aa6-9929-bd67d650e7b5</UserSecretsId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="$(Microsoft_AspNetCore_Razor_Design)" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="$(Microsoft_VisualStudio_Azure_Containers_Tools_Targets)" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="$(Microsoft_VisualStudio_Web_CodeGeneration_Design)" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="$(Microsoft_AspNetCore_Authentication_OpenIdConnect)" />


Loading…
Cancel
Save