Skip to content

Commit

Permalink
Default AWS region to us-east-1 (#5211) (#5244)
Browse files Browse the repository at this point in the history
  • Loading branch information
tustvold authored Dec 30, 2023
1 parent 9863486 commit c578570
Showing 1 changed file with 26 additions and 18 deletions.
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
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 {
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

0 comments on commit c578570

Please sign in to comment.