-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support S3 IAD Regional option (#2194)
* Support S3 IAD Regional option * Undo 2.11.419 bump * Add downcase for regional option
- Loading branch information
Showing
14 changed files
with
219 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
@@ -1 +1 @@ | ||
2.11.419 | ||
2.11.418 |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
58 changes: 58 additions & 0 deletions
58
aws-sdk-core/lib/aws-sdk-core/plugins/s3_iad_regional_endpoint.rb
This file contains 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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
module Aws | ||
module Plugins | ||
|
||
class S3IADRegionalEndpoint < Seahorse::Client::Plugin | ||
|
||
option(:s3_us_east_1_regional_endpoint, | ||
default: 'legacy', | ||
doc_type: String, | ||
docstring: <<-DOCS) do |cfg| | ||
Passing in `regional` to enable regional endpoint for S3's `us-east-1` | ||
region. Defaults to `legacy` mode using global endpoint. | ||
DOCS | ||
resolve_iad_regional_endpoint(cfg) | ||
end | ||
|
||
def add_handlers(handlers, config) | ||
if config.region == 'us-east-1' | ||
handlers.add(Handler) | ||
end | ||
end | ||
|
||
# @api private | ||
class Handler < Seahorse::Client::Handler | ||
|
||
def call(context) | ||
# keep legacy global endpoint pattern by default | ||
if context.config.s3_us_east_1_regional_endpoint == 'legacy' | ||
context.http_request.endpoint.host = S3IADRegionalEndpoint.legacy_host( | ||
context.http_request.endpoint.host) | ||
end | ||
@handler.call(context) | ||
end | ||
|
||
end | ||
|
||
def self.legacy_host(host) | ||
host.sub(".us-east-1", '') | ||
end | ||
|
||
private | ||
|
||
def self.resolve_iad_regional_endpoint(cfg) | ||
mode = ENV['AWS_S3_US_EAST_1_REGIONAL_ENDPOINT'] || | ||
Aws.shared_config.s3_us_east_1_regional_endpoint(profile: cfg.profile) || | ||
'legacy' | ||
mode.downcase! | ||
unless %w(legacy regional).include?(mode) | ||
raise ArgumentError, "expected :s3_us_east_1_regional_endpoint or"\ | ||
" ENV['AWS_S3_US_EAST_1_REGIONAL_ENDPOINT'] to be `legacy` or"\ | ||
" `regional`." | ||
end | ||
mode | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Aws | ||
VERSION = '2.11.419' | ||
VERSION = '2.11.418' | ||
end |
97 changes: 97 additions & 0 deletions
97
aws-sdk-core/spec/aws/s3/client/iad_regional_endpoint_spec.rb
This file contains 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 |
---|---|---|
@@ -0,0 +1,97 @@ | ||
require 'spec_helper' | ||
|
||
module Aws | ||
module S3 | ||
describe Client do | ||
|
||
describe ':s3_us_east_1_regional_endpoint' do | ||
|
||
it 'defaults to `legacy`' do | ||
client = Client.new(stub_responses: true, region: 'us-east-1') | ||
expect(client.config.s3_us_east_1_regional_endpoint).to eq('legacy') | ||
resp = client.list_buckets | ||
expect(resp.context.http_request.endpoint.to_s).to eq( | ||
'https://s3.amazonaws.com/') | ||
end | ||
|
||
it 'can be set to `regional` in the constructor' do | ||
client = Client.new( | ||
stub_responses: true, | ||
region: 'us-east-1', | ||
s3_us_east_1_regional_endpoint: 'regional' | ||
) | ||
expect(client.config.s3_us_east_1_regional_endpoint).to eq('regional') | ||
resp = client.list_buckets | ||
expect(resp.context.http_request.endpoint.to_s).to eq( | ||
'https://s3.us-east-1.amazonaws.com/') | ||
end | ||
|
||
it 'raise an error when invalid option provided' do | ||
ENV['AWS_S3_US_EAST_1_REGIONAL_ENDPOINT'] = 'foo' | ||
expect do | ||
Client.new( | ||
stub_responses: true, | ||
region: 'us-east-1' | ||
) | ||
end.to raise_error(ArgumentError) | ||
end | ||
|
||
it 'can be set from ENV' do | ||
ENV['AWS_S3_US_EAST_1_REGIONAL_ENDPOINT'] = 'regional' | ||
client = Client.new( | ||
stub_responses: true, | ||
region: 'us-east-1' | ||
) | ||
expect(client.config.s3_us_east_1_regional_endpoint).to eq('regional') | ||
resp = client.list_buckets | ||
expect(resp.context.http_request.endpoint.to_s).to eq( | ||
'https://s3.us-east-1.amazonaws.com/') | ||
end | ||
|
||
it 'uses client option before ENV' do | ||
ENV['AWS_S3_US_EAST_1_REGIONAL_ENDPOINT'] = 'legacy' | ||
client = Client.new( | ||
stub_responses: true, | ||
region: 'us-east-1', | ||
s3_us_east_1_regional_endpoint: 'regional' | ||
) | ||
expect(client.config.s3_us_east_1_regional_endpoint).to eq('regional') | ||
resp = client.list_buckets | ||
expect(resp.context.http_request.endpoint.to_s).to eq( | ||
'https://s3.us-east-1.amazonaws.com/') | ||
end | ||
|
||
it 'is case insensitive' do | ||
ENV['AWS_S3_US_EAST_1_REGIONAL_ENDPOINT'] = 'LEGACY' | ||
client = Client.new( | ||
stub_responses: true, | ||
region: 'us-east-1' | ||
) | ||
expect(client.config.s3_us_east_1_regional_endpoint).to eq('legacy') | ||
end | ||
|
||
it 'has no effect on non-IAD regions' do | ||
client = Client.new( | ||
stub_responses: true, | ||
region: 'us-west-2', | ||
s3_us_east_1_regional_endpoint: 'legacy' | ||
) | ||
resp = client.list_buckets | ||
expect(resp.context.http_request.endpoint.to_s).to eq( | ||
'https://s3.us-west-2.amazonaws.com/') | ||
|
||
client = Client.new( | ||
stub_responses: true, | ||
region: 'us-west-2', | ||
s3_us_east_1_regional_endpoint: 'regional' | ||
) | ||
resp = client.list_buckets | ||
expect(resp.context.http_request.endpoint.to_s).to eq( | ||
'https://s3.us-west-2.amazonaws.com/') | ||
end | ||
|
||
end | ||
|
||
end | ||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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
This file contains 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