| | | 1 | | using Microsoft.Extensions.Configuration; |
| | | 2 | | using Microsoft.Extensions.Options; |
| | | 3 | | |
| | | 4 | | namespace Elsa.Secrets.Stores; |
| | | 5 | | |
| | 31 | 6 | | public class ConfigurationSecretStore(IConfiguration configuration, IOptions<SecretsOptions> options) : ISecretStore |
| | | 7 | | { |
| | | 8 | | private const string ConfigurationKeyMetadataName = "configurationKey"; |
| | | 9 | | |
| | 37 | 10 | | public string Name => SecretStoreNames.Configuration; |
| | | 11 | | |
| | 38 | 12 | | public SecretStoreDescriptor Descriptor { get; } = new( |
| | 31 | 13 | | SecretStoreNames.Configuration, |
| | 31 | 14 | | "Configuration", |
| | 31 | 15 | | "Reads values from application configuration without storing the value in Elsa.", |
| | 31 | 16 | | SecretStoreCapabilities.Read | SecretStoreCapabilities.Write | SecretStoreCapabilities.Test, |
| | 31 | 17 | | true); |
| | | 18 | | |
| | | 19 | | public Task<SecretPayload> WriteAsync(Secret secret, SecretVersion version, SecretPayload payload, CancellationToken |
| | | 20 | | { |
| | 5 | 21 | | if (!payload.Metadata.TryGetValue(ConfigurationKeyMetadataName, out var key) || string.IsNullOrWhiteSpace(key)) |
| | 0 | 22 | | throw new InvalidOperationException("A configuration key is required."); |
| | | 23 | | |
| | 5 | 24 | | return Task.FromResult(new SecretPayload { Metadata = new Dictionary<string, string>(payload.Metadata, StringCom |
| | | 25 | | } |
| | | 26 | | |
| | | 27 | | public Task<SecretPayload?> ReadAsync(Secret secret, SecretVersion version, CancellationToken cancellationToken = de |
| | | 28 | | { |
| | 4 | 29 | | if (!version.Payload.Metadata.TryGetValue(ConfigurationKeyMetadataName, out var key) || string.IsNullOrWhiteSpac |
| | 0 | 30 | | return Task.FromResult<SecretPayload?>(null); |
| | | 31 | | |
| | 4 | 32 | | var configuredValue = configuration[$"{options.Value.ConfigurationSectionName}:{key}"] ?? configuration[key]; |
| | 4 | 33 | | return configuredValue == null ? Task.FromResult<SecretPayload?>(null) : Task.FromResult<SecretPayload?>(SecretP |
| | | 34 | | } |
| | | 35 | | |
| | 0 | 36 | | public Task DeleteAsync(Secret secret, CancellationToken cancellationToken = default) => Task.CompletedTask; |
| | | 37 | | |
| | | 38 | | public async Task<bool> TestAsync(Secret secret, SecretVersion version, CancellationToken cancellationToken = defaul |
| | | 39 | | { |
| | 1 | 40 | | var payload = await ReadAsync(secret, version, cancellationToken); |
| | 1 | 41 | | return payload?.Value != null; |
| | 1 | 42 | | } |
| | | 43 | | } |