hive-c0re: wire up openapi spec + swagger ui (#2872)
This commit is contained in:
parent
e9a1764f42
commit
44651544a8
7 changed files with 256 additions and 8 deletions
|
|
@ -15,13 +15,14 @@ use axum::{
|
|||
response::{IntoResponse, Response},
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use utoipa::IntoParams;
|
||||
|
||||
use problem_details::ProblemDetails;
|
||||
|
||||
use super::{Ident, error_problem, strip_container_prefix};
|
||||
use crate::lifecycle;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Deserialize, IntoParams)]
|
||||
pub(super) struct JournalQuery {
|
||||
/// Optional systemd unit filter — e.g. `hive-agent.service`. When
|
||||
/// omitted, returns the full machine journal.
|
||||
|
|
@ -43,6 +44,20 @@ pub(super) struct JournalQuery {
|
|||
/// [`hive_priv_sock::InfraContainer`]). Infra containers don't run the
|
||||
/// per-agent hive daemons, so `unit` is ignored for them — always the
|
||||
/// full machine journal.
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/journal/{name}",
|
||||
params(
|
||||
("name" = String, Path, description = "agent name, or one of the four infra container names"),
|
||||
JournalQuery,
|
||||
),
|
||||
responses(
|
||||
(status = 200, description = "journal text", body = String, content_type = "text/plain"),
|
||||
(status = 400, description = "bad agent name or unknown unit"),
|
||||
(status = 404, description = "no such managed container"),
|
||||
),
|
||||
tag = "journal"
|
||||
)]
|
||||
pub(super) async fn get_journal(
|
||||
AxumPath(name): AxumPath<String>,
|
||||
axum::extract::Query(q): axum::extract::Query<JournalQuery>,
|
||||
|
|
@ -134,7 +149,7 @@ async fn read_journal_response(
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Deserialize, IntoParams)]
|
||||
pub(super) struct JournalHostQuery {
|
||||
/// Service unit name to filter to. If omitted, returns all logs.
|
||||
#[serde(default)]
|
||||
|
|
@ -148,6 +163,16 @@ pub(super) struct JournalHostQuery {
|
|||
/// `-M` container flag). Restricted to an allow-list of known host services
|
||||
/// so arbitrary unit names can't be probed. Operator-only by virtue of the
|
||||
/// dashboard binding to a host-only port.
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/journal-host",
|
||||
params(JournalHostQuery),
|
||||
responses(
|
||||
(status = 200, description = "journal text", body = String, content_type = "text/plain"),
|
||||
(status = 400, description = "unknown unit"),
|
||||
),
|
||||
tag = "journal"
|
||||
)]
|
||||
pub(super) async fn get_journal_host(
|
||||
axum::extract::Query(q): axum::extract::Query<JournalHostQuery>,
|
||||
) -> Result<Response, ProblemDetails> {
|
||||
|
|
|
|||
Loading…
Reference in a new issue