#[non_exhaustive]pub struct AuditEntry {
pub actor: String,
pub tenant: Option<String>,
pub operation: String,
pub object: Option<String>,
pub outcome: String,
pub request_id: Option<String>,
pub details: Vec<(String, String)>,
}Expand description
An audit record of a sensitive — typically administrative — mutation
(ADR 0013): who did what, to which object, with what result, and a
correlation id. Field-level details are redacted of secrets before they
ever reach a sink (see AuditEntry::redacted); the full request body with
its secrets is never stored.
#[non_exhaustive]: build one from AuditEntry::default and set fields, never
by exhaustive literal, so a new audit field is a non-breaking addition.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.actor: StringThe acting principal’s subject (empty for anonymous).
tenant: Option<String>The tenant the action was scoped to, if any.
operation: StringThe operation, e.g. "POST /v1/accounts/create_user".
object: Option<String>The target object’s id, when the handler knows it.
outcome: StringThe result, e.g. the HTTP status as a string ("201", "403").
request_id: Option<String>The request’s correlation id, for tracing.
details: Vec<(String, String)>Redacted field-level detail (never the full body, never a secret value).
Implementations§
Source§impl AuditEntry
impl AuditEntry
Sourcepub fn new(
actor: impl Into<String>,
operation: impl Into<String>,
outcome: impl Into<String>,
) -> AuditEntry
pub fn new( actor: impl Into<String>, operation: impl Into<String>, outcome: impl Into<String>, ) -> AuditEntry
Starts an entry for actor performing operation with the given outcome
(e.g. an HTTP status as a string), then refined through the builder methods.
Build entries this way, not by field literal: AuditEntry is
#[non_exhaustive], so a new field never breaks a caller.
Sourcepub fn in_tenant(self, tenant: Option<impl Into<String>>) -> AuditEntry
pub fn in_tenant(self, tenant: Option<impl Into<String>>) -> AuditEntry
Scopes the entry to tenant.
Sourcepub fn on_object(self, object: Option<impl Into<String>>) -> AuditEntry
pub fn on_object(self, object: Option<impl Into<String>>) -> AuditEntry
Records the target object’s id.
Sourcepub fn with_request_id(
self,
request_id: Option<impl Into<String>>,
) -> AuditEntry
pub fn with_request_id( self, request_id: Option<impl Into<String>>, ) -> AuditEntry
Attaches the request’s correlation id.
Sourcepub fn with_detail(
self,
name: impl Into<String>,
value: impl Into<String>,
) -> AuditEntry
pub fn with_detail( self, name: impl Into<String>, value: impl Into<String>, ) -> AuditEntry
Appends one redactable detail pair (redaction happens in redacted).
Sourcepub fn redacted(self) -> AuditEntry
pub fn redacted(self) -> AuditEntry
Returns the entry with every sensitive details value replaced by
"[redacted]" (is_sensitive_field). Call this before recording so a
password, hash, token or key can never land in the audit log.
Trait Implementations§
Source§impl Clone for AuditEntry
impl Clone for AuditEntry
Source§fn clone(&self) -> AuditEntry
fn clone(&self) -> AuditEntry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more