use std::sync::Arc;
use crate::sync::*;
use crate::types::*;
use crate::server::{address_space::address_space::AddressSpace, events::event::Event};
pub trait AuditEvent: Event {
fn parent_node() -> NodeId {
NodeId::null()
}
fn event_type_id() -> NodeId;
fn log_message(&self) -> String;
}
#[macro_use]
pub mod event;
#[macro_use]
pub mod security_event;
#[macro_use]
pub mod session_events;
#[macro_use]
pub mod certificate_events;
pub mod cancel_event;
pub mod node_management_event;
pub(crate) struct AuditLog {
address_space: Arc<RwLock<AddressSpace>>,
}
impl AuditLog {
pub fn new(address_space: Arc<RwLock<AddressSpace>>) -> AuditLog {
AuditLog { address_space }
}
pub fn raise_and_log<T>(&self, mut event: T) -> Result<NodeId, ()>
where
T: AuditEvent + Event,
{
let mut address_space = trace_write_lock!(self.address_space);
let result = event.raise(&mut address_space).map_err(|_| ());
if result.is_err() {
error!("Cannot raise an audit event, check audit event entry below to see if there are reasons for this");
}
info!("Audit Event: {}", event.log_message());
result
}
}