< Summary - Envilder .NET SDK

Information
Class: Envilder.Application.EnvilderClient
Assembly: Envilder
File(s): /home/runner/work/envilder/envilder/src/sdks/dotnet/Application/EnvilderClient.cs
Tag: 151_24479375065
Line coverage
100%
Covered lines: 13
Uncovered lines: 0
Coverable lines: 13
Total lines: 62
Line coverage: 100%
Branch coverage
87%
Covered branches: 7
Total branches: 8
Branch coverage: 87.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)50%22100%
InjectIntoEnvironment(...)100%22100%
ResolveSecretsAsync()100%44100%

File(s)

/home/runner/work/envilder/envilder/src/sdks/dotnet/Application/EnvilderClient.cs

#LineLine coverage
 1namespace Envilder.Application;
 2
 3using Envilder.Domain;
 4using Envilder.Domain.Ports;
 5using System;
 6using System.Collections.Generic;
 7using System.Threading;
 8using System.Threading.Tasks;
 9
 10/// <summary>
 11/// Core client that resolves secrets from a configured provider and optionally
 12/// injects them into the current process environment.
 13/// </summary>
 14public class EnvilderClient
 15{
 16    private readonly ISecretProvider _secretProvider;
 17
 18    /// <summary>
 19    /// Initializes a new <see cref="EnvilderClient"/> backed by the given provider.
 20    /// </summary>
 21    /// <param name="secretProvider">The secret store to resolve values from.</param>
 122    public EnvilderClient(ISecretProvider secretProvider)
 23    {
 124        _secretProvider = secretProvider ?? throw new ArgumentNullException(nameof(secretProvider));
 125    }
 26
 27    /// <summary>
 28    /// Sets every key/value pair as a process-level environment variable.
 29    /// </summary>
 30    /// <param name="secrets">Resolved secrets to inject.</param>
 31    public static void InjectIntoEnvironment(IDictionary<string, string> secrets)
 32    {
 133        foreach (var kvp in secrets)
 34        {
 135            Environment.SetEnvironmentVariable(kvp.Key, kvp.Value);
 36        }
 137    }
 38
 39    /// <summary>
 40    /// Resolves all mappings in <paramref name="mapFile"/> against the configured secret provider.
 41    /// Entries whose secret does not exist in the store are silently omitted from the result.
 42    /// </summary>
 43    /// <param name="mapFile">Parsed map file containing the config and variable mappings.</param>
 44    /// <param name="cancellationToken">Optional cancellation token.</param>
 45    /// <returns>A dictionary of resolved environment variable name → secret value pairs.</returns>
 46    public async Task<IDictionary<string, string>> ResolveSecretsAsync(ParsedMapFile mapFile,
 47                                                                       CancellationToken cancellationToken = default)
 48    {
 149        var result = new Dictionary<string, string>();
 50
 151        foreach (var entry in mapFile.Mappings)
 52        {
 153            var secretValue = await _secretProvider.GetSecretAsync(entry.Value, cancellationToken).ConfigureAwait(false)
 154            if (secretValue is not null)
 55            {
 156                result[entry.Key] = secretValue;
 57            }
 58        }
 59
 160        return result;
 161    }
 62}