< Summary

Information
Class: AsiBackbone.AspNetCore.Endpoints.AsiBackboneEndpointGovernanceOptions
Assembly: AsiBackbone.AspNetCore
File(s): /home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.AspNetCore/Endpoints/AsiBackboneEndpointGovernanceOptions.cs
Line coverage
95%
Covered lines: 20
Uncovered lines: 1
Coverable lines: 21
Total lines: 101
Line coverage: 95.2%
Branch coverage
50%
Covered branches: 3
Total branches: 6
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.AspNetCore/Endpoints/AsiBackboneEndpointGovernanceOptions.cs

#LineLine coverage
 1using Microsoft.AspNetCore.Http;
 2
 3namespace AsiBackbone.AspNetCore.Endpoints;
 4
 5/// <summary>
 6/// Provides options for ergonomic ASP.NET Core endpoint governance integration.
 7/// </summary>
 8public sealed class AsiBackboneEndpointGovernanceOptions
 9{
 10    /// <summary>
 11    /// Gets or sets the policy version attached to generated endpoint governance evaluation contexts.
 12    /// </summary>
 913    public string? PolicyVersion { get; set; }
 14
 15    /// <summary>
 16    /// Gets or sets the policy hash attached to generated endpoint governance evaluation contexts.
 17    /// </summary>
 918    public string? PolicyHash { get; set; }
 19
 20    /// <summary>
 21    /// Gets or sets a value indicating whether policy metadata should fail closed when no policy evaluator is configure
 22    /// </summary>
 2923    public bool FailClosedWhenPolicyEvaluatorMissing { get; set; } = true;
 24
 25    /// <summary>
 26    /// Gets or sets a value indicating whether capability metadata should fail closed when no capability validator is c
 27    /// </summary>
 3328    public bool FailClosedWhenCapabilityValidatorMissing { get; set; } = true;
 29
 30    /// <summary>
 31    /// Gets or sets a value indicating whether audit metadata should fail closed when no host-owned audit sink is confi
 32    /// </summary>
 2933    public bool FailClosedWhenAuditSinkMissing { get; set; } = true;
 34
 35    /// <summary>
 36    /// Gets or sets the HTTP status code used when endpoint governance is missing required host configuration.
 37    /// </summary>
 6738    public int ConfigurationFailureStatusCode { get; set; } = StatusCodes.Status500InternalServerError;
 39
 40    /// <summary>
 41    /// Gets or sets the HTTP status code used when endpoint capability validation fails before policy evaluation return
 42    /// </summary>
 7143    public int CapabilityFailureStatusCode { get; set; } = StatusCodes.Status403Forbidden;
 44
 45    /// <summary>
 46    /// Gets or sets the HTTP status code used when a governance decision requires acknowledgment and the endpoint reque
 47    /// </summary>
 6748    public int AcknowledgmentChallengeStatusCode { get; set; } = StatusCodes.Status428PreconditionRequired;
 49
 50    /// <summary>
 51    /// Gets or sets a value indicating whether selected endpoints without AsiBackbone governance metadata should fail c
 52    /// </summary>
 1053    public bool RequireGovernanceMetadata { get; set; }
 54
 55    /// <summary>
 56    /// Gets or sets a value indicating whether local-development ProblemDetails diagnostics should be emitted for endpo
 57    /// </summary>
 2258    public bool EnableDevelopmentDiagnostics { get; set; }
 59
 60    /// <summary>
 61    /// Gets or sets the documentation base URL used when development diagnostics include a troubleshooting link.
 62    /// </summary>
 863    public string? DevelopmentDiagnosticsDocumentationBaseUrl { get; set; }
 64
 65    /// <summary>
 66    /// Gets a collection of metadata keys whose values should be redacted from development diagnostics.
 67    /// </summary>
 4768    public ISet<string> DevelopmentDiagnosticsRedactedMetadataKeys { get; } = new HashSet<string>(StringComparer.Ordinal
 69
 70    /// <summary>
 71    /// Gets or sets a value indicating whether non-sensitive metadata values may be included in development diagnostics
 72    /// </summary>
 4773    public bool IncludeDevelopmentDiagnosticsMetadataValues { get; set; } = true;
 74
 75    /// <summary>
 76    /// Gets or sets an optional factory for the generic 403 response used by middleware when no explicit failure result
 77    /// </summary>
 78    /// <remarks>
 79    /// Leave this unset for the low-allocation, bodyless default 403 response. Hosts that prefer richer API responses
 80    /// may provide a safe factory, such as a ProblemDetails result, while avoiding sensitive governance details.
 81    /// </remarks>
 1682    public Func<HttpContext, IResult>? DefaultForbiddenResultFactory { get; set; }
 83
 84    /// <summary>
 85    /// Validates endpoint governance options.
 86    /// </summary>
 87    public void Validate()
 88    {
 3889        ValidateStatusCode(ConfigurationFailureStatusCode, nameof(ConfigurationFailureStatusCode));
 3890        ValidateStatusCode(CapabilityFailureStatusCode, nameof(CapabilityFailureStatusCode));
 3891        ValidateStatusCode(AcknowledgmentChallengeStatusCode, nameof(AcknowledgmentChallengeStatusCode));
 3892    }
 93
 94    private static void ValidateStatusCode(int statusCode, string propertyName)
 95    {
 11496        if (statusCode is < 100 or > 599)
 97        {
 098            throw new InvalidOperationException($"{propertyName} must be a valid HTTP status code.");
 99        }
 114100    }
 101}