Class/Module Index [+]

Quicksearch

Fog::AWS::CredentialFetcher::ServiceMethods

Public Instance Methods

fetch_credentials(options) click to toggle source
# 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']
      #these indicate the metadata service is unavailable or has no profile setup
      credentials
    rescue Excon::Errors::Error => e
      Fog::Logger.warning("Unable to fetch credentials: #{e.message}")
      super
    end
  else
    super
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.