mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-10 17:43:23 +01:00
Make auditlog work
This commit is contained in:
parent
3e4350d2cf
commit
495f9cb36a
@ -6,8 +6,6 @@ use std::sync::Mutex;
|
|||||||
use crate::Config;
|
use crate::Config;
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
use serde_json::Serializer;
|
use serde_json::Serializer;
|
||||||
use time::OffsetDateTime;
|
|
||||||
use crate::db::machine::{MachineIdentifier, MachineState};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct AuditLog {
|
pub struct AuditLog {
|
||||||
@ -17,8 +15,8 @@ pub struct AuditLog {
|
|||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct AuditLogLine {
|
pub struct AuditLogLine {
|
||||||
timestamp: i64,
|
timestamp: i64,
|
||||||
machine: MachineIdentifier,
|
machine: String,
|
||||||
state: MachineState,
|
state: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AuditLog {
|
impl AuditLog {
|
||||||
@ -28,9 +26,9 @@ impl AuditLog {
|
|||||||
Ok(Self { writer })
|
Ok(Self { writer })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn log(&self, machine: &MachineIdentifier, state: &MachineState) -> io::Result<()> {
|
pub fn log(&self, machine: &str, state: &str) -> io::Result<()> {
|
||||||
let timestamp = OffsetDateTime::now_utc().unix_timestamp();
|
let timestamp = chrono::Utc::now().timestamp();
|
||||||
let line = AuditLogLine { timestamp, machine: machine.clone(), state: state.clone() };
|
let line = AuditLogLine { timestamp, machine: machine.to_string(), state: state.to_string() };
|
||||||
|
|
||||||
let mut guard = self.writer.lock().unwrap();
|
let mut guard = self.writer.lock().unwrap();
|
||||||
let mut writer: &mut LineWriter<File> = &mut *guard;
|
let mut writer: &mut LineWriter<File> = &mut *guard;
|
||||||
|
@ -42,6 +42,7 @@ pub struct Config {
|
|||||||
pub init_connections: Vec<(String, String)>,
|
pub init_connections: Vec<(String, String)>,
|
||||||
|
|
||||||
pub db_path: PathBuf,
|
pub db_path: PathBuf,
|
||||||
|
pub auditlog_path: PathBuf,
|
||||||
|
|
||||||
pub roles: HashMap<RoleIdentifier, RoleConfig>,
|
pub roles: HashMap<RoleIdentifier, RoleConfig>,
|
||||||
|
|
||||||
@ -166,6 +167,7 @@ impl Default for Config {
|
|||||||
],
|
],
|
||||||
|
|
||||||
db_path: PathBuf::from("/run/bffh/database"),
|
db_path: PathBuf::from("/run/bffh/database"),
|
||||||
|
auditlog_path: PathBuf::from("/var/log/bffh/audit.log"),
|
||||||
roles: HashMap::new(),
|
roles: HashMap::new(),
|
||||||
|
|
||||||
tlsconfig: TlsListen {
|
tlsconfig: TlsListen {
|
||||||
|
Loading…
Reference in New Issue
Block a user