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(url_resolver, iam_role_arn, region) ⇒ AssumedRoleCredentialsProviderChain

Returns a new instance of AssumedRoleCredentialsProviderChain.



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

def initialize(url_resolver, iam_role_arn, region)

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

Instance Method Details

#get_credentials_providerObject

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 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