build.rs builds the string (git, or SLINUXM_* env for builds without .git) and the lib exposes it as VERSION. --version, /healthz, /api/v1/ping, MCP server info and OTel service.version use it; OpenAPI info.version stays on the semver so docs/openapi.json does not change per commit. The flake passes the commit date and short rev to the package.
41 lines
1.3 KiB
Rust
41 lines
1.3 KiB
Rust
//! GET /api/v1/ping: cheap authenticated liveness.
|
|
//!
|
|
//! `/healthz` does not validate a token, so a consolidator cannot use it to
|
|
//! prove "API running with our credentials". This route sits behind the same
|
|
//! auth layer as every other `/api/v1` route.
|
|
|
|
use axum::routing::get;
|
|
use axum::{Json, Router};
|
|
|
|
use crate::openapi::Health;
|
|
use crate::state::AppState;
|
|
|
|
pub fn routes() -> Router<AppState> {
|
|
Router::new().route("/ping", get(ping))
|
|
}
|
|
|
|
#[utoipa::path(
|
|
get,
|
|
path = "/api/v1/ping",
|
|
operation_id = "ping",
|
|
tag = "health",
|
|
summary = "Authenticated liveness",
|
|
description = "Cheap authenticated check. A consolidator calls it to prove that the API \
|
|
answers with its credential: a 401 still means the API is running.",
|
|
responses(
|
|
(status = 200, body = Health, description = "The API is running and the token is valid"),
|
|
(status = 401, body = crate::openapi::ErrorBody, description = "Missing or unknown bearer token"),
|
|
(status = 503, body = crate::openapi::ErrorBody, description = "The token database is unavailable"),
|
|
)
|
|
)]
|
|
pub(crate) async fn ping() -> Json<serde_json::Value> {
|
|
Json(serde_json::json!({
|
|
"status": "ok",
|
|
"version": crate::VERSION,
|
|
}))
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "ping_tests.rs"]
|
|
mod tests;
|