Skip to main content

CredentialResolver

Struct CredentialResolver 

Source
pub struct CredentialResolver { /* private fields */ }
Expand description

Resolves the credential for a single command invocation, memoizing the result.

Resolution — including any interactive browser/OAuth flow — runs once for a given scope set: a handler and an authorizer that both ask share a single resolution, and the engine resolves it up front for AuthRequirement::Required commands. For Optional commands resolution is deferred until a handler or authorizer calls resolve or try_resolve, and --schema/--dry-run short-circuit before any resolution happens.

resolve_with_scopes may trigger an additional resolution when it needs scopes the memoized credential does not yet cover (OAuth scope step-up); a scope-aware provider then re-authenticates for the wider set. Resolutions are serialized, so concurrent callers never launch overlapping interactive flows.

The resolved credential is memoized: callers that need no new scopes share a single resolution. Clones share the same underlying state, so the engine can observe (via peek) whatever a handler resolved.

Implementations§

Source§

impl CredentialResolver

Source

pub async fn resolve(&self) -> Result<Credential>

Resolves the credential, memoizing the result after the first success.

§Errors

Returns an error when the command is marked no_auth (such commands have no credential), or when the auth provider fails to produce one.

Source

pub async fn resolve_with_scopes(&self, extra: &[String]) -> Result<Credential>

Resolves a credential that additionally covers extra scopes (on top of the command’s declared CommandMeta::scopes).

Used by handlers whose required scopes are only known at runtime (for example a generic api call that derives scopes from the target endpoint). A scope-aware auth provider re-authenticates when the cached token does not already cover the requested set.

§Ordering with the transport injector

The HTTP transport’s bearer injector resolves its token through the provider’s scope-unaware path and caches the first token it sees for the injector’s lifetime. So when a handler both steps up scopes and makes HTTP calls through that injector, call resolve_with_scopes (or CommandContext::credential_with_scopes) before the first request: that populates the provider cache with the wider-scoped token, which the injector then picks up. Resolving after the injector’s first inject would send the narrower token.

§Errors

Returns an error when the command is marked no_auth, or when the auth provider fails to produce a credential.

Source

pub async fn try_resolve(&self) -> Result<Option<Credential>>

Resolves the credential when one is available.

Returns Ok(None) for no-auth commands, Ok(Some(_)) on success, and propagates the provider error on failure. Use this for commands whose auth is genuinely optional; most commands should call resolve instead.

§Errors

Propagates the auth provider error when resolution is attempted and fails.

Source

pub fn peek(&self) -> Option<&Credential>

Returns the memoized credential without triggering resolution.

Yields None until something resolves the credential. Used by the engine to record identity in audit/activity output after a handler runs.

Trait Implementations§

Source§

impl Clone for CredentialResolver

Source§

fn clone(&self) -> CredentialResolver

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 CredentialResolver

Source§

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

Formats the value using the given formatter. 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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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