Skip to content

Commit

Permalink
Use env::split_paths and env::var_os
Browse files Browse the repository at this point in the history
  • Loading branch information
kazk committed Feb 10, 2021
1 parent 01e89fb commit 6fa4990
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
14 changes: 6 additions & 8 deletions kube/src/config/file_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,16 @@ impl Kubeconfig {
}

/// Create `Kubeconfig` from `KUBECONFIG` environment variable.
/// Supports list of files to be merged. `KUBECONFIG` value must contain a valid unicode data.
/// Supports list of files to be merged.
///
/// # Panics
///
/// Panics if `KUBECONFIG` value contains the NUL character.
pub fn from_env() -> Result<Option<Self>> {
match std::env::var(KUBECONFIG) {
Ok(value) => {
let paths = value
.split(if cfg!(windows) { ';' } else { ':' })
.filter(|s| !s.is_empty())
match std::env::var_os(KUBECONFIG) {
Some(value) => {
let paths = std::env::split_paths(&value)
.filter(|p| !p.as_os_str().is_empty())
.collect::<Vec<_>>();
if paths.is_empty() {
return Ok(None);
Expand All @@ -208,8 +207,7 @@ impl Kubeconfig {
Ok(Some(merged))
}

Err(std::env::VarError::NotPresent) => Ok(None),
Err(std::env::VarError::NotUnicode(_)) => Err(ConfigError::InvalidKubeconfigEnv.into()),
None => Ok(None),
}
}

Expand Down
2 changes: 0 additions & 2 deletions kube/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ pub enum ConfigError {

#[error("Unable to find path of kubeconfig")]
NoKubeconfigPath,
#[error("KUBECONFIG environment variable must contain a valid unicode data")]
InvalidKubeconfigEnv,

#[error("Failed to decode base64: {0}")]
Base64Decode(#[source] base64::DecodeError),
Expand Down

0 comments on commit 6fa4990

Please sign in to comment.