You are viewing documentation for version 1 of the AWS SDK for Ruby. Version 2 documentation can be found here.

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

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, #set?

Constructor Details

#initialize(prefix, suffixes = Hash[KEYS.map{|key| [key, key.to_s.upcase]}]) ⇒ ENVProvider

Returns a new instance of ENVProvider

Parameters:

  • prefix (String)

    The prefix to apply to the ENV variable.



203
204
205
206
# File 'lib/aws/core/credential_providers.rb', line 203

def initialize(prefix, suffixes=Hash[KEYS.map{|key| [key, key.to_s.upcase]}])
  @prefix = prefix
  @suffixes = suffixes
end

Instance Attribute Details

#prefixString (readonly)

Returns:

  • (String)


209
210
211
# File 'lib/aws/core/credential_providers.rb', line 209

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 cached until the client calls Provider#refresh.

Returns:

  • (Hash)


212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/aws/core/credential_providers.rb', line 212

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

  # Merge in CredentialFileProvider credentials if
  # a #{@prefix}_CREDENTIAL_FILE environment(ENV) variable is set
  if ENV["#{@prefix}_CREDENTIAL_FILE"]
    credentials.merge! CredentialFileProvider.new(ENV["#{@prefix}_CREDENTIAL_FILE"]).get_credentials
  end

  credentials
end