pub struct AuditEventBuilder { /* private fields */ }Expand description
A fluent builder for AuditEvent.
Only event_type and description are required; every other field
receives a sensible default (auto-generated id, SystemTime::now()
timestamp, RiskLevel::Low, EventOutcome::Unknown, etc.).
§Example
use auth_framework::audit::*;
let event = AuditEvent::builder(AuditEventType::LoginSuccess, "User logged in")
.user_id("user_123")
.session_id("sess_abc")
.outcome(EventOutcome::Success)
.with_actor("user", "user_123")
.build();
assert_eq!(event.event_type, AuditEventType::LoginSuccess);
assert_eq!(event.user_id, Some("user_123".to_string()));Implementations§
Source§impl AuditEventBuilder
impl AuditEventBuilder
Sourcepub fn new(event_type: AuditEventType, description: impl Into<String>) -> Self
pub fn new(event_type: AuditEventType, description: impl Into<String>) -> Self
Create a new builder with required fields.
Sourcepub fn session_id(self, id: impl Into<String>) -> Self
pub fn session_id(self, id: impl Into<String>) -> Self
Set the session ID.
Sourcepub fn outcome(self, outcome: EventOutcome) -> Self
pub fn outcome(self, outcome: EventOutcome) -> Self
Set the event outcome.
Sourcepub fn risk_level(self, level: RiskLevel) -> Self
pub fn risk_level(self, level: RiskLevel) -> Self
Set the risk level.
Sourcepub fn with_actor(
self,
actor_type: impl Into<String>,
actor_id: impl Into<String>,
) -> Self
pub fn with_actor( self, actor_type: impl Into<String>, actor_id: impl Into<String>, ) -> Self
Set actor information.
Sourcepub fn request_metadata(self, metadata: RequestMetadata) -> Self
pub fn request_metadata(self, metadata: RequestMetadata) -> Self
Set request metadata.
Sourcepub fn resource(self, resource: ResourceInfo) -> Self
pub fn resource(self, resource: ResourceInfo) -> Self
Set the affected resource.
Sourcepub fn correlation_id(self, id: impl Into<String>) -> Self
pub fn correlation_id(self, id: impl Into<String>) -> Self
Set the correlation ID.
Sourcepub fn detail(self, key: impl Into<String>, value: impl Into<String>) -> Self
pub fn detail(self, key: impl Into<String>, value: impl Into<String>) -> Self
Insert a key-value pair into the event details.
Sourcepub fn build(self) -> AuditEvent
pub fn build(self) -> AuditEvent
Consume the builder and produce the AuditEvent.
Auto-generates a UUID id if one was not set, and sets the
timestamp to SystemTime::now() if it was left at the default.
Auto Trait Implementations§
impl Freeze for AuditEventBuilder
impl RefUnwindSafe for AuditEventBuilder
impl Send for AuditEventBuilder
impl Sync for AuditEventBuilder
impl Unpin for AuditEventBuilder
impl UnsafeUnpin for AuditEventBuilder
impl UnwindSafe for AuditEventBuilder
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more