| | | 1 | | using Elsa.Authorization; |
| | | 2 | | using Elsa.Abstractions; |
| | | 3 | | using Elsa.Secrets.Permissions; |
| | | 4 | | using Elsa.Secrets.Services; |
| | | 5 | | |
| | | 6 | | namespace Elsa.Secrets.Endpoints.Secrets.Rotate; |
| | | 7 | | |
| | 0 | 8 | | internal class Endpoint(ISecretManager manager) : ElsaEndpoint<RotateSecretRequest, SecretModel> |
| | | 9 | | { |
| | | 10 | | public override void Configure() |
| | | 11 | | { |
| | 0 | 12 | | Post("/secrets/{name}/rotate"); |
| | 0 | 13 | | RequirePermission(Elsa.Secrets.Permissions.SecretsResourcePermissions.Secrets, CoreVerbs.Write); |
| | 0 | 14 | | } |
| | | 15 | | |
| | | 16 | | public override async Task HandleAsync(RotateSecretRequest request, CancellationToken cancellationToken) |
| | | 17 | | { |
| | | 18 | | try |
| | | 19 | | { |
| | 0 | 20 | | var secret = await manager.RotateAsync(Route<string>("name")!, request, cancellationToken); |
| | 0 | 21 | | await Send.OkAsync(secret.ToModel(), cancellationToken); |
| | 0 | 22 | | } |
| | 0 | 23 | | catch (InvalidOperationException e) |
| | | 24 | | { |
| | 0 | 25 | | AddError(e.Message); |
| | 0 | 26 | | await Send.ErrorsAsync(cancellation: cancellationToken); |
| | 0 | 27 | | } |
| | 0 | 28 | | catch (KeyNotFoundException) |
| | | 29 | | { |
| | 0 | 30 | | await Send.NotFoundAsync(cancellationToken); |
| | | 31 | | } |
| | 0 | 32 | | } |
| | | 33 | | } |