Class: Hiera::Backend::Httpyaml_backend
- Defined in:
- puppet/modules/wmflib/lib/hiera/backend/httpyaml_backend.rb
Overview
This naming is required by puppet.
Instance Method Summary collapse
-
#initialize ⇒ Httpyaml_backend
constructor
A new instance of Httpyaml_backend.
- #lookup(key, scope, order_override, resolution_type) ⇒ Object
Constructor Details
#initialize ⇒ Httpyaml_backend
Returns a new instance of Httpyaml_backend.
6 7 8 |
# File 'puppet/modules/wmflib/lib/hiera/backend/httpyaml_backend.rb', line 6 def initialize @cache = Httpcache.new end |
Instance Method Details
#lookup(key, scope, order_override, resolution_type) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'puppet/modules/wmflib/lib/hiera/backend/httpyaml_backend.rb', line 10 def lookup(key, scope, order_override, resolution_type) answer = nil Hiera.debug("Looking up #{key}") Backend.datasources(scope, order_override) do |source| # Small hack: We don't want to search any datasource but the # httpyaml/%{::labsproject} hierarchy here; so we plainly exit # in any other case. next unless source.start_with?('httpyaml/') && source.length > 'httpyaml/'.length data = @cache.read(source) next if data.nil? || data.empty? next unless data.include?(key) new_answer = Backend.parse_answer(data[key], scope) case resolution_type when :array raise Exception, "Hiera type mismatch: expected Array and got #{new_answer.class}" unless new_answer.kind_of?(Array) || new_answer.kind_of?(String) 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 |