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:
@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user