Skip to content

Commit 49cc39d

Browse files
committed
update startups
1 parent fe93901 commit 49cc39d

9 files changed

Lines changed: 122 additions & 149 deletions

File tree

src/ApiGateways/ApiGw-Base/Startup.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,18 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
8989
app.UseDeveloperExceptionPage();
9090
}
9191

92-
app.UseHealthChecks("/hc", new HealthCheckOptions()
92+
app.UseRouting();
93+
app.UseEndpoints(endpoints =>
9394
{
94-
Predicate = _ => true,
95-
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
96-
});
97-
98-
app.UseHealthChecks("/liveness", new HealthCheckOptions
99-
{
100-
Predicate = r => r.Name.Contains("self")
95+
endpoints.MapHealthChecks("/hc", new HealthCheckOptions()
96+
{
97+
Predicate = _ => true,
98+
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
99+
});
100+
endpoints.MapHealthChecks("/liveness", new HealthCheckOptions
101+
{
102+
Predicate = r => r.Name.Contains("self")
103+
});
101104
});
102105

103106
app.UseCors("CorsPolicy");

src/ApiGateways/Mobile.Bff.Shopping/aggregator/Startup.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,6 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
6262
app.UsePathBase(pathBase);
6363
}
6464

65-
app.UseHealthChecks("/hc", new HealthCheckOptions()
66-
{
67-
Predicate = _ => true,
68-
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
69-
});
70-
71-
app.UseHealthChecks("/liveness", new HealthCheckOptions
72-
{
73-
Predicate = r => r.Name.Contains("self")
74-
});
75-
7665
app.UseCors("CorsPolicy");
7766

7867
if (env.IsDevelopment())
@@ -87,7 +76,20 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
8776

8877
app.UseAuthentication();
8978
app.UseHttpsRedirection();
90-
app.UseMvc();
79+
app.UseRouting();
80+
app.UseEndpoints(endpoints =>
81+
{
82+
endpoints.MapHealthChecks("/hc", new HealthCheckOptions()
83+
{
84+
Predicate = _ => true,
85+
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
86+
});
87+
endpoints.MapHealthChecks("/liveness", new HealthCheckOptions
88+
{
89+
Predicate = r => r.Name.Contains("self")
90+
});
91+
endpoints.MapDefaultControllerRoute();
92+
});
9193

