From 18f4d417a9cdd6ed78715ab3336155d5131cf8cf Mon Sep 17 00:00:00 2001 From: meysamhadeli Date: Wed, 16 Nov 2022 22:32:00 +0330 Subject: [PATCH] refactor --- src/ApiGateway/src/appsettings.docker.json | 7 ---- src/ApiGateway/src/appsettings.json | 30 +++-------------- src/BuildingBlocks/BuildingBlocks.csproj | 14 ++++---- .../Swagger/ServiceCollectionExtensions.cs | 33 ------------------- .../IntegrationTest/Integration.Test.csproj | 4 +++ .../AircraftAlreadyExistException.cs | 2 +- .../IntegrationTest/Integration.Test.csproj | 4 +++ .../Identity/src/Identity.Api/Program.cs | 1 - .../src/Identity.Api/appsettings.json | 4 +++ src/Services/Identity/src/Identity/Config.cs | 9 +++-- .../Identity/Identity/Constants/Constants.cs | 1 + .../Endpoints/V1/RegisterNewUserEndpoint.cs | 2 -- .../IntegrationTest/Integration.Test.csproj | 4 +++ .../IntegrationTest/Integration.Test.csproj | 4 +++ 14 files changed, 40 insertions(+), 79 deletions(-) diff --git a/src/ApiGateway/src/appsettings.docker.json b/src/ApiGateway/src/appsettings.docker.json index bda427a..fa64969 100644 --- a/src/ApiGateway/src/appsettings.docker.json +++ b/src/ApiGateway/src/appsettings.docker.json @@ -8,13 +8,6 @@ } } }, - "identity": { - "destinations": { - "destination1": { - "address": "http://identity" - } - } - }, "passenger": { "destinations": { "destination1": { diff --git a/src/ApiGateway/src/appsettings.json b/src/ApiGateway/src/appsettings.json index ee4339d..e6f026d 100644 --- a/src/ApiGateway/src/appsettings.json +++ b/src/ApiGateway/src/appsettings.json @@ -12,46 +12,26 @@ "identity": { "clusterId": "identity", "match": { - "path": "{**catch-all}" - }, - "transforms": [ - { - "pathPattern": "{**catch-all}" - } - ] + "path": "/{**catch-all}" + } }, "flight": { "clusterId": "flight", "match": { "path": "api/{version}/flight/{**catch-all}" - }, - "transforms": [ - { - "pathPattern": "api/{version}/flight/{**catch-all}" - } - ] + } }, "passenger": { "clusterId": "passenger", "match": { "path": "api/{version}/passenger/{**catch-all}" - }, - "transforms": [ - { - "pathPattern": "api/{version}/passenger/{**catch-all}" - } - ] + } }, "booking": { "clusterId": "booking", "match": { "path": "api/{version}/booking/{**catch-all}" - }, - "transforms": [ - { - "pathPattern": "api/{version}/booking/{**catch-all}" - } - ] + } } }, "clusters": { diff --git a/src/BuildingBlocks/BuildingBlocks.csproj b/src/BuildingBlocks/BuildingBlocks.csproj index ba56da6..1138fc0 100644 --- a/src/BuildingBlocks/BuildingBlocks.csproj +++ b/src/BuildingBlocks/BuildingBlocks.csproj @@ -81,22 +81,22 @@ - - + + - - - - + + + + - + diff --git a/src/BuildingBlocks/Swagger/ServiceCollectionExtensions.cs b/src/BuildingBlocks/Swagger/ServiceCollectionExtensions.cs index 3ef5193..f032b99 100644 --- a/src/BuildingBlocks/Swagger/ServiceCollectionExtensions.cs +++ b/src/BuildingBlocks/Swagger/ServiceCollectionExtensions.cs @@ -34,26 +34,6 @@ public static class ServiceCollectionExtensions var xmlFile = XmlCommentsFilePath(assembly); if (File.Exists(xmlFile)) options.IncludeXmlComments(xmlFile); - options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme - { - Description = @"JWT Authorization header using the Bearer scheme. \r\n\r\n - Enter 'Bearer' [space] and then your token in the text input below. - \r\n\r\nExample: 'Bearer 12345abcdef'", - Name = "Authorization", - In = ParameterLocation.Header, - Type = SecuritySchemeType.ApiKey, - Scheme = "Bearer" - }); - - options.AddSecurityDefinition( - HeaderName, - new OpenApiSecurityScheme - { - Description = "Api key needed to access the endpoints. X-Api-Key: My_API_Key", - In = ParameterLocation.Header, - Name = HeaderName, - Type = SecuritySchemeType.ApiKey - }); options.AddSecurityRequirement(new OpenApiSecurityRequirement { @@ -66,19 +46,6 @@ public static class ServiceCollectionExtensions In = ParameterLocation.Header }, new List() - }, - { - new OpenApiSecurityScheme - { - Name = HeaderName, - Type = SecuritySchemeType.ApiKey, - In = ParameterLocation.Header, - Reference = new OpenApiReference - { - Type = ReferenceType.SecurityScheme, Id = HeaderName - } - }, - Array.Empty() } }); diff --git a/src/Services/Booking/tests/IntegrationTest/Integration.Test.csproj b/src/Services/Booking/tests/IntegrationTest/Integration.Test.csproj index 559d998..3eadc6e 100644 --- a/src/Services/Booking/tests/IntegrationTest/Integration.Test.csproj +++ b/src/Services/Booking/tests/IntegrationTest/Integration.Test.csproj @@ -12,6 +12,10 @@ + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Services/Flight/src/Flight/Aircrafts/Features/CreateAircraft/Exceptions/AircraftAlreadyExistException.cs b/src/Services/Flight/src/Flight/Aircrafts/Features/CreateAircraft/Exceptions/AircraftAlreadyExistException.cs index e441645..f7901e4 100644 --- a/src/Services/Flight/src/Flight/Aircrafts/Features/CreateAircraft/Exceptions/AircraftAlreadyExistException.cs +++ b/src/Services/Flight/src/Flight/Aircrafts/Features/CreateAircraft/Exceptions/AircraftAlreadyExistException.cs @@ -5,7 +5,7 @@ namespace Flight.Aircrafts.Features.CreateAircraft.Exceptions; public class AircraftAlreadyExistException : AppException { - public AircraftAlreadyExistException() : base("Flight already exist!", HttpStatusCode.Conflict) + public AircraftAlreadyExistException() : base("Aircraft already exist!", HttpStatusCode.Conflict) { } } diff --git a/src/Services/Flight/tests/IntegrationTest/Integration.Test.csproj b/src/Services/Flight/tests/IntegrationTest/Integration.Test.csproj index 59b5659..ca1ce89 100644 --- a/src/Services/Flight/tests/IntegrationTest/Integration.Test.csproj +++ b/src/Services/Flight/tests/IntegrationTest/Integration.Test.csproj @@ -12,6 +12,10 @@ + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Services/Identity/src/Identity.Api/Program.cs b/src/Services/Identity/src/Identity.Api/Program.cs index 9a9c46d..0e4d4fa 100644 --- a/src/Services/Identity/src/Identity.Api/Program.cs +++ b/src/Services/Identity/src/Identity.Api/Program.cs @@ -15,7 +15,6 @@ using Identity; using Identity.Data; using Identity.Data.Seed; using Identity.Extensions; -using Microsoft.AspNetCore.Mvc.ApiExplorer; using Prometheus; using Serilog; diff --git a/src/Services/Identity/src/Identity.Api/appsettings.json b/src/Services/Identity/src/Identity.Api/appsettings.json index 7ab6d31..eec0635 100644 --- a/src/Services/Identity/src/Identity.Api/appsettings.json +++ b/src/Services/Identity/src/Identity.Api/appsettings.json @@ -11,6 +11,10 @@ "UserName": "guest", "Password": "guest" }, + "Jwt": { + "Authority": "https://localhost:5005", + "Audience": "identity-api" + }, "LogOptions": { "Level": "information", "LogTemplate": "{Timestamp:HH:mm:ss} [{Level:u4}] {Message:lj}{NewLine}{Exception}", diff --git a/src/Services/Identity/src/Identity/Config.cs b/src/Services/Identity/src/Identity/Config.cs index 924ac68..f042743 100644 --- a/src/Services/Identity/src/Identity/Config.cs +++ b/src/Services/Identity/src/Identity/Config.cs @@ -24,7 +24,8 @@ public static class Config { new(Constants.StandardScopes.FlightApi), new(Constants.StandardScopes.PassengerApi), - new(Constants.StandardScopes.BookingApi) + new(Constants.StandardScopes.BookingApi), + new(Constants.StandardScopes.IdentityApi) }; @@ -33,7 +34,8 @@ public static class Config { new(Constants.StandardScopes.FlightApi), new(Constants.StandardScopes.PassengerApi), - new(Constants.StandardScopes.BookingApi) + new(Constants.StandardScopes.BookingApi), + new(Constants.StandardScopes.IdentityApi) }; public static IEnumerable Clients => @@ -56,7 +58,8 @@ public static class Config IdentityServerConstants.StandardScopes.Profile, Constants.StandardScopes.FlightApi, Constants.StandardScopes.PassengerApi, - Constants.StandardScopes.BookingApi + Constants.StandardScopes.BookingApi, + new(Constants.StandardScopes.IdentityApi) } } }; diff --git a/src/Services/Identity/src/Identity/Identity/Constants/Constants.cs b/src/Services/Identity/src/Identity/Identity/Constants/Constants.cs index 665e99a..d87e053 100644 --- a/src/Services/Identity/src/Identity/Identity/Constants/Constants.cs +++ b/src/Services/Identity/src/Identity/Identity/Constants/Constants.cs @@ -14,5 +14,6 @@ public static class Constants public const string FlightApi = "flight-api"; public const string PassengerApi = "passenger-api"; public const string BookingApi = "booking-api"; + public const string IdentityApi = "identity-api"; } } diff --git a/src/Services/Identity/src/Identity/Identity/Features/RegisterNewUser/Endpoints/V1/RegisterNewUserEndpoint.cs b/src/Services/Identity/src/Identity/Identity/Features/RegisterNewUser/Endpoints/V1/RegisterNewUserEndpoint.cs index 419a4ca..f6a06f3 100644 --- a/src/Services/Identity/src/Identity/Identity/Features/RegisterNewUser/Endpoints/V1/RegisterNewUserEndpoint.cs +++ b/src/Services/Identity/src/Identity/Identity/Features/RegisterNewUser/Endpoints/V1/RegisterNewUserEndpoint.cs @@ -6,7 +6,6 @@ using Identity.Identity.Features.RegisterNewUser.Commands.V1; using MediatR; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Routing; using Swashbuckle.AspNetCore.Annotations; @@ -17,7 +16,6 @@ public class RegisterNewUserEndpoint : IMinimalEndpoint public IEndpointRouteBuilder MapEndpoint(IEndpointRouteBuilder endpoints) { endpoints.MapPost($"{EndpointConfig.BaseApiPath}/identity/register-user", RegisterNewUser) - .RequireAuthorization() .WithTags("Identity") .WithName("Register User") .WithMetadata(new SwaggerOperationAttribute("Register User", "Register User")) diff --git a/src/Services/Identity/tests/IntegrationTest/Integration.Test.csproj b/src/Services/Identity/tests/IntegrationTest/Integration.Test.csproj index 22a9fc8..c552b88 100644 --- a/src/Services/Identity/tests/IntegrationTest/Integration.Test.csproj +++ b/src/Services/Identity/tests/IntegrationTest/Integration.Test.csproj @@ -12,6 +12,10 @@ + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Services/Passenger/tests/IntegrationTest/Integration.Test.csproj b/src/Services/Passenger/tests/IntegrationTest/Integration.Test.csproj index 36c4c98..9d636b2 100644 --- a/src/Services/Passenger/tests/IntegrationTest/Integration.Test.csproj +++ b/src/Services/Passenger/tests/IntegrationTest/Integration.Test.csproj @@ -12,6 +12,10 @@ + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive