Class: Awssume::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/awssume/configuration.rb

Overview

A class for managing the properties needed for assuming a role

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Configuration

Returns a new instance of Configuration.



33
34
35
36
37
38
# File 'lib/awssume/configuration.rb', line 33

def initialize(opts = {})
  attrs.each do |k, _|
    attr_val = validate_attrs(attrs.merge(opts), k)
    instance_variable_set("@#{k}", attr_val)
  end
end

Class Method Details

.attrsObject



27
28
29
# File 'lib/awssume/configuration.rb', line 27

def self.attrs
  self.defaults.merge(self.options)
end

.default_session_nameObject



4
5
6
# File 'lib/awssume/configuration.rb', line 4

def self.default_session_name
  "AwssumedSession#{Time.new.to_i}"
end

.defaultsObject

Defaults must have a value: a value passed in or a hardcoded default The utility will exit with an error if a value is missing for a default



10
11
12
13
14
15
16
# File 'lib/awssume/configuration.rb', line 10

def self.defaults
  {
    region:            ENV['AWS_REGION'] || ENV['AWS_DEFAULT_REGION'],
    role_arn:          ENV['AWS_ROLE_ARN'],
    role_session_name: ENV['AWS_ROLE_SESSION_NAME'] || default_session_name,
  }
end

.optionsObject

Options are not required to have a value The utility will function without issue if an optional value is missing



20
21
22
23
24
25
# File 'lib/awssume/configuration.rb', line 20

def self.options
  {
    external_id:       ENV['AWS_ROLE_EXTERNAL_ID'],
    duration_seconds:  ENV['AWS_ROLE_DURATION_SECONDS'].to_i
  }
end