Resolve file macros after dropping root privileges

This commit is contained in:
mdecimus 2024-05-08 18:31:02 +02:00
parent 8a07a8133e
commit 53e6c352d8
3 changed files with 12 additions and 5 deletions

View file

@ -144,8 +144,8 @@ impl BootManager {
}
let cfg_local = config.keys.clone();
// Resolve macros
config.resolve_macros().await;
// Resolve environment macros
config.resolve_macros(&["env"]).await;
// Parser servers
let mut servers = Servers::parse(&mut config);
@ -153,6 +153,9 @@ impl BootManager {
// Bind ports and drop privileges
servers.bind_and_drop_priv(&mut config);
// Resolve file and configuration macros
config.resolve_macros(&["file", "cfg"]).await;
// Load stores
let mut stores = Stores::parse(&mut config).await;

View file

@ -76,7 +76,7 @@ impl ConfigManager {
keys: self.cfg_local.load().as_ref().clone(),
..Default::default()
};
config.resolve_macros().await;
config.resolve_all_macros().await;
self.extend_config(&mut config, prefix)
.await
.map(|_| config)

View file

@ -74,12 +74,16 @@ pub struct Rate {
pub type Result<T> = std::result::Result<T, String>;
impl Config {
pub async fn resolve_macros(&mut self) {
for macro_class in ["env", "file", "cfg"] {
pub async fn resolve_macros(&mut self, classes: &[&str]) {
for macro_class in classes {
self.resolve_macro_type(macro_class).await;
}
}
pub async fn resolve_all_macros(&mut self) {
self.resolve_macros(&["env", "file", "cfg"]).await;
}
async fn resolve_macro_type(&mut self, class: &str) {
let macro_start = format!("%{{{class}:");
let mut replacements = AHashMap::new();