pipa_core/logging/
schema.rs

1use serde::{Deserialize, Serialize};
2
3/// Top-level audit log entry.
4/// Each line in `audit-YYYY-MM-DD.jsonl` will be one of these.
5///
6/// This is the canonical structure for all audit events:
7/// - timestamped
8/// - leveled (INFO, AUDIT, ERROR, etc.)
9/// - typed by `event`
10/// - optionally tied to a contract, target, results, or summary
11#[derive(Serialize)]
12pub struct AuditLogEntry<'a> {
13    pub timestamp: String, // RFC3339 timestamp
14    pub level: &'a str,    // e.g. "AUDIT", "INFO", "ERROR"
15    pub event: &'a str,    // semantic event name ("movement_success", "contract_validated")
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub contract: Option<Contract<'a>>, // contract metadata
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub target: Option<Target<'a>>, // file/column/rule context
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub results: Option<Vec<RuleResult>>, // validation results (owned, no lifetime)
22    pub executor: Executor, // who/where ran this
23    #[serde(skip_serializing_if = "Option::is_none")]
24    pub details: Option<&'a str>, // freeform detail string
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub summary: Option<ProcessSummary>, // summary of a full run
27}
28
29/// Contract metadata (embedded in AuditLogEntry)
30#[derive(Serialize)]
31pub struct Contract<'a> {
32    pub name: &'a str,
33    pub version: &'a str,
34}
35
36/// Target of validation (file, column, rule)
37#[derive(Serialize)]
38pub struct Target<'a> {
39    pub file: &'a str,
40    #[serde(skip_serializing_if = "Option::is_none")]
41    pub column: Option<&'a str>,
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub rule: Option<&'a str>,
44}
45
46/// Result of a single rule evaluation
47#[derive(Clone, Debug, Serialize, Deserialize)]
48pub struct RuleResult {
49    pub column: String,          // which column was validated
50    pub rule: String,            // rule name (e.g. "not_null")
51    pub result: String,          // "pass" | "fail"
52    pub details: Option<String>, // optional failure details
53}
54
55/// Executor metadata (who/where ran the validation)
56#[derive(Clone, Serialize)]
57pub struct Executor {
58    pub user: String, // user ID or system account
59    pub host: String, // hostname or container ID
60}
61
62/// Summary of a full process run
63#[derive(Serialize)]
64pub struct ProcessSummary {
65    pub contracts_run: usize,
66    pub contracts_failed: usize,
67    pub status: String, // "SUCCESS" | "FAIL"
68}