class Aws::CredentialProviderChain

@api private

Public Class Methods

new(config = nil) click to toggle source
# File lib/aws-sdk-core/credential_provider_chain.rb, line 5
def initialize(config = nil)
  @config = config
end

Public Instance Methods

resolve() click to toggle source

@return [CredentialProvider, nil]

# File lib/aws-sdk-core/credential_provider_chain.rb, line 10
def resolve
  providers.each do |method_name, options|
    provider = send(method_name, options.merge(config: @config))
    return provider if provider && provider.set?
  end
  nil
end

Private Instance Methods

assume_role_credentials(options) click to toggle source
# File lib/aws-sdk-core/credential_provider_chain.rb, line 71
def assume_role_credentials(options)
  if Aws.shared_config.config_enabled?
    profile, region = nil, nil
    if options[:config]
      profile = options[:config].profile
      region = options[:config].region
      assume_role_with_profile(options[:config].profile, options[:config].region)
    end
    assume_role_with_profile(profile, region)
  else
    nil
  end
end
assume_role_with_profile(prof, region) click to toggle source
# File lib/aws-sdk-core/credential_provider_chain.rb, line 93
def assume_role_with_profile(prof, region)
  Aws.shared_config.assume_role_credentials_from_config(
    profile: prof,
    region: region
  )
end
env_credentials(options) click to toggle source
# File lib/aws-sdk-core/credential_provider_chain.rb, line 45
def env_credentials(options)
  key =    %w(AWS_ACCESS_KEY_ID     AMAZON_ACCESS_KEY_ID     AWS_ACCESS_KEY)
  secret = %w(AWS_SECRET_ACCESS_KEY AMAZON_SECRET_ACCESS_KEY AWS_SECRET_KEY)
  token =  %w(AWS_SESSION_TOKEN     AMAZON_SESSION_TOKEN)
  Credentials.new(envar(key), envar(secret), envar(token))
end
envar(keys) click to toggle source
# File lib/aws-sdk-core/credential_provider_chain.rb, line 52
def envar(keys)
  keys.each do |key|
    if ENV.key?(key)
      return ENV[key]
    end
  end
  nil
end
instance_profile_credentials(options) click to toggle source
# File lib/aws-sdk-core/credential_provider_chain.rb, line 85
def instance_profile_credentials(options)
  if ENV["AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"]
    ECSCredentials.new(options)
  else
    InstanceProfileCredentials.new(options)
  end
end
providers() click to toggle source
# File lib/aws-sdk-core/credential_provider_chain.rb, line 20
def providers
  [
    [:static_credentials, {}],
    [:env_credentials, {}],
    [:assume_role_credentials, {}],
    [:shared_credentials, {}],
    [:instance_profile_credentials, {
      retries: 0,
      http_open_timeout: 1,
      http_read_timeout: 1,
    }],
  ]
end
shared_credentials(options) click to toggle source
# File lib/aws-sdk-core/credential_provider_chain.rb, line 61
def shared_credentials(options)
  if options[:config]
    SharedCredentials.new(profile_name: options[:config].profile)
  else
    SharedCredentials.new(profile_name: 'default')
  end
rescue Errors::NoSuchProfileError
  nil
end
static_credentials(options) click to toggle source
# File lib/aws-sdk-core/credential_provider_chain.rb, line 34
def static_credentials(options)
  if options[:config]
    Credentials.new(
      options[:config].access_key_id,
      options[:config].secret_access_key,
      options[:config].session_token)
  else
    nil
  end
end