#[non_exhaustive]pub struct EnvOAuthConfig {
pub config: OAuthConfig,
pub problems: Vec<String>,
/* private fields */
}env only.Expand description
An OAuthConfig read from the environment but not yet resolved, with
the problems the loader itself found (variables that failed to load,
values that failed to parse).
Returned by unresolved_oauth_config_from_env so an application can
apply its own defaults to config before
resolve validates it — the same hook a config-file
application has between deserializing an OAuthConfig and calling
OAuthConfig::resolve. For example, to require api:read unless the
operator named a required scope:
use oauth_resource_server::env::unresolved_oauth_config_from_env;
if let Some(mut loaded) = unresolved_oauth_config_from_env("MYAPP_OAUTH_") {
let cfg = &mut loaded.config;
if cfg.required_scope.is_none() && cfg.required_scopes.is_empty() {
cfg.required_scope = Some("api:read".into());
}
let resolved = loaded.resolve()?;
}A default set this way is validated by resolve like any other value, and
is included in the scopes_supported default below.
config.scopes_supported is None when
<PREFIX>SCOPES_SUPPORTED was unset (or failed to load);
OAuthConfig::resolve turns None into the required scopes as they
stand at that point, application defaults included. Set it to Some(..) —
Some(vec![]) for an explicitly empty list — to override that.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.config: OAuthConfigThe loaded config, enabled: true, every unset field at its
OAuthConfig::default value. Free to modify before
resolve.
problems: Vec<String>Problems the loader found, each naming its variable. Reported by
resolve ahead of any it finds itself; resolve
fails whenever this is non-empty.
Kept for compatibility; the structured form is
problem_details, filled from the same list at
load time. Editing this field in place (an application appending its
own problem, say) does not update problem_details(), but
resolve reports whatever this field holds.
Implementations§
Source§impl EnvOAuthConfig
impl EnvOAuthConfig
Sourcepub fn problem_details(&self) -> &[ConfigProblem]
pub fn problem_details(&self) -> &[ConfigProblem]
The loader’s problems as structured ConfigProblems, in the order
problems lists them: ProblemKind::EnvLoad for a
variable or _FILE that could not be read, ProblemKind::EnvParse
for a value that could not be parsed. Match on the kind, not the text.
Fixed at load time: editing the public problems field in place does
not change it, so this can be stale until resolve,
which reconciles the two. keys() of an EnvLoad problem is the
variable and its _FILE twin when both were set, else the _FILE
variable whose file could not be used.
Sourcepub fn prefix(&self) -> &str
pub fn prefix(&self) -> &str
The variable prefix this config was loaded with, which
resolve also uses to name settings in problems.
Sourcepub fn resolve(self) -> Result<Option<ResolvedOAuthConfig>, ConfigError>
pub fn resolve(self) -> Result<Option<ResolvedOAuthConfig>, ConfigError>
OAuthConfig::resolve with KeyNaming::Env of this prefix,
failing with the loader’s problems followed by
resolve’s own if there are any of either.
Ok(None) only if the application set
config.enabled to false and the loader found no
problems.
§Errors
A ConfigError when problems is non-empty or
OAuthConfig::resolve finds any, listing the loader’s first. The
public problems decides what is reported: an entry
the application edited or added surfaces in the resulting
ConfigError as ProblemKind::Other, while an untouched one keeps
its kind and keys. problem_details may be
stale before this call; the reconciliation happens inside it.
Trait Implementations§
Source§impl Clone for EnvOAuthConfig
impl Clone for EnvOAuthConfig
Source§impl Debug for EnvOAuthConfig
impl Debug for EnvOAuthConfig
impl Eq for EnvOAuthConfig
Source§impl PartialEq for EnvOAuthConfig
Equality covers every field except the structured details, which are
derived from problems (this type derived PartialEq before they existed).
impl PartialEq for EnvOAuthConfig
Equality covers every field except the structured details, which are
derived from problems (this type derived PartialEq before they existed).