< Summary - Heimdall API

Information
Class: ArturRios.Heimdall.Command.Services.RegistrationOptions
Assembly: ArturRios.Heimdall.Command
File(s): /home/ci/agent/workspace/heimdall-api-docs_main/app/src/Application/ArturRios.Heimdall.Command/Services/RegistrationOptions.cs
Line coverage
100%
Covered lines: 10
Uncovered lines: 0
Coverable lines: 10
Total lines: 51
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage
100%
Covered methods: 4
Fully covered methods: 4
Total methods: 4
Method coverage: 100%
Full method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_MaxPendingPerScope()100%11100%
get_RejectedMaxPendingPerScope()100%11100%
FromEnvironment()100%11100%
From(...)100%88100%

File(s)

/home/ci/agent/workspace/heimdall-api-docs_main/app/src/Application/ArturRios.Heimdall.Command/Services/RegistrationOptions.cs

#LineLine coverage
 1using System.Globalization;
 2
 3namespace ArturRios.Heimdall.Command.Services;
 4
 5/// <summary>
 6///     The most live pending registrations (UC-47) one scope may hold at a time (#206). Read from
 7///     <c>HEIMDALL_REGISTRATION_MAX_PENDING_PER_SCOPE</c>; 1000 by default.
 8/// </summary>
 9/// <remarks>
 10///     <para>
 11///         Each registration a caller sends stores a row and mails a link, and the per-IP rate limit is the
 12///         only throttle on the caller: enough source addresses outpace the purge, and the table grows
 13///         without bound. FR-SR-13 bounds what one address can be sent; this bounds the scope, whatever the
 14///         addresses. A registration beyond it stores and mails nothing and is answered as any other.
 15///     </para>
 16///     <para>
 17///         Any positive integer is accepted. Anything else — unparsable, zero or negative — falls back to the
 18///         default rather than to no cap, and <see cref="RejectedMaxPendingPerScope" /> says so for start-up to
 19///         warn, as an unusable retention batch size does.
 20///     </para>
 21/// </remarks>
 22public class RegistrationOptions
 23{
 24    /// <summary>Environment variable holding the cap.</summary>
 25    public const string MaxPendingPerScopeVariable = "HEIMDALL_REGISTRATION_MAX_PENDING_PER_SCOPE";
 26
 27    /// <summary>The cap when none is configured.</summary>
 28    public const int DefaultMaxPendingPerScope = 1000;
 29
 30    /// <summary>The most live pending registrations one scope may hold.</summary>
 206231    public int MaxPendingPerScope { get; init; } = DefaultMaxPendingPerScope;
 32
 33    /// <summary>The configured text when it was present but unusable; <c>null</c> otherwise.</summary>
 196434    public string? RejectedMaxPendingPerScope { get; init; }
 35
 36    public static RegistrationOptions FromEnvironment() =>
 97337        From(Environment.GetEnvironmentVariable(MaxPendingPerScopeVariable));
 38
 39    /// <summary>Reads a configured cap, falling back to the default when it is unusable.</summary>
 40    public static RegistrationOptions From(string? configured)
 41    {
 98242        var usable = int.TryParse(configured, NumberStyles.Integer, CultureInfo.InvariantCulture, out var value)
 98243                     && value > 0;
 44
 98245        return new RegistrationOptions
 98246        {
 98247            MaxPendingPerScope = usable ? value : DefaultMaxPendingPerScope,
 98248            RejectedMaxPendingPerScope = usable || string.IsNullOrWhiteSpace(configured) ? null : configured
 98249        };
 50    }
 51}