Class: Cerberus::DefaultCredentialsProviderChain

Inherits:
Object
  • Object
show all
Defined in:
lib/cerberus/default_credentials_provider_chain.rb

Overview

Default credentials provider chain

Constant Summary collapse

AWS_EC2_METADATA_URL =

AWS metadata instance URL

"http://169.254.169.254/latest/meta-data"

Instance Method Summary collapse

Constructor Details

#initialize(url_resolver, region = nil, instance_metadata_url = AWS_EC2_METADATA_URL) ⇒ DefaultCredentialsProviderChain

Returns a new instance of DefaultCredentialsProviderChain.



19
20
21
22
23
24
# File 'lib/cerberus/default_credentials_provider_chain.rb', line 19

def initialize(url_resolver, region = nil,  = AWS_EC2_METADATA_URL)

  # return default array of providers
  @providers = [Cerberus::EnvCredentialsProvider.new,
                Cerberus::AwsPrincipalCredentialsProvider.new(url_resolver, region, )]
end

Instance Method Details

#get_credentials_providerObject

Return the first provider in the default hierarchy that has a valid token



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cerberus/default_credentials_provider_chain.rb', line 29

def get_credentials_provider
  @providers.each { |p|
    begin
      # if token is assigned, that's the provider we want.
      # providers must throw NoValueError so that we can fall to the next provider if necessary
      CerberusUtils::get_credentials_from_provider(p)
      return p

    rescue Cerberus::Exception::NoValueError
      next
    end
  }

  # we should have found and returned a valid provider above, else there's a problem
  CerberusUtils::Log.instance.error("Could not find a valid provider")
  raise Cerberus::Exception::NoValidProviders.new
end