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.



184
185
186
# File 'lib/aws/core/credential_providers.rb', line 184

def initialize prefix
  @prefix = prefix
end

Instance Attribute Details

#prefixString (readonly)

Returns:

  • (String)


189
190
191
# File 'lib/aws/core/credential_providers.rb', line 189

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)


192
193
194
195
196
197
198
199
200
# File 'lib/aws/core/credential_providers.rb', line 192

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