Skip to content
Merged
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
44 changes: 26 additions & 18 deletions object_store/src/aws/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ static DEFAULT_METADATA_ENDPOINT: &str = "http://169.254.169.254";
#[derive(Debug, Snafu)]
#[allow(missing_docs)]
enum Error {
#[snafu(display("Missing region"))]
MissingRegion,

#[snafu(display("Missing bucket name"))]
MissingBucketName,

Expand Down Expand Up @@ -559,19 +556,25 @@ impl AmazonS3Builder {
Ok(())
}

/// Set the AWS Access Key (required)
/// Set the AWS Access Key
pub fn with_access_key_id(mut self, access_key_id: impl Into<String>) -> Self {
self.access_key_id = Some(access_key_id.into());
self
}

/// Set the AWS Secret Access Key (required)
/// Set the AWS Secret Access Key
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a drive-by fix as these are no longer required (we support other forms of credential)

pub fn with_secret_access_key(mut self, secret_access_key: impl Into<String>) -> Self {
self.secret_access_key = Some(secret_access_key.into());
self
}

/// Set the region (e.g. `us-east-1`) (required)
/// Set the AWS Session Token to use for requests
pub fn with_token(mut self, token: impl Into<String>) -> Self {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is moved up from lower down, to sit alongside the credentials it relates to. I also tweaked the doc to make it a bit clearer.

self.token = Some(token.into());
self
}

/// Set the region, defaults to `us-east-1`
pub fn with_region(mut self, region: impl Into<String>) -> Self {
self.region = Some(region.into());
self
Expand All @@ -583,25 +586,21 @@ impl AmazonS3Builder {
self
}

/// Sets the endpoint for communicating with AWS S3. Default value
/// is based on region. The `endpoint` field should be consistent with
/// the field `virtual_hosted_style_request'.
/// Sets the endpoint for communicating with AWS S3, defaults to the [region endpoint]
///
/// For example, this might be set to `"http://localhost:4566:`
/// for testing against a localstack instance.
/// If `virtual_hosted_style_request` is set to true then `endpoint`
/// should have bucket name included.
///
/// The `endpoint` field should be consistent with [`Self::with_virtual_hosted_style_request`],
/// i.e. if `virtual_hosted_style_request` is set to true then `endpoint`
/// should have the bucket name included.
///
/// [region endpoint]: https://docs.aws.amazon.com/general/latest/gr/s3.html
pub fn with_endpoint(mut self, endpoint: impl Into<String>) -> Self {
self.endpoint = Some(endpoint.into());
self
}

/// Set the token to use for requests (passed to underlying provider)
pub fn with_token(mut self, token: impl Into<String>) -> Self {
self.token = Some(token.into());
self
}

/// Set the credential provider overriding any other options
pub fn with_credentials(mut self, credentials: AwsCredentialProvider) -> Self {
self.credentials = Some(credentials);
Expand Down Expand Up @@ -741,7 +740,7 @@ impl AmazonS3Builder {
}

let bucket = self.bucket_name.context(MissingBucketNameSnafu)?;
let region = self.region.context(MissingRegionSnafu)?;
let region = self.region.unwrap_or_else(|| "us-east-1".to_string());
let checksum = self.checksum_algorithm.map(|x| x.get()).transpose()?;
let copy_if_not_exists = self.copy_if_not_exists.map(|x| x.get()).transpose()?;
let put_precondition = self.conditional_put.map(|x| x.get()).transpose()?;
Expand Down Expand Up @@ -950,6 +949,15 @@ mod tests {
);
}

#[test]
fn s3_default_region() {
let builder = AmazonS3Builder::new()
.with_bucket_name("foo")
.build()
.unwrap();
assert_eq!(builder.client.config.region, "us-east-1");
}

#[test]
fn s3_test_urls() {
let mut builder = AmazonS3Builder::new();
Expand Down