Module audit

Module audit 

Source
Expand description

Audit logging system for EnvelopeCLI

Records all create, update, delete operations with before/after values in an append-only audit log.

§Architecture

The audit system consists of three components:

  • AuditEntry: Represents a single audit log entry with timestamp, operation, entity information, and optional before/after values.
  • AuditLogger: Handles writing entries to the audit log file using a line-delimited JSON format (JSONL).
  • generate_diff: Utility function to create human-readable diffs between entity states.

§Example

use envelope::audit::{AuditEntry, AuditLogger, EntityType, generate_diff};
use serde_json::json;

let logger = AuditLogger::new(audit_log_path);

// Log a create operation
let entry = AuditEntry::create(
    EntityType::Account,
    "acc-12345678",
    Some("Checking".to_string()),
    &account,
);
logger.log(&entry)?;

// Log an update with diff
let diff = generate_diff(&before_json, &after_json);
let entry = AuditEntry::update(
    EntityType::Account,
    "acc-12345678",
    Some("Checking".to_string()),
    &before,
    &after,
    diff,
);
logger.log(&entry)?;

Structs§

AuditEntry
A single audit log entry
AuditLogger
Handles writing audit entries to the audit log file

Enums§

EntityType
Types of entities that can be audited
Operation
Types of operations that can be audited

Functions§

generate_detailed_diff
Generate a detailed diff that includes nested changes
generate_diff
Generate a human-readable diff between two JSON values