From df49c687e2552b12099b6241125b588664811f58 Mon Sep 17 00:00:00 2001 From: Naian <126972030+nain-F49FF806@users.noreply.github.com> Date: Fri, 20 Oct 2023 19:03:14 +0200 Subject: [PATCH] refactor(mediator-client): move to separate package Signed-off-by: Naian <126972030+nain-F49FF806@users.noreply.github.com> --- Cargo.lock | 16 +++++++++++++++ Cargo.toml | 1 + agents/rust/mediator/client-webapi/Cargo.toml | 20 +++++++++++++++++++ .../src/http_routes.rs} | 10 ++++------ .../src/main.rs} | 18 ++++++++--------- agents/rust/mediator/src/http_routes/mod.rs | 3 --- 6 files changed, 50 insertions(+), 18 deletions(-) create mode 100644 agents/rust/mediator/client-webapi/Cargo.toml rename agents/rust/mediator/{src/http_routes/client.rs => client-webapi/src/http_routes.rs} (84%) rename agents/rust/mediator/{src/bin/client-web.rs => client-webapi/src/main.rs} (73%) diff --git a/Cargo.lock b/Cargo.lock index 9b950c7b70..b7a2edd474 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -930,6 +930,22 @@ dependencies = [ "os_str_bytes", ] +[[package]] +name = "client-webapi" +version = "0.1.0" +dependencies = [ + "aries_vcx_core", + "axum", + "log", + "mediation", + "mediator", + "messages", + "reqwest", + "serde_json", + "tokio", + "tower-http", +] + [[package]] name = "cmake" version = "0.1.50" diff --git a/Cargo.toml b/Cargo.toml index 8a9a08d879..e2733d722c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ members = [ "shared_vcx", "diddoc_legacy", "agents/rust/mediator", + "agents/rust/mediator/client-webapi", "agents/rust/aries-vcx-agent", "wrappers/vcx-napi-rs", "aries_vcx_core", diff --git a/agents/rust/mediator/client-webapi/Cargo.toml b/agents/rust/mediator/client-webapi/Cargo.toml new file mode 100644 index 0000000000..fde908b240 --- /dev/null +++ b/agents/rust/mediator/client-webapi/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "client-webapi" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +aries_vcx_core = { path = "../../../../aries_vcx_core", features = [ + "vdrtools_wallet", +] } +axum = "0.6.20" +log = "0.4.20" +mediation = { path = "../mediation" } +mediator = { version = "0.1.1", path = ".." } +messages = { path = "../../../../messages" } +reqwest = "0.11.22" +serde_json = "1.0.107" +tokio = { version = "1", features = ["rt-multi-thread", "macros"] } +tower-http = { version = "0.4.4", features = ["catch-panic"] } diff --git a/agents/rust/mediator/src/http_routes/client.rs b/agents/rust/mediator/client-webapi/src/http_routes.rs similarity index 84% rename from agents/rust/mediator/src/http_routes/client.rs rename to agents/rust/mediator/client-webapi/src/http_routes.rs index 61d8d49851..04b8f40b0a 100644 --- a/agents/rust/mediator/src/http_routes/client.rs +++ b/agents/rust/mediator/client-webapi/src/http_routes.rs @@ -1,13 +1,11 @@ -use std::collections::VecDeque; +use std::{collections::VecDeque, sync::Arc}; use aries_vcx_core::wallet::base_wallet::BaseWallet; -use axum::routing::post; +use axum::{extract::State, routing::post, Json, Router}; use mediation::storage::MediatorPersistence; +use mediator::aries_agent::{transports::AriesReqwest, Agent, ArcAgent}; use messages::msg_fields::protocols::out_of_band::invitation::Invitation as OOBInvitation; -use serde_json::json; - -use super::*; -use crate::aries_agent::transports::AriesReqwest; +use serde_json::{json, Value}; pub async fn handle_register( State(agent): State>, diff --git a/agents/rust/mediator/src/bin/client-web.rs b/agents/rust/mediator/client-webapi/src/main.rs similarity index 73% rename from agents/rust/mediator/src/bin/client-web.rs rename to agents/rust/mediator/client-webapi/src/main.rs index 05abc8c3ea..1cb4662440 100644 --- a/agents/rust/mediator/src/bin/client-web.rs +++ b/agents/rust/mediator/client-webapi/src/main.rs @@ -1,10 +1,11 @@ /// Client-side focused api accessible Aries Agent -#[cfg(feature = "client_http_api")] +mod http_routes; + #[tokio::main] async fn main() { + use http_routes::build_client_router; use mediator::{ aries_agent::AgentBuilder, - http_routes::client::build_client_router, utils::binary_utils::{load_dot_env, setup_logging}, }; @@ -25,10 +26,9 @@ async fn main() { .unwrap(); } -#[cfg(not(feature = "client_http_api"))] -fn main() { - print!( - "This is a placeholder binary. Please enable \"client_tui\" feature to to build the \ - functional client_tui binary." - ) -} +// fn main() { +// print!( +// "This is a placeholder binary. Please enable \"client_tui\" feature to to build the \ +// functional client_tui binary." +// ) +// } diff --git a/agents/rust/mediator/src/http_routes/mod.rs b/agents/rust/mediator/src/http_routes/mod.rs index abeae7fe10..2c5c3d21a8 100644 --- a/agents/rust/mediator/src/http_routes/mod.rs +++ b/agents/rust/mediator/src/http_routes/mod.rs @@ -17,9 +17,6 @@ use crate::{ didcomm_handlers, }; -#[cfg(any(test, feature = "client_tui", feature = "client_http_api"))] -pub mod client; - pub async fn oob_invite_qr( headers: HeaderMap, State(agent): State>,