Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions openstack_sdk/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,23 +648,33 @@ pub fn find_config_files_specified_in_env() -> impl IntoIterator<Item = PathBuf>
configs
);
for candidate in configs.split(":") {
let path = PathBuf::from(candidate);
if path.is_file() {
results.push(path);
} else if path.is_dir() {
for config_prefix in ["clouds", "secure"] {
CONFIG_SUFFIXES
.iter()
.map(|y| path.join(format!("{}{}", config_prefix, y)))
.find(|path| path.is_file())
.inspect(|path| results.push(path.to_owned()));
if let Some(path) = expand_path(candidate) {
if path.is_file() {
results.push(path);
} else if path.is_dir() {
for config_prefix in ["clouds", "secure"] {
CONFIG_SUFFIXES
.iter()
.map(|y| path.join(format!("{}{}", config_prefix, y)))
.find(|path| path.is_file())
.inspect(|path| results.push(path.to_owned()));
}
}
}
}
}
results
}

/// Expand the `~` in the path with the HOME environment variable.
fn expand_path(path: &str) -> Option<PathBuf> {
if path.starts_with("~/") {
dirs::home_dir().map(|home| home.join(&path[2..]))
} else {
Some(PathBuf::from(path))
}
}

impl ConfigFile {
/// A builder to create a `ConfigFile` by specifying which files to load.
pub fn builder() -> ConfigFileBuilder {
Expand Down Expand Up @@ -698,6 +708,7 @@ impl ConfigFile {
.chain(find_secure_file())
.chain(secure.map(|path| path.as_ref().to_owned()))
{
trace!("Try load configuration file {:?}", path);
builder = match builder.add_source(&path) {
Ok(builder) => {
trace!("Using config file {path:?}");
Expand Down