< Summary - Envilder .NET SDK

Information
Class: Envilder.EnvilderClient
Assembly: Envilder
File(s): /home/runner/work/envilder/envilder/src/sdks/dotnet/Application/EnvilderClient.cs
Tag: 352_26963168797
Line coverage
100%
Covered lines: 19
Uncovered lines: 0
Coverable lines: 19
Total lines: 83
Line coverage: 100%
Branch coverage
91%
Covered branches: 11
Total branches: 12
Branch coverage: 91.6%
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%
ResolveSecrets(...)100%44100%

File(s)

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

#LineLine coverage
 1namespace Envilder;
 2
 3using global::Envilder.Domain.Ports;
 4using System;
 5using System.Collections.Generic;
 6using System.Threading;
 7using System.Threading.Tasks;
 8
 9/// <summary>
 10/// Core client that resolves secrets from a configured provider and optionally
 11/// injects them into the current process environment.
 12/// </summary>
 13public class EnvilderClient
 14{
 15  private readonly ISecretProvider _secretProvider;
 16
 17  /// <summary>
 18  /// Initializes a new <see cref="EnvilderClient"/> backed by the given provider.
 19  /// </summary>
 20  /// <param name="secretProvider">The secret store to resolve values from.</param>
 121  public EnvilderClient(ISecretProvider secretProvider)
 22  {
 123    _secretProvider = secretProvider ?? throw new ArgumentNullException(nameof(secretProvider));
 124  }
 25
 26  /// <summary>
 27  /// Sets every key/value pair as a process-level environment variable.
 28  /// </summary>
 29  /// <param name="secrets">Resolved secrets to inject.</param>
 30  public static void InjectIntoEnvironment(IEnumerable<KeyValuePair<string, string>> secrets)
 31  {
 132    foreach (var kvp in secrets)
 33    {
 134      Environment.SetEnvironmentVariable(kvp.Key, kvp.Value);
 35    }
 136  }
 37
 38  /// <summary>
 39  /// Resolves all mappings in <paramref name="mapFile"/> against the configured secret provider.
 40  /// Entries whose secret does not exist in the store are silently omitted from the result.
 41  /// </summary>
 42  /// <param name="mapFile">Parsed map file containing the config and variable mappings.</param>
 43  /// <param name="cancellationToken">Optional cancellation token.</param>
 44  /// <returns>A dictionary of resolved environment variable name → secret value pairs.</returns>
 45  public async Task<IDictionary<string, string>> ResolveSecretsAsync(ParsedMapFile mapFile,
 46                                     CancellationToken cancellationToken = default)
 47  {
 148    var result = new Dictionary<string, string>();
 49
 150    foreach (var entry in mapFile.Mappings)
 51    {
 152      var secretValue = await _secretProvider.GetSecretAsync(entry.Value, cancellationToken).ConfigureAwait(false);
 153      if (secretValue is not null)
 54      {
 155        result[entry.Key] = secretValue;
 56      }
 57    }
 58
 159    return result;
 160  }
 61
 62  /// <summary>
 63  /// Resolves all mappings in <paramref name="mapFile"/> against the configured secret provider.
 64  /// Entries whose secret does not exist in the store are silently omitted from the result.
 65  /// </summary>
 66  /// <param name="mapFile">Parsed map file containing the config and variable mappings.</param>
 67  /// <returns>A dictionary of resolved environment variable name → secret value pairs.</returns>
 68  public IDictionary<string, string> ResolveSecrets(ParsedMapFile mapFile)
 69  {
 170    var result = new Dictionary<string, string>();
 71
 172    foreach (var entry in mapFile.Mappings)
 73    {
 174      var secretValue = _secretProvider.GetSecret(entry.Value);
 175      if (secretValue is not null)
 76      {
 177        result[entry.Key] = secretValue;
 78      }
 79    }
 80
 181    return result;
 82  }
 83}