< Summary - Heimdall API

Information
Class: ArturRios.Heimdall.Command.Services.ScopeInvitationOptions
Assembly: ArturRios.Heimdall.Command
File(s): /home/ci/agent/workspace/heimdall-api-docs_main/app/src/Application/ArturRios.Heimdall.Command/Services/ScopeInvitationOptions.cs
Line coverage
100%
Covered lines: 11
Uncovered lines: 0
Coverable lines: 11
Total lines: 46
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_Lifetime()100%11100%
get_RejectedLifetime()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/ScopeInvitationOptions.cs

#LineLine coverage
 1using System.Globalization;
 2
 3namespace ArturRios.Heimdall.Command.Services;
 4
 5/// <summary>
 6///     How long a scope owner invitation stays acceptable (UC-21, FR-SC-18). Read from
 7///     <c>HEIMDALL_SCOPE_INVITATION_LIFETIME_IN_SECONDS</c>; seven days by default.
 8/// </summary>
 9/// <remarks>
 10///     Values from 3600 (an hour) to 2592000 (thirty days) are accepted. Anything else — unparsable or out
 11///     of range — falls back to the default rather than to an invitation that never expires, and
 12///     <see cref="RejectedLifetime" /> says so for start-up to warn.
 13/// </remarks>
 14public class ScopeInvitationOptions
 15{
 16    public const string LifetimeVariable = "HEIMDALL_SCOPE_INVITATION_LIFETIME_IN_SECONDS";
 17
 18    /// <summary>Seven days, in seconds.</summary>
 19    public const double DefaultLifetimeSeconds = 604800;
 20
 21    private const double MinLifetimeSeconds = 3600;
 22
 23    private const double MaxLifetimeSeconds = 2592000;
 24
 25    /// <summary>How long after its creation an invitation can still be accepted.</summary>
 202226    public TimeSpan Lifetime { get; init; } = TimeSpan.FromSeconds(DefaultLifetimeSeconds);
 27
 28    /// <summary>The configured text when it was present but unusable; <c>null</c> otherwise.</summary>
 196829    public string? RejectedLifetime { get; init; }
 30
 97331    public static ScopeInvitationOptions FromEnvironment() => From(Environment.GetEnvironmentVariable(LifetimeVariable))
 32
 33    /// <summary>Reads a configured number of seconds, falling back to the default when it is unusable.</summary>
 34    public static ScopeInvitationOptions From(string? configured)
 35    {
 98436        var usable =
 98437            double.TryParse(configured, NumberStyles.Float, CultureInfo.InvariantCulture, out var value)
 98438            && value is >= MinLifetimeSeconds and <= MaxLifetimeSeconds;
 39
 98440        return new ScopeInvitationOptions
 98441        {
 98442            Lifetime = TimeSpan.FromSeconds(usable ? value : DefaultLifetimeSeconds),
 98443            RejectedLifetime = usable || string.IsNullOrWhiteSpace(configured) ? null : configured
 98444        };
 45    }
 46}