feat(#2302): parse agent names into AgentName newtype at dashboard boundary

This commit is contained in:
damocles 2026-07-19 17:46:04 +02:00 committed by mara
commit cfac917b4d
8 changed files with 162 additions and 103 deletions

View file

@ -10,7 +10,7 @@ use axum::{
};
use serde::Deserialize;
use super::{AppState, error_response, scan_validated_paths, validate_agent_name};
use super::{AppState, error_response, idents::AgentName, scan_validated_paths};
/// Unread operator-directed messages for the dashboard's Y3R C4LL inbox.
/// Returns messages addressed to `"operator"` that haven't been
@ -113,10 +113,13 @@ pub(super) async fn post_mark_all_read(
State(state): State<AppState>,
AxumPath(name): AxumPath<String>,
) -> Response {
if let Some(reason) = validate_agent_name(&name) {
return (StatusCode::BAD_REQUEST, format!("bad agent name: {reason}")).into_response();
}
match state.coord.broker.mark_all_read(&name) {
let name = match AgentName::parse(&name) {
Ok(n) => n,
Err(reason) => {
return (StatusCode::BAD_REQUEST, format!("bad agent name: {reason}")).into_response();
}
};
match state.coord.broker.mark_all_read(name.as_str()) {
Ok(n) => {
tracing::info!(%name, marked = n, "operator marked all messages read");
axum::Json(serde_json::json!({ "marked": n })).into_response()