#[derive(Debug, Clone)]
pub enum Credentials {
Basic(String, String),
Bearer(String),
#[cfg(any(feature = "native-tls", feature = "rustls-tls"))]
Certificate(ClientCertificate),
ApiKey(String, String),
#[cfg(feature = "aws-auth")]
AwsSigV4(
aws_credential_types::provider::SharedCredentialsProvider,
aws_types::region::Region,
),
}
#[cfg(any(feature = "native-tls", feature = "rustls-tls"))]
#[derive(Debug, Clone)]
pub enum ClientCertificate {
#[cfg(feature = "native-tls")]
Pkcs12(Vec<u8>, Option<String>),
#[cfg(feature = "rustls-tls")]
Pem(Vec<u8>),
}
#[cfg(any(feature = "native-tls", feature = "rustls-tls"))]
impl From<ClientCertificate> for Credentials {
fn from(cert: ClientCertificate) -> Self {
Credentials::Certificate(cert)
}
}
#[cfg(feature = "aws-auth")]
impl std::convert::TryFrom<&aws_types::SdkConfig> for Credentials {
type Error = super::Error;
fn try_from(value: &aws_types::SdkConfig) -> Result<Self, Self::Error> {
let credentials = value
.credentials_provider()
.ok_or_else(|| super::error::lib("SdkConfig does not have a credentials_provider"))?
.clone();
let region = value
.region()
.ok_or_else(|| super::error::lib("SdkConfig does not have a region"))?
.clone();
Ok(Credentials::AwsSigV4(credentials, region))
}
}
#[cfg(feature = "aws-auth")]
impl std::convert::TryFrom<aws_types::SdkConfig> for Credentials {
type Error = super::Error;
fn try_from(value: aws_types::SdkConfig) -> Result<Self, Self::Error> {
Credentials::try_from(&value)
}
}