features: app engine #1
| @ -1,5 +1,5 @@ | |||||||
| use super::Error; | use super::Error; | ||||||
| use crate::constants::{ACCOUNT, ACTIVE_APP, APP_NODE, NEW_APP_REQ}; | use crate::constants::{ACCOUNT, ACTIVE_APP, APP_NODE, DELETED_APP, NEW_APP_REQ}; | ||||||
| use crate::db; | use crate::db; | ||||||
| use crate::db::general::Report; | use crate::db::general::Report; | ||||||
| use crate::old_brain; | use crate::old_brain; | ||||||
| @ -158,24 +158,47 @@ impl AppNodeWithReports { | |||||||
| 
 | 
 | ||||||
| #[derive(Debug, Serialize, Deserialize)] | #[derive(Debug, Serialize, Deserialize)] | ||||||
| pub struct ActiveApp { | pub struct ActiveApp { | ||||||
|     id: RecordId, |     pub id: RecordId, | ||||||
|     #[serde(rename = "in")] |     #[serde(rename = "in")] | ||||||
|     admin: RecordId, |     pub admin: RecordId, | ||||||
|     #[serde(rename = "out")] |     #[serde(rename = "out")] | ||||||
|     app_node: RecordId, |     pub app_node: RecordId, | ||||||
|     app_name: String, |     pub app_name: String, | ||||||
|     mapped_ports: Vec<(u64, u64)>, |     pub mapped_ports: Vec<(u64, u64)>, | ||||||
|     host_ipv4: String, |     pub host_ipv4: String, | ||||||
|     vcpus: u64, |     pub vcpus: u64, | ||||||
|     memory_mb: u64, |     pub memory_mb: u64, | ||||||
|     disk_size_gb: u64, |     pub disk_size_gb: u64, | ||||||
|     created_at: Datetime, |     pub created_at: Datetime, | ||||||
|     price_per_unit: u64, |     pub price_per_unit: u64, | ||||||
|     locked_nano: u64, |     pub locked_nano: u64, | ||||||
|     collected_at: Datetime, |     pub collected_at: Datetime, | ||||||
|     mr_enclave: String, |     pub mr_enclave: String, | ||||||
|     package_url: String, |     pub package_url: String, | ||||||
|     hratls_pubkey: String, |     pub hratls_pubkey: String, | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl From<ActiveApp> for DeletedApp { | ||||||
|  |     fn from(value: ActiveApp) -> Self { | ||||||
|  |         Self { | ||||||
|  |             id: value.id, | ||||||
|  |             admin: value.admin, | ||||||
|  |             app_node: value.app_node, | ||||||
|  |             app_name: value.app_name, | ||||||
|  |             mapped_ports: value.mapped_ports, | ||||||
|  |             host_ipv4: value.host_ipv4, | ||||||
|  |             vcpus: value.vcpus, | ||||||
|  |             memory_mb: value.memory_mb, | ||||||
|  |             disk_size_gb: value.disk_size_gb, | ||||||
|  |             created_at: value.created_at, | ||||||
|  |             price_per_unit: value.price_per_unit, | ||||||
|  |             locked_nano: value.locked_nano, | ||||||
|  |             collected_at: value.collected_at, | ||||||
|  |             mr_enclave: value.mr_enclave, | ||||||
|  |             package_url: value.package_url, | ||||||
|  |             hratls_pubkey: value.hratls_pubkey, | ||||||
|  |         } | ||||||
|  |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl ActiveApp { | impl ActiveApp { | ||||||
| @ -208,6 +231,17 @@ impl ActiveApp { | |||||||
| 
 | 
 | ||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     pub async fn delete(db: &Surreal<Client>, id: &str) -> Result<bool, Error> { | ||||||
|  |         let deleted_app: Option<Self> = db.delete((ACTIVE_APP, id)).await?; | ||||||
|  |         if let Some(deleted_app) = deleted_app { | ||||||
|  |             let deleted_app: DeletedApp = deleted_app.into(); | ||||||
|  |             let _: Vec<DeletedApp> = db.insert(DELETED_APP).relation(deleted_app).await?; | ||||||
|  |             Ok(true) | ||||||
|  |         } else { | ||||||
|  |             Ok(false) | ||||||
|  |         } | ||||||
|  |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Serialize, Deserialize)] | #[derive(Debug, Serialize, Deserialize)] | ||||||
|  | |||||||
| @ -1,4 +1,5 @@ | |||||||
| use crate::constants::{ACCOUNT, APP_NODE}; | use crate::constants::{ACCOUNT, APP_NODE}; | ||||||
|  | use crate::db::app::ActiveApp; | ||||||
| use crate::db::prelude as db; | use crate::db::prelude as db; | ||||||
| use crate::grpc::{check_sig_from_parts, check_sig_from_req}; | use crate::grpc::{check_sig_from_parts, check_sig_from_req}; | ||||||
| use detee_shared::app_proto::brain_app_cli_server::BrainAppCli; | use detee_shared::app_proto::brain_app_cli_server::BrainAppCli; | ||||||
| @ -37,8 +38,7 @@ impl BrainAppDaemon for AppDaemonServer { | |||||||
|     async fn register_app_node( |     async fn register_app_node( | ||||||
|         &self, |         &self, | ||||||
|         req: tonic::Request<RegisterAppNodeReq>, |         req: tonic::Request<RegisterAppNodeReq>, | ||||||
|     ) -> Result<tonic::Response<<Self as BrainAppDaemon>::RegisterAppNodeStream>, tonic::Status> |     ) -> Result<tonic::Response<<Self as BrainAppDaemon>::RegisterAppNodeStream>, Status> { | ||||||
|     { |  | ||||||
|         let req = check_sig_from_req(req)?; |         let req = check_sig_from_req(req)?; | ||||||
|         info!("Starting app_node registration process for {:?}", req); |         info!("Starting app_node registration process for {:?}", req); | ||||||
| 
 | 
 | ||||||
| @ -77,7 +77,7 @@ impl BrainAppDaemon for AppDaemonServer { | |||||||
|     async fn brain_messages( |     async fn brain_messages( | ||||||
|         &self, |         &self, | ||||||
|         req: tonic::Request<DaemonAuth>, |         req: tonic::Request<DaemonAuth>, | ||||||
|     ) -> Result<tonic::Response<<Self as BrainAppDaemon>::BrainMessagesStream>, tonic::Status> { |     ) -> Result<tonic::Response<<Self as BrainAppDaemon>::BrainMessagesStream>, Status> { | ||||||
|         let auth = req.into_inner(); |         let auth = req.into_inner(); | ||||||
|         let pubkey = auth.pubkey.clone(); |         let pubkey = auth.pubkey.clone(); | ||||||
|         check_sig_from_parts( |         check_sig_from_parts( | ||||||
| @ -114,7 +114,7 @@ impl BrainAppDaemon for AppDaemonServer { | |||||||
|     async fn daemon_messages( |     async fn daemon_messages( | ||||||
|         &self, |         &self, | ||||||
|         req: tonic::Request<Streaming<DaemonMessageApp>>, |         req: tonic::Request<Streaming<DaemonMessageApp>>, | ||||||
|     ) -> Result<tonic::Response<Empty>, tonic::Status> { |     ) -> Result<tonic::Response<Empty>, Status> { | ||||||
|         let mut req_stream = req.into_inner(); |         let mut req_stream = req.into_inner(); | ||||||
|         let pubkey: String; |         let pubkey: String; | ||||||
|         if let Some(Ok(msg)) = req_stream.next().await { |         if let Some(Ok(msg)) = req_stream.next().await { | ||||||
| @ -186,7 +186,7 @@ impl BrainAppCli for AppCliServer { | |||||||
|     async fn deploy_app( |     async fn deploy_app( | ||||||
|         &self, |         &self, | ||||||
|         req: tonic::Request<detee_shared::app_proto::NewAppReq>, |         req: tonic::Request<detee_shared::app_proto::NewAppReq>, | ||||||
|     ) -> Result<tonic::Response<detee_shared::app_proto::NewAppRes>, tonic::Status> { |     ) -> Result<tonic::Response<detee_shared::app_proto::NewAppRes>, Status> { | ||||||
|         let req = check_sig_from_req(req)?; |         let req = check_sig_from_req(req)?; | ||||||
|         info!("deploy_app process starting for {:?}", req); |         info!("deploy_app process starting for {:?}", req); | ||||||
| 
 | 
 | ||||||
| @ -196,17 +196,19 @@ impl BrainAppCli for AppCliServer { | |||||||
|     async fn delete_app( |     async fn delete_app( | ||||||
|         &self, |         &self, | ||||||
|         req: tonic::Request<DelAppReq>, |         req: tonic::Request<DelAppReq>, | ||||||
|     ) -> Result<tonic::Response<detee_shared::common_proto::Empty>, tonic::Status> { |     ) -> Result<tonic::Response<Empty>, Status> { | ||||||
|         let req = check_sig_from_req(req)?; |         let req = check_sig_from_req(req)?; | ||||||
|         info!("delete_app process starting for {:?}", req); |         info!("delete_app process starting for {:?}", req); | ||||||
| 
 |         match ActiveApp::delete(&self.db, &req.uuid).await? { | ||||||
|         todo!() |             true => Ok(Response::new(Empty {})), | ||||||
|  |             false => Err(Status::not_found(format!("Could not find App contract {}", &req.uuid))), | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async fn list_app_contracts( |     async fn list_app_contracts( | ||||||
|         &self, |         &self, | ||||||
|         req: tonic::Request<ListAppContractsReq>, |         req: tonic::Request<ListAppContractsReq>, | ||||||
|     ) -> Result<tonic::Response<<Self as BrainAppCli>::ListAppContractsStream>, tonic::Status> { |     ) -> Result<tonic::Response<<Self as BrainAppCli>::ListAppContractsStream>, Status> { | ||||||
|         let req = check_sig_from_req(req)?; |         let req = check_sig_from_req(req)?; | ||||||
|         info!("list_app_contracts process starting for {:?}", req); |         info!("list_app_contracts process starting for {:?}", req); | ||||||
| 
 | 
 | ||||||
| @ -245,7 +247,7 @@ impl BrainAppCli for AppCliServer { | |||||||
|     async fn list_app_nodes( |     async fn list_app_nodes( | ||||||
|         &self, |         &self, | ||||||
|         req: tonic::Request<AppNodeFilters>, |         req: tonic::Request<AppNodeFilters>, | ||||||
|     ) -> Result<tonic::Response<<Self as BrainAppCli>::ListAppNodesStream>, tonic::Status> { |     ) -> Result<tonic::Response<<Self as BrainAppCli>::ListAppNodesStream>, Status> { | ||||||
|         let req = check_sig_from_req(req)?; |         let req = check_sig_from_req(req)?; | ||||||
|         info!("list_app_nodes process starting for {:?}", req); |         info!("list_app_nodes process starting for {:?}", req); | ||||||
|         let app_nodes = db::AppNodeWithReports::find_by_filters(&self.db, req, false).await?; |         let app_nodes = db::AppNodeWithReports::find_by_filters(&self.db, req, false).await?; | ||||||
| @ -262,7 +264,7 @@ impl BrainAppCli for AppCliServer { | |||||||
|     async fn get_one_app_node( |     async fn get_one_app_node( | ||||||
|         &self, |         &self, | ||||||
|         req: tonic::Request<AppNodeFilters>, |         req: tonic::Request<AppNodeFilters>, | ||||||
|     ) -> Result<tonic::Response<AppNodeListResp>, tonic::Status> { |     ) -> Result<tonic::Response<AppNodeListResp>, Status> { | ||||||
|         let req = check_sig_from_req(req)?; |         let req = check_sig_from_req(req)?; | ||||||
|         info!("get_one_app_node process starting for {:?}", req); |         info!("get_one_app_node process starting for {:?}", req); | ||||||
|         let app_node = db::AppNodeWithReports::find_by_filters(&self.db, req, true) |         let app_node = db::AppNodeWithReports::find_by_filters(&self.db, req, true) | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user