refactor: move report_node grpc call to general module and update CLI handler
This commit is contained in:
parent
703a3e2c18
commit
683c49564d
@ -1,9 +1,9 @@
|
|||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::snp::grpc::proto::VmContract;
|
use crate::snp::grpc::proto::VmContract;
|
||||||
use crate::utils::sign_request;
|
use crate::utils::sign_request;
|
||||||
|
use detee_shared::general_proto::ReportNodeReq;
|
||||||
use log::{debug, info, warn};
|
use log::{debug, info, warn};
|
||||||
use tokio_stream::StreamExt;
|
use tokio_stream::StreamExt;
|
||||||
// use tonic::metadata::errors::InvalidMetadataValue;
|
|
||||||
|
|
||||||
pub mod proto {
|
pub mod proto {
|
||||||
pub use detee_shared::common_proto::*;
|
pub use detee_shared::common_proto::*;
|
||||||
@ -23,12 +23,6 @@ pub enum Error {
|
|||||||
#[error("Received error from brain: status: {}, message: {}",
|
#[error("Received error from brain: status: {}, message: {}",
|
||||||
_0.code().to_string(), _0.message())]
|
_0.code().to_string(), _0.message())]
|
||||||
ResponseStatus(#[from] tonic::Status),
|
ResponseStatus(#[from] tonic::Status),
|
||||||
// #[error(transparent)]
|
|
||||||
// ConfigError(#[from] crate::config::Error),
|
|
||||||
// #[error("Could not find contract {0}")]
|
|
||||||
// VmContractNotFound(String),
|
|
||||||
// #[error(transparent)]
|
|
||||||
// InternalError(#[from] InvalidMetadataValue),
|
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
InternalError(#[from] crate::utils::Error),
|
InternalError(#[from] crate::utils::Error),
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
@ -107,6 +101,24 @@ pub async fn ban_user(user_wallet: String) -> Result<(), Error> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn report_node(
|
||||||
|
node_pubkey: String,
|
||||||
|
contract: String,
|
||||||
|
reason: String,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
debug!("Getting contracts from brain...");
|
||||||
|
let mut client = BrainGeneralCliClient::connect(Config::get_brain_url()).await?;
|
||||||
|
client
|
||||||
|
.report_node(sign_request(ReportNodeReq {
|
||||||
|
admin_pubkey: Config::get_detee_wallet()?,
|
||||||
|
node_pubkey,
|
||||||
|
contract,
|
||||||
|
reason,
|
||||||
|
})?)
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
// super admin
|
// super admin
|
||||||
|
|
||||||
pub async fn admin_list_accounts() -> Result<Vec<Account>, Error> {
|
pub async fn admin_list_accounts() -> Result<Vec<Account>, Error> {
|
||||||
|
@ -2,3 +2,15 @@ pub mod cli_handler;
|
|||||||
pub mod grpc;
|
pub mod grpc;
|
||||||
pub mod operators;
|
pub mod operators;
|
||||||
pub mod packagers;
|
pub mod packagers;
|
||||||
|
|
||||||
|
use crate::utils::block_on;
|
||||||
|
use crate::SimpleOutput;
|
||||||
|
|
||||||
|
pub fn report_node(
|
||||||
|
node_pubkey: String,
|
||||||
|
contract: String,
|
||||||
|
reason: String,
|
||||||
|
) -> Result<SimpleOutput, grpc::Error> {
|
||||||
|
block_on(grpc::report_node(node_pubkey, contract, reason))?;
|
||||||
|
Ok(SimpleOutput::from("The node got reported."))
|
||||||
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use crate::general;
|
||||||
use crate::name_generator;
|
use crate::name_generator;
|
||||||
use crate::snp;
|
use crate::snp;
|
||||||
use crate::{cli_print, SimpleOutput};
|
use crate::{cli_print, SimpleOutput};
|
||||||
@ -37,7 +38,7 @@ pub fn handle_vm_nodes(matches: &ArgMatches) {
|
|||||||
let contract_uuid: String =
|
let contract_uuid: String =
|
||||||
path_subcommand.get_one::<String>("contract").unwrap().clone();
|
path_subcommand.get_one::<String>("contract").unwrap().clone();
|
||||||
let reason: String = path_subcommand.get_one::<String>("reason").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))
|
cli_print(general::report_node(node_pubkey, contract_uuid, reason).map_err(Into::into))
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
println!("Available commands are search and report. Use --help for more information.")
|
println!("Available commands are search and report. Use --help for more information.")
|
||||||
|
@ -4,12 +4,11 @@ pub mod proto {
|
|||||||
}
|
}
|
||||||
|
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use detee_shared::general_proto::brain_general_cli_client::BrainGeneralCliClient;
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use log::{debug, info, warn};
|
use log::{debug, info, warn};
|
||||||
use proto::{
|
use proto::{
|
||||||
brain_vm_cli_client::BrainVmCliClient, DeleteVmReq, ExtendVmReq, ListVmContractsReq, NewVmReq,
|
brain_vm_cli_client::BrainVmCliClient, DeleteVmReq, ExtendVmReq, ListVmContractsReq, NewVmReq,
|
||||||
NewVmResp, ReportNodeReq, UpdateVmReq, UpdateVmResp, VmContract, VmNodeFilters, VmNodeListResp,
|
NewVmResp, UpdateVmReq, UpdateVmResp, VmContract, VmNodeFilters, VmNodeListResp,
|
||||||
};
|
};
|
||||||
use tokio_stream::StreamExt;
|
use tokio_stream::StreamExt;
|
||||||
use tonic::metadata::errors::InvalidMetadataValue;
|
use tonic::metadata::errors::InvalidMetadataValue;
|
||||||
@ -128,24 +127,6 @@ pub async fn create_vm(req: NewVmReq) -> Result<NewVmResp, Error> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn report_node(
|
|
||||||
node_pubkey: String,
|
|
||||||
contract: String,
|
|
||||||
reason: String,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
debug!("Getting contracts from brain...");
|
|
||||||
let mut client = BrainGeneralCliClient::connect(Config::get_brain_url()).await?;
|
|
||||||
client
|
|
||||||
.report_node(sign_request(ReportNodeReq {
|
|
||||||
admin_pubkey: Config::get_detee_wallet()?,
|
|
||||||
node_pubkey,
|
|
||||||
contract,
|
|
||||||
reason,
|
|
||||||
})?)
|
|
||||||
.await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn list_contracts(req: ListVmContractsReq) -> Result<Vec<VmContract>, Error> {
|
pub async fn list_contracts(req: ListVmContractsReq) -> Result<Vec<VmContract>, Error> {
|
||||||
debug!("Getting contracts from brain...");
|
debug!("Getting contracts from brain...");
|
||||||
let mut client = BrainVmCliClient::connect(Config::get_brain_url()).await?;
|
let mut client = BrainVmCliClient::connect(Config::get_brain_url()).await?;
|
||||||
|
@ -367,15 +367,6 @@ pub fn inspect_node(ip: String) -> Result<proto::VmNodeListResp, Error> {
|
|||||||
Ok(block_on(grpc::get_one_node(req))?)
|
Ok(block_on(grpc::get_one_node(req))?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn report_node(
|
|
||||||
node_pubkey: String,
|
|
||||||
contract: String,
|
|
||||||
reason: String,
|
|
||||||
) -> Result<super::SimpleOutput, Error> {
|
|
||||||
block_on(grpc::report_node(node_pubkey, contract, reason))?;
|
|
||||||
Ok(super::SimpleOutput::from("The node got reported."))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn calculate_nanolp(
|
pub fn calculate_nanolp(
|
||||||
vcpus: u32,
|
vcpus: u32,
|
||||||
memory_mb: u32,
|
memory_mb: u32,
|
||||||
|
Loading…
Reference in New Issue
Block a user