Class: Puppet::Pops::Lookup::GlobalDataProvider Private

Inherits:
ConfiguredDataProvider show all
Defined in:
lib/puppet/pops/lookup/global_data_provider.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Methods inherited from ConfiguredDataProvider

#config, #config=, #config_path, #initialize, #name

Methods included from DataProvider

#key_lookup, #key_lookup_in_default, key_type, #lookup, #module_name, #name, register_types, #validate_data_hash, #validate_data_value, #value_is_validated?, value_type

Constructor Details

This class inherits a constructor from Puppet::Pops::Lookup::ConfiguredDataProvider

Instance Method Details

#placeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'lib/puppet/pops/lookup/global_data_provider.rb', line 10

def place
  'Global'
end

#unchecked_key_lookup(key, lookup_invocation, merge) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/puppet/pops/lookup/global_data_provider.rb', line 14

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)
      return lookup_invocation.with_scope(Hiera::Scope.new(scope)) do |hiera_invocation|
        # Confine to global scope unless an environment data provider has been defined (same as for hiera_xxx functions)
        adapter = lookup_invocation.lookup_adapter
        hiera_invocation.set_global_only unless adapter.global_only? || adapter.has_environment_data_provider?(lookup_invocation)
        hiera_invocation.lookup(key, lookup_invocation.module_name) { unchecked_key_lookup(key, hiera_invocation, merge) }
      end
    end

    merge = MergeStrategy.strategy(merge)
    unless config.merge_strategy.is_a?(DefaultMergeStrategy)
      if lookup_invocation.hiera_xxx_call? && merge.is_a?(HashMergeStrategy)
        # Merge strategy defined in the hiera config only applies when the call stems from a hiera_hash call.
        merge = config.merge_strategy
        lookup_invocation.set_hiera_v3_merge_behavior
      end
    end

    value = super(key, lookup_invocation, merge)
    if lookup_invocation.hiera_xxx_call?
      if merge.is_a?(HashMergeStrategy) || merge.is_a?(DeepMergeStrategy)
        # hiera_hash calls should error when found values are not hashes
        Types::TypeAsserter.assert_instance_of('value', Types::PHashType::DEFAULT, value)
      end
      if !key.segments.nil? && (merge.is_a?(HashMergeStrategy) || merge.is_a?(UniqueMergeStrategy))
        strategy = merge.is_a?(HashMergeStrategy) ? 'hash' : 'array'

        # Fail with old familiar message from Hiera 3
        raise Puppet::DataBinding::LookupError, "Resolution type :#{strategy} is illegal when accessing values using dotted keys. Offending key was '#{key}'"
      end
    end
    value
  else
    super
  end
end