feat(#2302): parse agent names into AgentName newtype at dashboard boundary
This commit is contained in:
parent
427328c4eb
commit
cfac917b4d
8 changed files with 162 additions and 103 deletions
|
|
@ -18,7 +18,7 @@ use serde::{Deserialize, Serialize};
|
|||
use tokio_stream::Stream;
|
||||
use tokio_stream::wrappers::ReceiverStream;
|
||||
|
||||
use super::{AppState, error_response, validate_agent_name};
|
||||
use super::{AppState, error_response, idents::AgentName};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub(super) struct BuildLogsAllQuery {
|
||||
|
|
@ -58,11 +58,18 @@ pub(super) async fn get_build_logs_agent(
|
|||
AxumPath(name): AxumPath<String>,
|
||||
axum::extract::Query(q): axum::extract::Query<BuildLogsQuery>,
|
||||
) -> Response {
|
||||
if let Some(reason) = validate_agent_name(&name) {
|
||||
return (StatusCode::BAD_REQUEST, format!("bad agent name: {reason}")).into_response();
|
||||
}
|
||||
let name = match AgentName::parse(&name) {
|
||||
Ok(n) => n,
|
||||
Err(reason) => {
|
||||
return (StatusCode::BAD_REQUEST, format!("bad agent name: {reason}")).into_response();
|
||||
}
|
||||
};
|
||||
let limit = q.limit.unwrap_or(10);
|
||||
match state.coord.build_logs.list_recent_for_agent(&name, limit) {
|
||||
match state
|
||||
.coord
|
||||
.build_logs
|
||||
.list_recent_for_agent(name.as_str(), limit)
|
||||
{
|
||||
Ok(rows) => axum::Json(rows).into_response(),
|
||||
Err(e) => error_response(&format!("build-logs {name}: {e:#}")),
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue