| | | 1 | | using AsiBackbone.Core.Actors; |
| | | 2 | | using AsiBackbone.Core.Audit; |
| | | 3 | | using AsiBackbone.Core.Decisions; |
| | | 4 | | |
| | | 5 | | namespace AsiBackbone.AspNetCore.Correlation; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Provides helpers for applying ASP.NET Core request correlation data to framework-neutral audit residue. |
| | | 9 | | /// </summary> |
| | | 10 | | public static class AsiBackboneHttpRequestCorrelationAuditExtensions |
| | | 11 | | { |
| | | 12 | | /// <summary> |
| | | 13 | | /// Creates audit residue from a governance decision and enriches it with safe ASP.NET Core request correlation data |
| | | 14 | | /// </summary> |
| | | 15 | | /// <param name="correlation">The resolved ASP.NET Core request correlation data.</param> |
| | | 16 | | /// <param name="actor">The actor associated with the operation.</param> |
| | | 17 | | /// <param name="operationName">The operation name.</param> |
| | | 18 | | /// <param name="decision">The governance decision to audit.</param> |
| | | 19 | | /// <param name="eventId">Optional audit event identifier. When omitted, a new identifier is generated.</param> |
| | | 20 | | /// <param name="occurredUtc">Optional event timestamp. When omitted, the current UTC timestamp is used.</param> |
| | | 21 | | /// <param name="metadata">Optional host-provided audit metadata to merge with safe request metadata.</param> |
| | | 22 | | /// <returns>An enriched audit residue value.</returns> |
| | | 23 | | public static AuditResidue CreateAuditResidue( |
| | | 24 | | this AsiBackboneHttpRequestCorrelation correlation, |
| | | 25 | | IAsiBackboneActorContext actor, |
| | | 26 | | string operationName, |
| | | 27 | | GovernanceDecision decision, |
| | | 28 | | string? eventId = null, |
| | | 29 | | DateTimeOffset? occurredUtc = null, |
| | | 30 | | IReadOnlyDictionary<string, string>? metadata = null) |
| | | 31 | | { |
| | 6 | 32 | | ArgumentNullException.ThrowIfNull(correlation); |
| | 6 | 33 | | ArgumentNullException.ThrowIfNull(decision); |
| | | 34 | | |
| | 6 | 35 | | return AuditResidue.Create( |
| | 6 | 36 | | actor, |
| | 6 | 37 | | operationName, |
| | 6 | 38 | | decision.Outcome.ToString(), |
| | 6 | 39 | | decision.ReasonCodes, |
| | 6 | 40 | | eventId, |
| | 6 | 41 | | occurredUtc, |
| | 6 | 42 | | correlation.CorrelationId ?? decision.CorrelationId, |
| | 6 | 43 | | correlation.TraceId ?? decision.TraceId, |
| | 6 | 44 | | decision.PolicyVersion, |
| | 6 | 45 | | decision.PolicyHash, |
| | 6 | 46 | | correlation.MergeMetadata(metadata)); |
| | | 47 | | } |
| | | 48 | | } |