feat: add --as-operator flag to list command for apps

This commit is contained in:
Noor 2025-03-24 17:29:40 +05:30
parent 7d7200bca4
commit 0bd0eb19ed
Signed by: noormohammedb
GPG Key ID: D83EFB8B3B967146
2 changed files with 20 additions and 4 deletions

@ -277,6 +277,12 @@ fn clap_cmd() -> Command {
Command::new("list") Command::new("list")
.about("list all deployed apps") .about("list all deployed apps")
.long_about("List all the deployed apps in the enclave") .long_about("List all the deployed apps in the enclave")
.arg(
Arg::new("as-operator")
.long("as-operator")
.help("list Apps running on your SGX nodes")
.action(clap::ArgAction::SetTrue)
)
) )
) )
.subcommand(Command::new("app-node") .subcommand(Command::new("app-node")

@ -26,7 +26,7 @@ pub fn handle_app(app_matche: &ArgMatches) {
Some(("deploy", subcom_args)) => cli_print(handle_deploy(subcom_args)), Some(("deploy", subcom_args)) => cli_print(handle_deploy(subcom_args)),
Some(("inspect", subcom_args)) => handle_inspect(subcom_args), Some(("inspect", subcom_args)) => handle_inspect(subcom_args),
Some(("delete", subcom_args)) => cli_print(handle_delete(subcom_args)), Some(("delete", subcom_args)) => cli_print(handle_delete(subcom_args)),
Some(("list", _)) => cli_print(handle_list()), Some(("list", subcom_args)) => cli_print(handle_list(subcom_args)),
Some(("config", subcom_args)) => handle_config(subcom_args), Some(("config", subcom_args)) => handle_config(subcom_args),
_ => println!("No valid subcommand provided. Use --help for more information."), _ => println!("No valid subcommand provided. Use --help for more information."),
} }
@ -170,9 +170,19 @@ fn handle_delete(
} }
} }
fn handle_list() -> Result<Vec<AppContract>, Box<dyn std::error::Error>> { fn handle_list(list_matche: &ArgMatches) -> Result<Vec<AppContract>, Box<dyn std::error::Error>> {
let req = let as_operator = *list_matche.get_one::<bool>("as-operator").unwrap_or(&false);
ListAppContractsReq { admin_pubkey: Config::get_detee_wallet()?, ..Default::default() };
let req = if as_operator {
ListAppContractsReq {
admin_pubkey: Config::get_detee_wallet()?,
as_operator,
..Default::default()
}
} else {
ListAppContractsReq { admin_pubkey: Config::get_detee_wallet()?, ..Default::default() }
};
let contracts: Vec<AppContract> = let contracts: Vec<AppContract> =
block_on(list_contracts(req))?.into_iter().map(|n| n.into()).collect(); block_on(list_contracts(req))?.into_iter().map(|n| n.into()).collect();