spawn_access_control/
audit.rs1use chrono::{DateTime, Utc};
2use serde::{Serialize, Deserialize};
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub enum ActionResult {
6 Success,
7 Failure { reason: String },
8}
9
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct AuditLogEntry {
12 pub id: String,
13 pub timestamp: DateTime<Utc>,
14 pub user_id: String,
15 pub resource_id: String,
16 pub action: String,
17 pub result: ActionResult,
18 pub details: Option<String>,
19 pub ip_address: Option<String>,
20 pub user_agent: Option<String>,
21}
22
23impl AuditLogEntry {
24 pub fn new(
25 user_id: String,
26 resource_id: String,
27 action: String,
28 result: ActionResult,
29 ) -> Self {
30 Self {
31 id: uuid::Uuid::new_v4().to_string(),
32 timestamp: Utc::now(),
33 user_id,
34 resource_id,
35 action,
36 result,
37 details: None,
38 ip_address: None,
39 user_agent: None,
40 }
41 }
42
43 pub fn with_details(mut self, details: String) -> Self {
44 self.details = Some(details);
45 self
46 }
47
48 pub fn with_ip(mut self, ip: String) -> Self {
49 self.ip_address = Some(ip);
50 self
51 }
52
53 pub fn with_user_agent(mut self, user_agent: String) -> Self {
54 self.user_agent = Some(user_agent);
55 self
56 }
57}