handle app state file and detee dir
This commit is contained in:
parent
2f84ee60d4
commit
414eacad2b
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -273,6 +273,7 @@ dependencies = [
|
||||
"detee-shared",
|
||||
"env_logger",
|
||||
"flate2",
|
||||
"home",
|
||||
"log",
|
||||
"prost",
|
||||
"prost-types",
|
||||
@ -534,6 +535,15 @@ version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||
|
||||
[[package]]
|
||||
name = "home"
|
||||
version = "0.5.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "589533453244b0995c858700322199b2becb13b627df2851f64a2775d024abcf"
|
||||
dependencies = [
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "http"
|
||||
version = "1.2.0"
|
||||
|
@ -22,6 +22,7 @@ log = "0.4.25"
|
||||
serde = "1.0.217"
|
||||
serde_json = "1.0.138"
|
||||
serde_yml = "0.0.12"
|
||||
home = "0.5.11"
|
||||
|
||||
[build-dependencies]
|
||||
tonic-build = "0.12.3"
|
||||
|
@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::container::delete_enclave;
|
||||
use crate::container::deploy_enclave;
|
||||
use crate::global::APP_CONFIG_DIR;
|
||||
use crate::global::app_config_dir;
|
||||
use crate::global::APP_NAME_PREFIX;
|
||||
use crate::utils::handle_package;
|
||||
use crate::utils::prepare_port_map;
|
||||
@ -100,7 +100,10 @@ impl App {
|
||||
}
|
||||
|
||||
fn write_config(&self) -> Result<()> {
|
||||
let mut file = File::create(APP_CONFIG_DIR.to_string() + &self.uuid + ".yaml")?;
|
||||
let app_config_dir = app_config_dir();
|
||||
std::fs::create_dir_all(&app_config_dir)?;
|
||||
|
||||
let mut file = File::create(app_config_dir + &self.uuid + ".yaml")?;
|
||||
file.write_all(serde_yml::to_string(self)?.as_bytes())?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -6,5 +6,11 @@ pub const PACKAGE_ARCHIVE_DIR_PATH: &str = "./enclave_archives";
|
||||
pub const PACKAGE_DIR_PATH: &str = "./enclaves";
|
||||
|
||||
pub const APP_NAME_PREFIX: &str = "dtpm";
|
||||
// TODO: handle this home directory properly
|
||||
pub const APP_CONFIG_DIR: &str = "~/.dtpm/app_daemon/";
|
||||
|
||||
const DETEE_DIR_ENV_NAME: &str = "DETEE_DIR";
|
||||
|
||||
// TODO: try lazy static later
|
||||
pub fn app_config_dir() -> String {
|
||||
let home = home::home_dir().unwrap().to_string_lossy().into_owned();
|
||||
std::env::var(DETEE_DIR_ENV_NAME).unwrap_or(format!("{home}/.detee/app_daemon/"))
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ use detee_shared::pb::brain::DaemonMessageApp;
|
||||
use detee_shared::pb::brain::MappedPort;
|
||||
use detee_shared::pb::brain::NewAppRes;
|
||||
use detee_shared::types::brain::AppDeployConfig;
|
||||
use global::APP_CONFIG_DIR;
|
||||
use global::app_config_dir;
|
||||
use log::info;
|
||||
use std::time::Duration;
|
||||
use tokio::sync::mpsc::Receiver;
|
||||
@ -106,10 +106,13 @@ impl AppHandler {
|
||||
}
|
||||
|
||||
async fn handle_del_app_req(&mut self, uuid: String) -> Result<()> {
|
||||
let content = std::fs::read_to_string(APP_CONFIG_DIR.to_string() + &uuid + ".yaml")?;
|
||||
let app_config_dir = app_config_dir();
|
||||
let app_handle_file_name = format!("{app_config_dir}{}.yaml", &uuid);
|
||||
let content = std::fs::read_to_string(&app_handle_file_name)?;
|
||||
let app_instance: App = serde_yml::from_str(&content)?;
|
||||
|
||||
app_instance.delete_app(&mut self.host_resource).await?;
|
||||
std::fs::remove_file(&app_handle_file_name)?;
|
||||
|
||||
if let Err(er) = cleanup_enclave_disk_and_package(uuid).await {
|
||||
log::error!("Failed to cleanup disk:\n{er}");
|
||||
|
Loading…
Reference in New Issue
Block a user