Skip to content

Commit 4095c35

Browse files
feature(#22): this commit introduces a handler for rotating realm secrets to rotate the secrets of a specific realm, using the rotation service and validating the realm's existence.
1 parent 659c70e commit 4095c35

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
namespace HttpsRichardy.Federation.Application.Handlers.Secret;
2+
3+
public sealed class RotateRealmSecretsHandler(ISecretRotationService rotationService, IRealmCollection realmCollection) :
4+
IDispatchHandler<RotateRealmSecretsParameters, Result>
5+
{
6+
public async Task<Result> HandleAsync(
7+
RotateRealmSecretsParameters parameters, CancellationToken cancellation = default)
8+
{
9+
var realmFilters = RealmFilters.WithSpecifications()
10+
.WithIdentifier(parameters.RealmId)
11+
.Build();
12+
13+
var realms = await realmCollection.GetRealmsAsync(realmFilters, cancellation);
14+
var realm = realms.FirstOrDefault();
15+
16+
if (realm is null)
17+
{
18+
return Result.Failure(RealmErrors.RealmDoesNotExist);
19+
}
20+
21+
await rotationService.RotateSecretAsync(realm, cancellation);
22+
23+
return Result.Success();
24+
}
25+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace HttpsRichardy.Federation.Application.Payloads.Secret;
2+
3+
public sealed record RotateRealmSecretsParameters :
4+
IDispatchable<Result>
5+
{
6+
public string RealmId { get; init; } = default!;
7+
}

0 commit comments

Comments
 (0)