Migrate locations api
This commit is contained in:
parent
577aca1d4c
commit
e7f26be573
@ -1,6 +1,6 @@
|
||||
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Swashbuckle.AspNetCore.Swagger;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -9,7 +9,7 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Filt
|
||||
{
|
||||
internal 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() ||
|
||||
@ -17,16 +17,21 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Filt
|
||||
|
||||
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 [] { "locationsapi" } }
|
||||
}
|
||||
Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "oauth2" }
|
||||
};
|
||||
|
||||
operation.Security = new List<OpenApiSecurityRequirement>
|
||||
{
|
||||
new OpenApiSecurityRequirement
|
||||
{
|
||||
[ oAuthScheme ] = new [] { "locationsapi" }
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,15 +5,16 @@
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.ActionResults;
|
||||
using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Exceptions;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Net;
|
||||
|
||||
public class HttpGlobalExceptionFilter : IExceptionFilter
|
||||
{
|
||||
private readonly IHostingEnvironment env;
|
||||
private readonly IHostEnvironment env;
|
||||
private readonly ILogger<HttpGlobalExceptionFilter> logger;
|
||||
|
||||
public HttpGlobalExceptionFilter(IHostingEnvironment env, ILogger<HttpGlobalExceptionFilter> logger)
|
||||
public HttpGlobalExceptionFilter(IHostEnvironment env, ILogger<HttpGlobalExceptionFilter> logger)
|
||||
{
|
||||
this.env = env;
|
||||
this.logger = logger;
|
||||
|
@ -4,6 +4,7 @@
|
||||
<TargetFramework>$(NetCoreTargetVersion)</TargetFramework>
|
||||
<DockerComposeProjectPath>..\..\..\..\docker-compose.dcproj</DockerComposeProjectPath>
|
||||
<UserSecretsId>aspnet-Locations.API-20161122013619</UserSecretsId>
|
||||
<LangVersion>$(LangVersion)</LangVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AspNetCore.HealthChecks.AzureServiceBus" Version="$(AspNetCore_HealthChecks_AzureServiceBus)" />
|
||||
@ -14,6 +15,7 @@
|
||||
<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.AspNetCore.Authentication.JwtBearer" Version="$(Microsoft_AspNetCore_Authentication_JwtBearer)" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" Version="$(Microsoft_AspNetCore_Diagnostics_HealthChecks)" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.HealthChecks" Version="$(Microsoft_AspNetCore_HealthChecks)" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="$(Microsoft_Extensions_Configuration_AzureKeyVault)" />
|
||||
|
@ -1,8 +1,6 @@
|
||||
using Autofac;
|
||||
using Autofac.Extensions.DependencyInjection;
|
||||
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;
|
||||
@ -23,8 +21,8 @@ using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using RabbitMQ.Client;
|
||||
using Swashbuckle.AspNetCore.Swagger;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
@ -50,7 +48,7 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API
|
||||
{
|
||||
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
|
||||
})
|
||||
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
|
||||
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
|
||||
.AddControllersAsServices();
|
||||
|
||||
ConfigureAuthService(services);
|
||||
@ -99,7 +97,7 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API
|
||||
|
||||
return new DefaultRabbitMQPersistentConnection(factory, logger, retryCount);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
RegisterEventBus(services);
|
||||
|
||||
@ -107,23 +105,27 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API
|
||||
services.AddSwaggerGen(options =>
|
||||
{
|
||||
options.DescribeAllEnumsAsStrings();
|
||||
options.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info
|
||||
options.SwaggerDoc("v1", new OpenApiInfo
|
||||
{
|
||||
Title = "eShopOnContainers - Location HTTP API",
|
||||
Version = "v1",
|
||||
Description = "The Location Microservice HTTP API. This is a Data-Driven/CRUD microservice sample",
|
||||
TermsOfService = "Terms Of Service"
|
||||
});
|
||||
|
||||
options.AddSecurityDefinition("oauth2", new OAuth2Scheme
|
||||
options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
|
||||
{
|
||||
Type = "oauth2",
|
||||
Flow = "implicit",
|
||||
AuthorizationUrl = $"{Configuration.GetValue<string>("IdentityUrlExternal")}/connect/authorize",
|
||||
TokenUrl = $"{Configuration.GetValue<string>("IdentityUrlExternal")}/connect/token",
|
||||
Scopes = new Dictionary<string, string>()
|
||||
Type = SecuritySchemeType.OAuth2,
|
||||
Flows = new OpenApiOAuthFlows()
|
||||
{
|
||||
{ "locations", "Locations API" }
|
||||
Implicit = new OpenApiOAuthFlow()
|
||||
{
|
||||
AuthorizationUrl = new Uri($"{Configuration.GetValue<string>("IdentityUrlExternal")}/connect/authorize"),
|
||||
TokenUrl = new Uri($"{Configuration.GetValue<string>("IdentityUrlExternal")}/connect/token"),
|
||||
Scopes = new Dictionary<string, string>()
|
||||
{
|
||||
{ "locations", "Locations API" }
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -204,12 +206,6 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API
|
||||
// Enable K8s telemetry initializer
|
||||
services.AddApplicationInsightsKubernetesEnricher();
|
||||
}
|
||||
if (orchestratorType?.ToUpper() == "SF")
|
||||
{
|
||||
// Enable SF telemetry initializer
|
||||
services.AddSingleton<ITelemetryInitializer>((serviceProvider) =>
|
||||
new FabricTelemetryInitializer());
|
||||
}
|
||||
}
|
||||
|
||||
private void ConfigureAuthService(IServiceCollection services)
|
||||
|
@ -3,7 +3,7 @@
|
||||
<NetStandardTargetVersion>netstandard2.1</NetStandardTargetVersion>
|
||||
<NetCoreTargetVersion>netcoreapp3.0</NetCoreTargetVersion>
|
||||
<MicrosoftNETTestSdkPackageVersion>15.8.0</MicrosoftNETTestSdkPackageVersion>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<LangVersion>preview</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Label="Package Versions">
|
||||
@ -37,9 +37,11 @@
|
||||
<Microsoft_ApplicationInsights_DependencyCollector>2.6.1</Microsoft_ApplicationInsights_DependencyCollector>
|
||||
<Microsoft_ApplicationInsights_Kubernetes>1.0.2</Microsoft_ApplicationInsights_Kubernetes>
|
||||
<Microsoft_AspNetCore_Authentication_JwtBearer>3.0.0-preview6.19307.2</Microsoft_AspNetCore_Authentication_JwtBearer>
|
||||
<Microsoft_AspNetCore_Authentication_OpenIdConnect>3.0.0-preview6.19307.2</Microsoft_AspNetCore_Authentication_OpenIdConnect>
|
||||
<Microsoft_AspNetCore_Diagnostics_HealthChecks>2.2.0</Microsoft_AspNetCore_Diagnostics_HealthChecks>
|
||||
<Microsoft_AspNetCore_HealthChecks>1.0.0</Microsoft_AspNetCore_HealthChecks>
|
||||
<Microsoft_AspNetCore_Http_Abstractions>2.2.0</Microsoft_AspNetCore_Http_Abstractions>
|
||||
<Microsoft_AspNetCore_Mvc_Testing>3.0.0-preview6.19307.2</Microsoft_AspNetCore_Mvc_Testing>
|
||||
<Microsoft_AspNetCore_TestHost>3.0.0-preview6.19307.2</Microsoft_AspNetCore_TestHost>
|
||||
<Microsoft_Azure_ServiceBus>3.0.0</Microsoft_Azure_ServiceBus>
|
||||
<Microsoft_CSharp>4.5.0</Microsoft_CSharp>
|
||||
|
Loading…
x
Reference in New Issue
Block a user