Skip to main content

made_core/entities/
audit_fact.rs

1use time::OffsetDateTime;
2
3use crate::entities::CeremonyEvent;
4use crate::value_objects::{
5    AuditActor, AuthorizationEvidence, CeremonyId, CeremonyName, CeremonyVersion, EventId,
6    TraceContext,
7};
8
9use super::AuthorizedAuditFact;
10
11/// Everything an audit record states before the journal assigns its position.
12///
13/// The event is the fact itself, payload included. The type a record
14/// names is derived from it (`fact.event.event_type()`) rather than
15/// declared beside it, so a fact cannot claim one thing and carry
16/// another.
17#[derive(Debug, Clone, PartialEq, Eq)]
18pub struct AuditFact {
19    pub event_id: EventId,
20    pub event: CeremonyEvent,
21    pub ceremony_id: CeremonyId,
22    pub definition_name: CeremonyName,
23    pub definition_version: CeremonyVersion,
24    pub occurred_at: OffsetDateTime,
25    pub actor: AuditActor,
26    pub correlation_id: Option<EventId>,
27    pub causation_id: Option<EventId>,
28    pub trace: Option<TraceContext>,
29}
30
31impl AuditFact {
32    /// Bind a successful admission decision to this fact.
33    ///
34    /// The wrapper makes authorization-bearing records explicit without adding
35    /// an optional field to every historical and unauthorised fact builder.
36    #[must_use]
37    pub fn authorized(self, evidence: AuthorizationEvidence) -> AuthorizedAuditFact {
38        AuthorizedAuditFact::new(self, evidence)
39    }
40}