Sha256: 160343a56c6d650b41c23519df2cd79e5d3ee1baac1fe7eff4123c3769f9e4c2

Contents?: true

Size: 1.6 KB

Versions: 9

Compression:

Stored size: 1.6 KB

Contents

module Aws
  # @api private
  class CredentialProviderChain

    def initialize(config)
      @config = config
    end

    def resolve
      providers.each do |method_name, options|
        credentials = send(method_name, options.merge(config: @config))
        return credentials if credentials && credentials.set?
      end
      nil
    end

    private

    def providers
      [
        [:static_credentials, {}],
        [:env_credentials, { prefix: 'AWS' }],
        [:env_credentials, { prefix: 'AMAZON' }],
        [:env_credentials, { key:'AWS_ACCESS_KEY', secret:'AWS_SECRET_KEY' }],
        [:shared_credentials, {}],
        [:instance_profile_credentials, {
          retries: 0,
          http_open_timeout: 1,
          http_read_timeout: 1,
        }],
      ]
    end

    def static_credentials(options)
      config = options[:config]
      Credentials.new(
        config.access_key_id,
        config.secret_access_key,
        config.session_token)
    end

    def env_credentials(options)
      env_keys = []
      if prefix = options[:prefix]
        env_keys << "#{prefix}_ACCESS_KEY_ID"
        env_keys << "#{prefix}_SECRET_ACCESS_KEY"
        env_keys << "#{prefix}_SESSION_TOKEN"
      else
        env_keys << options[:key]
        env_keys << options[:secret]
      end
      Credentials.new(*ENV.values_at(*env_keys))
    end

    def shared_credentials(options = {})
      SharedCredentials.new(profile_name: options[:config].profile)
    rescue Errors::NoSuchProfileError
      nil
    end

    def instance_profile_credentials(options)
      InstanceProfileCredentials.new(options)
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
aws-sdk-core-2.0.33 lib/aws-sdk-core/credential_provider_chain.rb
aws-sdk-core-2.0.32 lib/aws-sdk-core/credential_provider_chain.rb
aws-sdk-core-2.0.31 lib/aws-sdk-core/credential_provider_chain.rb
aws-sdk-core-2.0.30 lib/aws-sdk-core/credential_provider_chain.rb
aws-sdk-core-2.0.29 lib/aws-sdk-core/credential_provider_chain.rb
aws-sdk-core-2.0.28 lib/aws-sdk-core/credential_provider_chain.rb
aws-sdk-core-2.0.27 lib/aws-sdk-core/credential_provider_chain.rb
aws-sdk-core-2.0.26 lib/aws-sdk-core/credential_provider_chain.rb
aws-sdk-core-2.0.25 lib/aws-sdk-core/credential_provider_chain.rb