Make auditlog work

This commit is contained in:
Nadja Reitzenstein 2022-03-12 01:27:41 +01:00
parent 3e4350d2cf
commit 495f9cb36a
2 changed files with 7 additions and 7 deletions

View File

@ -6,8 +6,6 @@ use std::sync::Mutex;
use crate::Config;
use serde::{Serialize, Deserialize};
use serde_json::Serializer;
use time::OffsetDateTime;
use crate::db::machine::{MachineIdentifier, MachineState};
#[derive(Debug)]
pub struct AuditLog {
@ -17,8 +15,8 @@ pub struct AuditLog {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AuditLogLine {
timestamp: i64,
machine: MachineIdentifier,
state: MachineState,
machine: String,
state: String,
}
impl AuditLog {
@ -28,9 +26,9 @@ impl AuditLog {
Ok(Self { writer })
}
pub fn log(&self, machine: &MachineIdentifier, state: &MachineState) -> io::Result<()> {
let timestamp = OffsetDateTime::now_utc().unix_timestamp();
let line = AuditLogLine { timestamp, machine: machine.clone(), state: state.clone() };
pub fn log(&self, machine: &str, state: &str) -> io::Result<()> {
let timestamp = chrono::Utc::now().timestamp();
let line = AuditLogLine { timestamp, machine: machine.to_string(), state: state.to_string() };
let mut guard = self.writer.lock().unwrap();
let mut writer: &mut LineWriter<File> = &mut *guard;

View File

@ -42,6 +42,7 @@ pub struct Config {
pub init_connections: Vec<(String, String)>,
pub db_path: PathBuf,
pub auditlog_path: PathBuf,
pub roles: HashMap<RoleIdentifier, RoleConfig>,
@ -166,6 +167,7 @@ impl Default for Config {
],
db_path: PathBuf::from("/run/bffh/database"),
auditlog_path: PathBuf::from("/var/log/bffh/audit.log"),
roles: HashMap::new(),
tlsconfig: TlsListen {