Skip to content

Commit

Permalink
anonymous can be resolved checking auth values
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Feb 4, 2022
1 parent b49b233 commit b54ab4e
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ pub struct AwsS3Fs {
secret_key: Option<String>,
security_token: Option<String>,
session_token: Option<String>,
/// Anonymous connection (no credentials)
anonymous: bool,
/// New path style. Required for some backends, such as MinIO
new_path_style: bool,
}
Expand All @@ -76,7 +74,6 @@ impl AwsS3Fs {
secret_key: None,
security_token: None,
session_token: None,
anonymous: false,
new_path_style: false,
}
}
Expand All @@ -100,12 +97,6 @@ impl AwsS3Fs {
self
}

/// Set whether to use anonymous credentials (Default: False)
pub fn anonymous(mut self, anonymous: bool) -> Self {
self.anonymous = anonymous;
self
}

/// Set whether to use new path style. Required for backends such as MinIO (Default: False)
pub fn new_path_style(mut self, new_path_style: bool) -> Self {
self.new_path_style = new_path_style;
Expand Down Expand Up @@ -270,9 +261,17 @@ impl AwsS3Fs {
}
}

/// Return whether connection should use anonymous credentials
fn is_anonymous(&self) -> bool {
self.access_key.is_none()
&& self.secret_key.is_none()
&& self.security_token.is_none()
&& self.session_token.is_none()
}

/// Load credentials for current session
fn load_credentials(&self) -> RemoteResult<Credentials> {
if self.anonymous {
if self.is_anonymous() {
Credentials::anonymous().map_err(|e| {
RemoteError::new_ex(
RemoteErrorType::AuthenticationFailed,
Expand Down Expand Up @@ -599,7 +598,7 @@ mod test {
assert_eq!(s3.bucket_name.as_str(), "aws-s3-test");
assert!(s3.region.is_none());
assert!(s3.endpoint.is_none());
assert_eq!(s3.anonymous, false);
assert_eq!(s3.is_anonymous(), true);
assert_eq!(s3.new_path_style, false);
assert!(s3.bucket.is_none());
assert!(s3.access_key.is_none());
Expand All @@ -620,7 +619,6 @@ mod test {
.secret_access_key("PASSWORD")
.security_token("secret")
.session_token("token")
.anonymous(true)
.new_path_style(true)
.endpoint("omar");
assert_eq!(s3.bucket_name.as_str(), "aws-s3-test");
Expand All @@ -630,7 +628,7 @@ mod test {
assert_eq!(s3.security_token.as_deref().unwrap(), "secret");
assert_eq!(s3.session_token.as_deref().unwrap(), "token");
assert_eq!(s3.endpoint.as_deref().unwrap(), "omar");
assert_eq!(s3.anonymous, true);
assert_eq!(s3.is_anonymous(), false);
assert_eq!(s3.new_path_style, true);
}

Expand Down

0 comments on commit b54ab4e

Please sign in to comment.