module Hiera::Backend

Public Class Methods

lookup(key, default, scope, order_override, resolution_type) click to toggle source

NOTE: This method is overridden so we can collect accumulated hiera parameters and their values on a particular provisioning run for reporting purposes.

   # File lib/core/mod/hiera_backend.rb
10 def lookup(key, default, scope, order_override, resolution_type)
11   @backends ||= {}
12   answer = nil
13 
14   Config[:backends].each do |backend|
15     if constants.include?("#{backend.capitalize}_backend") || constants.include?("#{backend.capitalize}_backend".to_sym)
16       @backends[backend] ||= Backend.const_get("#{backend.capitalize}_backend").new
17       new_answer = @backends[backend].lookup(key, scope, order_override, resolution_type)
18 
19       if not new_answer.nil?
20         case resolution_type
21         when :array
22           raise Exception, "Hiera type mismatch: expected Array and got #{new_answer.class}" unless new_answer.kind_of? Array or new_answer.kind_of? String
23           answer ||= []
24           answer << new_answer
25         when :hash
26           raise Exception, "Hiera type mismatch: expected Hash and got #{new_answer.class}" unless new_answer.kind_of? Hash
27           answer ||= {}
28           answer = merge_answer(new_answer,answer)
29         else
30           answer = new_answer
31           break
32         end
33       end
34     end
35   end
36 
37   answer = resolve_answer(answer, resolution_type) unless answer.nil?
38   answer = parse_string(default, scope) if answer.nil? and default.is_a?(String)
39   answer = default if answer.nil?
40   
41   # This is why we override this method!!
42   # TODO: Submit a patch that allows for some kind of hook into the process.
43   if CORL::Config.get_property(key).nil? || answer    
44     CORL::Config.set_property(key, answer)
45   end
46   return answer
47 end