Skip to content

Commit 22dfdd6

Browse files
committed
chore: fix static analysis for AWS impls
1 parent da4a502 commit 22dfdd6

17 files changed

Lines changed: 74 additions & 92 deletions

File tree

user-management/CodeAnalysis.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
<_SkipUpgradeNetAnalyzersNuGetWarning>false</_SkipUpgradeNetAnalyzersNuGetWarning>
1414
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
1515
<!-- CA2007 is calling .ConfigureAwait(false), which isn't required for non-libraries -->
16-
<NoWarn>$(NoWarn);CA2007</NoWarn>
16+
<NoWarn>$(NoWarn);CA2007;CA1016</NoWarn>
1717
</PropertyGroup>
1818
</Project>

user-management/src/Stickerlandia.UserManagement.AWS/AwsConfiguration.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// This product includes software developed at Datadog (https://www.datadoghq.com/).
33
// Copyright 2025 Datadog, Inc.
44

5+
// The SQS queue URL is required as a string
6+
#pragma warning disable CA1056
7+
58
namespace Stickerlandia.UserManagement.AWS;
69

710
public class AwsConfiguration

user-management/src/Stickerlandia.UserManagement.AWS/ServiceExtensions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ public static class ServiceExtensions
1515
{
1616
public static IServiceCollection AddAwsAdapters(this IServiceCollection services, IConfiguration configuration)
1717
{
18+
ArgumentNullException.ThrowIfNull(configuration);
19+
1820
services.AddPostgresAuthServices(configuration);
1921

2022
services.Configure<AwsConfiguration>(
2123
configuration.GetSection("Aws"));
2224

2325
services.AddSingleton<IMessagingWorker, SqsStickerClaimedWorker>();
24-
services.AddSingleton(new AmazonSQSClient());
25-
services.AddSingleton(new AmazonSimpleNotificationServiceClient());
26+
services.AddSingleton(sp => new AmazonSQSClient());
27+
services.AddSingleton(sp => new AmazonSimpleNotificationServiceClient());
2628

2729
services.AddSingleton<IUserEventPublisher, SnsEventPublisher>();
2830

user-management/src/Stickerlandia.UserManagement.AWS/SnsEventPublisher.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
using Microsoft.Extensions.Logging;
1111
using Microsoft.Extensions.Options;
1212
using Saunter.Attributes;
13+
using Stickerlandia.UserManagement.Agnostic.Observability;
1314
using Stickerlandia.UserManagement.Core;
1415
using Stickerlandia.UserManagement.Core.RegisterUser;
16+
using Log = Stickerlandia.UserManagement.Core.Observability.Log;
1517

1618
namespace Stickerlandia.UserManagement.AWS;
1719

@@ -25,6 +27,8 @@ public class SnsEventPublisher(
2527
[PublishOperation(typeof(UserRegisteredEvent))]
2628
public async Task PublishUserRegisteredEventV1(UserRegisteredEvent userRegisteredEvent)
2729
{
30+
ArgumentNullException.ThrowIfNull(userRegisteredEvent, nameof(userRegisteredEvent));
31+
2832
var cloudEvent = new CloudEvent(CloudEventsSpecVersion.V1_0)
2933
{
3034
Id = Guid.NewGuid().ToString(),
@@ -62,8 +66,9 @@ private async Task Publish(CloudEvent cloudEvent)
6266
}
6367
catch (Exception ex)
6468
{
65-
logger.LogError(ex, "Failure publishing message");
69+
Log.MessagePublishingError(logger, "Failure publishing event", ex);
6670
processScope?.Span.SetException(ex);
71+
throw;
6772
}
6873
finally
6974
{

user-management/src/Stickerlandia.UserManagement.AWS/SqsStickerClaimedWorker.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Microsoft.Extensions.Options;
1212
using Saunter.Attributes;
1313
using Stickerlandia.UserManagement.Core;
14+
using Stickerlandia.UserManagement.Core.Observability;
1415
using Stickerlandia.UserManagement.Core.StickerClaimedEvent;
1516

1617
namespace Stickerlandia.UserManagement.AWS;
@@ -40,7 +41,7 @@ private async Task ProcessMessageAsync(Message message)
4041
using var processSpan = Tracer.Instance.StartActive($"process users.stickerClaimed.v1");
4142

4243
using var scope = _serviceScopeFactory.CreateScope();
43-
var handler = scope.ServiceProvider.GetRequiredService<StickerClaimedEventHandler>();
44+
var handler = scope.ServiceProvider.GetRequiredService<StickerClaimedHandler>();
4445

4546
var evtData = JsonSerializer.Deserialize<StickerClaimedEventV1>(message.Body);
4647

@@ -58,7 +59,8 @@ private async Task ProcessMessageAsync(Message message)
5859
}
5960
catch (InvalidUserException ex)
6061
{
61-
_logger.LogWarning(ex, "User with account in this event not found");
62+
Log.InvalidUser(_logger, ex);
63+
6264
await _sqsClient.SendMessageAsync(_awsConfiguration.Value.StickerClaimedDLQUrl, message.Body);
6365
}
6466

@@ -67,12 +69,11 @@ private async Task ProcessMessageAsync(Message message)
6769

6870
public Task StartAsync()
6971
{
70-
_logger.LogInformation("Starting SQS processor");
71-
72+
Log.StartingMessageProcessor(_logger, "sqs");
7273
return Task.CompletedTask;
7374
}
7475

75-
public async Task PollAsync(CancellationToken cancellationToken)
76+
public async Task PollAsync(CancellationToken stoppingToken)
7677
{
7778
var request = new ReceiveMessageRequest
7879
{
@@ -81,13 +82,13 @@ public async Task PollAsync(CancellationToken cancellationToken)
8182
MaxNumberOfMessages = 10 // Fetch up to 10 messages per call
8283
};
8384

84-
var messages = await _sqsClient.ReceiveMessageAsync(request, cancellationToken);
85+
var messages = await _sqsClient.ReceiveMessageAsync(request, stoppingToken);
8586
foreach (var message in messages.Messages) await ProcessMessageAsync(message);
8687
}
8788

8889
public async Task StopAsync(CancellationToken cancellationToken)
8990
{
90-
_logger.LogInformation("Stopping SQS processor");
91+
Log.StoppingMessageProcessor(_logger, "sqs");
9192
// No specific stop logic for SQS, as it is a pull-based system.
9293
await Task.CompletedTask;
9394
}

user-management/src/Stickerlandia.UserManagement.Api/Configurations/AuthorizeOperationFilter.cs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,17 @@
22
// This product includes software developed at Datadog (https://www.datadoghq.com/).
33
// Copyright 2025 Datadog, Inc.
44

5-
<<<<<<< chore/update-user-docs
6-
=======
75
// This is a class that is not intended to be instantiated directly, so we suppress the warning.
86
#pragma warning disable CA1812
9-
10-
>>>>>>> main
117
using System.Net;
128
using Microsoft.AspNetCore.Authorization;
139
using Microsoft.OpenApi.Models;
1410
using Swashbuckle.AspNetCore.SwaggerGen;
1511

1612
namespace Stickerlandia.UserManagement.Api.Configurations;
17-
18-
<<<<<<< chore/update-user-docs
1913
/// <summary>
2014
/// Operation filter to add authorization responses and security requirements to Swagger operations.
2115
/// </summary>
22-
internal class AuthorizeOperationFilter
23-
: IOperationFilter
24-
{
25-
public void Apply(OpenApiOperation operation, OperationFilterContext context)
26-
{
27-
var authAttributes = context.MethodInfo.DeclaringType.GetCustomAttributes(true)
28-
.Union(context.MethodInfo.GetCustomAttributes(true))
29-
.OfType<AuthorizeAttribute>();
30-
31-
if (authAttributes.Any())
32-
=======
3316
internal sealed class AuthorizeOperationFilter
3417
: IOperationFilter
3518
{
@@ -44,37 +27,24 @@ public void Apply(OpenApiOperation operation, OperationFilterContext context)
4427
.ToList();
4528

4629
if (authAttributes.Count > 0)
47-
>>>>>>> main
4830
{
4931
operation.Responses.Add(StatusCodes.Status401Unauthorized.ToString(), new OpenApiResponse { Description = nameof(HttpStatusCode.Unauthorized) });
5032
operation.Responses.Add(StatusCodes.Status403Forbidden.ToString(), new OpenApiResponse { Description = nameof(HttpStatusCode.Forbidden) });
5133
}
52-
53-
<<<<<<< chore/update-user-docs
54-
if (authAttributes.Any())
55-
=======
34+
5635
if (authAttributes.Count > 0)
57-
>>>>>>> main
5836
{
5937
operation.Security = new List<OpenApiSecurityRequirement>();
6038

6139
var oauth2SecurityScheme = new OpenApiSecurityScheme()
6240
{
63-
<<<<<<< chore/update-user-docs
6441
Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "oauth2" },
65-
=======
66-
Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "OAuth2" },
67-
>>>>>>> main
6842
};
6943

7044

7145
operation.Security.Add(new OpenApiSecurityRequirement()
7246
{
73-
<<<<<<< chore/update-user-docs
74-
[oauth2SecurityScheme] = new[] { "oauth2" }
75-
=======
7647
[oauth2SecurityScheme] = item
77-
>>>>>>> main
7848
});
7949
}
8050
}

user-management/src/Stickerlandia.UserManagement.Api/Configurations/DocumentationConfig.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ public static IHostApplicationBuilder AddDocumentationEndpoints(this IHostApplic
3636
var xmlFiles = Directory.GetFiles(AppContext.BaseDirectory, "*.xml");
3737
foreach (var xmlFile in xmlFiles) options.IncludeXmlComments(xmlFile);
3838

39-
<<<<<<< chore/update-user-docs
4039
// This manually removes some types from the auth-gen Swagger definitions that aren't required.
41-
=======
42-
>>>>>>> main
4340
options.DocumentFilter<RemoveSwaggerDefinitionsFilter>();
4441
options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
4542
{

user-management/src/Stickerlandia.UserManagement.Api/Configurations/RemoveSwaggerDefinitionsFilter.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,21 @@
22
// This product includes software developed at Datadog (https://www.datadoghq.com/).
33
// Copyright 2025 Datadog, Inc.
44

5-
<<<<<<< chore/update-user-docs
6-
=======
75
// This is a class that is not intended to be instantiated directly, so we suppress the warning.
86
#pragma warning disable CA1812
9-
>>>>>>> main
107

118
using System.Security.Claims;
129
using Microsoft.OpenApi.Models;
1310
using Swashbuckle.AspNetCore.SwaggerGen;
1411

1512
namespace Stickerlandia.UserManagement.Api.Configurations;
1613

17-
<<<<<<< chore/update-user-docs
18-
public class RemoveSwaggerDefinitionsFilter : IDocumentFilter
19-
=======
2014
internal sealed class RemoveSwaggerDefinitionsFilter : IDocumentFilter
21-
>>>>>>> main
2215
{
2316
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
2417
{
2518
swaggerDoc.Components.Schemas.Remove(nameof(Claim));
2619
swaggerDoc.Components.Schemas.Remove(nameof(ClaimsIdentity));
27-
<<<<<<< chore/update-user-docs
2820
swaggerDoc.Components.Schemas.Remove(nameof(ClaimsPrincipal));
29-
=======
30-
>>>>>>> main
3121
}
3222
}

user-management/src/Stickerlandia.UserManagement.Aspire/AppBuilderExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ public static IDistributedApplicationBuilder WithAwsLambda(
252252
this IDistributedApplicationBuilder builder,
253253
InfrastructureResources resources)
254254
{
255+
ArgumentNullException.ThrowIfNull(resources.MessagingResource, nameof(resources.MessagingResource));
256+
ArgumentNullException.ThrowIfNull(resources.DatabaseResource, nameof(resources.DatabaseResource));
255257
var apiLambdaFunction = builder.AddAWSLambdaFunction<Projects.Stickerlandia_UserManagement_Api>("UsersApi",
256258
"Stickerlandia.UserManagement.Api")
257259
.WithEnvironment("ConnectionStrings__messaging", resources.MessagingResource)

user-management/src/Stickerlandia.UserManagement.Core/Observability/LogMessages.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ public static partial void UnknownException(
8585
Message = "{Message}")]
8686
public static partial void GenericWarning(
8787
ILogger logger, string message, Exception? exception);
88+
89+
[LoggerMessage(
90+
EventId = 5,
91+
Level = LogLevel.Trace,
92+
Message = "Stopping message processor for transport: {MessageTransport}")]
93+
public static partial void StoppingMessageProcessor(
94+
ILogger logger, string messageTransport);
8895
}
8996

9097
public static class LogMessages

0 commit comments

Comments
 (0)