< Summary

Information
Class: Elsa.Secrets.Stores.ConfigurationSecretStore
Assembly: Elsa.Secrets
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Secrets/Stores/ConfigurationSecretStore.cs
Line coverage
84%
Covered lines: 16
Uncovered lines: 3
Coverable lines: 19
Total lines: 43
Line coverage: 84.2%
Branch coverage
64%
Covered branches: 9
Total branches: 14
Branch coverage: 64.2%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Name()100%11100%
get_Descriptor()100%11100%
WriteAsync(...)50%5466.66%
ReadAsync(...)75%9875%
DeleteAsync(...)100%210%
TestAsync()50%22100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Secrets/Stores/ConfigurationSecretStore.cs

#LineLine coverage
 1using Microsoft.Extensions.Configuration;
 2using Microsoft.Extensions.Options;
 3
 4namespace Elsa.Secrets.Stores;
 5
 316public class ConfigurationSecretStore(IConfiguration configuration, IOptions<SecretsOptions> options) : ISecretStore
 7{
 8    private const string ConfigurationKeyMetadataName = "configurationKey";
 9
 3710    public string Name => SecretStoreNames.Configuration;
 11
 3812    public SecretStoreDescriptor Descriptor { get; } = new(
 3113        SecretStoreNames.Configuration,
 3114        "Configuration",
 3115        "Reads values from application configuration without storing the value in Elsa.",
 3116        SecretStoreCapabilities.Read | SecretStoreCapabilities.Write | SecretStoreCapabilities.Test,
 3117        true);
 18
 19    public Task<SecretPayload> WriteAsync(Secret secret, SecretVersion version, SecretPayload payload, CancellationToken
 20    {
 521        if (!payload.Metadata.TryGetValue(ConfigurationKeyMetadataName, out var key) || string.IsNullOrWhiteSpace(key))
 022            throw new InvalidOperationException("A configuration key is required.");
 23
 524        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    {
 429        if (!version.Payload.Metadata.TryGetValue(ConfigurationKeyMetadataName, out var key) || string.IsNullOrWhiteSpac
 030            return Task.FromResult<SecretPayload?>(null);
 31
 432        var configuredValue = configuration[$"{options.Value.ConfigurationSectionName}:{key}"] ?? configuration[key];
 433        return configuredValue == null ? Task.FromResult<SecretPayload?>(null) : Task.FromResult<SecretPayload?>(SecretP
 34    }
 35
 036    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    {
 140        var payload = await ReadAsync(secret, version, cancellationToken);
 141        return payload?.Value != null;
 142    }
 43}