-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Default AWS region to us-east-1 (#5211) #5244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
@@ -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(); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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)