1use crate::tools;
2use anyhow::Result;
3use config::Config;
4
5pub fn get() -> Result<Config> {
6 let home = tools::get_home()?;
7 let config_file = home.join(".config").join("ssh-vault").join("config.yml");
8
9 let builder = Config::builder()
10 .add_source(config::Environment::with_prefix("SSH_VAULT"))
11 .add_source(config::File::from(config_file));
12
13 match builder.build() {
14 Ok(config) => Ok(config),
15 Err(_) => Ok(Config::builder()
16 .add_source(config::Environment::with_prefix("SSH_VAULT"))
17 .build()?),
18 }
19}
20
21#[cfg(test)]
22mod tests {
23 use super::*;
24
25 #[test]
26 fn test_config_get() {
27 temp_env::with_vars([("SSH_VAULT_SSHKEYS_ONLINE", Some("localhost"))], || {
28 let config = get().unwrap();
29 assert_eq!(config.get_string("sshkeys_online").unwrap(), "localhost");
30 });
31 }
32}