9294
app.UseSwagger().UseSwaggerUI(c =>
9395
{

src/ApiGateways/Web.Bff.Shopping/aggregator/Startup.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,6 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
6161
app.UsePathBase(pathBase);
6262
}
6363

64-
app.UseHealthChecks("/hc", new HealthCheckOptions()
65-
{
66-
Predicate = _ => true,
67-
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
68-
});
69-
70-
app.UseHealthChecks("/liveness", new HealthCheckOptions
71-
{
72-
Predicate = r => r.Name.Contains("self")
73-
});
74-
7564
app.UseCors("CorsPolicy");
7665

7766
if (env.IsDevelopment())
@@ -86,7 +75,20 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
8675

8776
app.UseAuthentication();
8877
app.UseHttpsRedirection();
89-
app.UseMvc();
78+
app.UseRouting();
79+
app.UseEndpoints(endpoints =>
80+
{
81+
endpoints.MapHealthChecks("/hc", new HealthCheckOptions()
82+
{
83+
Predicate = _ => true,
84+
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
85+
});
86+
endpoints.MapHealthChecks("/liveness", new HealthCheckOptions
87+
{
88+
Predicate = r => r.Name.Contains("self")
89+
});
90+
endpoints.MapDefaultControllerRoute();
91+
});
9092

9193
app.UseSwagger()
9294
.UseSwaggerUI(c =>
Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
11
using Microsoft.AspNetCore.Authorization;
2-
using Swashbuckle.AspNetCore.Swagger;
2+
using Microsoft.OpenApi.Models;
33
using Swashbuckle.AspNetCore.SwaggerGen;
4-
using System;
54
using System.Collections.Generic;
65
using System.Linq;
7-
using System.Threading.Tasks;
86

97
namespace Webhooks.API.Infrastructure
108
{
119
public class AuthorizeCheckOperationFilter : IOperationFilter
1210
{
13-
public void Apply(Operation operation, OperationFilterContext context)
11+
public void Apply(OpenApiOperation operation, OperationFilterContext context)
1412
{
1513
// Check for authorize attribute
1614
var hasAuthorize = context.MethodInfo.DeclaringType.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any() ||
1715
context.MethodInfo.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any();
1816

1917
if (!hasAuthorize) return;
2018

21-
operation.Responses.TryAdd("401", new Response { Description = "Unauthorized" });
22-
operation.Responses.TryAdd("403", new Response { Description = "Forbidden" });
19+
operation.Responses.TryAdd("401", new OpenApiResponse { Description = "Unauthorized" });
20+
operation.Responses.TryAdd("403", new OpenApiResponse { Description = "Forbidden" });
2321

24-
operation.Security = new List<IDictionary<string, IEnumerable<string>>>
22+
var oAuthScheme = new OpenApiSecurityScheme
2523
{
26-
new Dictionary<string, IEnumerable<string>>
27-
{
28-
{ "oauth2", new [] { "webhooksapi" } }
29-
}
24+
Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "oauth2" }
3025
};
26+
27+
operation.Security = new List<OpenApiSecurityRequirement>
28+
{
29+
new OpenApiSecurityRequirement
30+
{
31+
[ oAuthScheme ] = new [] { "webhooksapi" }
32+
}
33+
};
3134
}
3235
}
3336
}

src/Services/Webhooks/Webhooks.API/Startup.cs

Lines changed: 37 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Data.Common;
4-
using System.IdentityModel.Tokens.Jwt;
5-
using System.Linq;
6-
using System.Reflection;
7-
using System.Threading;
8-
using System.Threading.Tasks;
9-
using Autofac;
1+
using Autofac;
102
using Autofac.Extensions.DependencyInjection;
113
using Devspaces.Support;
124
using HealthChecks.UI.Client;
13-
using Microsoft.ApplicationInsights.Extensibility;
14-
using Microsoft.ApplicationInsights.ServiceFabric;
155
using Microsoft.AspNetCore.Authentication.JwtBearer;
166
using Microsoft.AspNetCore.Builder;
177
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
18-
using Microsoft.AspNetCore.Hosting;
198
using Microsoft.AspNetCore.Http;
209
using Microsoft.AspNetCore.Mvc;
2110
using Microsoft.Azure.ServiceBus;
@@ -31,7 +20,12 @@
3120
using Microsoft.Extensions.Diagnostics.HealthChecks;
3221
using Microsoft.Extensions.Logging;
3322
using RabbitMQ.Client;
34-
using Swashbuckle.AspNetCore.Swagger;
23+
using System;
24+
using System.Collections.Generic;
25+
using System.Data.Common;
26+
using System.IdentityModel.Tokens.Jwt;
27+
using System.Reflection;
28+
using System.Threading;
3529
using Webhooks.API.Infrastructure;
3630
using Webhooks.API.IntegrationEvents;
3731
using Webhooks.API.Services;
@@ -84,22 +78,25 @@ public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
8478
app.UsePathBase(pathBase);
8579
}
8680

87-
app.UseHealthChecks("/hc", new HealthCheckOptions()
88-
{
89-
Predicate = _ => true,
90-
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
91-
});
92-
93-
app.UseHealthChecks("/liveness", new HealthCheckOptions
94-
{
95-
Predicate = r => r.Name.Contains("self")
96-
});
97-
9881
app.UseCors("CorsPolicy");
9982

10083
ConfigureAuth(app);
10184

102-
app.UseMvcWithDefaultRoute();
85+
app.UseRouting();
86+
app.UseEndpoints(endpoints =>
87+
{
88+
endpoints.MapHealthChecks("/hc", new HealthCheckOptions()
89+
{
90+
Predicate = _ => true,
91+
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
92+
});
93+
endpoints.MapHealthChecks("/liveness", new HealthCheckOptions
94+
{
95+
Predicate = r => r.Name.Contains("self")
96+
});
97+
98+
endpoints.MapDefaultControllerRoute();
99+
});
103100

