use sqlx::PgPool;
use std::collections::HashSet;
#[derive(Clone)]
pub struct AuditConfig {
pub pool: PgPool,
pub service_name: String,
pub table_name: String,
pub skip_paths: HashSet<String>,
pub batch_size: usize,
pub flush_interval_ms: u64,
}
impl AuditConfig {
pub fn new(pool: PgPool, service_name: impl Into<String>) -> Self {
let mut skip_paths = HashSet::new();
skip_paths.insert("/health".into());
skip_paths.insert("/metrics".into());
Self {
pool,
service_name: service_name.into(),
table_name: "audit_log".into(),
skip_paths,
batch_size: 50,
flush_interval_ms: 100,
}
}
pub fn table_name(mut self, name: impl Into<String>) -> Self {
self.table_name = name.into();
self
}
pub fn skip_path(mut self, path: impl Into<String>) -> Self {
self.skip_paths.insert(path.into());
self
}
pub fn skip_paths(mut self, paths: HashSet<String>) -> Self {
self.skip_paths = paths;
self
}
pub fn batch_size(mut self, size: usize) -> Self {
self.batch_size = size;
self
}
pub fn flush_interval_ms(mut self, ms: u64) -> Self {
self.flush_interval_ms = ms;
self
}
}