Skip to main content

do_memory_mcp/server/audit/
relationship_ops.rs

1//! Audit logging operations - Relationship operations
2//!
3//! This module provides logging methods for relationship-related operations.
4
5use super::core::AuditLogger;
6use super::types::AuditLogLevel;
7use serde_json::json;
8
9impl AuditLogger {
10    /// Log relationship addition between episodes
11    pub async fn log_add_relationship(
12        &self,
13        client_id: &str,
14        from_episode_id: &str,
15        to_episode_id: &str,
16        relationship_type: &str,
17        relationship_id: &str,
18        success: bool,
19    ) {
20        let metadata = json!({
21            "from_episode_id": from_episode_id,
22            "to_episode_id": to_episode_id,
23            "relationship_type": relationship_type,
24            "relationship_id": relationship_id
25        });
26
27        self.log_event(
28            AuditLogLevel::Info,
29            client_id,
30            "add_episode_relationship",
31            if success { "success" } else { "failure" },
32            metadata,
33        )
34        .await;
35    }
36
37    /// Log relationship removal
38    pub async fn log_remove_relationship(
39        &self,
40        client_id: &str,
41        relationship_id: &str,
42        success: bool,
43    ) {
44        let metadata = json!({
45            "relationship_id": relationship_id
46        });
47
48        self.log_event(
49            AuditLogLevel::Info,
50            client_id,
51            "remove_episode_relationship",
52            if success { "success" } else { "failure" },
53            metadata,
54        )
55        .await;
56    }
57
58    /// Log get episode relationships query
59    pub async fn log_get_relationships(
60        &self,
61        client_id: &str,
62        episode_id: &str,
63        total_count: usize,
64        success: bool,
65    ) {
66        let metadata = json!({
67            "episode_id": episode_id,
68            "total_count": total_count
69        });
70
71        self.log_event(
72            AuditLogLevel::Info,
73            client_id,
74            "get_episode_relationships",
75            if success { "success" } else { "failure" },
76            metadata,
77        )
78        .await;
79    }
80
81    /// Log find related episodes query
82    pub async fn log_find_related(
83        &self,
84        client_id: &str,
85        episode_id: &str,
86        count: usize,
87        success: bool,
88    ) {
89        let metadata = json!({
90            "episode_id": episode_id,
91            "count": count
92        });
93
94        self.log_event(
95            AuditLogLevel::Info,
96            client_id,
97            "find_related_episodes",
98            if success { "success" } else { "failure" },
99            metadata,
100        )
101        .await;
102    }
103
104    /// Log check relationship exists query
105    pub async fn log_check_relationship(
106        &self,
107        client_id: &str,
108        from_episode_id: &str,
109        to_episode_id: &str,
110        relationship_type: &str,
111        exists: bool,
112        success: bool,
113    ) {
114        let metadata = json!({
115            "from_episode_id": from_episode_id,
116            "to_episode_id": to_episode_id,
117            "relationship_type": relationship_type,
118            "exists": exists
119        });
120
121        self.log_event(
122            AuditLogLevel::Info,
123            client_id,
124            "check_relationship_exists",
125            if success { "success" } else { "failure" },
126            metadata,
127        )
128        .await;
129    }
130
131    /// Log dependency graph generation
132    pub async fn log_dependency_graph(
133        &self,
134        client_id: &str,
135        episode_id: &str,
136        node_count: usize,
137        edge_count: usize,
138        success: bool,
139    ) {
140        let metadata = json!({
141            "episode_id": episode_id,
142            "node_count": node_count,
143            "edge_count": edge_count
144        });
145
146        self.log_event(
147            AuditLogLevel::Info,
148            client_id,
149            "get_dependency_graph",
150            if success { "success" } else { "failure" },
151            metadata,
152        )
153        .await;
154    }
155
156    /// Log cycle validation check
157    pub async fn log_validate_cycles(
158        &self,
159        client_id: &str,
160        from_episode_id: &str,
161        to_episode_id: &str,
162        relationship_type: &str,
163        would_create_cycle: bool,
164        success: bool,
165    ) {
166        let metadata = json!({
167            "from_episode_id": from_episode_id,
168            "to_episode_id": to_episode_id,
169            "relationship_type": relationship_type,
170            "would_create_cycle": would_create_cycle
171        });
172
173        self.log_event(
174            AuditLogLevel::Info,
175            client_id,
176            "validate_no_cycles",
177            if success { "success" } else { "failure" },
178            metadata,
179        )
180        .await;
181    }
182
183    /// Log topological order computation
184    pub async fn log_topological_order(
185        &self,
186        client_id: &str,
187        input_count: usize,
188        output_count: usize,
189        has_cycles: bool,
190        success: bool,
191    ) {
192        let metadata = json!({
193            "input_count": input_count,
194            "output_count": output_count,
195            "has_cycles": has_cycles
196        });
197
198        self.log_event(
199            AuditLogLevel::Info,
200            client_id,
201            "get_topological_order",
202            if success { "success" } else { "failure" },
203            metadata,
204        )
205        .await;
206    }
207}