mirror of
https://github.com/fog/fog-aws.git
synced 2022-11-09 13:50:52 -05:00
add default region to use_iam_profile
This commit is contained in:
parent
f00473554d
commit
17a05759af
1 changed files with 8 additions and 0 deletions
|
@ -1,8 +1,11 @@
|
||||||
module Fog
|
module Fog
|
||||||
module AWS
|
module AWS
|
||||||
module CredentialFetcher
|
module CredentialFetcher
|
||||||
|
|
||||||
INSTANCE_METADATA_HOST = "http://169.254.169.254"
|
INSTANCE_METADATA_HOST = "http://169.254.169.254"
|
||||||
INSTANCE_METADATA_PATH = "/latest/meta-data/iam/security-credentials/"
|
INSTANCE_METADATA_PATH = "/latest/meta-data/iam/security-credentials/"
|
||||||
|
INSTANCE_METADATA_AZ = "/latest/meta-data/placement/availability-zone/"
|
||||||
|
|
||||||
module ServiceMethods
|
module ServiceMethods
|
||||||
def fetch_credentials(options)
|
def fetch_credentials(options)
|
||||||
if options[:use_iam_profile] && Fog.mocking?
|
if options[:use_iam_profile] && Fog.mocking?
|
||||||
|
@ -13,6 +16,8 @@ module Fog
|
||||||
connection = options[:connection] || Excon.new(INSTANCE_METADATA_HOST)
|
connection = options[:connection] || Excon.new(INSTANCE_METADATA_HOST)
|
||||||
role_name = connection.get(:path => INSTANCE_METADATA_PATH, :expects => 200).body
|
role_name = connection.get(:path => INSTANCE_METADATA_PATH, :expects => 200).body
|
||||||
role_data = connection.get(:path => INSTANCE_METADATA_PATH+role_name, :expects => 200).body
|
role_data = connection.get(:path => INSTANCE_METADATA_PATH+role_name, :expects => 200).body
|
||||||
|
az_data = connection.get(:path => INSTANCE_METADATA_AZ, :expects => 200).body
|
||||||
|
region = az_data[0..-2] # get region from az
|
||||||
|
|
||||||
session = Fog::JSON.decode(role_data)
|
session = Fog::JSON.decode(role_data)
|
||||||
credentials = {}
|
credentials = {}
|
||||||
|
@ -20,6 +25,9 @@ module Fog
|
||||||
credentials[:aws_secret_access_key] = session['SecretAccessKey']
|
credentials[:aws_secret_access_key] = session['SecretAccessKey']
|
||||||
credentials[:aws_session_token] = session['Token']
|
credentials[:aws_session_token] = session['Token']
|
||||||
credentials[:aws_credentials_expire_at] = Time.xmlschema session['Expiration']
|
credentials[:aws_credentials_expire_at] = Time.xmlschema session['Expiration']
|
||||||
|
|
||||||
|
# set region by default to the one the instance is in.
|
||||||
|
credentials[:region] = region
|
||||||
#these indicate the metadata service is unavailable or has no profile setup
|
#these indicate the metadata service is unavailable or has no profile setup
|
||||||
credentials
|
credentials
|
||||||
rescue Excon::Errors::Error => e
|
rescue Excon::Errors::Error => e
|
||||||
|
|
Loading…
Reference in a new issue