class Puppet::Pops::Lookup::GlobalDataProvider

@api private

Public Instance Methods

place() click to toggle source
   # File lib/puppet/pops/lookup/global_data_provider.rb
 9 def place
10   'Global'
11 end
unchecked_key_lookup(key, lookup_invocation, merge) click to toggle source
   # File lib/puppet/pops/lookup/global_data_provider.rb
13 def unchecked_key_lookup(key, lookup_invocation, merge)
14   config = config(lookup_invocation)
15   if(config.version == 3)
16     # Hiera version 3 needs access to special scope variables
17     scope = lookup_invocation.scope
18     unless scope.is_a?(Hiera::Scope)
19       return lookup_invocation.with_scope(Hiera::Scope.new(scope)) do |hiera_invocation|
20 
21         # Confine to global scope unless an environment data provider has been defined (same as for hiera_xxx functions)
22         adapter = lookup_invocation.lookup_adapter
23         hiera_invocation.set_global_only unless adapter.global_only? || adapter.has_environment_data_provider?(lookup_invocation)
24         hiera_invocation.lookup(key, lookup_invocation.module_name) { unchecked_key_lookup(key , hiera_invocation, merge) }
25       end
26     end
27 
28     merge = MergeStrategy.strategy(merge)
29     unless config.merge_strategy.is_a?(DefaultMergeStrategy)
30       if lookup_invocation.hiera_xxx_call? && merge.is_a?(HashMergeStrategy)
31         # Merge strategy defined in the hiera config only applies when the call stems from a hiera_hash call.
32         merge = config.merge_strategy
33         lookup_invocation.set_hiera_v3_merge_behavior
34       end
35     end
36 
37     value = super(key, lookup_invocation, merge)
38     if lookup_invocation.hiera_xxx_call?
39       if merge.is_a?(HashMergeStrategy) || merge.is_a?(DeepMergeStrategy)
40         # hiera_hash calls should error when found values are not hashes
41         Types::TypeAsserter.assert_instance_of('value', Types::PHashType::DEFAULT, value)
42       end
43       if !key.segments.nil? && (merge.is_a?(HashMergeStrategy) || merge.is_a?(UniqueMergeStrategy))
44         strategy = merge.is_a?(HashMergeStrategy) ? 'hash' : 'array'
45 
46         # Fail with old familiar message from Hiera 3
47         raise Puppet::DataBinding::LookupError, "Resolution type :#{strategy} is illegal when accessing values using dotted keys. Offending key was '#{key}'"
48       end
49     end
50     value
51   else
52     super
53   end
54 end

Protected Instance Methods

assert_config_version(config) click to toggle source
   # File lib/puppet/pops/lookup/global_data_provider.rb
58 def assert_config_version(config)
59   config.fail(Issues::HIERA_UNSUPPORTED_VERSION_IN_GLOBAL) if config.version == 4
60   config
61 end
configuration_path(lookup_invocation) click to toggle source
   # File lib/puppet/pops/lookup/global_data_provider.rb
71 def configuration_path(lookup_invocation)
72   lookup_invocation.global_hiera_config_path
73 end
provider_root(lookup_invocation) click to toggle source

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

   # File lib/puppet/pops/lookup/global_data_provider.rb
67 def provider_root(lookup_invocation)
68   configuration_path(lookup_invocation).parent
69 end