ProvideCredentialChain

Struct ProvideCredentialChain 

Source
pub struct ProvideCredentialChain<C> { /* private fields */ }
Expand description

A chain of credential providers that will be tried in order.

This is a generic implementation that can be used by any service to chain multiple credential providers together. The chain will try each provider in order until one returns credentials or all providers have been exhausted.

§Example

use reqsign_core::{ProvideCredentialChain, Context, ProvideCredential, Result};
use async_trait::async_trait;

#[derive(Debug)]
struct MyCredential {
    token: String,
}

#[derive(Debug)]
struct EnvironmentProvider;

#[async_trait]
impl ProvideCredential for EnvironmentProvider {
    type Credential = MyCredential;

    async fn provide_credential(&self, ctx: &Context) -> Result<Option<Self::Credential>> {
        // Implementation
        Ok(None)
    }
}

let chain = ProvideCredentialChain::new()
    .push(EnvironmentProvider);

let credentials = chain.provide_credential(&ctx).await;

Implementations§

Source§

impl<C> ProvideCredentialChain<C>
where C: Send + Sync + Unpin + 'static,

Source

pub fn new() -> Self

Create a new empty credential provider chain.

Source

pub fn push( self, provider: impl ProvideCredential<Credential = C> + 'static, ) -> Self

Add a credential provider to the chain.

Source

pub fn push_front( self, provider: impl ProvideCredential<Credential = C> + 'static, ) -> Self

Add a credential provider to the front of the chain.

This provider will be tried first before all existing providers.

Source

pub fn from_vec( providers: Vec<Box<dyn ProvideCredential<Credential = C>>>, ) -> Self

Create a credential provider chain from a vector of providers.

Source

pub fn len(&self) -> usize

Get the number of providers in the chain.

Source

pub fn is_empty(&self) -> bool

Check if the chain is empty.

Trait Implementations§

Source§

impl<C> Debug for ProvideCredentialChain<C>
where C: Send + Sync + Unpin + 'static,

Source§

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

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

impl<C> Default for ProvideCredentialChain<C>
where C: Send + Sync + Unpin + 'static,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<C> ProvideCredential for ProvideCredentialChain<C>
where C: Send + Sync + Unpin + 'static,

Source§

type Credential = C

Credential returned by this loader. Read more
Source§

fn provide_credential<'life0, 'life1, 'async_trait>( &'life0 self, ctx: &'life1 Context, ) -> Pin<Box<dyn Future<Output = Result<Option<Self::Credential>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Load signing credential from current env.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
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.