refactor: General grpc update client
reorganize proto imports fix rename Brain vm client
This commit is contained in:
parent
6bf97faac3
commit
aeca70e062
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1109,7 +1109,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "detee-shared"
|
name = "detee-shared"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+ssh://git@gitea.detee.cloud/testnet/proto.git?branch=main#be4e41db050c6d59e9fb5abf47e647f5bbdc24b2"
|
source = "git+ssh://git@gitea.detee.cloud/testnet/proto.git?branch=main#cf0c9a2c0d2edf9254f25c6faa7494afcfa00d64"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"prost",
|
"prost",
|
||||||
|
@ -43,14 +43,14 @@ impl super::HumanOutput for brain::InspectOperatorResp {
|
|||||||
}
|
}
|
||||||
None => (),
|
None => (),
|
||||||
}
|
}
|
||||||
if self.nodes.len() == 0 {
|
if self.vm_nodes.len() == 0 {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
println!("\n-- VM NODES --");
|
println!("\n-- VM NODES --");
|
||||||
let mut count = 1;
|
let mut count = 1;
|
||||||
for node in self.nodes.iter() {
|
for vm_node in self.vm_nodes.iter() {
|
||||||
println!("\nNODE #{count}:");
|
println!("\nNODE #{count}:");
|
||||||
node.human_cli_print();
|
vm_node.human_cli_print();
|
||||||
count += 1;
|
count += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use detee_shared::sgx::pb::brain::brain_app_cli_client::BrainAppCliClient;
|
use detee_shared::app_proto::brain_app_cli_client::BrainAppCliClient;
|
||||||
use detee_shared::sgx::pb::brain::{
|
use detee_shared::app_proto::{
|
||||||
AppContract, AppNodeFilters, AppNodeListResp, DelAppReq, ListAppContractsReq, NewAppReq,
|
AppContract, AppNodeFilters, AppNodeListResp, DelAppReq, ListAppContractsReq, NewAppReq,
|
||||||
NewAppRes,
|
NewAppRes,
|
||||||
};
|
};
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
use detee_sgx::{prelude::*, HRaTlsConfigBuilder};
|
use detee_sgx::{prelude::*, HRaTlsConfigBuilder};
|
||||||
use detee_shared::sgx::pb::dtpm::DtpmGetConfigReq;
|
use detee_shared::sgx::pb::dtpm_proto::DtpmGetConfigReq;
|
||||||
use hyper_rustls::HttpsConnectorBuilder;
|
use hyper_rustls::HttpsConnectorBuilder;
|
||||||
use rustls::ClientConfig;
|
use rustls::ClientConfig;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
use tonic::transport::{Channel, Endpoint};
|
use tonic::transport::{Channel, Endpoint};
|
||||||
|
|
||||||
use detee_shared::sgx::{
|
use detee_shared::sgx::{
|
||||||
pb::dtpm::{
|
pb::dtpm_proto::{
|
||||||
dtpm_config_manager_client::DtpmConfigManagerClient, DtpmConfigData, DtpmSetConfigReq,
|
dtpm_config_manager_client::DtpmConfigManagerClient, DtpmConfigData, DtpmSetConfigReq,
|
||||||
},
|
},
|
||||||
types::dtpm::DtpmConfig,
|
types::dtpm::DtpmConfig,
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use detee_shared::sgx::{
|
use detee_shared::{
|
||||||
pb::brain::{
|
app_proto::{
|
||||||
AppContract as AppContractPB, AppNodeFilters, AppNodeListResp, AppResource, NewAppRes,
|
AppContract as AppContractPB, AppNodeFilters, AppNodeListResp, AppResource, NewAppRes,
|
||||||
},
|
},
|
||||||
types::brain::Resource,
|
sgx::types::brain::Resource,
|
||||||
};
|
};
|
||||||
use grpc_brain::get_one_app_node;
|
use grpc_brain::get_one_app_node;
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
pub mod brain {
|
pub mod brain {
|
||||||
// tonic::include_proto!("vm_proto");
|
// tonic::include_proto!("vm_proto");
|
||||||
pub use detee_shared::snp::pb::vm::*;
|
pub use detee_shared::common_proto::*;
|
||||||
|
pub use detee_shared::general_proto::*;
|
||||||
|
pub use detee_shared::vm_proto::*;
|
||||||
}
|
}
|
||||||
|
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
@ -9,10 +11,11 @@ use crate::snp::brain::AccountBalance;
|
|||||||
use crate::snp::brain::InspectOperatorResp;
|
use crate::snp::brain::InspectOperatorResp;
|
||||||
use crate::snp::brain::Pubkey;
|
use crate::snp::brain::Pubkey;
|
||||||
use brain::{
|
use brain::{
|
||||||
brain_cli_client::BrainCliClient, BanUserReq, DeleteVmReq, Empty, ExtendVmReq, KickReq,
|
brain_vm_cli_client::BrainVmCliClient, BanUserReq, DeleteVmReq, Empty, ExtendVmReq, KickReq,
|
||||||
ListOperatorsResp, ListVmContractsReq, NewVmReq, NewVmResp, RegOperatorReq, ReportNodeReq,
|
ListOperatorsResp, ListVmContractsReq, NewVmReq, NewVmResp, RegOperatorReq, ReportNodeReq,
|
||||||
UpdateVmReq, UpdateVmResp, VmContract, VmNodeFilters, VmNodeListResp,
|
UpdateVmReq, UpdateVmResp, VmContract, VmNodeFilters, VmNodeListResp,
|
||||||
};
|
};
|
||||||
|
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 tokio_stream::StreamExt;
|
use tokio_stream::StreamExt;
|
||||||
@ -99,7 +102,7 @@ fn sign_request<T: std::fmt::Debug>(req: T) -> Result<Request<T>, Error> {
|
|||||||
|
|
||||||
pub async fn get_node_list(req: VmNodeFilters) -> Result<Vec<VmNodeListResp>, Error> {
|
pub async fn get_node_list(req: VmNodeFilters) -> Result<Vec<VmNodeListResp>, Error> {
|
||||||
debug!("Getting nodes from brain...");
|
debug!("Getting nodes from brain...");
|
||||||
let mut client = BrainCliClient::connect(Config::get_brain_url()).await?;
|
let mut client = BrainVmCliClient::connect(Config::get_brain_url()).await?;
|
||||||
let mut nodes = Vec::new();
|
let mut nodes = Vec::new();
|
||||||
let mut grpc_stream = client.list_vm_nodes(sign_request(req)?).await?.into_inner();
|
let mut grpc_stream = client.list_vm_nodes(sign_request(req)?).await?.into_inner();
|
||||||
while let Some(stream_update) = grpc_stream.next().await {
|
while let Some(stream_update) = grpc_stream.next().await {
|
||||||
@ -118,7 +121,7 @@ pub async fn get_node_list(req: VmNodeFilters) -> Result<Vec<VmNodeListResp>, Er
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_balance(account: &str) -> Result<AccountBalance, Error> {
|
pub async fn get_balance(account: &str) -> Result<AccountBalance, Error> {
|
||||||
let mut client = BrainCliClient::connect(Config::get_brain_url()).await?;
|
let mut client = BrainGeneralCliClient::connect(Config::get_brain_url()).await?;
|
||||||
let response =
|
let response =
|
||||||
client.get_balance(sign_request(Pubkey { pubkey: account.to_string() })?).await?;
|
client.get_balance(sign_request(Pubkey { pubkey: account.to_string() })?).await?;
|
||||||
log::info!("Received account from brain: {response:?}");
|
log::info!("Received account from brain: {response:?}");
|
||||||
@ -126,27 +129,27 @@ pub async fn get_balance(account: &str) -> Result<AccountBalance, Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn admin_airdrop(pubkey: String, tokens: u64) -> Result<(), Error> {
|
pub async fn admin_airdrop(pubkey: String, tokens: u64) -> Result<(), Error> {
|
||||||
let mut client = BrainCliClient::connect(Config::get_brain_url()).await?;
|
let mut client = BrainGeneralCliClient::connect(Config::get_brain_url()).await?;
|
||||||
let req = sign_request(brain::AirdropReq { pubkey, tokens })?;
|
let req = sign_request(brain::AirdropReq { pubkey, tokens })?;
|
||||||
let _ = client.airdrop(req).await?;
|
let _ = client.airdrop(req).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn admin_slash(pubkey: String, tokens: u64) -> Result<(), Error> {
|
pub async fn admin_slash(pubkey: String, tokens: u64) -> Result<(), Error> {
|
||||||
let mut client = BrainCliClient::connect(Config::get_brain_url()).await?;
|
let mut client = BrainGeneralCliClient::connect(Config::get_brain_url()).await?;
|
||||||
let req = sign_request(brain::SlashReq { pubkey, tokens })?;
|
let req = sign_request(brain::SlashReq { pubkey, tokens })?;
|
||||||
let _ = client.slash(req).await?;
|
let _ = client.slash(req).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_one_node(req: VmNodeFilters) -> Result<VmNodeListResp, Error> {
|
pub async fn get_one_node(req: VmNodeFilters) -> Result<VmNodeListResp, Error> {
|
||||||
let mut client = BrainCliClient::connect(Config::get_brain_url()).await?;
|
let mut client = BrainVmCliClient::connect(Config::get_brain_url()).await?;
|
||||||
let response = client.get_one_vm_node(sign_request(req)?).await?;
|
let response = client.get_one_vm_node(sign_request(req)?).await?;
|
||||||
Ok(response.into_inner())
|
Ok(response.into_inner())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create_vm(req: NewVmReq) -> Result<NewVmResp, Error> {
|
pub async fn create_vm(req: NewVmReq) -> Result<NewVmResp, Error> {
|
||||||
let mut client = BrainCliClient::connect(Config::get_brain_url()).await?;
|
let mut client = BrainVmCliClient::connect(Config::get_brain_url()).await?;
|
||||||
debug!("Sending NewVmReq to brain: {req:?}");
|
debug!("Sending NewVmReq to brain: {req:?}");
|
||||||
match client.new_vm(sign_request(req)?).await {
|
match client.new_vm(sign_request(req)?).await {
|
||||||
Ok(resp) => Ok(resp.into_inner()),
|
Ok(resp) => Ok(resp.into_inner()),
|
||||||
@ -160,7 +163,7 @@ pub async fn report_node(
|
|||||||
reason: String,
|
reason: String,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
debug!("Getting contracts from brain...");
|
debug!("Getting contracts from brain...");
|
||||||
let mut client = BrainCliClient::connect(Config::get_brain_url()).await?;
|
let mut client = BrainGeneralCliClient::connect(Config::get_brain_url()).await?;
|
||||||
client
|
client
|
||||||
.report_node(sign_request(ReportNodeReq {
|
.report_node(sign_request(ReportNodeReq {
|
||||||
admin_pubkey: Config::get_detee_wallet()?,
|
admin_pubkey: Config::get_detee_wallet()?,
|
||||||
@ -174,13 +177,13 @@ pub async fn report_node(
|
|||||||
|
|
||||||
pub async fn inspect_operator(wallet: String) -> Result<InspectOperatorResp, Error> {
|
pub async fn inspect_operator(wallet: String) -> Result<InspectOperatorResp, Error> {
|
||||||
debug!("Getting information about operator {wallet} from brain.");
|
debug!("Getting information about operator {wallet} from brain.");
|
||||||
let mut client = BrainCliClient::connect(Config::get_brain_url()).await?;
|
let mut client = BrainGeneralCliClient::connect(Config::get_brain_url()).await?;
|
||||||
Ok(client.inspect_operator(Pubkey { pubkey: wallet }).await?.into_inner())
|
Ok(client.inspect_operator(Pubkey { pubkey: wallet }).await?.into_inner())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn list_operators() -> Result<Vec<ListOperatorsResp>, Error> {
|
pub async fn list_operators() -> Result<Vec<ListOperatorsResp>, Error> {
|
||||||
debug!("Getting contracts from brain...");
|
debug!("Getting contracts from brain...");
|
||||||
let mut client = BrainCliClient::connect(Config::get_brain_url()).await?;
|
let mut client = BrainGeneralCliClient::connect(Config::get_brain_url()).await?;
|
||||||
let mut operators = Vec::new();
|
let mut operators = Vec::new();
|
||||||
let mut grpc_stream = client.list_operators(sign_request(Empty {})?).await?.into_inner();
|
let mut grpc_stream = client.list_operators(sign_request(Empty {})?).await?.into_inner();
|
||||||
while let Some(stream_update) = grpc_stream.next().await {
|
while let Some(stream_update) = grpc_stream.next().await {
|
||||||
@ -199,7 +202,7 @@ pub async fn list_operators() -> Result<Vec<ListOperatorsResp>, Error> {
|
|||||||
|
|
||||||
pub async fn register_operator(escrow: u64, email: String) -> Result<(), Error> {
|
pub async fn register_operator(escrow: u64, email: String) -> Result<(), Error> {
|
||||||
debug!("Connecting to brain to register operator...");
|
debug!("Connecting to brain to register operator...");
|
||||||
let mut client = BrainCliClient::connect(Config::get_brain_url()).await?;
|
let mut client = BrainGeneralCliClient::connect(Config::get_brain_url()).await?;
|
||||||
client
|
client
|
||||||
.register_operator(sign_request(RegOperatorReq {
|
.register_operator(sign_request(RegOperatorReq {
|
||||||
pubkey: Config::get_detee_wallet()?,
|
pubkey: Config::get_detee_wallet()?,
|
||||||
@ -212,7 +215,7 @@ pub async fn register_operator(escrow: u64, email: String) -> Result<(), Error>
|
|||||||
|
|
||||||
pub async fn kick_contract(contract_uuid: String, reason: String) -> Result<u64, Error> {
|
pub async fn kick_contract(contract_uuid: String, reason: String) -> Result<u64, Error> {
|
||||||
debug!("gRPC module: connecting to brain and kicking contract {contract_uuid} for reason: {reason}");
|
debug!("gRPC module: connecting to brain and kicking contract {contract_uuid} for reason: {reason}");
|
||||||
let mut client = BrainCliClient::connect(Config::get_brain_url()).await?;
|
let mut client = BrainGeneralCliClient::connect(Config::get_brain_url()).await?;
|
||||||
Ok(client
|
Ok(client
|
||||||
.kick_contract(sign_request(KickReq {
|
.kick_contract(sign_request(KickReq {
|
||||||
operator_wallet: Config::get_detee_wallet()?,
|
operator_wallet: Config::get_detee_wallet()?,
|
||||||
@ -226,7 +229,7 @@ pub async fn kick_contract(contract_uuid: String, reason: String) -> Result<u64,
|
|||||||
|
|
||||||
pub async fn ban_user(user_wallet: String) -> Result<(), Error> {
|
pub async fn ban_user(user_wallet: String) -> Result<(), Error> {
|
||||||
debug!("Connecting to brain to ban user...");
|
debug!("Connecting to brain to ban user...");
|
||||||
let mut client = BrainCliClient::connect(Config::get_brain_url()).await?;
|
let mut client = BrainGeneralCliClient::connect(Config::get_brain_url()).await?;
|
||||||
client
|
client
|
||||||
.ban_user(sign_request(BanUserReq {
|
.ban_user(sign_request(BanUserReq {
|
||||||
operator_wallet: Config::get_detee_wallet()?,
|
operator_wallet: Config::get_detee_wallet()?,
|
||||||
@ -238,7 +241,7 @@ pub async fn ban_user(user_wallet: String) -> Result<(), Error> {
|
|||||||
|
|
||||||
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 = BrainCliClient::connect(Config::get_brain_url()).await?;
|
let mut client = BrainVmCliClient::connect(Config::get_brain_url()).await?;
|
||||||
let mut contracts = Vec::new();
|
let mut contracts = Vec::new();
|
||||||
let mut grpc_stream = client.list_vm_contracts(sign_request(req)?).await?.into_inner();
|
let mut grpc_stream = client.list_vm_contracts(sign_request(req)?).await?.into_inner();
|
||||||
while let Some(stream_update) = grpc_stream.next().await {
|
while let Some(stream_update) = grpc_stream.next().await {
|
||||||
@ -257,7 +260,7 @@ pub async fn list_contracts(req: ListVmContractsReq) -> Result<Vec<VmContract>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn admin_list_contracts() -> Result<Vec<VmContract>, Error> {
|
pub async fn admin_list_contracts() -> Result<Vec<VmContract>, Error> {
|
||||||
let mut client = BrainCliClient::connect(Config::get_brain_url()).await?;
|
let mut client = BrainGeneralCliClient::connect(Config::get_brain_url()).await?;
|
||||||
let mut contracts = Vec::new();
|
let mut contracts = Vec::new();
|
||||||
let mut grpc_stream =
|
let mut grpc_stream =
|
||||||
client.list_all_vm_contracts(sign_request(brain::Empty {})?).await?.into_inner();
|
client.list_all_vm_contracts(sign_request(brain::Empty {})?).await?.into_inner();
|
||||||
@ -277,7 +280,7 @@ pub async fn admin_list_contracts() -> Result<Vec<VmContract>, Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn admin_list_accounts() -> Result<Vec<Account>, Error> {
|
pub async fn admin_list_accounts() -> Result<Vec<Account>, Error> {
|
||||||
let mut client = BrainCliClient::connect(Config::get_brain_url()).await?;
|
let mut client = BrainGeneralCliClient::connect(Config::get_brain_url()).await?;
|
||||||
let mut accounts = Vec::new();
|
let mut accounts = Vec::new();
|
||||||
let mut grpc_stream = client.list_accounts(sign_request(brain::Empty {})?).await?.into_inner();
|
let mut grpc_stream = client.list_accounts(sign_request(brain::Empty {})?).await?.into_inner();
|
||||||
while let Some(stream_update) = grpc_stream.next().await {
|
while let Some(stream_update) = grpc_stream.next().await {
|
||||||
@ -296,7 +299,7 @@ pub async fn admin_list_accounts() -> Result<Vec<Account>, Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_vm(uuid: &str) -> Result<(), Error> {
|
pub async fn delete_vm(uuid: &str) -> Result<(), Error> {
|
||||||
let mut client = BrainCliClient::connect(Config::get_brain_url()).await?;
|
let mut client = BrainVmCliClient::connect(Config::get_brain_url()).await?;
|
||||||
let req = DeleteVmReq { uuid: uuid.to_string(), admin_pubkey: Config::get_detee_wallet()? };
|
let req = DeleteVmReq { uuid: uuid.to_string(), admin_pubkey: Config::get_detee_wallet()? };
|
||||||
let result = client.delete_vm(sign_request(req)?).await;
|
let result = client.delete_vm(sign_request(req)?).await;
|
||||||
match result {
|
match result {
|
||||||
@ -312,7 +315,7 @@ pub async fn delete_vm(uuid: &str) -> Result<(), Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn extend_vm(uuid: String, admin_pubkey: String, locked_nano: u64) -> Result<(), Error> {
|
pub async fn extend_vm(uuid: String, admin_pubkey: String, locked_nano: u64) -> Result<(), Error> {
|
||||||
let mut client = BrainCliClient::connect(Config::get_brain_url()).await?;
|
let mut client = BrainVmCliClient::connect(Config::get_brain_url()).await?;
|
||||||
let req = ExtendVmReq { admin_pubkey, uuid, locked_nano };
|
let req = ExtendVmReq { admin_pubkey, uuid, locked_nano };
|
||||||
let result = client.extend_vm(sign_request(req)?).await;
|
let result = client.extend_vm(sign_request(req)?).await;
|
||||||
match result {
|
match result {
|
||||||
@ -334,7 +337,7 @@ pub async fn extend_vm(uuid: String, admin_pubkey: String, locked_nano: u64) ->
|
|||||||
|
|
||||||
pub async fn update_vm(req: UpdateVmReq) -> Result<UpdateVmResp, Error> {
|
pub async fn update_vm(req: UpdateVmReq) -> Result<UpdateVmResp, Error> {
|
||||||
info!("Updating VM {req:?}");
|
info!("Updating VM {req:?}");
|
||||||
let mut client = BrainCliClient::connect(Config::get_brain_url()).await?;
|
let mut client = BrainVmCliClient::connect(Config::get_brain_url()).await?;
|
||||||
let result = client.update_vm(sign_request(req)?).await;
|
let result = client.update_vm(sign_request(req)?).await;
|
||||||
match result {
|
match result {
|
||||||
Ok(resp) => {
|
Ok(resp) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user