Sha256: ed0dd5bcb405011757ed6d78b23248511360e19680fe77fa0c4664ab16f14001

Contents?: true

Size: 1.19 KB

Versions: 118

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module Aws
  # @api private
  class TokenProviderChain
    def initialize(config = nil)
      @config = config
    end

    # @return [TokenProvider, nil]
    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

    def providers
      [
        [:static_profile_sso_token, {}],
        [:sso_token, {}]
      ]
    end

    def static_profile_sso_token(options)
      if Aws.shared_config.config_enabled? && options[:config] && options[:config].profile
        Aws.shared_config.sso_token_from_config(
          profile: options[:config].profile
        )
      end
    end


    def sso_token(options)
      profile_name = determine_profile_name(options)
      if Aws.shared_config.config_enabled?
        Aws.shared_config.sso_token_from_config(profile: profile_name)
      end
    rescue Errors::NoSuchProfileError
      nil
    end

    def determine_profile_name(options)
      (options[:config] && options[:config].profile) || ENV['AWS_PROFILE'] || ENV['AWS_DEFAULT_PROFILE'] || 'default'
    end

  end
end

Version data entries

118 entries across 118 versions & 1 rubygems

Version Path
aws-sdk-core-3.168.1 lib/aws-sdk-core/token_provider_chain.rb
aws-sdk-core-3.168.0 lib/aws-sdk-core/token_provider_chain.rb
aws-sdk-core-3.167.0 lib/aws-sdk-core/token_provider_chain.rb
aws-sdk-core-3.166.0 lib/aws-sdk-core/token_provider_chain.rb
aws-sdk-core-3.165.1 lib/aws-sdk-core/token_provider_chain.rb
aws-sdk-core-3.165.0 lib/aws-sdk-core/token_provider_chain.rb
aws-sdk-core-3.164.0 lib/aws-sdk-core/token_provider_chain.rb
aws-sdk-core-3.163.0 lib/aws-sdk-core/token_provider_chain.rb
aws-sdk-core-3.162.0 lib/aws-sdk-core/token_provider_chain.rb
aws-sdk-core-3.161.0 lib/aws-sdk-core/token_provider_chain.rb
aws-sdk-core-3.160.0 lib/aws-sdk-core/token_provider_chain.rb
aws-sdk-core-3.159.0 lib/aws-sdk-core/token_provider_chain.rb
aws-sdk-core-3.158.1 lib/aws-sdk-core/token_provider_chain.rb
aws-sdk-core-3.158.0 lib/aws-sdk-core/token_provider_chain.rb
aws-sdk-core-3.157.0 lib/aws-sdk-core/token_provider_chain.rb
aws-sdk-core-3.156.0 lib/aws-sdk-core/token_provider_chain.rb
aws-sdk-core-3.155.0 lib/aws-sdk-core/token_provider_chain.rb
aws-sdk-core-3.154.0 lib/aws-sdk-core/token_provider_chain.rb
aws-sdk-core-3.153.0 lib/aws-sdk-core/token_provider_chain.rb
aws-sdk-core-3.152.0 lib/aws-sdk-core/token_provider_chain.rb