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
# File 'lib/aws_assume_role/credentials/factories/assume_role.rb', line 10

def initialize(options)
    if options[: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(prof, region) ⇒ Object



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

def assume_role_with_profile(prof, region)
    AwsAssumeRole.shared_config.assume_role_credentials_from_config(
        profile: prof,
        region: region,
    )
end

#try_with_profile(options) ⇒ Object



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

def try_with_profile(options)
    if AwsAssumeRole.shared_config.config_enabled?
        @profile = options[:profile]
        @region = options[:region]
        @credentials = assume_role_with_profile(options[:profle], options[:region])
    end
    @credentials = assume_role_with_profile(@profile, @region)
    @region ||= AwsAssumeRole.shared_config.profile_region(@profiles)
    @role_arn ||= AwsAssumeRole.shared_config.profile_role(@profile)
end