pub struct AuditLog { /* private fields */ }Expand description
Append-only audit logger that writes to a local JSONL file.
Implementations§
Source§impl AuditLog
impl AuditLog
pub fn new() -> Result<Self>
Sourcepub fn with_path(path: PathBuf) -> Result<Self>
pub fn with_path(path: PathBuf) -> Result<Self>
Construct an AuditLog at a caller-provided path. Used by tests so they
don’t pollute the real audit log at ~/.local/share/audex/audit/audit.jsonl.
pub fn log(&self, session_id: &str, event: AuditEvent) -> Result<()>
pub fn log_with_provider( &self, session_id: &str, provider: &str, event: AuditEvent, ) -> Result<()>
pub fn log_session_created(&self, session: &Session) -> Result<()>
pub fn log_session_ended( &self, session: &Session, exit_code: Option<i32>, ) -> Result<()>
Sourcepub fn read(&self, session_id: Option<&str>) -> Result<Vec<AuditEntry>>
pub fn read(&self, session_id: Option<&str>) -> Result<Vec<AuditEntry>>
Read all audit entries, optionally filtered by session ID.
Sourcepub fn read_filtered(
&self,
session_id: Option<&str>,
provider: Option<&str>,
) -> Result<Vec<AuditEntry>>
pub fn read_filtered( &self, session_id: Option<&str>, provider: Option<&str>, ) -> Result<Vec<AuditEntry>>
Read audit entries with optional session ID and provider filters.
Sourcepub fn read_recent(&self, max_entries: usize) -> Result<Vec<AuditEntry>>
pub fn read_recent(&self, max_entries: usize) -> Result<Vec<AuditEntry>>
Read at most max_entries recent audit entries without loading the
entire log into memory. Reads the last max_bytes of the file
(default 1 MB) and parses only those lines.
Takes a shared file lock for the duration of the read so concurrent
writers in log_with_provider cannot tear a line mid-flush
(R6-H20), verifies the HMAC chain before returning any data and
refuses to serve entries from a tampered log (R6-H21), and uses a
byte-oriented tail reader so seeks landing inside a multi-byte
UTF-8 character or a pathological log with no newlines no longer
silently return zero entries (R6-H19).
Sourcepub fn verify(&self) -> Result<VerificationResult>
pub fn verify(&self) -> Result<VerificationResult>
Verify the integrity of the audit log using chain HMACs.
pub fn path(&self) -> &PathBuf
Auto Trait Implementations§
impl Freeze for AuditLog
impl RefUnwindSafe for AuditLog
impl Send for AuditLog
impl Sync for AuditLog
impl Unpin for AuditLog
impl UnsafeUnpin for AuditLog
impl UnwindSafe for AuditLog
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more