Compare commits

..

2 Commits

6 changed files with 71 additions and 63 deletions

@ -1,7 +1,8 @@
use clap::{builder::PossibleValue, Arg, ArgMatches, Command};
use clap_complete::{generate, Shell};
use detee_cli::general::cli_handler::handle_operators;
use detee_cli::sgx::cli_handler::handle_app;
use detee_cli::snp::cli_handler::handle_vm;
use detee_cli::snp::cli_handler::{handle_vm, handle_vm_nodes};
use detee_cli::*;
use std::error::Error;
use std::io;
@ -599,26 +600,6 @@ fn handle_completion(matches: &ArgMatches, cmd: Command) {
}
}
fn handle_vm_nodes(matches: &ArgMatches) {
match matches.subcommand() {
Some(("search", _)) => cli_print(snp::print_nodes().map_err(Into::into)),
Some(("inspect", path_subcommand)) => {
let ip: String = path_subcommand.get_one::<String>("ip").unwrap().clone();
cli_print(snp::inspect_node(ip).map_err(Into::into));
}
Some(("report", path_subcommand)) => {
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 reason: String = path_subcommand.get_one::<String>("reason").unwrap().clone();
cli_print(snp::report_node(node_pubkey, contract_uuid, reason).map_err(Into::into))
}
_ => {
println!("Available commands are search and report. Use --help for more information.")
}
}
}
fn handle_account(matches: &ArgMatches) {
match matches.subcommand() {
Some(("show", _)) => cli_print(Ok(config::Config::get_account_data())),
@ -638,39 +619,6 @@ fn handle_account(matches: &ArgMatches) {
}
}
fn handle_operators(matches: &ArgMatches) {
match matches.subcommand() {
Some(("list", _)) => {
cli_print(crate::operators::print_operators().map_err(Into::into));
}
Some(("register", subcom_args)) => {
let escrow: u64 = *subcom_args.get_one::<u64>("escrow").unwrap();
let email: String = subcom_args.get_one::<String>("email").unwrap().clone();
cli_print(crate::operators::register(escrow, email).map_err(Into::into));
}
Some(("inspect", inspect_args)) => {
let wallet = match inspect_args.get_one::<String>("wallet") {
Some(wallet) => wallet.to_string(),
None => config::Config::get_detee_wallet().unwrap_or("".to_string()),
};
cli_print(crate::operators::inspect_operator(wallet).map_err(Into::into));
}
Some(("kick", subcom_args)) => {
let uuid: String = subcom_args.get_one::<String>("contract").unwrap().clone();
let reason: String = subcom_args.get_one::<String>("reason").unwrap().clone();
cli_print(crate::operators::kick(uuid, reason).map_err(Into::into));
}
Some(("ban-user", subcom_args)) => {
let user_wallet: String = subcom_args.get_one::<String>("wallet").unwrap().clone();
cli_print(crate::operators::ban(user_wallet).map_err(Into::into));
}
Some(("decom", _)) => {
todo!("Currently decomissioning is not supported. Will be ");
}
_ => println!("To get more information about operators, use: detee-cli operator --help"),
}
}
fn handle_packagers(
_matches: &ArgMatches,
) -> Result<Vec<crate::packagers::Packager>, Box<dyn Error>> {

@ -0,0 +1,36 @@
use super::operators;
use crate::{cli_print, config};
use clap::ArgMatches;
pub fn handle_operators(matches: &ArgMatches) {
match matches.subcommand() {
Some(("list", _)) => {
cli_print(operators::print_operators().map_err(Into::into));
}
Some(("register", subcom_args)) => {
let escrow: u64 = *subcom_args.get_one::<u64>("escrow").unwrap();
let email: String = subcom_args.get_one::<String>("email").unwrap().clone();
cli_print(operators::register(escrow, email).map_err(Into::into));
}
Some(("inspect", inspect_args)) => {
let wallet = match inspect_args.get_one::<String>("wallet") {
Some(wallet) => wallet.to_string(),
None => config::Config::get_detee_wallet().unwrap_or("".to_string()),
};
cli_print(operators::inspect_operator(wallet).map_err(Into::into));
}
Some(("kick", subcom_args)) => {
let uuid: String = subcom_args.get_one::<String>("contract").unwrap().clone();
let reason: String = subcom_args.get_one::<String>("reason").unwrap().clone();
cli_print(operators::kick(uuid, reason).map_err(Into::into));
}
Some(("ban-user", subcom_args)) => {
let user_wallet: String = subcom_args.get_one::<String>("wallet").unwrap().clone();
cli_print(operators::ban(user_wallet).map_err(Into::into));
}
Some(("decom", _)) => {
todo!("Currently decomissioning is not supported. Will be ");
}
_ => println!("To get more information about operators, use: detee-cli operator --help"),
}
}

3
src/general/mod.rs Normal file

@ -0,0 +1,3 @@
pub mod cli_handler;
pub mod operators;
// pub mod grpc;

@ -26,12 +26,12 @@ impl From<grpc::brain::ListOperatorsResp> for TabledOperator {
}
}
pub fn register(escrow: u64, email: String) -> Result<super::SimpleOutput, grpc::Error> {
pub fn register(escrow: u64, email: String) -> Result<crate::SimpleOutput, grpc::Error> {
block_on(grpc::register_operator(escrow, email))?;
Ok(super::SimpleOutput::from("Successfully registered you as operator."))
Ok(crate::SimpleOutput::from("Successfully registered you as operator."))
}
impl super::HumanOutput for brain::InspectOperatorResp {
impl crate::HumanOutput for brain::InspectOperatorResp {
fn human_cli_print(&self) {
match &self.operator {
Some(op) => {
@ -65,7 +65,7 @@ pub fn inspect_operator(wallet: String) -> Result<brain::InspectOperatorResp, gr
block_on(grpc::inspect_operator(wallet))
}
impl super::HumanOutput for Vec<brain::ListOperatorsResp> {
impl crate::HumanOutput for Vec<brain::ListOperatorsResp> {
fn human_cli_print(&self) {
let operators: Vec<TabledOperator> = self.iter().map(|op| op.clone().into()).collect();
@ -80,14 +80,14 @@ pub fn print_operators() -> Result<Vec<brain::ListOperatorsResp>, grpc::Error> {
Ok(block_on(grpc::list_operators())?)
}
pub fn kick(contract_uuid: String, reason: String) -> Result<super::SimpleOutput, grpc::Error> {
pub fn kick(contract_uuid: String, reason: String) -> Result<crate::SimpleOutput, grpc::Error> {
let nano_lp = block_on(grpc::kick_contract(contract_uuid, reason))?;
Ok(super::SimpleOutput::from(
Ok(crate::SimpleOutput::from(
format!("Successfully terminated contract. Refunded {} nanoLP.", nano_lp).as_str(),
))
}
pub fn ban(wallet: String) -> Result<super::SimpleOutput, grpc::Error> {
pub fn ban(wallet: String) -> Result<crate::SimpleOutput, grpc::Error> {
block_on(grpc::ban_user(wallet))?;
Ok(super::SimpleOutput::from("Successfully banned user"))
Ok(crate::SimpleOutput::from("Successfully banned user"))
}

@ -1,7 +1,7 @@
pub mod config;
pub mod constants;
pub mod general;
pub mod name_generator;
pub mod operators;
pub mod packagers;
pub mod sgx;
pub mod snp;

@ -24,6 +24,27 @@ pub fn handle_vm(matches: &ArgMatches) {
_ => println!("No valid VM subcommand provided."),
}
}
pub fn handle_vm_nodes(matches: &ArgMatches) {
match matches.subcommand() {
Some(("search", _)) => cli_print(snp::print_nodes().map_err(Into::into)),
Some(("inspect", path_subcommand)) => {
let ip: String = path_subcommand.get_one::<String>("ip").unwrap().clone();
cli_print(snp::inspect_node(ip).map_err(Into::into));
}
Some(("report", path_subcommand)) => {
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 reason: String = path_subcommand.get_one::<String>("reason").unwrap().clone();
cli_print(snp::report_node(node_pubkey, contract_uuid, reason).map_err(Into::into))
}
_ => {
println!("Available commands are search and report. Use --help for more information.")
}
}
}
fn handle_vm_deploy(matches: &ArgMatches) -> Result<snp::VmSshArgs, Box<dyn Error>> {
if let Some(path) = matches.get_one::<String>("yaml-path") {
return Ok(snp::deploy::Request::load_from_yaml(path)?);