Skip to content

Commit

Permalink
refactor: move client features behind feature flags
Browse files Browse the repository at this point in the history
Signed-off-by: Naian <[email protected]>
  • Loading branch information
nain-F49FF806 committed Oct 19, 2023
1 parent 8386049 commit 77fdaec
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 46 deletions.
15 changes: 11 additions & 4 deletions agents/rust/mediator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = []
client_tui=["cursive"]
default = ["client_http_api"]
client = []
client_http_api = ["client"]
client_tui = ["client", "cursive"]


[dependencies]
anyhow = "1.0.75"
aries-vcx = { path = "../../../aries_vcx" }
aries_vcx_core = { path = "../../../aries_vcx_core", features = ["vdrtools_wallet"] }
aries_vcx_core = { path = "../../../aries_vcx_core", features = [
"vdrtools_wallet",
] }
async-trait = "0.1.73"
axum = "0.6"
axum-macros = "0.3.8"
cursive = { version = "0.20.0", features = ["crossterm-backend"], optional = true}
cursive = { version = "0.20.0", features = [
"crossterm-backend",
], optional = true }
diddoc_legacy = { path = "../../../diddoc_legacy" }
dotenvy = "0.15"
env_logger = "0.10.0"
Expand Down
13 changes: 0 additions & 13 deletions agents/rust/mediator/src/aries_agent/me.rs

This file was deleted.

2 changes: 1 addition & 1 deletion agents/rust/mediator/src/aries_agent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::utils::{prelude::*, structs::VeriKey};

pub mod transports;
pub mod utils;
// #[cfg(test)]
#[cfg(any(test, feature = "client"))]
pub mod client;

#[derive(Clone)]
Expand Down
24 changes: 10 additions & 14 deletions agents/rust/mediator/src/bin/client-tui.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
#[cfg(feature = "client_tui")]
use log::info;
/// Aries Agent TUI
#[cfg(feature = "client_tui")]
use mediator::{aries_agent::AgentMaker, tui};

#[cfg(feature = "client_tui")]
#[tokio::main]
async fn main() {
fn setup_logging() {
let env = env_logger::Env::default().default_filter_or("info");
env_logger::init_from_env(env);
}
use mediator::{
aries_agent::AgentMaker,
tui,
utils::binary_utils::{load_dot_env, setup_logging},
};

fn load_dot_env() {
let _ = dotenvy::dotenv();
}
info!("TUI initializing!");
load_dot_env();
setup_logging();
log::info!("TUI initializing!");
let agent = AgentMaker::new_demo_agent().await.unwrap();
tui::init_tui(agent).await;
}

#[cfg(not(feature = "client_tui"))]
fn main() {
print!("This is a placeholder binary. Please enable \"client_tui\" feature to to build the functional client_tui binary.")
print!(
"This is a placeholder binary. Please enable \"client_tui\" feature to to build the \
functional client_tui binary."
)
}
27 changes: 15 additions & 12 deletions agents/rust/mediator/src/bin/client-web.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
/// Client-side focused api accessible Aries Agent
use log::info;
use mediator::{aries_agent::AgentMaker, http_routes::client::build_client_router};

#[cfg(feature = "client_http_api")]
#[tokio::main]
async fn main() {
info!("Putting up local web interface controlling client");
use mediator::{
aries_agent::AgentMaker,
http_routes::client::build_client_router,
utils::binary_utils::{load_dot_env, setup_logging},
};

load_dot_env();
setup_logging();
log::info!("Putting up local web interface controlling client");
let endpoint_root = std::env::var("ENDPOINT_ROOT").unwrap_or("127.0.0.1:3003".into());
info!("Client web endpoint root address {}", endpoint_root);
log::info!("Client web endpoint root address {}", endpoint_root);
let agent = AgentMaker::new_demo_agent().await.unwrap();
let app_router = build_client_router(agent).await;
axum::Server::bind(
Expand All @@ -21,11 +25,10 @@ async fn main() {
.unwrap();
}

fn setup_logging() {
let env = env_logger::Env::default().default_filter_or("info");
env_logger::init_from_env(env);
}

fn load_dot_env() {
let _ = dotenvy::dotenv();
#[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."
)
}
1 change: 1 addition & 0 deletions agents/rust/mediator/src/http_routes/client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::VecDeque;

use aries_vcx_core::wallet::base_wallet::BaseWallet;
use axum::routing::post;
use messages::msg_fields::protocols::out_of_band::invitation::Invitation as OOBInvitation;
use serde_json::json;
use xum_test_server::storage::MediatorPersistence;
Expand Down
3 changes: 2 additions & 1 deletion agents/rust/mediator/src/http_routes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use axum::{
extract::State,
http::header::{HeaderMap, ACCEPT},
response::{Html, IntoResponse, Response},
routing::{get, post},
routing::get,
Json, Router,
};
use log::info;
Expand All @@ -25,6 +25,7 @@ use xum_test_server::{
use crate::{aries_agent::Agent, utils::string_from_std_error};
type ArcAgent<T, P> = Arc<Agent<T, P>>;

#[cfg(any(test, feature = "client_tui", feature = "client_http_api"))]
pub mod client;

#[derive(Debug, Serialize, Deserialize)]
Expand Down
8 changes: 8 additions & 0 deletions agents/rust/mediator/src/utils/binary_utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pub fn setup_logging() {
let env = env_logger::Env::default().default_filter_or("info");
env_logger::init_from_env(env);
}

pub fn load_dot_env() {
let _ = dotenvy::dotenv();
}
2 changes: 1 addition & 1 deletion agents/rust/mediator/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pub use prelude::*;

pub mod binary_utils;
pub mod prelude;
pub mod structs;

///// Utility function for mapping any error into a `500 Internal Server Error`
///// response.
// fn internal_error<E>(err: E) -> (axum::http::StatusCode, String)
Expand Down

0 comments on commit 77fdaec

Please sign in to comment.