Class: AWS::Core::CredentialProviders::ENVProvider

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

Overview

Fetches credentials from the environment (ENV). You construct an ENV provider with a prefix. Given the prefix “AWS” ENV will be checked for the following keys:

  • AWS_ACCESS_KEY_ID

  • AWS_SECRET_ACCESS_KEY

  • AWS_SESSION_TOKEN (optional)

Constant Summary

Constants included from Provider

Provider::KEYS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Provider

#access_key_id, #credentials, #refresh, #secret_access_key, #session_token

Constructor Details

#initialize(prefix) ⇒ ENVProvider

Returns a new instance of ENVProvider.

Parameters:

  • prefix (String)

    The prefix to apply to the ENV variable.



181
182
183
# File 'lib/aws/core/credential_providers.rb', line 181

def initialize prefix
  @prefix = prefix
end

Instance Attribute Details

#prefixString (readonly)

Returns:

  • (String)


186
187
188
# File 'lib/aws/core/credential_providers.rb', line 186

def prefix
  @prefix
end

Instance Method Details

#get_credentialsHash

This method is called on a credential provider to fetch credentials. The credentials hash returned from this method will be cashed until the client calls Provider#refresh.

Returns:

  • (Hash)


189
190
191
192
193
194
195
196
197
# File 'lib/aws/core/credential_providers.rb', line 189

def get_credentials
  credentials = {}
  KEYS.each do |key|
    if value = ENV["#{@prefix}_#{key.to_s.upcase}"]
      credentials[key] = value
    end
  end
  credentials
end