Class: Puppet::Pops::Lookup::LookupAdapter Private
- Inherits:
-
DataAdapter
- Object
- Adaptable::Adapter
- DataAdapter
- Puppet::Pops::Lookup::LookupAdapter
- Defined in:
- lib/puppet/pops/lookup/lookup_adapter.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.
Constant Summary collapse
- LOOKUP_OPTIONS_PREFIX =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
LOOKUP_OPTIONS + '.'
- LOOKUP_OPTIONS_PATTERN_START =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'^'.freeze
- HASH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'hash'.freeze
- MERGE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'merge'.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #extract_lookup_options_for_key(key, options) ⇒ Object private
-
#global_hiera_config_path ⇒ Pathname
private
The full path of the hiera.yaml config file.
- #global_only? ⇒ Boolean private
-
#has_environment_data_provider?(lookup_invocation) ⇒ Boolean
private
‘true` if an environment data provider version 5 is configured.
-
#initialize(compiler) ⇒ LookupAdapter
constructor
private
A new instance of LookupAdapter.
-
#lookup(key, lookup_invocation, merge) ⇒ Object
private
Performs a lookup using global, environment, and module data providers.
- #lookup_default_in_module(key, lookup_invocation) ⇒ Object private
- #lookup_global(key, lookup_invocation, merge_strategy) ⇒ Object private
- #lookup_in_environment(key, lookup_invocation, merge_strategy) ⇒ Object private
- #lookup_in_module(key, lookup_invocation, merge_strategy) ⇒ Object private
-
#lookup_lookup_options(key, lookup_invocation) ⇒ String, ...
private
Retrieve the lookup options that match the given ‘name`.
-
#lookup_merge_options(key, lookup_invocation) ⇒ String, ...
private
Retrieve the merge options that match the given ‘name`.
-
#set_global_hiera_config_path(path) ⇒ LookupAdapter
private
Self.
-
#set_global_only ⇒ LookupAdapter
private
Instructs the lookup framework to only perform lookups in the global layer.
Methods inherited from DataAdapter
Methods inherited from Adaptable::Adapter
adapt, adapt_new, associate_adapter, clear, get, instance_var_name, self_attr_name, type_name
Constructor Details
#initialize(compiler) ⇒ LookupAdapter
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.
Returns a new instance of LookupAdapter.
24 25 26 27 28 |
# File 'lib/puppet/pops/lookup/lookup_adapter.rb', line 24 def initialize(compiler) super() @compiler = compiler @lookup_options = {} end |
Class Method Details
.create_adapter(compiler) ⇒ 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.
20 21 22 |
# File 'lib/puppet/pops/lookup/lookup_adapter.rb', line 20 def self.create_adapter(compiler) new(compiler) end |
Instance Method Details
#extract_lookup_options_for_key(key, options) ⇒ 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.
190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/puppet/pops/lookup/lookup_adapter.rb', line 190 def (key, ) return nil if .nil? rk = key.root_key key_opts = [0] unless key_opts.nil? key_opt = key_opts[rk] return key_opt unless key_opt.nil? end patterns = [1] patterns.each_pair { |pattern, value| return value if pattern =~ rk } unless patterns.nil? nil end |
#global_hiera_config_path ⇒ Pathname
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.
Returns the full path of the hiera.yaml config file.
213 214 215 |
# File 'lib/puppet/pops/lookup/lookup_adapter.rb', line 213 def global_hiera_config_path @global_hiera_config_path ||= Pathname.new(Puppet.settings[:hiera_config]) end |
#global_only? ⇒ Boolean
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.
224 225 226 |
# File 'lib/puppet/pops/lookup/lookup_adapter.rb', line 224 def global_only? instance_variable_defined?(:@global_only) ? @global_only : false end |
#has_environment_data_provider?(lookup_invocation) ⇒ Boolean
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.
Returns ‘true` if an environment data provider version 5 is configured.
207 208 209 210 |
# File 'lib/puppet/pops/lookup/lookup_adapter.rb', line 207 def has_environment_data_provider?(lookup_invocation) ep = env_provider(lookup_invocation) ep.nil? ? false : ep.config(lookup_invocation).version >= 5 end |
#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.
Performs a lookup using global, environment, and module data providers. Merge the result using the given merge strategy. If the merge strategy is nil, then an attempt is made to find merge options in the ‘lookup_options` hash for an entry associated with the key. If no options are found, the no merge is performed and the first found entry is returned.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/puppet/pops/lookup/lookup_adapter.rb', line 41 def lookup(key, lookup_invocation, merge) # The 'lookup_options' key is reserved and not found as normal data if key == LOOKUP_OPTIONS || key.start_with?(LOOKUP_OPTIONS_PREFIX) lookup_invocation.with(:invalid_key, LOOKUP_OPTIONS) do throw :no_such_key end end key = LookupKey.new(key) lookup_invocation.lookup(key, key.module_name) do merge_explained = false if lookup_invocation. catch(:no_such_key) { do_lookup(LookupKey::LOOKUP_OPTIONS, lookup_invocation, HASH) } nil else if merge.nil? # Used cached lookup_options merge = (key, lookup_invocation) lookup_invocation.report_merge_source(LOOKUP_OPTIONS) unless merge.nil? end lookup_invocation.with(:data, key.to_s) do catch(:no_such_key) { return do_lookup(key, lookup_invocation, merge) } throw :no_such_key if lookup_invocation.global_only? key.dig(lookup_invocation, lookup_default_in_module(key, lookup_invocation)) end end end end |
#lookup_default_in_module(key, lookup_invocation) ⇒ 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.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/puppet/pops/lookup/lookup_adapter.rb', line 123 def lookup_default_in_module(key, lookup_invocation) module_name = lookup_invocation.module_name # Do not attempt to do a lookup in a module unless the name is qualified. throw :no_such_key if module_name.nil? provider = module_provider(lookup_invocation, module_name) throw :no_such_key if provider.nil? || !provider.config(lookup_invocation).has_default_hierarchy? lookup_invocation.with(:scope, "Searching default_hierarchy of module \"#{module_name}\"") do merge_strategy = nil if merge_strategy.nil? @module_default_lookup_options ||= {} = @module_default_lookup_options.fetch(module_name) do |k| = Invocation.new(lookup_invocation.scope) .lookup(LookupKey::LOOKUP_OPTIONS, k) do opts = nil lookup_invocation.with(:scope, "Searching for \"#{LookupKey::LOOKUP_OPTIONS}\"") do catch(:no_such_key) do opts = compile_patterns( ( provider.key_lookup_in_default(LookupKey::LOOKUP_OPTIONS, , MergeStrategy.strategy(HASH)), k)) end end @module_default_lookup_options[k] = opts end end = (key, ) merge_strategy = [MERGE] unless .nil? end lookup_invocation.with(:scope, "Searching for \"#{key}\"") do provider.key_lookup_in_default(key, lookup_invocation, merge_strategy) end end end |
#lookup_global(key, lookup_invocation, merge_strategy) ⇒ 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.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/puppet/pops/lookup/lookup_adapter.rb', line 70 def lookup_global(key, lookup_invocation, merge_strategy) # hiera_xxx will always use global_provider regardless of data_binding_terminus setting terminus = lookup_invocation.hiera_xxx_call? ? :hiera : Puppet[:data_binding_terminus] case terminus when :hiera, 'hiera' provider = global_provider(lookup_invocation) throw :no_such_key if provider.nil? provider.key_lookup(key, lookup_invocation, merge_strategy) when :none, 'none', '', nil # If global lookup is disabled, immediately report as not found lookup_invocation.report_not_found(key) throw :no_such_key else lookup_invocation.with(:global, terminus) do catch(:no_such_key) do return lookup_invocation.report_found(key, Puppet::DataBinding.indirection.find(key.root_key, {:environment => environment, :variables => lookup_invocation.scope, :merge => merge_strategy})) end lookup_invocation.report_not_found(key) throw :no_such_key end end rescue Puppet::DataBinding::LookupError => detail raise detail unless detail.issue_code.nil? error = Puppet::Error.new(_("Lookup of key '%{key}' failed: %{detail}") % { key: lookup_invocation.top_key, detail: detail. }) error.set_backtrace(detail.backtrace) raise error end |
#lookup_in_environment(key, lookup_invocation, merge_strategy) ⇒ 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.
99 100 101 102 103 |
# File 'lib/puppet/pops/lookup/lookup_adapter.rb', line 99 def lookup_in_environment(key, lookup_invocation, merge_strategy) provider = env_provider(lookup_invocation) throw :no_such_key if provider.nil? provider.key_lookup(key, lookup_invocation, merge_strategy) end |
#lookup_in_module(key, lookup_invocation, merge_strategy) ⇒ 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.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/puppet/pops/lookup/lookup_adapter.rb', line 105 def lookup_in_module(key, lookup_invocation, merge_strategy) module_name = lookup_invocation.module_name # Do not attempt to do a lookup in a module unless the name is qualified. throw :no_such_key if module_name.nil? provider = module_provider(lookup_invocation, module_name) if provider.nil? if environment.module(module_name).nil? lookup_invocation.report_module_not_found(module_name) else lookup_invocation.report_module_provider_not_found(module_name) end throw :no_such_key end provider.key_lookup(key, lookup_invocation, merge_strategy) end |
#lookup_lookup_options(key, lookup_invocation) ⇒ String, ...
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.
Retrieve the lookup options that match the given ‘name`.
177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/puppet/pops/lookup/lookup_adapter.rb', line 177 def (key, lookup_invocation) module_name = key.module_name # Retrieve the options for the module. We use nil as a key in case we have no module if !@lookup_options.include?(module_name) = (module_name, lookup_invocation, MergeStrategy.strategy(HASH)) @lookup_options[module_name] = else = @lookup_options[module_name] end (key, ) end |
#lookup_merge_options(key, lookup_invocation) ⇒ String, ...
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.
Retrieve the merge options that match the given ‘name`.
166 167 168 169 |
# File 'lib/puppet/pops/lookup/lookup_adapter.rb', line 166 def (key, lookup_invocation) = (key, lookup_invocation) .nil? ? nil : [MERGE] end |
#set_global_hiera_config_path(path) ⇒ LookupAdapter
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.
Returns self.
219 220 221 222 |
# File 'lib/puppet/pops/lookup/lookup_adapter.rb', line 219 def set_global_hiera_config_path(path) @global_hiera_config_path = Pathname.new(path) self end |
#set_global_only ⇒ LookupAdapter
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.
Instructs the lookup framework to only perform lookups in the global layer
230 231 232 233 |
# File 'lib/puppet/pops/lookup/lookup_adapter.rb', line 230 def set_global_only @global_only = true self end |