< 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: 299_25910610327
Line coverage
100%
Covered lines: 19
Uncovered lines: 0
Coverable lines: 19
Total lines: 84
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.Application;
 2
 3using global::Envilder.Domain;
 4using global::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(IEnumerable<KeyValuePair<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
 63  /// <summary>
 64  /// Resolves all mappings in <paramref name="mapFile"/> against the configured secret provider.
 65  /// Entries whose secret does not exist in the store are silently omitted from the result.
 66  /// </summary>
 67  /// <param name="mapFile">Parsed map file containing the config and variable mappings.</param>
 68  /// <returns>A dictionary of resolved environment variable name → secret value pairs.</returns>
 69  public IDictionary<string, string> ResolveSecrets(ParsedMapFile mapFile)
 70  {
 171    var result = new Dictionary<string, string>();
 72
 173    foreach (var entry in mapFile.Mappings)
 74    {
 175      var secretValue = _secretProvider.GetSecret(entry.Value);
 176      if (secretValue is not null)
 77      {
 178        result[entry.Key] = secretValue;
 79      }
 80    }
 81
 182    return result;
 83  }
 84}