class Cerberus::AssumedRoleCredentialsProviderChain

Default credentials provider chain

Public Class Methods

new(url_resolver, iam_role_arn, region) click to toggle source
# 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

Public Instance Methods

get_credentials_provider() click to toggle source

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

# 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