Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

brokkr-models::models::audit_logs Rust

Audit log models for tracking administrative and security-sensitive operations.

Audit logs are immutable records that track who did what to which resource. They are used for compliance, debugging, and security incident investigation.

Structs

brokkr-models::models::audit_logs::AuditLog

pub

Derives: Debug, Clone, Queryable, Selectable, Identifiable, Serialize, Deserialize, ToSchema

An audit log record from the database.

Fields

NameTypeDescription
idUuidUnique identifier for the log entry.
timestampDateTime < Utc >When the event occurred.
actor_typeStringType of actor: admin, agent, generator, system.
actor_idOption < Uuid >ID of the actor (NULL for system or unauthenticated).
actionStringThe action performed (e.g., “agent.created”, “auth.failed”).
resource_typeStringType of resource affected.
resource_idOption < Uuid >ID of the affected resource (NULL if not applicable).
detailsOption < serde_json :: Value >Additional structured details.
ip_addressOption < String >Client IP address.
user_agentOption < String >Client user agent string.
created_atDateTime < Utc >When the record was created.

brokkr-models::models::audit_logs::NewAuditLog

pub

Derives: Debug, Clone, Insertable, Serialize, Deserialize

A new audit log entry to be inserted.

Fields

NameTypeDescription
actor_typeStringType of actor.
actor_idOption < Uuid >ID of the actor.
actionStringThe action performed.
resource_typeStringType of resource affected.
resource_idOption < Uuid >ID of the affected resource.
detailsOption < serde_json :: Value >Additional structured details.
ip_addressOption < String >Client IP address.
user_agentOption < String >Client user agent string.

Methods

new pub
#![allow(unused)]
fn main() {
fn new (actor_type : & str , actor_id : Option < Uuid > , action : & str , resource_type : & str , resource_id : Option < Uuid > ,) -> Result < Self , String >
}

Creates a new audit log entry.

Parameters:

NameTypeDescription
actor_type-Type of actor (admin, agent, generator, system).
actor_id-ID of the actor (None for system).
action-The action performed.
resource_type-Type of resource affected.
resource_id-ID of the affected resource (None if not applicable).
Source
#![allow(unused)]
fn main() {
    pub fn new(
        actor_type: &str,
        actor_id: Option<Uuid>,
        action: &str,
        resource_type: &str,
        resource_id: Option<Uuid>,
    ) -> Result<Self, String> {
        // Validate actor type
        if !VALID_ACTOR_TYPES.contains(&actor_type) {
            return Err(format!(
                "Invalid actor_type '{}'. Must be one of: {:?}",
                actor_type, VALID_ACTOR_TYPES
            ));
        }

        // Validate action is not empty
        if action.trim().is_empty() {
            return Err("Action cannot be empty".to_string());
        }

        // Validate resource_type is not empty
        if resource_type.trim().is_empty() {
            return Err("Resource type cannot be empty".to_string());
        }

        Ok(Self {
            actor_type: actor_type.to_string(),
            actor_id,
            action: action.to_string(),
            resource_type: resource_type.to_string(),
            resource_id,
            details: None,
            ip_address: None,
            user_agent: None,
        })
    }
}
with_details pub
#![allow(unused)]
fn main() {
fn with_details (mut self , details : serde_json :: Value) -> Self
}

Adds details to the audit log entry.

Source
#![allow(unused)]
fn main() {
    pub fn with_details(mut self, details: serde_json::Value) -> Self {
        self.details = Some(details);
        self
    }
}
with_ip_address pub
#![allow(unused)]
fn main() {
fn with_ip_address (mut self , ip : impl Into < String >) -> Self
}

Adds client IP address to the audit log entry.

Source
#![allow(unused)]
fn main() {
    pub fn with_ip_address(mut self, ip: impl Into<String>) -> Self {
        self.ip_address = Some(ip.into());
        self
    }
}
with_user_agent pub
#![allow(unused)]
fn main() {
fn with_user_agent (mut self , user_agent : String) -> Self
}

Adds user agent to the audit log entry.

Source
#![allow(unused)]
fn main() {
    pub fn with_user_agent(mut self, user_agent: String) -> Self {
        self.user_agent = Some(user_agent);
        self
    }
}

brokkr-models::models::audit_logs::AuditLogFilter

pub

Derives: Debug, Clone, Default, Serialize, Deserialize, ToSchema

Filters for querying audit logs.

Fields

NameTypeDescription
actor_typeOption < String >Filter by actor type.
actor_idOption < Uuid >Filter by actor ID.
actionOption < String >Filter by action (exact match or prefix with *).
resource_typeOption < String >Filter by resource type.
resource_idOption < Uuid >Filter by resource ID.
fromOption < DateTime < Utc > >Filter by start time (inclusive).
toOption < DateTime < Utc > >Filter by end time (exclusive).