Class: Covalence::HieraDB::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/covalence/core/data_stores/hiera.rb

Overview

TODO: maybe HieraWrapper :reek:DataClump

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, scope = {}) ⇒ Client

Returns a new instance of Client.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/covalence/core/data_stores/hiera.rb', line 12

def initialize(config, scope = {})
  @config = config
  @scope = scope

  begin
    @client = Hiera.new(:config => config)
  rescue RuntimeError => e
    Covalence::LOGGER.error e.message
    exit 1
  end
end

Instance Attribute Details

#scopeObject (readonly)

Returns the value of attribute scope.



10
11
12
# File 'lib/covalence/core/data_stores/hiera.rb', line 10

def scope
  @scope
end

Instance Method Details

#array_lookup(key, default = nil, scope = @scope) ⇒ Object



45
46
47
# File 'lib/covalence/core/data_stores/hiera.rb', line 45

def array_lookup(key, default = nil, scope = @scope)
  @client.lookup(key, default, scope, nil, :array)
end

#hash_lookup(key, default = nil, scope = @scope) ⇒ Object



39
40
41
42
43
# File 'lib/covalence/core/data_stores/hiera.rb', line 39

def hash_lookup(key, default = nil, scope = @scope)
  # https://github.com/puppetlabs/hiera/blob/d7ed74f4eec8f4fb1aa84cd0e158a595f86debd4/lib/hiera/backend.rb#L241
  # def lookup(key, default, scope, order_override, resolution_type, context = {:recurse_guard => nil})
  @client.lookup(key, default, scope, nil, :hash)
end

#initialize_scope(scope) ⇒ Object



24
25
26
# File 'lib/covalence/core/data_stores/hiera.rb', line 24

def initialize_scope(scope)
  self.class.new(@config, scope)
end

#lookup(key, default = nil, scope = @scope) ⇒ Object



35
36
37
# File 'lib/covalence/core/data_stores/hiera.rb', line 35

def lookup(key, default = nil, scope = @scope)
  @client.lookup(key, default, scope)
end

#set_scope(env, stack) ⇒ Object



28
29
30
31
32
33
# File 'lib/covalence/core/data_stores/hiera.rb', line 28

def set_scope(env, stack)
  @scope = {
    "environment" => env,
    "stack" => stack
  }
end