From db66e029730f6581e51a943e2cdb2f0a3306dc48 Mon Sep 17 00:00:00 2001 From: Edyta Pawlak Date: Mon, 25 Nov 2024 11:35:24 +0100 Subject: [PATCH] feat: add info endpoint for witness and watcher --- components/watcher/src/watcher_listener.rs | 19 +++++++++++++++++-- components/witness/src/witness_listener.rs | 13 ++++++++++++- keriox_core/src/mailbox/exchange.rs | 4 ++-- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/components/watcher/src/watcher_listener.rs b/components/watcher/src/watcher_listener.rs index f40b1019..ceec34b0 100644 --- a/components/watcher/src/watcher_listener.rs +++ b/components/watcher/src/watcher_listener.rs @@ -59,6 +59,10 @@ impl WatcherListener { "/query/tel", actix_web::web::post().to(http_handlers::process_tel_query), ) + .route( + "info", + actix_web::web::get().to(http_handlers::info), + ) }) .disable_signals() .bind(addr) @@ -95,8 +99,7 @@ pub mod http_handlers { use std::sync::Arc; use actix_web::{ - http::{header::ContentType, StatusCode}, - web, HttpResponse, ResponseError, + http::{header::ContentType, StatusCode}, web, HttpResponse, Responder, ResponseError }; use itertools::Itertools; use keri_core::{ @@ -269,6 +272,18 @@ pub mod http_handlers { HttpResponse::build(self.status_code()).json(&self.0) } } + + pub async fn info( + ) -> impl Responder { + let version = option_env!("CARGO_PKG_VERSION"); + if let Some(version) = version { + HttpResponse::Ok().json(serde_json::json!({ "version": version })) + } else { + HttpResponse::InternalServerError() + .json(serde_json::json!({ "error": "Failed to retrieve version information" })) + } + + } } mod test { diff --git a/components/witness/src/witness_listener.rs b/components/witness/src/witness_listener.rs index 2b23a7dc..53a537f6 100644 --- a/components/witness/src/witness_listener.rs +++ b/components/witness/src/witness_listener.rs @@ -79,6 +79,7 @@ impl WitnessListener { "/forward", actix_web::web::post().to(http_handlers::process_exchange), ) + .route("/info", actix_web::web::get().to(http_handlers::info)) }) .bind(addr) .unwrap() @@ -213,7 +214,7 @@ pub mod http_handlers { use actix_web::{ http::{header::ContentType, StatusCode}, - web, HttpResponse, ResponseError, + web, HttpResponse, Responder, ResponseError, }; use itertools::Itertools; use keri_core::{ @@ -427,6 +428,16 @@ pub mod http_handlers { Ok(HttpResponse::Ok().body(())) } + pub async fn info() -> impl Responder { + let version = option_env!("CARGO_PKG_VERSION"); + if let Some(version) = version { + HttpResponse::Ok().json(serde_json::json!({ "version": version })) + } else { + HttpResponse::InternalServerError() + .json(serde_json::json!({ "error": "Failed to retrieve version information" })) + } + } + #[derive(Debug, derive_more::Display, derive_more::From, derive_more::Error)] pub struct ApiError(pub ActorError); diff --git a/keriox_core/src/mailbox/exchange.rs b/keriox_core/src/mailbox/exchange.rs index 6aee1c68..d186b014 100644 --- a/keriox_core/src/mailbox/exchange.rs +++ b/keriox_core/src/mailbox/exchange.rs @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize}; use crate::event::KeyEvent; use crate::event_message::msg::KeriEvent; use crate::event_message::timestamped::Timestamped; -use crate::{error::Error, prefix::IdentifierPrefix}; +use crate::prefix::IdentifierPrefix; use crate::event_message::{signature::Signature, EventTypeTag, Typeable}; @@ -75,7 +75,7 @@ impl Typeable for Exchange { } #[test] -fn test_exn_serialization() -> Result<(), Error> { +fn test_exn_serialization() -> Result<(), crate::error::Error> { let exn_event = r#"{"v":"KERI10JSON0002f1_","t":"exn","d":"EPfS_lQ-hZIFX6ug1ggLlzVN09VnCWsubpE-jAC1Fx0W","dt":"2022-10-25T09:53:04.117732+00:00","r":"/fwd","q":{"pre":"EJccSRTfXYF6wrUVuenAIHzwcx3hJugeiJsEKmndi5q1","topic":"multisig"},"a":{"v":"KERI10JSON000215_","t":"icp","d":"EC61gZ9lCKmHAS7U5ehUfEbGId5rcY0D7MirFZHDQcE2","i":"EC61gZ9lCKmHAS7U5ehUfEbGId5rcY0D7MirFZHDQcE2","s":"0","kt":"2","k":["DOZlWGPfDHLMf62zSFzE8thHmnQUOgA3_Y-KpOyF9ScG","DHGb2qY9WwZ1sBnC9Ip0F-M8QjTM27ftI-3jTGF9mc6K"],"nt":"2","n":["EBvD5VIVvf6NpP9GRmTqu_Cd1KN0RKrKNfPJ-uhIxurj","EHlpcaxffvtcpoUUMTc6tpqAVtb2qnOYVk_3HRsZ34PH"],"bt":"3","b":["BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha","BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM","BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX"],"c":[],"a":[]}}"#; //-HABEKYLUMmNPZeEs77Zvclf0bSN5IN-mLfLpx2ySb-HDlk4-AABAACJvddJrANYlrJ7CxEU9Z_AKJMxJZ7PNSyZeS4F6x2qZ2vTLtmD6mOOQ748TlddgB2ZFAMYt3xtzNdfrYNHS4IA-LAZ5AABAA-a-AABABBng3jTIIx_YUX-tS0caV1aV9QOvD5IM7WKt_wQz6Hvjm7nPhJgElP6K4Pu2JAIqCO93wBgBOx1DD3iawt0rb4"#; let parsed: ExchangeMessage = serde_json::from_str(exn_event).unwrap();