< Summary - Envilder .NET SDK

Information
Class: Envilder.Infrastructure.Configuration.ConfigurationBuilderExtensions
Assembly: Envilder
File(s): /home/runner/work/envilder/envilder/src/sdks/dotnet/Infrastructure/Configuration/ConfigurationBuilderExtensions.cs
Tag: 151_24479375065
Line coverage
90%
Covered lines: 9
Uncovered lines: 1
Coverable lines: 10
Total lines: 51
Line coverage: 90%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddEnvilder(...)83.33%6690%

File(s)

/home/runner/work/envilder/envilder/src/sdks/dotnet/Infrastructure/Configuration/ConfigurationBuilderExtensions.cs

#LineLine coverage
 1namespace Envilder.Infrastructure.Configuration;
 2
 3using Envilder.Application;
 4using Envilder.Domain.Ports;
 5using Microsoft.Extensions.Configuration;
 6using System;
 7using System.IO;
 8
 9/// <summary>
 10/// Extension methods for integrating Envilder into the
 11/// <see cref="IConfigurationBuilder"/> pipeline.
 12/// </summary>
 13public static class ConfigurationBuilderExtensions
 14{
 15    /// <summary>
 16    /// Adds an Envilder configuration source that reads a JSON map file from disk,
 17    /// resolves every mapping against the given <paramref name="secretProvider"/>,
 18    /// and exposes the results as <see cref="IConfiguration"/> keys.
 19    /// </summary>
 20    /// <param name="builder">The configuration builder.</param>
 21    /// <param name="mapFilePath">Absolute or relative path to the JSON map file.</param>
 22    /// <param name="secretProvider">The secret provider to resolve values from.</param>
 23    /// <returns>The same <see cref="IConfigurationBuilder"/> for chaining.</returns>
 24    /// <exception cref="ArgumentException"><paramref name="mapFilePath"/> is null or empty.</exception>
 25    /// <exception cref="FileNotFoundException">The map file does not exist on disk.</exception>
 26    public static IConfigurationBuilder AddEnvilder(this IConfigurationBuilder builder,
 27                                                    string mapFilePath,
 28                                                    ISecretProvider secretProvider)
 29    {
 130        if (secretProvider is null)
 31        {
 032            throw new ArgumentNullException(nameof(secretProvider));
 33        }
 34
 135        if (string.IsNullOrWhiteSpace(mapFilePath))
 36        {
 137            throw new ArgumentException("Map file path cannot be null or empty.", nameof(mapFilePath));
 38        }
 39
 140        if (!File.Exists(mapFilePath))
 41        {
 142            throw new FileNotFoundException("Map file not found.", mapFilePath);
 43        }
 44
 145        var json = File.ReadAllText(mapFilePath);
 146        var mapFile = new MapFileParser().Parse(json);
 147        var client = new EnvilderClient(secretProvider);
 48
 149        return builder.Add(new EnvilderConfigurationSource(client, mapFile));
 50    }
 51}