Sha256: 9f9d74e6da0d344e6e48b68cb9eee7191229388d7795820a17dd7e90bcde4114

Contents?: true

Size: 1.88 KB

Versions: 4

Compression:

Stored size: 1.88 KB

Contents

require 'hiera/scope'
require_relative 'configured_data_provider'

module Puppet::Pops
module Lookup
# @api private
class GlobalDataProvider < ConfiguredDataProvider
  def place
    'Global'
  end

  def unchecked_key_lookup(key, lookup_invocation, merge)
    config = config(lookup_invocation)
    if(config.version == 3)
      # Hiera version 3 needs access to special scope variables
      scope = lookup_invocation.scope
      unless scope.is_a?(Hiera::Scope)
        lookup_invocation = Invocation.new(
          Hiera::Scope.new(scope),
          lookup_invocation.override_values,
          lookup_invocation.default_values,
          lookup_invocation.explainer)
      end

      unless config.merge_strategy.is_a?(DefaultMergeStrategy)
        if lookup_invocation.hiera_xxx_call?
          # Merge strategy of the hiera_xxx call should only be applied when no merge strategy is defined in the hiera config
          merge = config.merge_strategy
          lookup_invocation.set_hiera_v3_merge_behavior
        elsif merge.is_a?(DefaultMergeStrategy)
          # For all other calls, the strategy of the call overrides the strategy defined in the hiera config
          merge = config.merge_strategy
          lookup_invocation.set_hiera_v3_merge_behavior
        end
      end
    end
    super(key, lookup_invocation, merge)
  end

  protected

  def assert_config_version(config)
    raise Puppet::DataBinding::LookupError, "#{config.name} cannot be used in the global layer" if config.version == 4
    config
  end

  # Return the root of the environment
  #
  # @param lookup_invocation [Invocation] The current lookup invocation
  # @return [Pathname] Path to the parent of the hiera configuration file
  def provider_root(lookup_invocation)
    configuration_path(lookup_invocation).parent
  end

  def configuration_path(lookup_invocation)
    lookup_invocation.global_hiera_config_path
  end
end
end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
puppet-4.9.3 lib/puppet/pops/lookup/global_data_provider.rb
puppet-4.9.3-x86-mingw32 lib/puppet/pops/lookup/global_data_provider.rb
puppet-4.9.3-x64-mingw32 lib/puppet/pops/lookup/global_data_provider.rb
puppet-4.9.3-universal-darwin lib/puppet/pops/lookup/global_data_provider.rb