Class: AwsAssumeRole::ProfileConfiguration

Inherits:
Dry::Struct
  • Object
show all
Includes:
Logging
Defined in:
lib/aws_assume_role/profile_configuration.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

included

Instance Attribute Details

#credentials=(value) ⇒ Object (writeonly)

Sets the attribute credentials


30
31
32
# File 'lib/aws_assume_role/profile_configuration.rb', line 30

def credentials=(value)
  @credentials = value
end

Class Method Details

.merge_mfa_variable(options) ⇒ Object


32
33
34
35
36
37
38
39
# File 'lib/aws_assume_role/profile_configuration.rb', line 32

def self.merge_mfa_variable(options)
    new_hash = options.key?(:mfa_serial) ? options.merge(serial_number: options[:mfa_serial]) : options
    new_hash[:use_mfa] ||= new_hash.fetch(:serial_number, nil) ? true : false
    if new_hash.key?(:serial_number) && new_hash[:serial_number] == "automatic"
        new_hash.delete(:serial_number)
    end
    new_hash
end

.new_from_cli(global_options, options, args) ⇒ Object


41
42
43
44
45
46
47
48
# File 'lib/aws_assume_role/profile_configuration.rb', line 41

def self.new_from_cli(global_options, options, args)
    options = global_options.merge options
    options = options.map do |k, v|
        [k.to_s.underscore.to_sym, v]
    end.to_h
    options[:args] = args
    new merge_mfa_variable(options)
end

.new_from_credential_provider(options = {}, credentials: nil, delete: []) ⇒ Object


55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/aws_assume_role/profile_configuration.rb', line 55

def self.new_from_credential_provider(options = {}, credentials: nil, delete: [])
    option_hash = options.to_h
    config = option_hash.fetch(:config, {}).to_h
    hash_to_merge = option_hash.merge config
    hash_to_merge.merge(credentials: credentials) if credentials
    delete.each do |k|
        hash_to_merge.delete k
    end
    hash = merge_mfa_variable(hash_to_merge)
    logger.debug "new_from_credential_provider with #{hash}"
    new hash
end

.new_from_credential_provider_initialization(options) ⇒ Object


50
51
52
53
# File 'lib/aws_assume_role/profile_configuration.rb', line 50

def self.new_from_credential_provider_initialization(options)
    logger.debug "new_from_credential_provider_initialization with #{options.to_h}"
    new_from_credential_provider(options, credentials: nil, delete: [])
end

Instance Method Details

#to_hObject


68
69
70
# File 'lib/aws_assume_role/profile_configuration.rb', line 68

def to_h
    to_hash
end