forked from ghe0/brain-mock
delete app and list contracts
This commit is contained in:
parent
5ae69dee52
commit
c7b4d40846
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -329,6 +329,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "detee-shared"
|
||||
version = "0.1.0"
|
||||
source = "git+ssh://git@gitea.detee.cloud/noormohammedb/detee-shared#7f431e7180ef77e6f66f434866bebc90608a9c82"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"prost",
|
||||
|
73
src/grpc.rs
73
src/grpc.rs
@ -18,7 +18,8 @@ use tonic::{Request, Response, Status, Streaming};
|
||||
use detee_shared::pb::brain::brain_app_cli_server::BrainAppCli;
|
||||
use detee_shared::pb::brain::brain_app_daemon_server::BrainAppDaemon;
|
||||
use detee_shared::pb::brain::{
|
||||
AppContract, BrainMessageApp, NewAppReq, NewAppRes, RegisterAppNodeReq,
|
||||
AppContract, BrainMessageApp, DaemonMessageApp, DelAppReq, ListAppContractsReq, NewAppReq,
|
||||
NewAppRes, RegisterAppNodeReq,
|
||||
};
|
||||
|
||||
pub struct BrainDaemonMock {
|
||||
@ -275,6 +276,8 @@ impl BrainCli for BrainCliMock {
|
||||
|
||||
#[tonic::async_trait]
|
||||
impl BrainAppCli for BrainAppCliMock {
|
||||
type ListAppContractsStream = Pin<Box<dyn Stream<Item = Result<AppContract, Status>> + Send>>;
|
||||
|
||||
async fn create_app(
|
||||
&self,
|
||||
req: tonic::Request<NewAppReq>,
|
||||
@ -299,49 +302,42 @@ impl BrainAppCli for BrainAppCliMock {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
async fn delete_container(
|
||||
async fn delete_app(
|
||||
&self,
|
||||
req: tonic::Request<ContainerFilters>,
|
||||
) -> Result<tonic::Response<detee_shared::pb::shared::Empty>, Status> {
|
||||
req: tonic::Request<DelAppReq>,
|
||||
) -> Result<tonic::Response<detee_shared::pb::brain::Empty>, Status> {
|
||||
let req = req.into_inner();
|
||||
log::info!(
|
||||
"deleting container: {}",
|
||||
req.uuid.clone().unwrap_or_default()
|
||||
);
|
||||
log::info!("deleting container: {}", req.uuid.clone());
|
||||
if let Err(er) = self.data.send_del_container_req(req).await {
|
||||
info!("Could not delete container: {er}");
|
||||
return Err(Status::not_found("Could not find container"));
|
||||
};
|
||||
|
||||
Ok(Response::new(detee_shared::pb::shared::Empty {}))
|
||||
Ok(Response::new(detee_shared::pb::brain::Empty {}))
|
||||
}
|
||||
|
||||
async fn list_containers(
|
||||
async fn list_app_contracts(
|
||||
&self,
|
||||
req: tonic::Request<ContainerFilters>,
|
||||
) -> Result<tonic::Response<ContainerListResp>, Status> {
|
||||
req: tonic::Request<ListAppContractsReq>,
|
||||
) -> Result<tonic::Response<Self::ListAppContractsStream>, Status> {
|
||||
let req_data = req.into_inner();
|
||||
dbg!(&req_data);
|
||||
|
||||
// let containers = self.data.find_app_contracts_by_admin_pubkey(&req_data.admin_pubkey).into();
|
||||
Ok(Response::new(ContainerListResp {
|
||||
..Default::default()
|
||||
}))
|
||||
let app_contracts = self
|
||||
.data
|
||||
.find_app_contracts_by_admin_pubkey(&req_data.admin_pubkey);
|
||||
|
||||
let (tx, rx) = mpsc::channel(6);
|
||||
tokio::spawn(async move {
|
||||
for contract in app_contracts {
|
||||
let _ = tx.send(contract.into()).await;
|
||||
}
|
||||
});
|
||||
let output_stream = ReceiverStream::new(rx).map(Ok);
|
||||
Ok(Response::new(
|
||||
Box::pin(output_stream) as Self::ListAppContractsStream
|
||||
))
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
// async fn inspect_container(
|
||||
// &self,
|
||||
// req: tonic::Request<detee_shared::pb::shared::Uuid>,
|
||||
// ) -> Result<tonic::Response<ContainerInspectResp>, Status> {
|
||||
// dbg!(req);
|
||||
// Ok(Response::new(ContainerInspectResp {
|
||||
// ..Default::default()
|
||||
// }))
|
||||
// }
|
||||
}
|
||||
|
||||
#[tonic::async_trait]
|
||||
@ -401,23 +397,25 @@ impl BrainAppDaemon for BrainAppDaemonMock {
|
||||
))
|
||||
}
|
||||
|
||||
/*
|
||||
async fn daemon_messages(
|
||||
&self,
|
||||
req: tonic::Request<Streaming<detee_shared::pb::daemon::DaemonMessage>>,
|
||||
) -> Result<tonic::Response<detee_shared::pb::shared::Empty>, Status> {
|
||||
req: tonic::Request<Streaming<DaemonMessageApp>>,
|
||||
) -> Result<tonic::Response<detee_shared::pb::brain::Empty>, Status> {
|
||||
let mut req_stream = req.into_inner();
|
||||
let mut pubkey = String::new();
|
||||
|
||||
while let Some(daemon_message) = req_stream.next().await {
|
||||
match daemon_message {
|
||||
Ok(msg) => match msg.msg {
|
||||
Some(sgx_daemon_message::Msg::Pubkey(something)) => {
|
||||
pubkey = something.pubkey;
|
||||
Some(detee_shared::pb::brain::daemon_message_app::Msg::Pubkey(node_pubkey)) => {
|
||||
pubkey = node_pubkey;
|
||||
}
|
||||
Some(sgx_daemon_message::Msg::NewContainerResp(new_cont)) => {
|
||||
Some(detee_shared::pb::brain::daemon_message_app::Msg::NewAppRes(new_cont)) => {
|
||||
self.data.send_new_container_resp(new_cont).await;
|
||||
}
|
||||
Some(detee_shared::pb::brain::daemon_message_app::Msg::AppNodeResources(_)) => {
|
||||
todo!("AppNodeResources not implemented yet");
|
||||
}
|
||||
None => {
|
||||
dbg!("None");
|
||||
}
|
||||
@ -430,7 +428,6 @@ impl BrainAppDaemon for BrainAppDaemonMock {
|
||||
//
|
||||
}
|
||||
|
||||
Ok(Response::new(detee_shared::pb::shared::Empty {}))
|
||||
Ok(Response::new(detee_shared::pb::brain::Empty {}))
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user