pub struct ChainCredentialsProviderBuilder { /* private fields */ }
Expand description

串联认证信息构建器

接受多个认证信息获取接口的实例并将他们串联成串联认证信息

Implementations§

构建新的串联认证信息构建器

Examples found in repository?
src/lib.rs (line 945)
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
    pub fn builder(credential: impl CredentialProvider + 'static) -> ChainCredentialsProviderBuilder {
        ChainCredentialsProviderBuilder::new(credential)
    }
}

impl CredentialProvider for ChainCredentialsProvider {
    fn get(&self, opts: GetOptions) -> IoResult<GotCredential> {
        let mut last_err = None;
        if let Some(credential) = self.credentials.iter().find_map(|c| match c.get(opts) {
            Ok(cred) => Some(cred),
            Err(err) => {
                last_err = Some(err);
                None
            }
        }) {
            Ok(credential)
        } else {
            Err(last_err.expect("No credential in ChainCredentialsProvider, which is unexpected"))
        }
    }

    #[cfg(feature = "async")]
    #[cfg_attr(feature = "docs", doc(cfg(feature = "async")))]
    fn async_get(&self, opts: GetOptions) -> AsyncIoResult<'_, GotCredential> {
        Box::pin(async move {
            let mut last_err = None;
            for provider in self.credentials.iter() {
                match provider.async_get(opts).await {
                    Ok(cred) => {
                        return Ok(cred);
                    }
                    Err(err) => {
                        last_err = Some(err);
                    }
                }
            }
            Err(last_err.expect("No credential in ChainCredentialsProvider, which is unexpected"))
        })
    }
}

impl Default for ChainCredentialsProvider {
    #[inline]
    fn default() -> Self {
        ChainCredentialsProviderBuilder::new(Box::new(GlobalCredentialProvider))
            .append_credential(Box::new(EnvCredentialProvider))
            .build()
    }

将认证信息获取接口的实例推送到认证串末端

Examples found in repository?
src/lib.rs (line 989)
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
    fn default() -> Self {
        ChainCredentialsProviderBuilder::new(Box::new(GlobalCredentialProvider))
            .append_credential(Box::new(EnvCredentialProvider))
            .build()
    }
}

impl FromIterator<Box<dyn CredentialProvider>> for ChainCredentialsProvider {
    #[inline]
    fn from_iter<T: IntoIterator<Item = Box<dyn CredentialProvider>>>(iter: T) -> Self {
        ChainCredentialsProviderBuilder::from_iter(iter).build()
    }
}

impl<'a> IntoIterator for &'a ChainCredentialsProvider {
    type Item = &'a Box<dyn CredentialProvider + 'static>;
    type IntoIter = std::slice::Iter<'a, Box<dyn CredentialProvider + 'static>>;

    #[inline]
    fn into_iter(self) -> Self::IntoIter {
        self.credentials.iter()
    }
}

/// 串联认证信息构建器
///
/// 接受多个认证信息获取接口的实例并将他们串联成串联认证信息
#[derive(Debug, Clone, Default)]
pub struct ChainCredentialsProviderBuilder {
    credentials: VecDeque<Box<dyn CredentialProvider + 'static>>,
}

impl ChainCredentialsProviderBuilder {
    /// 构建新的串联认证信息构建器
    #[inline]
    pub fn new(credential: impl CredentialProvider + 'static) -> Self {
        let mut builder = Self::default();
        builder.append_credential(credential);
        builder
    }

将认证信息获取接口的实例推送到认证串顶端

串联认证信息

Examples found in repository?
src/lib.rs (line 990)
987
988
989
990
991
992
993
994
995
996
997
998
    fn default() -> Self {
        ChainCredentialsProviderBuilder::new(Box::new(GlobalCredentialProvider))
            .append_credential(Box::new(EnvCredentialProvider))
            .build()
    }
}

impl FromIterator<Box<dyn CredentialProvider>> for ChainCredentialsProvider {
    #[inline]
    fn from_iter<T: IntoIterator<Item = Box<dyn CredentialProvider>>>(iter: T) -> Self {
        ChainCredentialsProviderBuilder::from_iter(iter).build()
    }

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Extends a collection with the contents of an iterator. Read more
🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Creates a value from an iterator. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.