Class: Cerberus::AssumedRoleCredentialsProviderChain

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

Overview

Default credentials provider chain

Instance Method Summary collapse

Constructor Details

#initialize(urlResolver, instanceMdSvcBaseUrl = nil, roleName, roleRegion, roleAccountId) ⇒ AssumedRoleCredentialsProviderChain

Returns a new instance of AssumedRoleCredentialsProviderChain.



14
15
16
17
18
19
20
# File 'lib/cerberus/assumed_role_credentials_provider_chain.rb', line 14

def initialize(urlResolver, instanceMdSvcBaseUrl = nil, roleName, roleRegion, roleAccountId)
  vaultBaseUrl = CerberusClient.getUrlFromResolver(urlResolver)

  # return default array of providers
  @providers = [Cerberus::EnvCredentialsProvider.new,
                Cerberus::AwsRoleCredentialsProvider.new(vaultBaseUrl, instanceMdSvcBaseUrl, roleName, roleRegion, roleAccountId)]
end

Instance Method Details

#getCredentialsProviderObject

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



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/cerberus/assumed_role_credentials_provider_chain.rb', line 26

def getCredentialsProvider
  @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
      CerberusClient.getCredentialsFromProvider(p)
      return p

    rescue Cerberus::Exception::NoValueError
      next
    end
  }

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