feat: JSON-Logging mit Correlation-ID, Anfrage-Log und Audit (M2.4)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-09 17:39:03 +01:00
parent 2ec9eccde6
commit 6cb930d0b0
31 changed files with 1050 additions and 67 deletions

View File

@ -8,6 +8,7 @@ use axum::http::request::Parts;
use nexus_core::Priority;
use nexus_store::ApiKeyRecord;
use crate::access::AccessSlot;
use crate::error::ApiError;
use crate::state::AppState;
@ -28,12 +29,25 @@ impl FromRequestParts<Arc<AppState>> for Authed {
.and_then(|v| v.strip_prefix("Bearer "))
.map(str::trim)
.filter(|t| !t.is_empty())
.ok_or_else(ApiError::invalid_key)?;
.ok_or_else(|| {
tracing::warn!("Anfrage ohne API-Key");
ApiError::invalid_key()
})?;
match state.store().find_api_key(token) {
Ok(Some(key)) => Ok(Authed(key)),
Ok(None) => Err(ApiError::invalid_key()),
Ok(Some(key)) => {
if let Some(slot) = parts.extensions.get::<AccessSlot>() {
let mut info = slot.lock().unwrap_or_else(|e| e.into_inner());
info.key_id = Some(key.id);
info.key_name = Some(key.name.clone());
}
Ok(Authed(key))
}
Ok(None) => {
tracing::warn!("Ungültiger oder gesperrter API-Key");
Err(ApiError::invalid_key())
}
Err(e) => {
eprintln!("FEHLER Key-Prüfung: {e}");
tracing::error!(fehler = %e, "Key-Prüfung fehlgeschlagen");
Err(ApiError::internal())
}
}