104101
app.UseSwagger()
105102
.UseSwaggerUI(c =>
@@ -138,19 +135,7 @@ static class CustomExtensionMethods
138135
public static IServiceCollection AddAppInsight(this IServiceCollection services, IConfiguration configuration)
139136
{
140137
services.AddApplicationInsightsTelemetry(configuration);
141-
var orchestratorType = configuration.GetValue<string>("OrchestratorType");
142-
143-
if (orchestratorType?.ToUpper() == "K8S")
144-
{
145-
// Enable K8s telemetry initializer
146-
services.AddApplicationInsightsKubernetesEnricher();
147-
}
148-
if (orchestratorType?.ToUpper() == "SF")
149-
{
150-
// Enable SF telemetry initializer
151-
services.AddSingleton<ITelemetryInitializer>((serviceProvider) =>
152-
new FabricTelemetryInitializer());
153-
}
138+
services.AddApplicationInsightsKubernetesEnricher();
154139

155140
return services;
156141
}
@@ -161,7 +146,7 @@ public static IServiceCollection AddCustomMVC(this IServiceCollection services,
161146
{
162147
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
163148
})
164-
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
149+
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
165150
.AddControllersAsServices();
166151

167152
services.AddCors(options =>
@@ -203,23 +188,26 @@ public static IServiceCollection AddSwagger(this IServiceCollection services, IC
203188
services.AddSwaggerGen(options =>
204189
{
205190
options.DescribeAllEnumsAsStrings();
206-
options.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info
191+
options.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo
207192
{
208193
Title = "eShopOnContainers - Webhooks HTTP API",
209194
Version = "v1",
210-
Description = "The Webhooks Microservice HTTP API. This is a simple webhooks CRUD registration entrypoint",
211-
TermsOfService = "Terms Of Service"
195+
Description = "The Webhooks Microservice HTTP API. This is a simple webhooks CRUD registration entrypoint"
212196
});
213197

214-
options.AddSecurityDefinition("oauth2", new OAuth2Scheme
198+
options.AddSecurityDefinition("oauth2", new Microsoft.OpenApi.Models.OpenApiSecurityScheme
215199
{
216-
Type = "oauth2",
217-
Flow = "implicit",
218-
AuthorizationUrl = $"{configuration.GetValue<string>("IdentityUrlExternal")}/connect/authorize",
219-
TokenUrl = $"{configuration.GetValue<string>("IdentityUrlExternal")}/connect/token",
220-
Scopes = new Dictionary<string, string>()
200+
Flows = new Microsoft.OpenApi.Models.OpenApiOAuthFlows()
221201
{
222-
{ "webhooks", "Webhooks API" }
202+
Implicit = new Microsoft.OpenApi.Models.OpenApiOAuthFlow()
203+
{
204+
AuthorizationUrl = new Uri($"{configuration.GetValue<string>("IdentityUrlExternal")}/connect/authorize"),
205+
TokenUrl = new Uri($"{configuration.GetValue<string>("IdentityUrlExternal")}/connect/token"),
206+
Scopes = new Dictionary<string, string>()
207+
{
208+
{ "marketing", "Marketing API" }
209+
}
210+
}
223211
}
224212
});
225213

src/Services/Webhooks/Webhooks.API/Webhooks.API.csproj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,24 @@
44
<TargetFramework>$(NetCoreTargetVersion)</TargetFramework>
55
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
66
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
7+
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
8+
<GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks>
9+
<LangVersion>8.0</LangVersion>
710
</PropertyGroup>
811

912
<ItemGroup>
10-
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
11-
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.0.2105168" />
13+
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="$(Microsoft_AspNetCore_Razor_Design)" PrivateAssets="All" />
14+
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="$(Microsoft_VisualStudio_Azure_Containers_Tools_Targets)" />
1215
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="$(Autofac_Extensions_DependencyInjection)" />
1316
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="$(Microsoft_ApplicationInsights_AspNetCore)" />
1417
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="$(Microsoft_ApplicationInsights_DependencyCollector)" />
1518
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="$(Microsoft_ApplicationInsights_Kubernetes)" />
16-
<PackageReference Include="Microsoft.ApplicationInsights.ServiceFabric" Version="2.2.2" />
1719
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="$(Microsoft_Extensions_Logging_AzureAppServices)" />
1820
<PackageReference Include="Microsoft.AspNetCore.HealthChecks" Version="$(Microsoft_AspNetCore_HealthChecks)" />
1921
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="$(AspNetCore_HealthChecks_UI_Client)" />
2022
<PackageReference Include="Swashbuckle.AspNetCore" Version="$(Swashbuckle_AspNetCore)" />
2123
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="$(AspNetCore_HealthChecks_SqlServer)" />
24+
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="$(Microsoft_AspNetCore_Authentication_JwtBearer)" />
2225
</ItemGroup>
2326
<ItemGroup>
2427
<ProjectReference Include="..\..\..\BuildingBlocks\Devspaces.Support\Devspaces.Support.csproj" />

0 commit comments

Comments
 (0)