feat: add app-node inspect

This commit is contained in:
Noor 2025-03-22 01:32:06 +05:30
parent bf8a4f3a8b
commit 4bd6b48877
Signed by: noormohammedb
GPG Key ID: D83EFB8B3B967146
4 changed files with 25 additions and 4 deletions

@ -269,7 +269,6 @@ fn clap_cmd() -> Command {
.subcommand(Command::new("app-node") .subcommand(Command::new("app-node")
.about("info about Intel SGX servers registerd to DeTEE") .about("info about Intel SGX servers registerd to DeTEE")
.subcommand(Command::new("search").about("search nodes based on filters")) .subcommand(Command::new("search").about("search nodes based on filters"))
/*
.subcommand(Command::new("inspect").about("get detailed information about a node") .subcommand(Command::new("inspect").about("get detailed information about a node")
.arg( .arg(
Arg::new("ip") Arg::new("ip")
@ -278,6 +277,7 @@ fn clap_cmd() -> Command {
.required(true) .required(true)
) )
) )
/*
.subcommand(Command::new("report").about("report a node for poor performance") .subcommand(Command::new("report").about("report a node for poor performance")
.arg( .arg(
Arg::new("pubkey") Arg::new("pubkey")

@ -3,6 +3,7 @@ use super::utils::deploy_new_app_and_update_config;
use super::{get_app_node, AppContract, AppDeployResponse}; use super::{get_app_node, AppContract, AppDeployResponse};
use crate::name_generator::random_app_name; use crate::name_generator::random_app_name;
use crate::sgx;
use crate::sgx::config::{validate_yaml, DeteeCliExt}; use crate::sgx::config::{validate_yaml, DeteeCliExt};
use crate::sgx::grpc_brain::delete_app; use crate::sgx::grpc_brain::delete_app;
use crate::sgx::grpc_dtpm::{attest_and_send_config, get_config_from_enclave}; use crate::sgx::grpc_dtpm::{attest_and_send_config, get_config_from_enclave};
@ -28,8 +29,11 @@ pub fn handle_app(app_matche: &ArgMatches) {
pub fn handle_app_nodes(matches: &ArgMatches) { pub fn handle_app_nodes(matches: &ArgMatches) {
match matches.subcommand() { match matches.subcommand() {
Some(("search", _)) => cli_print(crate::sgx::print_nodes().map_err(Into::into)), Some(("search", _)) => cli_print(sgx::print_nodes().map_err(Into::into)),
Some(("inspect", _)) => todo!(), Some(("inspect", subcom_args)) => {
let ip: String = subcom_args.get_one::<String>("ip").unwrap().clone();
cli_print(sgx::inspect_node(ip).map_err(Into::into));
}
Some(("report", _)) => { Some(("report", _)) => {
// let node_pubkey: String = path_subcommand.get_one::<String>("pubkey").unwrap().clone(); // let node_pubkey: String = path_subcommand.get_one::<String>("pubkey").unwrap().clone();
// let contract_uuid: String = path_subcommand.get_one::<String>("contract").unwrap().clone(); // let contract_uuid: String = path_subcommand.get_one::<String>("contract").unwrap().clone();

@ -24,6 +24,18 @@ pub enum Error {
type Result<T> = std::result::Result<T, Error>; type Result<T> = std::result::Result<T, Error>;
impl crate::HumanOutput for AppNodeListResp {
fn human_cli_print(&self) {
println!("The pubkey of this node is {} and the IP is {}", self.node_pubkey, self.ip);
println!("It belongs to the operator {}", self.operator);
println!(
"This node is located in the city {}, within the region of {}, in {}",
self.city, self.region, self.country
);
println!("The price multiplier for the node is {}.", self.price);
}
}
pub async fn new_app(app_deploy_config: AppDeployConfig) -> Result<NewAppRes> { pub async fn new_app(app_deploy_config: AppDeployConfig) -> Result<NewAppRes> {
let resource = app_deploy_config.clone().resource; let resource = app_deploy_config.clone().resource;
let mut req: NewAppReq = app_deploy_config.clone().into(); let mut req: NewAppReq = app_deploy_config.clone().into();

@ -165,6 +165,11 @@ pub async fn get_app_node(
get_one_app_node(app_node_filter).await get_one_app_node(app_node_filter).await
} }
pub fn inspect_node(ip: String) -> Result<AppNodeListResp, grpc_brain::Error> {
let req = AppNodeFilters { ip, ..Default::default() };
block_on(get_one_app_node(req))
}
#[derive(Tabled, Debug, Serialize, Deserialize)] #[derive(Tabled, Debug, Serialize, Deserialize)]
pub struct TabledAppNode { pub struct TabledAppNode {
#[tabled(rename = "Operator")] #[tabled(rename = "Operator")]
@ -204,5 +209,5 @@ impl super::HumanOutput for Vec<AppNodeListResp> {
pub fn print_nodes() -> Result<Vec<AppNodeListResp>, grpc_brain::Error> { pub fn print_nodes() -> Result<Vec<AppNodeListResp>, grpc_brain::Error> {
log::debug!("This will support flags in the future, but we have only one node atm."); log::debug!("This will support flags in the future, but we have only one node atm.");
let req = AppNodeFilters { ..Default::default() }; let req = AppNodeFilters { ..Default::default() };
Ok(block_on(grpc_brain::get_app_node_list(req))?) block_on(grpc_brain::get_app_node_list(req))
} }