mirror of
https://github.com/threefoldtech/mycelium.git
synced 2026-05-25 09:54:05 +00:00
Add CLI functionality to check queried routes
Signed-off-by: Lee Smet <lee.smet@hotmail.com>
This commit is contained in:
@@ -8,4 +8,4 @@ pub use inspect::inspect;
|
||||
#[cfg(feature = "message")]
|
||||
pub use message::{recv_msg, send_msg};
|
||||
pub use peer::{add_peers, list_peers, remove_peers};
|
||||
pub use routes::{list_fallback_routes, list_selected_routes};
|
||||
pub use routes::{list_fallback_routes, list_queried_subnets, list_selected_routes};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use mycelium_api::Route;
|
||||
use mycelium_api::{QueriedSubnet, Route};
|
||||
use prettytable::{row, Table};
|
||||
use std::net::SocketAddr;
|
||||
|
||||
@@ -82,3 +82,37 @@ pub async fn list_fallback_routes(
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn list_queried_subnets(
|
||||
server_addr: SocketAddr,
|
||||
json_print: bool,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let request_url = format!("http://{server_addr}/api/v1/admin/routes/queried");
|
||||
match reqwest::get(&request_url).await {
|
||||
Err(e) => {
|
||||
error!("Failed to retrieve queried subnets");
|
||||
return Err(e.into());
|
||||
}
|
||||
Ok(resp) => {
|
||||
debug!("Listing queried routes");
|
||||
|
||||
if json_print {
|
||||
// API call returns routes in JSON format by default
|
||||
let queried_routes = resp.text().await?;
|
||||
println!("{queried_routes}");
|
||||
} else {
|
||||
// Print routes in table format
|
||||
let queries: Vec<QueriedSubnet> = resp.json().await?;
|
||||
let mut table = Table::new();
|
||||
table.add_row(row!["Subnet", "Query expiration"]);
|
||||
|
||||
for query in queries.iter() {
|
||||
table.add_row(row![query.subnet, query.expiration,]);
|
||||
}
|
||||
|
||||
table.printstd();
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user