Skip to main content

EnvOAuthConfig

Struct EnvOAuthConfig 

Source
#[non_exhaustive]
pub struct EnvOAuthConfig { pub config: OAuthConfig, pub problems: Vec<String>, /* private fields */ }
Available on crate feature 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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§config: OAuthConfig

The 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

Source

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.

Source

pub fn prefix(&self) -> &str

The variable prefix this config was loaded with, which resolve also uses to name settings in problems.

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EnvOAuthConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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).

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more