use std::sync::Arc;
use aa_storage::{AuditEntry, AuditSink, Result};
use async_trait::async_trait;
use parking_lot::Mutex;
#[derive(Clone, Default)]
pub struct MemoryAuditSink {
entries: Arc<Mutex<Vec<AuditEntry>>>,
}
impl MemoryAuditSink {
pub fn new() -> Self {
Self::default()
}
pub fn len(&self) -> usize {
self.entries.lock().len()
}
pub fn is_empty(&self) -> bool {
self.entries.lock().is_empty()
}
pub fn drain(&self) -> Vec<AuditEntry> {
std::mem::take(&mut *self.entries.lock())
}
}
#[async_trait]
impl AuditSink for MemoryAuditSink {
async fn emit(&self, event: AuditEntry) -> Result<()> {
self.entries.lock().push(event);
Ok(())
}
}