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