delete app and list contracts

This commit is contained in:
Noor 2025-02-05 12:08:48 +05:30
parent 5ae69dee52
commit c7b4d40846
Signed by: noormohammedb
GPG Key ID: D83EFB8B3B967146
2 changed files with 36 additions and 38 deletions

1
Cargo.lock generated

@ -329,6 +329,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/noormohammedb/detee-shared#7f431e7180ef77e6f66f434866bebc90608a9c82"
dependencies = [ dependencies = [
"base64", "base64",
"prost", "prost",

@ -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_cli_server::BrainAppCli;
use detee_shared::pb::brain::brain_app_daemon_server::BrainAppDaemon; use detee_shared::pb::brain::brain_app_daemon_server::BrainAppDaemon;
use detee_shared::pb::brain::{ use detee_shared::pb::brain::{
AppContract, BrainMessageApp, NewAppReq, NewAppRes, RegisterAppNodeReq, AppContract, BrainMessageApp, DaemonMessageApp, DelAppReq, ListAppContractsReq, NewAppReq,
NewAppRes, RegisterAppNodeReq,
}; };
pub struct BrainDaemonMock { pub struct BrainDaemonMock {
@ -275,6 +276,8 @@ impl BrainCli for BrainCliMock {
#[tonic::async_trait] #[tonic::async_trait]
impl BrainAppCli for BrainAppCliMock { impl BrainAppCli for BrainAppCliMock {
type ListAppContractsStream = Pin<Box<dyn Stream<Item = Result<AppContract, Status>> + Send>>;
async fn create_app( async fn create_app(
&self, &self,
req: tonic::Request<NewAppReq>, req: tonic::Request<NewAppReq>,
@ -299,49 +302,42 @@ impl BrainAppCli for BrainAppCliMock {
} }
} }
/* async fn delete_app(
async fn delete_container(
&self, &self,
req: tonic::Request<ContainerFilters>, req: tonic::Request<DelAppReq>,
) -> Result<tonic::Response<detee_shared::pb::shared::Empty>, Status> { ) -> Result<tonic::Response<detee_shared::pb::brain::Empty>, Status> {
let req = req.into_inner(); let req = req.into_inner();
log::info!( log::info!("deleting container: {}", req.uuid.clone());
"deleting container: {}",
req.uuid.clone().unwrap_or_default()
);
if let Err(er) = self.data.send_del_container_req(req).await { if let Err(er) = self.data.send_del_container_req(req).await {
info!("Could not delete container: {er}"); info!("Could not delete container: {er}");
return Err(Status::not_found("Could not find container")); 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, &self,
req: tonic::Request<ContainerFilters>, req: tonic::Request<ListAppContractsReq>,
) -> Result<tonic::Response<ContainerListResp>, Status> { ) -> Result<tonic::Response<Self::ListAppContractsStream>, Status> {
let req_data = req.into_inner(); let req_data = req.into_inner();
dbg!(&req_data); dbg!(&req_data);
// let containers = self.data.find_app_contracts_by_admin_pubkey(&req_data.admin_pubkey).into(); let app_contracts = self
Ok(Response::new(ContainerListResp { .data
..Default::default() .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] #[tonic::async_trait]
@ -401,23 +397,25 @@ impl BrainAppDaemon for BrainAppDaemonMock {
)) ))
} }
/*
async fn daemon_messages( async fn daemon_messages(
&self, &self,
req: tonic::Request<Streaming<detee_shared::pb::daemon::DaemonMessage>>, req: tonic::Request<Streaming<DaemonMessageApp>>,
) -> Result<tonic::Response<detee_shared::pb::shared::Empty>, Status> { ) -> Result<tonic::Response<detee_shared::pb::brain::Empty>, Status> {
let mut req_stream = req.into_inner(); let mut req_stream = req.into_inner();
let mut pubkey = String::new(); let mut pubkey = String::new();
while let Some(daemon_message) = req_stream.next().await { while let Some(daemon_message) = req_stream.next().await {
match daemon_message { match daemon_message {
Ok(msg) => match msg.msg { Ok(msg) => match msg.msg {
Some(sgx_daemon_message::Msg::Pubkey(something)) => { Some(detee_shared::pb::brain::daemon_message_app::Msg::Pubkey(node_pubkey)) => {
pubkey = something.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; 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 => { None => {
dbg!("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 {}))
} }
*/
} }