Skip to content

Commit

Permalink
feat: add info endpoint for witness and watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
edytapawlak committed Nov 25, 2024
1 parent f65e612 commit db66e02
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
19 changes: 17 additions & 2 deletions components/watcher/src/watcher_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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::{
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 12 additions & 1 deletion components/witness/src/witness_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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::{
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions keriox_core/src/mailbox/exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit db66e02

Please sign in to comment.