Sha256: ae69e2588153a691472ff620dc551e9e45080233129965faa34386c9be51991d

Contents?: true

Size: 1.72 KB

Versions: 32

Compression:

Stored size: 1.72 KB

Contents

class Hiera
module Backend
class << self
  #
  # NOTE: This method is overridden so we can collect accumulated hiera
  # parameters and their values on a particular provisioning run for reporting 
  # purposes.
  #
  def lookup(key, default, scope, order_override, resolution_type)
    @backends ||= {}
    answer = nil

    Config[:backends].each do |backend|
      if constants.include?("#{backend.capitalize}_backend") || constants.include?("#{backend.capitalize}_backend".to_sym)
        @backends[backend] ||= Backend.const_get("#{backend.capitalize}_backend").new
        new_answer = @backends[backend].lookup(key, scope, order_override, resolution_type)

        if not 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 or 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 = merge_answer(new_answer,answer)
          else
            answer = new_answer
            break
          end
        end
      end
    end

    answer = resolve_answer(answer, resolution_type) unless answer.nil?
    answer = parse_string(default, scope) if answer.nil? and default.is_a?(String)
    answer = default if answer.nil?
    
    # This is why we override this method!!
    # TODO: Submit a patch that allows for some kind of hook into the process.
    if CORL::Config.get_property(key).nil? || answer    
      CORL::Config.set_property(key, answer)
    end
    return answer
  end
end
end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
corl-0.5.18 lib/core/mod/hiera_backend.rb
corl-0.5.17 lib/core/mod/hiera_backend.rb
corl-0.5.16 lib/core/mod/hiera_backend.rb
corl-0.5.15 lib/core/mod/hiera_backend.rb
corl-0.5.14 lib/core/mod/hiera_backend.rb
corl-0.5.13 lib/core/mod/hiera_backend.rb
corl-0.5.12 lib/core/mod/hiera_backend.rb
corl-0.5.11 lib/core/mod/hiera_backend.rb
corl-0.5.10 lib/core/mod/hiera_backend.rb
corl-0.5.9 lib/core/mod/hiera_backend.rb
corl-0.5.8 lib/core/mod/hiera_backend.rb
corl-0.5.7 lib/core/mod/hiera_backend.rb
corl-0.5.6 lib/core/mod/hiera_backend.rb
corl-0.5.5 lib/core/mod/hiera_backend.rb
corl-0.5.4 lib/core/mod/hiera_backend.rb
corl-0.5.3 lib/core/mod/hiera_backend.rb
corl-0.5.2 lib/core/mod/hiera_backend.rb
corl-0.5.1 lib/core/mod/hiera_backend.rb
corl-0.5.0 lib/core/mod/hiera_backend.rb
corl-0.4.29 lib/core/mod/hiera_backend.rb