8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/fog/aws/credential_fetcher.rb', line 8
def fetch_credentials(options)
if options[:use_iam_profile]
begin
connection = options[:connection] || Excon.new(INSTANCE_METADATA_HOST)
role_name = connection.get(:path => INSTANCE_METADATA_PATH, :expects => 200).body
role_data = connection.get(:path => INSTANCE_METADATA_PATH+role_name, :expects => 200).body
session = Fog::JSON.decode(role_data)
credentials = {}
credentials[:aws_access_key_id] = session['AccessKeyId']
credentials[:aws_secret_access_key] = session['SecretAccessKey']
credentials[:aws_session_token] = session['Token']
credentials[:aws_credentials_expire_at] = Time.xmlschema session['Expiration']
credentials
rescue Excon::Errors::Error => e
Fog::Logger.warning("Unable to fetch credentuals: #{e.message}")
super
end
else
super
end
end
|