generated from coulomb/repo-seed
Moved audit forward somewhat
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
"""Development-only file backend for Audit Core.
|
||||
|
||||
This backend intentionally writes local JSONL files under /tmp by default. It
|
||||
is useful for wiring integrations before the durable Audit Core archive exists,
|
||||
but it is not production audit custody.
|
||||
Writes hourly JSONL files under ``/tmp/audit-core`` by default. See
|
||||
``docs/audit-backend-contract.md`` for retention guarantees and the migration
|
||||
path to durable archive backends.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -12,11 +12,15 @@ import os
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from pathlib import Path
|
||||
|
||||
from audit_core.interface import AuditEvent
|
||||
from audit_core.interface import AuditEvent, EventValidationError, RetentionPolicy, validate_event
|
||||
|
||||
|
||||
class MockFileAuditBackend:
|
||||
"""Append audit events to hourly JSONL files and clean up old files."""
|
||||
"""Append audit events to hourly JSONL files and clean up old files.
|
||||
|
||||
Implements :class:`~audit_core.interface.AuditBackend` with
|
||||
``custody_class=development``. Not suitable for production audit custody.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -32,7 +36,23 @@ class MockFileAuditBackend:
|
||||
)
|
||||
self._now = now
|
||||
|
||||
@property
|
||||
def retention_policy(self) -> RetentionPolicy:
|
||||
days = self.retention_days if self.retention_days >= 0 else None
|
||||
return RetentionPolicy(
|
||||
custody_class="development",
|
||||
retention_days=days,
|
||||
immutable=False,
|
||||
tamper_evidence=False,
|
||||
durable=False,
|
||||
)
|
||||
|
||||
def emit(self, event: AuditEvent) -> str:
|
||||
try:
|
||||
validate_event(event)
|
||||
except EventValidationError as exc:
|
||||
raise ValueError(str(exc)) from exc
|
||||
|
||||
self.base_dir.mkdir(parents=True, exist_ok=True)
|
||||
self.cleanup_old_files()
|
||||
path = self.current_path()
|
||||
|
||||
Reference in New Issue
Block a user