This is an automated email from the ASF dual-hosted git repository.
tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/master by this push:
new c57857031f Default AWS region to us-east-1 (#5211) (#5244)
c57857031f is described below
commit c57857031fb39559924df56e1c8e5f60a1a6e69a
Author: Raphael Taylor-Davies <[email protected]>
AuthorDate: Sat Dec 30 14:29:03 2023 +0000
Default AWS region to us-east-1 (#5211) (#5244)
---
object_store/src/aws/builder.rs | 44 ++++++++++++++++++++++++-----------------
1 file changed, 26 insertions(+), 18 deletions(-)
diff --git a/object_store/src/aws/builder.rs b/object_store/src/aws/builder.rs
index 5f7f1c945a..5e05b05f46 100644
--- a/object_store/src/aws/builder.rs
+++ b/object_store/src/aws/builder.rs
@@ -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,
@@ -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
@@ -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);
@@ -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()?;
@@ -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();