Skip to content

Commit

Permalink
reduce environment variable provider precedence
Browse files Browse the repository at this point in the history
- inverts precedence of variables providers giving the environment variable
provider least precedence

Signed-off-by: Kate Goldenring <[email protected]>
  • Loading branch information
kate-goldenring committed Oct 14, 2024
1 parent ed8ab6f commit e7c960f
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 e7c960f

Please sign in to comment.