Skip to content

Commit

Permalink
Merge pull request #2886 from kate-goldenring/invert-variables-provid…
Browse files Browse the repository at this point in the history
…er-precedence

reduce environment variable provider precedence
  • Loading branch information
kate-goldenring authored Oct 17, 2024
2 parents 1154682 + e7c960f commit 2a9bf7c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions crates/variables/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,22 @@ use spin_factor_variables::runtime_config::RuntimeConfig;
/// Resolves a runtime configuration for the variables factor from a TOML table.
pub fn runtime_config_from_toml(table: &impl GetTomlValue) -> anyhow::Result<RuntimeConfig> {
// Always include the environment variable provider.
let mut providers = vec![Box::<EnvVariablesProvider>::default() as _];
let var_provider = vec![Box::<EnvVariablesProvider>::default() as _];
let value = table
.get("variables_provider")
.or_else(|| table.get("config_provider"));
let Some(array) = value else {
return Ok(RuntimeConfig { providers });
return Ok(RuntimeConfig {
providers: var_provider,
});
};

let provider_configs: Vec<VariableProviderConfiguration> = array.clone().try_into()?;
let new_providers = provider_configs
let mut providers = provider_configs
.into_iter()
.map(VariableProviderConfiguration::into_provider)
.collect::<anyhow::Result<Vec<_>>>()?;
providers.extend(new_providers);
providers.extend(var_provider);
Ok(RuntimeConfig { providers })
}

Expand Down

0 comments on commit 2a9bf7c

Please sign in to comment.