feat: implement encryption guard for secure data handling in YAML operations

This commit is contained in:
Tunglies
2025-11-05 15:05:19 +08:00
parent 7145096729
commit 8c3e9c9ea9
4 changed files with 54 additions and 180 deletions
+3 -1
View File
@@ -1,4 +1,4 @@
use crate::{enhance::seq::SeqMap, logging, utils::logging::Type};
use crate::{config::EncryptionGuard, enhance::seq::SeqMap, logging, utils::logging::Type};
use anyhow::{Context, Result, anyhow, bail};
use nanoid::nanoid;
use serde::{Serialize, de::DeserializeOwned};
@@ -11,6 +11,7 @@ pub async fn read_yaml<T: DeserializeOwned>(path: &PathBuf) -> Result<T> {
bail!("file not found \"{}\"", path.display());
}
let _guard = EncryptionGuard::new();
let yaml_str = tokio::fs::read_to_string(path).await?;
Ok(serde_yaml_ng::from_str::<T>(&yaml_str)?)
@@ -65,6 +66,7 @@ pub async fn save_yaml<T: Serialize + Sync>(
data: &T,
prefix: Option<&str>,
) -> Result<()> {
let _guard = EncryptionGuard::new();
let data_str = serde_yaml_ng::to_string(data)?;
let yaml_str = match prefix {