Skip to main content

nodedb_types/
audit_dml.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! `AuditDmlMode` — per-database DML audit level.
4//!
5//! Controls which DML operations are recorded in the audit log for a given
6//! database. Set via `ALTER DATABASE <name> SET AUDIT_DML = <mode>`.
7
8/// DML audit mode for a database.
9///
10/// Every match on this enum must be exhaustive — no `_ =>` arms anywhere.
11#[derive(
12    Debug,
13    Clone,
14    Copy,
15    PartialEq,
16    Eq,
17    Default,
18    serde::Serialize,
19    serde::Deserialize,
20    zerompk::ToMessagePack,
21    zerompk::FromMessagePack,
22)]
23#[msgpack(c_enum)]
24pub enum AuditDmlMode {
25    /// No DML auditing (default).
26    #[default]
27    None = 0,
28    /// Audit write operations: INSERT, UPDATE, DELETE, BulkInsert, BulkDelete.
29    Writes = 1,
30    /// Audit all DML operations (reads + writes).
31    ///
32    /// Currently equivalent to `Writes` — read events do not flow through the
33    /// Event Plane yet. Tracked separately.
34    All = 2,
35}
36
37impl std::str::FromStr for AuditDmlMode {
38    type Err = String;
39
40    fn from_str(s: &str) -> Result<Self, Self::Err> {
41        match s.to_uppercase().as_str() {
42            "NONE" => Ok(Self::None),
43            "WRITES" => Ok(Self::Writes),
44            "ALL" => Ok(Self::All),
45            other => Err(format!(
46                "unknown AUDIT_DML mode '{other}'; expected NONE, WRITES, or ALL"
47            )),
48        }
49    }
50}
51
52impl std::fmt::Display for AuditDmlMode {
53    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
54        match self {
55            Self::None => write!(f, "NONE"),
56            Self::Writes => write!(f, "WRITES"),
57            Self::All => write!(f, "ALL"),
58        }
59    }
60}