32 lines
855 B
Rust
32 lines
855 B
Rust
use crate::models::now_utc_rfc3339;
|
|
use axum::http::HeaderMap;
|
|
use serde_json::Value;
|
|
use sqlx::SqliteConnection;
|
|
|
|
pub fn get_actor_from_request(_headers: &HeaderMap) -> String {
|
|
// Placeholder: later read X-Authentik-Username or similar trusted header.
|
|
"local".to_string()
|
|
}
|
|
|
|
pub async fn log_event(
|
|
conn: &mut SqliteConnection,
|
|
event_type: &str,
|
|
allocation_id: Option<i64>,
|
|
pool_id: Option<i64>,
|
|
actor: &str,
|
|
details: Value,
|
|
) -> anyhow::Result<()> {
|
|
let json = details.to_string();
|
|
sqlx::query(
|
|
"INSERT INTO audit_events (event_type, allocation_id, pool_id, actor, details_json, created_at) VALUES (?, ?, ?, ?, ?, ?)",
|
|
)
|
|
.bind(event_type)
|
|
.bind(allocation_id)
|
|
.bind(pool_id)
|
|
.bind(actor)
|
|
.bind(json)
|
|
.bind(now_utc_rfc3339())
|
|
.execute(&mut *conn)
|
|
.await?;
|
|
Ok(())
|
|
}
|