From fe5ec4432a260a489e8d4c879006e517d24a4d73 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Fri, 28 Jun 2024 14:11:52 +0200 Subject: [PATCH] http: Change `/api/v1/node` version to node user agent We used the `RADICLE_VERSION` env variable to display the node version, which as of recently matched always the `radicle-httpd` version. Since the separation this isn't the case anymore, and the user agent seems a more reliable metric. --- radicle-httpd/src/api/v1/node.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/radicle-httpd/src/api/v1/node.rs b/radicle-httpd/src/api/v1/node.rs index f0326edf4..6d9c12ef7 100644 --- a/radicle-httpd/src/api/v1/node.rs +++ b/radicle-httpd/src/api/v1/node.rs @@ -7,12 +7,13 @@ use hyper::StatusCode; use serde_json::json; use radicle::identity::RepoId; +use radicle::node::address::Store as AddressStore; use radicle::node::routing::Store; use radicle::node::{AliasStore, Handle, NodeId, DEFAULT_TIMEOUT}; use radicle::Node; use crate::api::error::Error; -use crate::api::{self, Context, PoliciesQuery, RADICLE_VERSION}; +use crate::api::{self, Context, PoliciesQuery}; use crate::axum_extra::{Path, Query}; pub fn router(ctx: Context) -> Router { @@ -35,6 +36,10 @@ pub fn router(ctx: Context) -> Router { async fn node_handler(State(ctx): State) -> impl IntoResponse { let node = Node::new(ctx.profile.socket()); let node_id = ctx.profile.public_key; + let home = ctx.profile.home.database()?; + let agent = AddressStore::get(&home, &node_id) + .unwrap_or_default() + .map(|node| node.agent); let node_state = if node.is_running() { "running" } else { @@ -49,7 +54,7 @@ async fn node_handler(State(ctx): State) -> impl IntoResponse { }; let response = json!({ "id": node_id.to_string(), - "version": format!("{}-{}", RADICLE_VERSION, env!("GIT_HEAD")), + "agent": agent, "config": config, "state": node_state, });