Class: AWS::Core::CredentialProviders::DefaultProvider

Inherits:
Object
  • Object
show all
Includes:
Provider
Defined in:
lib/aws/core/credential_providers.rb

Overview

The default credential provider makes a best effort to locate your AWS credentials. It checks a variety of locations in the following order:

* Static credentials from AWS.config (e.g. AWS.config.access_key_id,
  AWS.config.secret_access_key)

* The environment (e.g. ENV['AWS_ACCESS_KEY_ID'] or
  ENV['AMAZON_ACCESS_KEY_ID'])

* EC2 metadata service (checks for credentials provided by
  roles for instances).

Constant Summary

Constants included from Provider

Provider::KEYS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Provider

#access_key_id, #secret_access_key, #session_token

Constructor Details

#initialize(static_credentials = {}) ⇒ DefaultProvider

Returns a new instance of DefaultProvider.



107
108
109
110
111
112
113
# File 'lib/aws/core/credential_providers.rb', line 107

def initialize static_credentials = {}
  @providers = []
  @providers << StaticProvider.new(static_credentials)
  @providers << ENVProvider.new('AWS')
  @providers << ENVProvider.new('AMAZON')
  @providers << EC2Provider.new
end

Instance Attribute Details

#providersArray<Provider> (readonly)

Returns:



116
117
118
# File 'lib/aws/core/credential_providers.rb', line 116

def providers
  @providers
end

Instance Method Details

#credentialsObject



118
119
120
121
122
123
124
125
126
# File 'lib/aws/core/credential_providers.rb', line 118

def credentials
  providers.each do |provider|
    begin
      return provider.credentials
    rescue Errors::MissingCredentialsError
    end
  end
  raise Errors::MissingCredentialsError
end

#refreshObject



128
129
130
131
132
# File 'lib/aws/core/credential_providers.rb', line 128

def refresh
  providers.each do |provider|
    provider.refresh
  end
end