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
Section titled “Structs”struct AuditLog
Section titled “struct AuditLog”pub
Derives: Debug, Clone, Queryable, Selectable, Identifiable, Serialize, Deserialize, ToSchema
An audit log record from the database.
Fields
Section titled “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. |
struct NewAuditLog
Section titled “struct NewAuditLog”pub
Derives: Debug, Clone, Insertable, Serialize, Deserialize
A new audit log entry to be inserted.
Fields
Section titled “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
Section titled “Methods”pub
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 |
&str |
Type of actor (admin, agent, generator, system). |
actor_id |
Option<Uuid> |
ID of the actor (None for system). |
action |
&str |
The action performed. |
resource_type |
&str |
Type of resource affected. |
resource_id |
Option<Uuid> |
ID of the affected resource (None if not applicable). |
Source
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
Section titled “with_details”pub
fn with_details(mut self, details: serde_json::Value) -> SelfAdds details to the audit log entry.
Source
pub fn with_details(mut self, details: serde_json::Value) -> Self { self.details = Some(details); self }with_ip_address
Section titled “with_ip_address”pub
fn with_ip_address(mut self, ip: impl Into<String>) -> SelfAdds client IP address to the audit log entry.
Source
pub fn with_ip_address(mut self, ip: impl Into<String>) -> Self { self.ip_address = Some(ip.into()); self }with_user_agent
Section titled “with_user_agent”pub
fn with_user_agent(mut self, user_agent: String) -> SelfAdds user agent to the audit log entry.
Source
pub fn with_user_agent(mut self, user_agent: String) -> Self { self.user_agent = Some(user_agent); self }struct AuditLogFilter
Section titled “struct AuditLogFilter”pub
Derives: Debug, Clone, Default, Serialize, Deserialize, ToSchema
Filters for querying audit logs.
Fields
Section titled “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). |
Constants
Section titled “Constants”| Name | Type | Value | Description |
|---|---|---|---|
ACTOR_TYPE_ADMIN |
&str |
"admin" |
Actor type for admin users. |
ACTOR_TYPE_AGENT |
&str |
"agent" |
Actor type for agents. |
ACTOR_TYPE_GENERATOR |
&str |
"generator" |
Actor type for generators. |
ACTOR_TYPE_SYSTEM |
&str |
"system" |
Actor type for system operations. |
VALID_ACTOR_TYPES |
&[&str] |
&[ACTOR_TYPE_ADMIN, ACTOR_TYPE_AGENT, ACTOR_TYPE_GENERATO... |
|
ACTION_PAK_CREATED |
&str |
"pak.created" |
|
ACTION_PAK_ROTATED |
&str |
"pak.rotated" |
|
ACTION_PAK_DELETED |
&str |
"pak.deleted" |
|
ACTION_AUTH_FAILED |
&str |
"auth.failed" |
|
ACTION_AUTH_SUCCESS |
&str |
"auth.success" |
|
ACTION_AGENT_CREATED |
&str |
"agent.created" |
|
ACTION_AGENT_UPDATED |
&str |
"agent.updated" |
|
ACTION_AGENT_DELETED |
&str |
"agent.deleted" |
|
ACTION_AGENT_REGISTERED |
&str |
"agent.registered" |
|
ACTION_AGENT_DEREGISTERED |
&str |
"agent.deregistered" |
|
ACTION_STACK_CREATED |
&str |
"stack.created" |
|
ACTION_STACK_UPDATED |
&str |
"stack.updated" |
|
ACTION_STACK_DELETED |
&str |
"stack.deleted" |
|
ACTION_GENERATOR_CREATED |
&str |
"generator.created" |
|
ACTION_GENERATOR_UPDATED |
&str |
"generator.updated" |
|
ACTION_GENERATOR_DELETED |
&str |
"generator.deleted" |
|
ACTION_TEMPLATE_CREATED |
&str |
"template.created" |
|
ACTION_TEMPLATE_UPDATED |
&str |
"template.updated" |
|
ACTION_TEMPLATE_DELETED |
&str |
"template.deleted" |
|
ACTION_WEBHOOK_CREATED |
&str |
"webhook.created" |
|
ACTION_WEBHOOK_UPDATED |
&str |
"webhook.updated" |
|
ACTION_WEBHOOK_DELETED |
&str |
"webhook.deleted" |
|
ACTION_WEBHOOK_DELIVERY_FAILED |
&str |
"webhook.delivery_failed" |
|
ACTION_WORKORDER_CREATED |
&str |
"workorder.created" |
|
ACTION_WORKORDER_CLAIMED |
&str |
"workorder.claimed" |
|
ACTION_WORKORDER_COMPLETED |
&str |
"workorder.completed" |
|
ACTION_WORKORDER_FAILED |
&str |
"workorder.failed" |
|
ACTION_WORKORDER_RETRY |
&str |
"workorder.retry" |
|
ACTION_CONFIG_RELOADED |
&str |
"config.reloaded" |
|
RESOURCE_TYPE_AGENT |
&str |
"agent" |
|
RESOURCE_TYPE_STACK |
&str |
"stack" |
|
RESOURCE_TYPE_GENERATOR |
&str |
"generator" |
|
RESOURCE_TYPE_TEMPLATE |
&str |
"template" |
|
RESOURCE_TYPE_WEBHOOK |
&str |
"webhook_subscription" |
|
RESOURCE_TYPE_WORKORDER |
&str |
"work_order" |
|
RESOURCE_TYPE_PAK |
&str |
"pak" |
|
RESOURCE_TYPE_CONFIG |
&str |
"config" |
|
RESOURCE_TYPE_SYSTEM |
&str |
"system" |