Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

#[derive(Debug, Clone)]
pub enum Credential {
/// Plain refers to no credential has been provided, fallback to services'
/// default logic.
Plain,
/// Basic refers to HTTP Basic Authentication.
Basic { username: String, password: String },
/// HMAC, also known as Access Key/Secret Key authentication.
Expand All @@ -33,20 +36,32 @@ pub enum Credential {

impl Credential {
pub fn basic(username: &str, password: &str) -> Credential {
if username.is_empty() && password.is_empty() {
return Credential::Plain;
}

Credential::Basic {
username: username.to_string(),
password: password.to_string(),
}
}

pub fn hmac(access_key_id: &str, secret_access_key: &str) -> Credential {
if access_key_id.is_empty() && secret_access_key.is_empty() {
return Credential::Plain;
}

Credential::HMAC {
access_key_id: access_key_id.to_string(),
secret_access_key: secret_access_key.to_string(),
}
}

pub fn token(token: &str) -> Credential {
if token.is_empty() {
return Credential::Plain;
}

Credential::Token(token.to_string())
}
}
2 changes: 2 additions & 0 deletions src/services/s3/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ impl Builder {
None,
));
}
// We don't need to do anything if user tries to read credential from env.
Credential::Plain => {}
_ => {
return Err(Error::Backend {
kind: Kind::BackendConfigurationInvalid,
Expand Down