Class: Aws::LoginCredentials

Inherits:
Object
  • Object
show all
Includes:
CredentialProvider, RefreshingCredentials
Defined in:
gems/aws-sdk-core/lib/aws-sdk-core/login_credentials.rb

Overview

An auto-refreshing credential provider that retrieves credentials from a cached login token. This class does NOT implement the AWS Sign-In login flow - tokens must be generated separately by running aws login from the AWS CLI/AWS Tools for PowerShell with the correct profile. The LoginCredentials will auto-refresh the AWS credentials from AWS Sign-In.

# You must first run aws login --profile your-login-profile
 = Aws::LoginCredentials.new(login_session: 'my_login_session')
ec2 = Aws::EC2::Client.new(credentials: )

If you omit the :client option, a new Signin::Client object will be constructed with additional options that were provided.

Constant Summary

Constants included from RefreshingCredentials

RefreshingCredentials::ASYNC_EXPIRATION_LENGTH, RefreshingCredentials::CLIENT_EXCLUDE_OPTIONS, RefreshingCredentials::SYNC_EXPIRATION_LENGTH

Instance Attribute Summary collapse

Attributes included from CredentialProvider

#credentials, #expiration

Instance Method Summary collapse

Methods included from RefreshingCredentials

#credentials, #refresh!

Methods included from CredentialProvider

#set?

Constructor Details

#initialize(options = {}) ⇒ LoginCredentials

Returns a new instance of LoginCredentials.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :login_session (required, String)

    An opaque string used to determine the cache file location. This value can be found in the AWS config file which is set by the AWS CLI/AWS Tools for PowerShell automatically.

  • :client (Signin::Client)

    Optional Signin::Client. If not provided, a client will be constructed.

Raises:

  • (ArgumentError)


27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'gems/aws-sdk-core/lib/aws-sdk-core/login_credentials.rb', line 27

def initialize(options = {})
  raise ArgumentError, 'Missing login_session' unless options[:login_session]

  @login_session = options.delete(:login_session)
  @client = options[:client]
  unless @client
    client_opts = options.reject { |key, _| CLIENT_EXCLUDE_OPTIONS.include?(key) }
    @client = Signin::Client.new(client_opts.merge(credentials: nil))
  end
  @metrics = ['CREDENTIALS_LOGIN']
  @async_refresh = true
  super
end

Instance Attribute Details

#clientSignin::Client (readonly)

Returns:



42
43
44
# File 'gems/aws-sdk-core/lib/aws-sdk-core/login_credentials.rb', line 42

def client
  @client
end