Class: Hiera::Backend::Aws::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/hiera/backend/aws/base.rb

Overview

Base class for all AWS service classes

Direct Known Subclasses

Cloudformation, ElastiCache, RDS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope = {}) ⇒ Base

Returns a new instance of Base.



10
11
12
# File 'lib/hiera/backend/aws/base.rb', line 10

def initialize(scope = {})
  @scope = scope
end

Instance Attribute Details

#scopeObject (readonly)

Returns the value of attribute scope.



14
15
16
# File 'lib/hiera/backend/aws/base.rb', line 14

def scope
  @scope
end

Instance Method Details

#aws_account_numberObject



20
21
22
23
# File 'lib/hiera/backend/aws/base.rb', line 20

def 
  puppet_fact("aws_account_number") ||
    AWS::IAM.new.users.first.arn.split(":")[4]
end

#aws_regionObject



16
17
18
# File 'lib/hiera/backend/aws/base.rb', line 16

def aws_region
  AWS.config.region
end

#lookup(key, scope) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/hiera/backend/aws/base.rb', line 25

def lookup(key, scope)
  @scope = scope
  if respond_to? key
    send(key)
  else
    # Found no handler for key
    nil
  end
end

#puppet_fact(name) ⇒ Object



35
36
37
38
39
# File 'lib/hiera/backend/aws/base.rb', line 35

def puppet_fact(name)
  fact = scope[name]
  return nil if fact == :undefined
  fact
end

#stringify_keys(hash) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/hiera/backend/aws/base.rb', line 42

def stringify_keys(hash)
  hash.reduce({}) do |result, (key, value)|
    new_key = case key
              when Symbol then key.to_s
              else key
              end
    new_value = case value
                when Hash then stringify_keys(value)
                else value
                end
    result[new_key] = new_value
    result
  end
end