| | | 1 | | namespace Elsa.Secrets.Types; |
| | | 2 | | |
| | | 3 | | public class TextSecretTypeProvider : ISecretTypeProvider |
| | | 4 | | { |
| | 115 | 5 | | public SecretTypeDescriptor Descriptor { get; } = new( |
| | 31 | 6 | | SecretTypeNames.Text, |
| | 31 | 7 | | "Text", |
| | 31 | 8 | | "A text value such as a password, token, or connection string.", |
| | 31 | 9 | | "secret-text", |
| | 31 | 10 | | [SecretStoreNames.Encrypted, SecretStoreNames.Configuration]); |
| | | 11 | | |
| | | 12 | | public bool Validate(CreateSecretRequest request, out string? error) |
| | | 13 | | { |
| | 28 | 14 | | if (request.StoreName == SecretStoreNames.Encrypted && string.IsNullOrEmpty(request.Value)) |
| | | 15 | | { |
| | 1 | 16 | | error = "A text value is required for encrypted secrets."; |
| | 1 | 17 | | return false; |
| | | 18 | | } |
| | | 19 | | |
| | 27 | 20 | | if (request.StoreName == SecretStoreNames.Configuration && string.IsNullOrWhiteSpace(request.ConfigurationKey)) |
| | | 21 | | { |
| | 0 | 22 | | error = "A configuration key is required for configuration-backed secrets."; |
| | 0 | 23 | | return false; |
| | | 24 | | } |
| | | 25 | | |
| | 27 | 26 | | error = null; |
| | 27 | 27 | | return true; |
| | | 28 | | } |
| | | 29 | | |
| | | 30 | | public bool ValidateRotation(RotateSecretRequest request, string storeName, out string? error) |
| | | 31 | | { |
| | 4 | 32 | | if (storeName == SecretStoreNames.Encrypted && string.IsNullOrEmpty(request.Value)) |
| | | 33 | | { |
| | 1 | 34 | | error = "A replacement value is required."; |
| | 1 | 35 | | return false; |
| | | 36 | | } |
| | | 37 | | |
| | 3 | 38 | | if (storeName == SecretStoreNames.Configuration && string.IsNullOrWhiteSpace(request.ConfigurationKey)) |
| | | 39 | | { |
| | 0 | 40 | | error = "A replacement configuration key is required."; |
| | 0 | 41 | | return false; |
| | | 42 | | } |
| | | 43 | | |
| | 3 | 44 | | error = null; |
| | 3 | 45 | | return true; |
| | | 46 | | } |
| | | 47 | | } |