pub struct AuditEvent {Show 15 fields
pub id: String,
pub timestamp: String,
pub event_type: String,
pub user_id: String,
pub username: String,
pub ip_address: String,
pub resource_type: String,
pub resource_id: Option<String>,
pub action: String,
pub before_state: Option<Value>,
pub after_state: Option<Value>,
pub status: String,
pub error_message: Option<String>,
pub tenant_id: Option<String>,
pub metadata: Value,
}Expand description
Audit event representing a security-relevant operation.
Captures detailed information about user actions, system events, and data mutations for compliance and security auditing.
Fields§
§id: StringUnique event identifier (UUID)
timestamp: StringISO 8601 timestamp of the event
event_type: StringEvent type (e.g., “user_login”, “data_modification”, “access_denied”)
user_id: StringUser ID (None for system events)
username: StringUsername for human readability
ip_address: StringIP address of the request origin
resource_type: StringResource type affected (e.g., “users”, “posts”, “admin_config”)
resource_id: Option<String>Resource ID (None for bulk operations or system events)
action: StringAction performed (e.g., “create”, “update”, “delete”, “read”)
before_state: Option<Value>State before modification (None for read operations)
after_state: Option<Value>State after modification (None for deletions or reads)
status: StringEvent status: “success”, “failure”, or “denied”
error_message: Option<String>Error message if status is “failure” or “denied”
tenant_id: Option<String>Tenant ID for multi-tenant deployments
metadata: ValueAdditional context as JSON (user_agent, correlation_id, etc.)
Implementations§
Source§impl AuditEvent
impl AuditEvent
Sourcepub fn new_user_action(
user_id: impl Into<String>,
username: impl Into<String>,
ip_address: impl Into<String>,
resource_type: impl Into<String>,
action: impl Into<String>,
status: impl Into<String>,
) -> Self
pub fn new_user_action( user_id: impl Into<String>, username: impl Into<String>, ip_address: impl Into<String>, resource_type: impl Into<String>, action: impl Into<String>, status: impl Into<String>, ) -> Self
Create a new audit event for a user action.
§Arguments
user_id- User performing the actionusername- User’s name for readabilityip_address- Request origin IPresource_type- Type of resource affectedaction- Action performedstatus- Result status (success/failure/denied)
Sourcepub fn with_resource_id(self, id: impl Into<String>) -> Self
pub fn with_resource_id(self, id: impl Into<String>) -> Self
Add resource ID to the event.
Sourcepub fn with_before_state(self, state: JsonValue) -> Self
pub fn with_before_state(self, state: JsonValue) -> Self
Add before state to track modifications.
Sourcepub fn with_after_state(self, state: JsonValue) -> Self
pub fn with_after_state(self, state: JsonValue) -> Self
Add after state to track modifications.
Sourcepub fn with_error(self, message: impl Into<String>) -> Self
pub fn with_error(self, message: impl Into<String>) -> Self
Add error message for failed operations.
Sourcepub fn with_tenant_id(self, tenant_id: impl Into<String>) -> Self
pub fn with_tenant_id(self, tenant_id: impl Into<String>) -> Self
Set tenant ID for multi-tenant tracking.
Sourcepub fn with_metadata(self, key: impl Into<String>, value: JsonValue) -> Self
pub fn with_metadata(self, key: impl Into<String>, value: JsonValue) -> Self
Add metadata (user agent, correlation ID, etc.).
Sourcepub fn validate(&self) -> AuditResult<()>
pub fn validate(&self) -> AuditResult<()>
Validate the audit event.
Trait Implementations§
Source§impl Clone for AuditEvent
impl Clone for AuditEvent
Source§fn clone(&self) -> AuditEvent
fn clone(&self) -> AuditEvent
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more