|
|
@ -1,6 +1,6 @@
|
|
|
|
use crate::secret_validation::SecretFormat;
|
|
|
|
use crate::secret_validation::SecretFormat;
|
|
|
|
use crate::utils::error::MultihookResult;
|
|
|
|
use crate::utils::error::MultihookResult;
|
|
|
|
use config::File;
|
|
|
|
use config::{Config, File};
|
|
|
|
use lazy_static::lazy_static;
|
|
|
|
use lazy_static::lazy_static;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::collections::HashMap;
|
|
|
@ -64,27 +64,24 @@ fn load_settings() -> MultihookResult<Settings> {
|
|
|
|
)?;
|
|
|
|
)?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let mut settings = config::Config::default();
|
|
|
|
let settings = Config::builder()
|
|
|
|
settings
|
|
|
|
.add_source(
|
|
|
|
.merge(
|
|
|
|
|
|
|
|
glob::glob(&format!("{}/*.toml", config_dir.to_string_lossy()))
|
|
|
|
glob::glob(&format!("{}/*.toml", config_dir.to_string_lossy()))
|
|
|
|
.unwrap()
|
|
|
|
.unwrap()
|
|
|
|
.map(|path| File::from(path.unwrap()))
|
|
|
|
.map(|path| File::from(path.unwrap()))
|
|
|
|
.collect::<Vec<_>>(),
|
|
|
|
.collect::<Vec<_>>(),
|
|
|
|
)?
|
|
|
|
)
|
|
|
|
.merge(config::Environment::with_prefix("MULTIHOOK"))?;
|
|
|
|
.add_source(config::Environment::with_prefix("MULTIHOOK"))
|
|
|
|
|
|
|
|
.add_source(File::from(PathBuf::from(".multihook.toml")))
|
|
|
|
|
|
|
|
.build()?;
|
|
|
|
|
|
|
|
|
|
|
|
let settings: Settings = settings.try_into()?;
|
|
|
|
let settings: Settings = settings.try_deserialize()?;
|
|
|
|
|
|
|
|
|
|
|
|
Ok(settings)
|
|
|
|
Ok(settings)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn write_toml_pretty<T: Serialize>(path: &PathBuf, value: &T) -> MultihookResult<()> {
|
|
|
|
fn write_toml_pretty<T: Serialize>(path: &PathBuf, value: &T) -> MultihookResult<()> {
|
|
|
|
let mut buf_str = String::new();
|
|
|
|
fs::write(path, toml::to_string_pretty(value)?)?;
|
|
|
|
let mut serializer = toml::Serializer::pretty(&mut buf_str);
|
|
|
|
|
|
|
|
serializer.pretty_array(true);
|
|
|
|
|
|
|
|
value.serialize(&mut serializer)?;
|
|
|
|
|
|
|
|
fs::write(path, buf_str.as_bytes())?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|