Class: AwsAssumeRole::Credentials::Factories::AssumeRole

Inherits:
AbstractFactory show all
Includes:
AwsAssumeRole::Credentials::Factories
Defined in:
lib/aws_assume_role/credentials/factories/assume_role.rb

Constant Summary

Constants included from AwsAssumeRole::Credentials::Factories

Types

Constants included from AwsAssumeRole

AwsAssumeRole::Config, DefaultProvider, VERSION

Instance Attribute Summary

Attributes inherited from AbstractFactory

#credentials, #profile, #region, #role_arn

Instance Method Summary collapse

Methods included from Logging

included

Methods included from AwsAssumeRole

shared_config

Methods inherited from AbstractFactory

priority, register_if_complete, type

Constructor Details

#initialize(options) ⇒ AssumeRole

Returns a new instance of AssumeRole.


10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/aws_assume_role/credentials/factories/assume_role.rb', line 10

def initialize(options)
    logger.debug "AwsAssumeRole::Credentials::Factories::AssumeRole initiated with #{options}"
    return unless options[:profile] || options[:role_arn]
    if options[:profile]
        logger.debug "AwsAssumeRole: #{options[:profile]} found. Trying with profile"
        try_with_profile(options)
    else
        if options[:use_mfa]
            options[:credentials] = AwsAssumeRole::Credentials::Providers::MfaSessionCredentials.new(options).credentials
        end
        @credentials = AwsAssumeRole::Credentials::Providers::AssumeRoleCredentials.new(options)
    end
end

Instance Method Details

#assume_role_with_profile(options) ⇒ Object


34
35
36
# File 'lib/aws_assume_role/credentials/factories/assume_role.rb', line 34

def assume_role_with_profile(options)
    AwsAssumeRole.shared_config.assume_role_credentials_from_config(options)
end

#try_with_profile(options) ⇒ Object


24
25
26
27
28
29
30
31
32
# File 'lib/aws_assume_role/credentials/factories/assume_role.rb', line 24

def try_with_profile(options)
    return unless AwsAssumeRole.shared_config.config_enabled?
    logger.debug "AwsAssumeRole: Shared Config enabled"
    @profile = options[:profile]
    @region = options[:region]
    @credentials = assume_role_with_profile(options)
    @region ||= AwsAssumeRole.shared_config.profile_region(@profile)
    @role_arn ||= AwsAssumeRole.shared_config.profile_role(@profile)
end