This repository has no description
1use std::sync::Arc;
2
3use axum::Json;
4use axum::extract::State;
5use axum::response::{IntoResponse, Response};
6use serde::Serialize;
7
8use knot_runtime::{Clock, HttpTransport};
9use knot_types::AccountDid;
10
11use crate::XrpcState;
12
13pub(crate) const VERSION_ROUTE: &str = "/xrpc/sh.tangled.knot.version";
14pub(crate) const OWNER_ROUTE: &str = "/xrpc/sh.tangled.owner";
15pub(crate) const HEALTH_ROUTE: &str = "/xrpc/_health";
16
17const WIRE_VERSION: &str = "v1.15.0";
18
19#[derive(Serialize)]
20struct VersionWire {
21 version: &'static str,
22 capabilities: [&'static str; 1],
23}
24
25#[derive(Serialize)]
26struct HealthWire {
27 version: String,
28}
29
30pub(crate) async fn health<H: HttpTransport, C: Clock>(
31 State(state): State<Arc<XrpcState<H, C>>>,
32) -> Response {
33 if let Some(lfs) = state.lfs.as_ref()
34 && !lfs.ready().await
35 {
36 return (
37 axum::http::StatusCode::SERVICE_UNAVAILABLE,
38 "lfs store is unreachable or not writable",
39 )
40 .into_response();
41 }
42 Json(HealthWire {
43 version: format!("knot {}", env!("CARGO_PKG_VERSION")),
44 })
45 .into_response()
46}
47
48#[derive(Serialize)]
49struct OwnerWire {
50 owner: AccountDid,
51}
52
53pub(crate) async fn version() -> Response {
54 Json(VersionWire {
55 version: WIRE_VERSION,
56 capabilities: ["knot-acl"],
57 })
58 .into_response()
59}
60
61pub(crate) async fn owner<H: HttpTransport, C: Clock>(
62 State(state): State<Arc<XrpcState<H, C>>>,
63) -> Response {
64 Json(OwnerWire {
65 owner: state.service_owner.clone(),
66 })
67 .into_response()
68}