diff --git a/src/config.rs b/src/config.rs index e3dba8c..b4a3800 100644 --- a/src/config.rs +++ b/src/config.rs @@ -27,8 +27,8 @@ use serde::{Deserialize, Serialize}; use serde_with::serde_as; use serde_with::{DisplayFromStr, skip_serializing_none}; use std::borrow::Cow; -use std::fs; use std::path::PathBuf; +use std::{env, fs}; use validator::{Validate, ValidationError}; #[skip_serializing_none] @@ -263,7 +263,7 @@ impl Config { /// println!("loaded config: {:?}", config); /// ``` pub fn load_config() -> Result { - let xdg_path = std::env::var_os("XDG_CONFIG_HOME").map(PathBuf::from); + let xdg_path = env::var_os("XDG_CONFIG_HOME").map(PathBuf::from); let mut config: Config = if let Some(base) = xdg_path.as_ref() { let app_dir = base.join("gman"); @@ -303,7 +303,7 @@ pub fn load_config() -> Result { /// Returns the configuration file path that `confy` will use for this app. pub fn get_config_file_path() -> Result { - if let Some(base) = std::env::var_os("XDG_CONFIG_HOME").map(PathBuf::from) { + if let Some(base) = env::var_os("XDG_CONFIG_HOME").map(PathBuf::from) { let dir = base.join("gman"); let yml = dir.join("config.yml"); let yaml = dir.join("config.yaml"); diff --git a/src/providers/local.rs b/src/providers/local.rs index 19b60ac..0931631 100644 --- a/src/providers/local.rs +++ b/src/providers/local.rs @@ -1,8 +1,8 @@ use anyhow::{Context, anyhow, bail}; use secrecy::{ExposeSecret, SecretString}; use std::collections::HashMap; -use std::fs; use std::path::{Path, PathBuf}; +use std::{env, fs}; use zeroize::Zeroize; use crate::config::ProviderConfig; @@ -197,6 +197,12 @@ impl SecretProvider for LocalProvider { } fn default_vault_path() -> Result { + let xdg_path = env::var_os("XDG_CONFIG_HOME").map(PathBuf::from); + + if let Some(xdg) = xdg_path { + return Ok(xdg.join("gman").join("vault.yml")); + } + confy::get_configuration_file_path("gman", "vault").with_context(|| "get config dir") }