diff --git a/Cargo.lock b/Cargo.lock index 6a6d63a..3b6622c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1989,7 +1989,7 @@ dependencies = [ [[package]] name = "tiny-encrypt" -version = "1.9.5" +version = "1.9.6" dependencies = [ "aes-gcm-stream", "base64 0.22.1", diff --git a/Cargo.toml b/Cargo.toml index 2e3516a..c2f4ef8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tiny-encrypt" -version = "1.9.5" +version = "1.9.6" edition = "2021" license = "MIT" description = "A simple and tiny file encrypt tool" diff --git a/src/config.rs b/src/config.rs index 8d0fb76..9e6d895 100644 --- a/src/config.rs +++ b/src/config.rs @@ -3,7 +3,6 @@ use std::collections::HashMap; use std::path::Path; use std::path::PathBuf; use std::{env, fs}; - use rust_util::util_file::resolve_file_path; use rust_util::{debugging, opt_result, simple_error, warning, XResult}; use serde::{Deserialize, Serialize}; @@ -366,20 +365,34 @@ pub fn load_includes_and_merge(mut config: TinyEncryptConfig) -> TinyEncryptConf } } } - if let Some(profiles) = &mut config.profiles { - let all_key_ids = config.envelops.iter().map(|e| e.kid.clone()).collect::>(); - if profiles.contains_key("__all__") { - warning!("Key __all__ in profiles exists") - } else { - profiles.insert("__all__".to_string(), all_key_ids); - } - } + } + } + if let Some(profiles) = &mut config.profiles { + let all_key_ids = config.envelops.iter().map(|e| e.kid.clone()).collect::>(); + if profiles.contains_key("__all__") { + warning!("Key __all__ in profiles exists") + } else { + profiles.insert("__all__".to_string(), all_key_ids); } } config } pub fn search_include_configs(includes_path: &str) -> Vec { + let includes_path = if includes_path.starts_with("$") { + let includes_path_env_var = includes_path.chars().skip(1).collect::(); + match env::var(&includes_path_env_var) { + Ok(includes_path) => includes_path, + Err(e) => { + warning!("Cannot find env var: {}, failed: {}", &includes_path_env_var, e); + return vec![]; + } + } + } else { + includes_path.to_string() + }; + + let includes_path = &includes_path; let mut sub_configs = vec![]; let read_dir = match fs::read_dir(includes_path) { Ok(read_dir) => read_dir,