generated from Patagia/template-nix
42 lines
1.2 KiB
Rust
42 lines
1.2 KiB
Rust
use dropshot::{endpoint, HttpError, HttpResponseOk, RequestContext};
|
|
use schemars::JsonSchema;
|
|
use serde::Serialize;
|
|
use std::sync::Arc;
|
|
use trace_request::trace_request;
|
|
|
|
use systemd_ipc::addrs::SYSTEMD_HOSTNAME;
|
|
use systemd_ipc::io_systemd_hostname::{self, VarlinkClientInterface};
|
|
|
|
use crate::context::ControllerContext;
|
|
|
|
/// Version and build information
|
|
#[derive(Serialize, JsonSchema)]
|
|
struct MachineInfo {
|
|
machine_id: String,
|
|
}
|
|
|
|
/// Fetch machine id
|
|
#[endpoint {
|
|
method = GET,
|
|
path = "/machine_id",
|
|
}]
|
|
#[trace_request]
|
|
pub async fn describe(
|
|
rqctx: RequestContext<Arc<ControllerContext>>,
|
|
) -> Result<HttpResponseOk<MachineInfo>, HttpError> {
|
|
let machine_info = tokio::task::spawn_blocking(move || {
|
|
// Connect to systemd.Hostname
|
|
let conn = varlink::Connection::with_address(SYSTEMD_HOSTNAME).unwrap();
|
|
let mut sd = io_systemd_hostname::VarlinkClient::new(conn);
|
|
|
|
let machine_id = sd.describe().call().unwrap().MachineID;
|
|
MachineInfo { machine_id }
|
|
})
|
|
.await
|
|
.unwrap();
|
|
|
|
tracing::info_span!("Hello, span hostd!");
|
|
|
|
tracing::info!(monotonic_counter.version_calls = 1);
|
|
Ok(HttpResponseOk(machine_info))
|
|
}
|