configbuilder_pattern_substitution/value_resolver.rs
1use crate::SubstitutionError;
2
3/// Resolves a substitution variable name to its value.
4///
5/// [`Substituter`] applies this after [`SubstitutionPolicy`] has approved a
6/// variable name, decoupling *which names are allowed* from *where their
7/// values come from*. The default implementor is [`EnvValueResolver`],
8/// backed by `std::env::var`; downstream consumers may supply their own
9/// implementation to source values from a secrets backend (Vault, AWS
10/// Secrets Manager, etc.) instead of the process environment.
11///
12/// [`Substituter`]: crate::Substituter
13/// [`SubstitutionPolicy`]: crate::SubstitutionPolicy
14/// [`EnvValueResolver`]: crate::EnvValueResolver
15pub trait ValueResolver: Send + Sync {
16 /// Resolve `var_name` to its value.
17 ///
18 /// `location` identifies the config file and key the placeholder
19 /// appeared in, for inclusion in the returned error on failure.
20 ///
21 /// # Errors
22 ///
23 /// Returns [`SubstitutionError`] when the variable cannot be resolved
24 /// (not found, access denied, backend unavailable, etc.).
25 fn resolve(&self, var_name: &str, location: &str) -> Result<String, SubstitutionError>;
26}