detee-cli/src/sgx/config.rs
2025-06-25 19:20:31 +05:30

38 lines
1.0 KiB
Rust

// SPDX-License-Identifier: Apache-2.0
use detee_shared::sgx::types::brain::AppDeployConfig;
use detee_shared::sgx::types::dtpm::DtpmConfig;
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("Disk Access Error: {0}")]
DiskAccess(#[from] std::io::Error),
#[error("Yaml Error: {0}")]
SerdeYaml(#[from] serde_yaml::Error),
#[error("App launch config Error: {0}")]
DtpmConfig(#[from] detee_shared::sgx::types::dtpm::Error),
}
type Result<T> = std::result::Result<T, Error>;
#[allow(dead_code)]
pub trait DeteeCliExt {
fn from_path(path: &str) -> Result<Self>
where
Self: std::marker::Sized;
}
impl DeteeCliExt for AppDeployConfig {
fn from_path(path: &str) -> Result<Self> {
let config_str = std::fs::read_to_string(path)?;
Ok(serde_yaml::from_str(&config_str)?)
}
}
pub fn validate_yaml(file_path: &str) -> Result<DtpmConfig> {
let parsed_config = DtpmConfig::from_path(file_path)?;
let loaded_config = parsed_config.clone().load_data()?;
Ok(loaded_config)
}