Class: Hiera::Backend::Proxy_backend
- Defined in:
- puppet/modules/wmflib/lib/hiera/backend/proxy_backend.rb
Overview
This naming is required by puppet.
Instance Method Summary collapse
-
#initialize ⇒ Proxy_backend
constructor
A new instance of Proxy_backend.
- #load_plugins ⇒ Object
- #lookup(key, scope, order_override, resolution_type) ⇒ Object
Constructor Details
#initialize ⇒ Proxy_backend
Returns a new instance of Proxy_backend.
26 27 28 29 30 |
# File 'puppet/modules/wmflib/lib/hiera/backend/proxy_backend.rb', line 26 def initialize Hiera.debug "Starting the proxy backend" @config = Config[:proxy] load_plugins end |
Instance Method Details
#load_plugins ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'puppet/modules/wmflib/lib/hiera/backend/proxy_backend.rb', line 32 def load_plugins @plugins ||= {} # Load plugins only once @config[:plugins].each do |plugin| Hiera.debug "Loading plugin #{plugin}" begin require "hiera/backend/#{plugin.downcase}_backend" @plugins[plugin] ||= Backend.const_get("#{plugin.capitalize}_backend").new rescue Hiera.warn "Failure: plugin #{plugin} failed to load" end end end |
#lookup(key, scope, order_override, resolution_type) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'puppet/modules/wmflib/lib/hiera/backend/proxy_backend.rb', line 47 def lookup(key, scope, order_override, resolution_type) answer = nil hierarchy = Config[:hierarchy].clone Backend.datasources(scope, order_override) do |source| if source.include? '@@' plugin, source = source.split('@@') else plugin = @config[:default_plugin] end unless @plugins.include? plugin Hiera. warn "Hierarchy specifies to use plugin '#{plugin}' but can't find it" next end # We look up onto a foreign backend by limiting us to a # single element of hierarchy. Config[:hierarchy] = [source] new_answer = @plugins[plugin]. lookup(key, scope, order_override, resolution_type) Config[:hierarchy] = hierarchy next if new_answer.nil? case resolution_type when :array raise Exception, "Hiera type mismatch: expected Array and got #{new_answer.class}" unless new_answer.kind_of? Array # The plugins already return an array of answers, so just concatenate it. answer ||= [] answer += new_answer when :hash raise Exception, "Hiera type mismatch: expected Hash and got #{new_answer.class}" unless new_answer.kind_of? Hash answer ||= {} answer = Backend.merge_answer(new_answer, answer) else answer = new_answer break end end answer end |