| | | 1 | | using Elsa.Abstractions; |
| | | 2 | | using Elsa.Secrets.Contracts; |
| | | 3 | | using Elsa.Secrets.Permissions; |
| | | 4 | | using Elsa.Secrets.Services; |
| | | 5 | | |
| | | 6 | | namespace Elsa.Secrets.Endpoints.Secrets.Picker; |
| | | 7 | | |
| | 0 | 8 | | internal class Endpoint(ISecretManager manager, ISecretStoreRegistry storeRegistry) : ElsaEndpoint<SecretPickerRequest, |
| | | 9 | | { |
| | | 10 | | public override void Configure() |
| | | 11 | | { |
| | 0 | 12 | | Post("/secrets/picker"); |
| | 0 | 13 | | ConfigurePermissions(SecretsPermissions.Read); |
| | 0 | 14 | | } |
| | | 15 | | |
| | | 16 | | public override async Task<SecretPickerResponse> ExecuteAsync(SecretPickerRequest request, CancellationToken cancell |
| | | 17 | | { |
| | 0 | 18 | | var listRequest = new ListSecretsRequest |
| | 0 | 19 | | { |
| | 0 | 20 | | Search = request.Search, |
| | 0 | 21 | | TypeNames = request.TypeNames, |
| | 0 | 22 | | StoreNames = request.StoreNames, |
| | 0 | 23 | | Scope = request.Scope, |
| | 0 | 24 | | Status = request.ActiveOnly ? SecretStatus.Active : null, |
| | 0 | 25 | | PageSize = 100 |
| | 0 | 26 | | }; |
| | | 27 | | |
| | 0 | 28 | | var items = await manager.ListAsync(listRequest, cancellationToken); |
| | 0 | 29 | | var models = items |
| | 0 | 30 | | .Select(x => x.ToModel()) |
| | 0 | 31 | | .ToList(); |
| | 0 | 32 | | var canCreate = storeRegistry.List().Any(x => !x.Descriptor.IsReadOnly); |
| | | 33 | | |
| | 0 | 34 | | return new SecretPickerResponse { Items = models, CanCreateInline = canCreate }; |
| | 0 | 35 | | } |
| | | 36 | | } |