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
| Name | Type | Description |
|---|---|---|
id | Uuid | Unique identifier for the log entry. |
timestamp | DateTime < Utc > | When the event occurred. |
actor_type | String | Type of actor: admin, agent, generator, system. |
actor_id | Option < Uuid > | ID of the actor (NULL for system or unauthenticated). |
action | String | The action performed (e.g., “agent.created”, “auth.failed”). |
resource_type | String | Type of resource affected. |
resource_id | Option < Uuid > | ID of the affected resource (NULL if not applicable). |
details | Option < serde_json :: Value > | Additional structured details. |
ip_address | Option < String > | Client IP address. |
user_agent | Option < String > | Client user agent string. |
created_at | DateTime < 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
| Name | Type | Description |
|---|---|---|
actor_type | String | Type of actor. |
actor_id | Option < Uuid > | ID of the actor. |
action | String | The action performed. |
resource_type | String | Type of resource affected. |
resource_id | Option < Uuid > | ID of the affected resource. |
details | Option < serde_json :: Value > | Additional structured details. |
ip_address | Option < String > | Client IP address. |
user_agent | Option < 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:
| Name | Type | Description |
|---|---|---|
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
| Name | Type | Description |
|---|---|---|
actor_type | Option < String > | Filter by actor type. |
actor_id | Option < Uuid > | Filter by actor ID. |
action | Option < String > | Filter by action (exact match or prefix with *). |
resource_type | Option < String > | Filter by resource type. |
resource_id | Option < Uuid > | Filter by resource ID. |
from | Option < DateTime < Utc > > | Filter by start time (inclusive). |
to | Option < DateTime < Utc > > | Filter by end time (exclusive). |