Sha256: 64c3f0b24d7c5f6340dec24e1b4f962bec3ee764cc0d64f82aac65a36b34ce2c

Contents?: true

Size: 1.29 KB

Versions: 29

Compression:

Stored size: 1.29 KB

Contents

module Aws

  # An auto-refreshing credential provider that works by assuming
  # a role via {Aws::STS::Client#assume_role}.
  #
  #    role_credentials = Aws::AssumeRoleCredentials.new(
  #      client: Aws::STS::Client.new(...),
  #      role_arn: "linked::account::arn",
  #      role_session_name: "session-name"
  #    )
  #
  #    ec2 = Aws::EC2::Client.new(credentials: role_credentials)
  #
  # If you omit `:client` option, a new {STS::Client} object will be
  # constructed.
  class AssumeRoleCredentials

    include CredentialProvider
    include RefreshingCredentials

    # @option options [required, String] :role_arn
    # @option options [required, String] :role_session_name
    # @option options [String] :policy
    # @option options [Integer] :duration_seconds
    # @option options [String] :external_id
    # @option opitons [STS::Client] :client
    def initialize(options = {})
      @options = options.dup
      @client = @options.delete(:client) || STS::Client.new
      super
    end

    # @return [STS::Client]
    attr_reader :client

    private

    def refresh
      c = @client.assume_role(@options).credentials
      @credentials = Credentials.new(
        c.access_key_id,
        c.secret_access_key,
        c.session_token
      )
      @expiration = c.expiration
    end

  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
aws-sdk-core-2.1.29 lib/aws-sdk-core/assume_role_credentials.rb
aws-sdk-core-2.1.28 lib/aws-sdk-core/assume_role_credentials.rb
aws-sdk-core-2.1.27 lib/aws-sdk-core/assume_role_credentials.rb
aws-sdk-core-2.1.26 lib/aws-sdk-core/assume_role_credentials.rb
aws-sdk-core-2.1.25 lib/aws-sdk-core/assume_role_credentials.rb
aws-sdk-core-2.1.24 lib/aws-sdk-core/assume_role_credentials.rb
aws-sdk-core-2.1.23 lib/aws-sdk-core/assume_role_credentials.rb
aws-sdk-core-2.1.22 lib/aws-sdk-core/assume_role_credentials.rb
aws-sdk-core-2.1.21 lib/aws-sdk-core/assume_role_credentials.rb
aws-sdk-core-2.1.20 lib/aws-sdk-core/assume_role_credentials.rb
aws-sdk-core-2.1.19 lib/aws-sdk-core/assume_role_credentials.rb
aws-sdk-core-2.1.18 lib/aws-sdk-core/assume_role_credentials.rb
aws-sdk-core-2.1.17 lib/aws-sdk-core/assume_role_credentials.rb
aws-sdk-core-2.1.16 lib/aws-sdk-core/assume_role_credentials.rb
aws-sdk-core-2.1.15 lib/aws-sdk-core/assume_role_credentials.rb
aws-sdk-core-2.1.14 lib/aws-sdk-core/assume_role_credentials.rb
aws-sdk-core-2.1.13 lib/aws-sdk-core/assume_role_credentials.rb
aws-sdk-core-2.1.12 lib/aws-sdk-core/assume_role_credentials.rb
aws-sdk-core-2.1.11 lib/aws-sdk-core/assume_role_credentials.rb
aws-sdk-core-2.1.10 lib/aws-sdk-core/assume_role_credentials.rb