diff --git a/BtmsGateway/BtmsGateway.csproj b/BtmsGateway/BtmsGateway.csproj index 4ca7cb19..88374bab 100644 --- a/BtmsGateway/BtmsGateway.csproj +++ b/BtmsGateway/BtmsGateway.csproj @@ -24,29 +24,29 @@ - - - - + + + + - - - + + + - - - - - - + + + + + + - + - - - - + + + + diff --git a/BtmsGateway/Config/BasicAuthRequirementFilter.cs b/BtmsGateway/Config/BasicAuthRequirementFilter.cs deleted file mode 100644 index ff587179..00000000 --- a/BtmsGateway/Config/BasicAuthRequirementFilter.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.Diagnostics.CodeAnalysis; -using BtmsGateway.Authentication; -using Microsoft.AspNetCore.Authorization; -using Microsoft.OpenApi.Models; -using Swashbuckle.AspNetCore.SwaggerGen; - -namespace BtmsGateway.Config; - -[ExcludeFromCodeCoverage] -public class BasicAuthRequirementFilter : IOperationFilter -{ - public void Apply(OpenApiOperation operation, OperationFilterContext context) - { - if (!context.ApiDescription.ActionDescriptor.EndpointMetadata.OfType().Any()) - return; - - operation.Security = new List - { - new OpenApiSecurityRequirement - { - [ - new OpenApiSecurityScheme - { - Reference = new OpenApiReference - { - Type = ReferenceType.SecurityScheme, - Id = BasicAuthenticationHandler.SchemeName, - }, - } - ] = new List(), - }, - }; - } -} diff --git a/BtmsGateway/Config/Swagger.cs b/BtmsGateway/Config/Swagger.cs index 89675a7c..dab73caa 100644 --- a/BtmsGateway/Config/Swagger.cs +++ b/BtmsGateway/Config/Swagger.cs @@ -1,6 +1,6 @@ using System.Diagnostics.CodeAnalysis; using BtmsGateway.Authentication; -using Microsoft.OpenApi.Models; +using Microsoft.OpenApi; namespace BtmsGateway.Config; @@ -23,7 +23,10 @@ public static void ConfigureSwaggerBuilder(this WebApplicationBuilder builder) Scheme = BasicAuthenticationHandler.SchemeName, } ); - c.OperationFilter(); + c.AddSecurityRequirement(document => new OpenApiSecurityRequirement + { + [new OpenApiSecuritySchemeReference("Basic", document)] = [], + }); }); } } diff --git a/BtmsGateway/Services/Admin/ResourceEventsDeadLetterService.cs b/BtmsGateway/Services/Admin/ResourceEventsDeadLetterService.cs index e7bdfcb6..ed3616ff 100644 --- a/BtmsGateway/Services/Admin/ResourceEventsDeadLetterService.cs +++ b/BtmsGateway/Services/Admin/ResourceEventsDeadLetterService.cs @@ -72,7 +72,7 @@ public async Task Remove(string messageId, CancellationToken cancellatio }; var response = await amazonSqs.ReceiveMessageAsync(request, cancellationToken); - if (response.Messages.Count == 0) + if (response.Messages is null || response.Messages.Count == 0) { return $"No messages found (visibility timeout used was {request.VisibilityTimeout} seconds, therefore wait before retrying)"; } @@ -152,18 +152,22 @@ public async Task Drain(CancellationToken cancellationToken) }; var deleteResponse = await amazonSqs.DeleteMessageBatchAsync(deleteRequest, cancellationToken); - if (deleteResponse.HttpStatusCode != HttpStatusCode.OK || deleteResponse.Failed.Count > 0) + if ( + deleteResponse.HttpStatusCode != HttpStatusCode.OK + || (deleteResponse.Failed is not null && deleteResponse.Failed.Count > 0) + ) { logger.LogWarning("Failed to remove a batch of message(s), stopping"); return false; } - removed += deleteResponse.Successful.Count; + var successfulCount = deleteResponse.Successful?.Count ?? 0; + removed += successfulCount; logger.LogInformation( "Removed batch of {Total} message(s), total so far {Removed}", - deleteResponse.Successful.Count, + successfulCount, removed ); diff --git a/tests/BtmsGateway.Test/BtmsGateway.Test.csproj b/tests/BtmsGateway.Test/BtmsGateway.Test.csproj index 94e481ac..d32c903a 100644 --- a/tests/BtmsGateway.Test/BtmsGateway.Test.csproj +++ b/tests/BtmsGateway.Test/BtmsGateway.Test.csproj @@ -9,13 +9,11 @@ - all runtime; build; native; contentfiles; analyzers; buildtransitive -