mirror of
https://github.com/fog/fog-aws.git
synced 2022-11-09 13:50:52 -05:00
Clean up STS regional work
We use the AWS_DEFAULT_REGION environment variable only if the region isn't specified explicitly in the configuration.
This commit is contained in:
parent
cbd3354777
commit
dad90af22d
2 changed files with 31 additions and 17 deletions
|
@ -21,7 +21,7 @@ module Fog
|
|||
if options[:use_iam_profile]
|
||||
begin
|
||||
role_data = nil
|
||||
region = options[:region]
|
||||
region = options[:region] || ENV["AWS_DEFAULT_REGION"]
|
||||
|
||||
if ENV["AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"]
|
||||
connection = options[:connection] || Excon.new(CONTAINER_CREDENTIALS_HOST)
|
||||
|
@ -43,13 +43,14 @@ module Fog
|
|||
:Version => "2011-06-15",
|
||||
}
|
||||
|
||||
if ENV["AWS_STS_REGIONAL_ENDPOINTS"] == "regional" && ENV["AWS_DEFAULT_REGION"]
|
||||
STS_ENDPOINT = "https://sts.#{ENV['AWS_DEFAULT_REGION']}.amazonaws.com"
|
||||
else
|
||||
STS_ENDPOINT = "https://sts.amazonaws.com"
|
||||
end
|
||||
sts_endpoint =
|
||||
if ENV["AWS_STS_REGIONAL_ENDPOINTS"] == "regional"
|
||||
"https://sts.#{region}.amazonaws.com"
|
||||
else
|
||||
"https://sts.amazonaws.com"
|
||||
end
|
||||
|
||||
connection = options[:connection] || Excon.new(STS_ENDPOINT, :query => params)
|
||||
connection = options[:connection] || Excon.new(sts_endpoint, :query => params)
|
||||
document = Nokogiri::XML(connection.get(:idempotent => true, :expects => 200).body)
|
||||
|
||||
session = {
|
||||
|
@ -82,6 +83,7 @@ module Fog
|
|||
|
||||
# set region by default to the one the instance is in.
|
||||
credentials[:region] = region
|
||||
credentials[:sts_endpoint] = sts_endpoint if sts_endpoint
|
||||
#these indicate the metadata service is unavailable or has no profile setup
|
||||
credentials
|
||||
rescue Excon::Error => e
|
||||
|
|
|
@ -83,7 +83,7 @@ Shindo.tests('AWS | credentials', ['aws']) do
|
|||
aws_secret_access_key: 'dummysecret',
|
||||
aws_session_token: 'dummytoken',
|
||||
region: 'us-west-1',
|
||||
STS_ENDPOINT: "https://sts.amazonaws.com"
|
||||
sts_endpoint: "https://sts.amazonaws.com",
|
||||
aws_credentials_expire_at: expires_at
|
||||
) { Fog::AWS::Compute.fetch_credentials(use_iam_profile: true) }
|
||||
end
|
||||
|
@ -96,27 +96,39 @@ Shindo.tests('AWS | credentials', ['aws']) do
|
|||
aws_secret_access_key: 'dummysecret',
|
||||
aws_session_token: 'dummytoken',
|
||||
region: 'us-west-1',
|
||||
STS_ENDPOINT: "https://sts.amazonaws.com"
|
||||
sts_endpoint: "https://sts.amazonaws.com",
|
||||
aws_credentials_expire_at: expires_at
|
||||
) { Fog::AWS::Compute.fetch_credentials(use_iam_profile: true) }
|
||||
) { Fog::AWS::Compute.fetch_credentials(use_iam_profile: true, region: 'us-west-1') }
|
||||
end
|
||||
|
||||
ENV["AWS_STS_REGIONAL_ENDPOINTS"] = "regional"
|
||||
ENV["AWS_REGION"] = "us-west-1"
|
||||
|
||||
tests('#fetch_credentials with regional sts endpoint') do
|
||||
tests('#fetch_credentials with regional STS endpoint') do
|
||||
returns(
|
||||
aws_access_key_id: 'dummykey',
|
||||
aws_secret_access_key: 'dummysecret',
|
||||
aws_session_token: 'dummytoken',
|
||||
region: 'us-west-1',
|
||||
STS_ENDPOINT: "https://sts.us-west-1.amazonaws.com"
|
||||
sts_endpoint: "https://sts.us-west-1.amazonaws.com",
|
||||
aws_credentials_expire_at: expires_at
|
||||
) { Fog::AWS::Compute.fetch_credentials(use_iam_profile: true, region: 'us-west-1') }
|
||||
end
|
||||
|
||||
ENV["AWS_DEFAULT_REGION"] = "us-west-1"
|
||||
|
||||
tests('#fetch_credentials with regional STS endpoint with region in env') do
|
||||
returns(
|
||||
aws_access_key_id: 'dummykey',
|
||||
aws_secret_access_key: 'dummysecret',
|
||||
aws_session_token: 'dummytoken',
|
||||
region: 'us-west-1',
|
||||
sts_endpoint: "https://sts.us-west-1.amazonaws.com",
|
||||
aws_credentials_expire_at: expires_at
|
||||
) { Fog::AWS::Compute.fetch_credentials(use_iam_profile: true) }
|
||||
end
|
||||
|
||||
ENV["AWS_STS_REGIONAL_ENDPOINTS"] = nil
|
||||
ENV["AWS_REGION"] = nil
|
||||
ENV["AWS_DEFAULT_REGION"] = nil
|
||||
ENV['AWS_WEB_IDENTITY_TOKEN_FILE'] = nil
|
||||
|
||||
compute = Fog::AWS::Compute.new(use_iam_profile: true)
|
||||
|
|
Loading…
Reference in a new issue