Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
282 additions
and
6 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
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
30 changes: 30 additions & 0 deletions
30
aws-sdk-core/lib/aws-sdk-core/plugins/sts_regional_endpoints.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,30 @@ | ||
module Aws | ||
module Plugins | ||
|
||
class STSRegionalEndpoints < Seahorse::Client::Plugin | ||
|
||
option(:sts_regional_endpoints, | ||
default: 'legacy', | ||
doc_type: String, | ||
docstring: <<-DOCS) do |cfg| | ||
Passing in 'regional' to enable regional endpoint for STS for all supported | ||
regions (except 'aws-global'), defaults to 'legacy' mode, using global endpoint | ||
for legacy regions. | ||
DOCS | ||
resolve_sts_regional_endpoints(cfg) | ||
end | ||
|
||
private | ||
|
||
def self.resolve_sts_regional_endpoints(cfg) | ||
env_mode = ENV['AWS_STS_REGIONAL_ENDPOINTS'] | ||
env_mode = nil if env_mode == '' | ||
cfg_mode = Aws.shared_config.sts_regional_endpoints( | ||
profile: cfg.profile) | ||
env_mode || cfg_mode || 'legacy' | ||
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
165 changes: 165 additions & 0 deletions
165
aws-sdk-core/spec/aws/sts/sts_regional_endpoints_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,165 @@ | ||
require_relative '../../spec_helper' | ||
|
||
module Aws | ||
module STS | ||
describe Client do | ||
|
||
describe ':sts_regional_endpoints' do | ||
|
||
let(:mock_config_file) { | ||
File.expand_path(File.join(File.dirname(__FILE__), | ||
'..', 'fixtures', 'credentials', 'mock_shared_config')) | ||
} | ||
|
||
it 'uses ENV before shared config' do | ||
ENV['AWS_STS_REGIONAL_ENDPOINTS'] = 'regional' | ||
config = SharedConfig.new( | ||
config_path: mock_config_file, | ||
config_enabled: true, | ||
profile_name: "sts_legacy" | ||
) | ||
|
||
allow(Aws).to receive(:shared_config).and_return(config) | ||
client = Client.new( | ||
stub_responses: true, | ||
region: 'us-west-2' | ||
) | ||
expect(client.config.sts_regional_endpoints).to eq('regional') | ||
end | ||
|
||
it 'defaults to `legacy`' do | ||
client = Client.new( | ||
stub_responses: true, | ||
region: 'us-west-2' | ||
) | ||
expect(client.config.sts_regional_endpoints).to eq('legacy') | ||
resp = client.get_caller_identity | ||
expect(resp.context.http_request.endpoint.to_s).to eq( | ||
'https://sts.amazonaws.com') | ||
end | ||
|
||
it 'can be set `regional` in the constructor' do | ||
client = Client.new( | ||
stub_responses: true, | ||
sts_regional_endpoints: 'regional', | ||
region: 'us-west-2' | ||
) | ||
expect(client.config.sts_regional_endpoints).to eq('regional') | ||
resp = client.get_caller_identity | ||
expect(resp.context.http_request.endpoint.to_s).to eq( | ||
'https://sts.us-west-2.amazonaws.com') | ||
end | ||
|
||
it 'can be set fron ENV' do | ||
ENV['AWS_STS_REGIONAL_ENDPOINTS'] = 'regional' | ||
client = Client.new( | ||
stub_responses: true, | ||
region: 'us-west-2' | ||
) | ||
expect(client.config.sts_regional_endpoints).to eq('regional') | ||
resp = client.get_caller_identity | ||
expect(resp.context.http_request.endpoint.to_s).to eq( | ||
'https://sts.us-west-2.amazonaws.com') | ||
end | ||
|
||
it 'has no effect on fips endpoint' do | ||
client = Client.new( | ||
stub_responses: true, | ||
region: 'us-west-2-fips' | ||
) | ||
expect(client.config.sts_regional_endpoints).to eq('legacy') | ||
resp = client.get_caller_identity | ||
expect(resp.context.http_request.endpoint.to_s).to eq( | ||
'https://sts-fips.us-west-2.amazonaws.com') | ||
|
||
client = Client.new( | ||
stub_responses: true, | ||
sts_regional_endpoints: 'regional', | ||
region: 'us-west-2-fips' | ||
) | ||
resp = client.get_caller_identity | ||
expect(resp.context.http_request.endpoint.to_s).to eq( | ||
'https://sts-fips.us-west-2.amazonaws.com') | ||
end | ||
|
||
it 'has no effect on aws-global even when `regional`' do | ||
client = Client.new( | ||
stub_responses: true, | ||
sts_regional_endpoints: 'regional', | ||
region: 'aws-global' | ||
) | ||
expect(client.config.sts_regional_endpoints).to eq('regional') | ||
resp = client.get_caller_identity | ||
expect(resp.context.http_request.endpoint.to_s).to eq( | ||
'https://sts.amazonaws.com') | ||
end | ||
|
||
it 'has no effect on current regionalized regions' do | ||
client = Client.new( | ||
stub_responses: true, | ||
region: 'ap-east-1' | ||
) | ||
expect(client.config.sts_regional_endpoints).to eq('legacy') | ||
resp = client.get_caller_identity | ||
expect(resp.context.http_request.endpoint.to_s).to eq( | ||
'https://sts.ap-east-1.amazonaws.com') | ||
|
||
client = Client.new( | ||
stub_responses: true, | ||
sts_regional_endpoints: 'regional', | ||
region: 'ap-east-1' | ||
) | ||
expect(client.config.sts_regional_endpoints).to eq('regional') | ||
resp = client.get_caller_identity | ||
expect(resp.context.http_request.endpoint.to_s).to eq( | ||
'https://sts.ap-east-1.amazonaws.com') | ||
end | ||
|
||
it 'has no effect on cn-north-1 region' do | ||
client = Client.new( | ||
stub_responses: true, | ||
region: 'cn-north-1' | ||
) | ||
expect(client.config.sts_regional_endpoints).to eq('legacy') | ||
resp = client.get_caller_identity | ||
expect(resp.context.http_request.endpoint.to_s).to eq( | ||
'https://sts.cn-north-1.amazonaws.com.cn') | ||
|
||
client = Client.new( | ||
stub_responses: true, | ||
sts_regional_endpoints: 'regional', | ||
region: 'cn-north-1' | ||
) | ||
expect(client.config.sts_regional_endpoints).to eq('regional') | ||
resp = client.get_caller_identity | ||
expect(resp.context.http_request.endpoint.to_s).to eq( | ||
'https://sts.cn-north-1.amazonaws.com.cn') | ||
end | ||
|
||
it 'configures properly at config' do | ||
client = Client.new( | ||
stub_responses: true, | ||
region: 'us-west-2' | ||
) | ||
expect(client.config.sts_regional_endpoints).to eq('legacy') | ||
expect(client.config.region).to eq('us-west-2') | ||
expect(client.config.sigv4_region).to eq('us-east-1') | ||
expect(client.config.endpoint.to_s).to eq('https://sts.amazonaws.com') | ||
|
||
client = Client.new( | ||
stub_responses: true, | ||
sts_regional_endpoints: 'regional', | ||
region: 'us-west-2' | ||
) | ||
expect(client.config.sts_regional_endpoints).to eq('regional') | ||
expect(client.config.region).to eq('us-west-2') | ||
expect(client.config.sigv4_region).to eq('us-west-2') | ||
expect(client.config.endpoint.to_s).to eq( | ||
'https://sts.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