| | | 1 | | namespace ProjectTemplate.Infrastructure.Data.Auditing; |
| | | 2 | | |
| | | 3 | | public static class ApplicationAuditReconciliationReasonCodes |
| | | 4 | | { |
| | | 5 | | public const string MissingCompletion = "MissingCompletion"; |
| | | 6 | | public const string MissingAuditBatch = "MissingAuditBatch"; |
| | | 7 | | public const string AuditRecordCountMismatch = "AuditRecordCountMismatch"; |
| | | 8 | | public const string ManifestVerificationFailed = "ManifestVerificationFailed"; |
| | | 9 | | public const string IncompleteGeneratedValues = "IncompleteGeneratedValues"; |
| | | 10 | | public const string MalformedCorrelation = "MalformedCorrelation"; |
| | | 11 | | public const string DuplicateCompletion = "DuplicateCompletion"; |
| | | 12 | | public const string StalePending = "StalePending"; |
| | | 13 | | public const string StaleRetryReady = "StaleRetryReady"; |
| | | 14 | | public const string DeliveryFailed = "DeliveryFailed"; |
| | | 15 | | public const string DeadLettered = "DeadLettered"; |
| | | 16 | | } |
| | | 17 | | |
| | | 18 | | public static class ApplicationAuditReconciliationSeverities |
| | | 19 | | { |
| | | 20 | | public const string Information = "Information"; |
| | | 21 | | public const string Warning = "Warning"; |
| | | 22 | | public const string Error = "Error"; |
| | | 23 | | public const string Critical = "Critical"; |
| | | 24 | | } |
| | | 25 | | |
| | | 26 | | public static class ApplicationAuditReconciliationRemediationStatuses |
| | | 27 | | { |
| | | 28 | | public const string Open = "Open"; |
| | | 29 | | public const string Acknowledged = "Acknowledged"; |
| | | 30 | | public const string Resolved = "Resolved"; |
| | | 31 | | } |
| | | 32 | | |
| | | 33 | | public sealed class ApplicationAuditReconciliationOptions |
| | | 34 | | { |
| | | 35 | | public bool Enabled { get; set; } = true; |
| | | 36 | | |
| | | 37 | | public bool RunWorker { get; set; } = true; |
| | | 38 | | |
| | | 39 | | public TimeSpan Interval { get; set; } = TimeSpan.FromMinutes(5); |
| | | 40 | | |
| | | 41 | | public TimeSpan CompletionGracePeriod { get; set; } = TimeSpan.FromMinutes(2); |
| | | 42 | | |
| | | 43 | | public TimeSpan StalePendingThreshold { get; set; } = TimeSpan.FromMinutes(15); |
| | | 44 | | |
| | | 45 | | public TimeSpan StaleRetryReadyThreshold { get; set; } = TimeSpan.FromMinutes(15); |
| | | 46 | | |
| | | 47 | | public int MaximumBatchesPerRun { get; set; } = 1_000; |
| | | 48 | | |
| | | 49 | | public int HealthWarningFindingCount { get; set; } = 1; |
| | | 50 | | |
| | | 51 | | public int HealthUnhealthyFindingCount { get; set; } = 10; |
| | | 52 | | } |
| | | 53 | | |
| | | 54 | | public interface IApplicationAuditReconciler |
| | | 55 | | { |
| | | 56 | | Task<ApplicationAuditReconciliationSummary> ReconcileAsync( |
| | | 57 | | CancellationToken cancellationToken = default); |
| | | 58 | | |
| | | 59 | | Task<ApplicationAuditReconciliationSummary> GetSummaryAsync( |
| | | 60 | | CancellationToken cancellationToken = default); |
| | | 61 | | |
| | | 62 | | Task<IReadOnlyList<ApplicationAuditReconciliationFindingItem>> QueryFindingsAsync( |
| | | 63 | | ApplicationAuditReconciliationQuery request, |
| | | 64 | | CancellationToken cancellationToken = default); |
| | | 65 | | |
| | | 66 | | Task<ApplicationAuditReconciliationRemediationItem> RecordRemediationAsync( |
| | | 67 | | Guid findingId, |
| | | 68 | | ApplicationAuditReconciliationRemediationRequest request, |
| | | 69 | | CancellationToken cancellationToken = default); |
| | | 70 | | } |
| | | 71 | | |
| | | 72 | | public sealed record ApplicationAuditReconciliationSummary( |
| | | 73 | | bool Enabled, |
| | | 74 | | DateTime? LastRunUtc, |
| | | 75 | | long OpenFindingCount, |
| | | 76 | | long ErrorFindingCount, |
| | | 77 | | long CriticalFindingCount, |
| | | 78 | | long ManifestVerificationFailureCount, |
| | | 79 | | long MissingCompletionCount, |
| | | 80 | | long StaleDeliveryCount, |
| | | 81 | | long DeadLetterCount); |
| | | 82 | | |
| | | 83 | | public sealed record ApplicationAuditReconciliationQuery( |
| | | 84 | | string? ReasonCode = null, |
| | | 85 | | string? Severity = null, |
| | | 86 | | string? MutationBatchId = null, |
| | | 87 | | string? RemediationStatus = null, |
| | | 88 | | int MaximumResults = 100); |
| | | 89 | | |
| | | 90 | | public sealed record ApplicationAuditReconciliationFindingItem( |
| | | 91 | | Guid Id, |
| | | 92 | | string SchemaVersion, |
| | | 93 | | string FindingKey, |
| | | 94 | | string ReasonCode, |
| | | 95 | | string Severity, |
| | | 96 | | string MutationBatchId, |
| | | 97 | | string? Destination, |
| | | 98 | | string Guidance, |
| | | 99 | | string RemediationStatus, |
| | | 100 | | DateTime FirstObservedUtc, |
| | | 101 | | DateTime LastObservedUtc, |
| | | 102 | | DateTime? ResolvedUtc); |
| | | 103 | | |
| | | 104 | | public sealed record ApplicationAuditReconciliationRemediationRequest( |
| | | 105 | | string ActionCode, |
| | | 106 | | string ActorId, |
| | | 107 | | string? EvidenceReference = null, |
| | | 108 | | bool ResolveFinding = false); |
| | | 109 | | |
| | 2 | 110 | | public sealed record ApplicationAuditReconciliationRemediationItem( |
| | 0 | 111 | | Guid Id, |
| | 2 | 112 | | Guid FindingId, |
| | 0 | 113 | | string MutationBatchId, |
| | 0 | 114 | | string ActionCode, |
| | 0 | 115 | | string ActorId, |
| | 0 | 116 | | string? EvidenceReference, |
| | 2 | 117 | | DateTime RecordedUtc); |
| | | 118 | | |
| | | 119 | | internal sealed record ApplicationAuditReconciliationCandidate( |
| | | 120 | | string FindingKey, |
| | | 121 | | string ReasonCode, |
| | | 122 | | string Severity, |
| | | 123 | | string MutationBatchId, |
| | | 124 | | string? Destination, |
| | | 125 | | string Guidance); |