puppet 4.3.1-x64-mingw32 → 4.3.2-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of puppet might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/ext/build_defaults.yaml +1 -1
- data/lib/hiera/scope.rb +1 -1
- data/lib/puppet/application/lookup.rb +41 -43
- data/lib/puppet/data_providers/lookup_adapter.rb +73 -26
- data/lib/puppet/functions/lookup.rb +126 -150
- data/lib/puppet/functions/match.rb +1 -0
- data/lib/puppet/indirector/hiera.rb +3 -1
- data/lib/puppet/indirector/indirection.rb +6 -2
- data/lib/puppet/indirector/json.rb +2 -2
- data/lib/puppet/module.rb +3 -2
- data/lib/puppet/node.rb +11 -2
- data/lib/puppet/parser/compiler.rb +1 -8
- data/lib/puppet/parser/functions/lookup.rb +128 -149
- data/lib/puppet/parser/functions/match.rb +1 -0
- data/lib/puppet/plugins/data_providers/data_provider.rb +3 -2
- data/lib/puppet/pops/adapters.rb +43 -0
- data/lib/puppet/pops/evaluator/access_operator.rb +3 -3
- data/lib/puppet/pops/evaluator/closure.rb +51 -51
- data/lib/puppet/pops/evaluator/collector_transformer.rb +16 -0
- data/lib/puppet/pops/evaluator/runtime3_support.rb +11 -2
- data/lib/puppet/pops/functions/function.rb +6 -2
- data/lib/puppet/pops/issues.rb +16 -0
- data/lib/puppet/pops/loader/puppet_function_instantiator.rb +3 -2
- data/lib/puppet/pops/lookup.rb +3 -0
- data/lib/puppet/pops/lookup/explainer.rb +73 -3
- data/lib/puppet/pops/lookup/invocation.rb +21 -19
- data/lib/puppet/pops/model/factory.rb +153 -155
- data/lib/puppet/pops/model/model.rb +9 -0
- data/lib/puppet/pops/model/model_label_provider.rb +1 -0
- data/lib/puppet/pops/parser/evaluating_parser.rb +3 -3
- data/lib/puppet/pops/parser/lexer2.rb +411 -393
- data/lib/puppet/pops/parser/slurp_support.rb +5 -1
- data/lib/puppet/pops/types/type_calculator.rb +2 -6
- data/lib/puppet/pops/types/types.rb +3 -9
- data/lib/puppet/pops/validation/checker4_0.rb +36 -12
- data/lib/puppet/provider/group/windows_adsi.rb +2 -2
- data/lib/puppet/provider/package/pip.rb +11 -1
- data/lib/puppet/provider/package/rpm.rb +0 -1
- data/lib/puppet/provider/package/yum.rb +1 -1
- data/lib/puppet/provider/service/debian.rb +5 -18
- data/lib/puppet/provider/service/init.rb +7 -0
- data/lib/puppet/provider/service/launchd.rb +6 -0
- data/lib/puppet/provider/service/systemd.rb +1 -1
- data/lib/puppet/provider/user/windows_adsi.rb +2 -2
- data/lib/puppet/provider/yumrepo/inifile.rb +6 -3
- data/lib/puppet/resource/type.rb +2 -1
- data/lib/puppet/transaction/additional_resource_generator.rb +17 -3
- data/lib/puppet/type/group.rb +6 -2
- data/lib/puppet/util/windows.rb +4 -0
- data/lib/puppet/util/windows/adsi.rb +61 -24
- data/lib/puppet/util/windows/principal.rb +181 -0
- data/lib/puppet/util/windows/registry.rb +21 -15
- data/lib/puppet/util/windows/sid.rb +42 -11
- data/lib/puppet/version.rb +1 -1
- data/spec/fixtures/unit/application/environments/production/data/common.yaml +4 -0
- data/spec/fixtures/unit/application/environments/production/manifests/site.pp +1 -0
- data/spec/fixtures/unit/application/environments/puppet_func_provider/environment.conf +1 -0
- data/spec/fixtures/unit/application/environments/puppet_func_provider/functions/data.pp +10 -0
- data/spec/fixtures/unit/application/environments/puppet_func_provider/manifests/site.pp +1 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_module_config/data/common.yaml +4 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_module_config/data/specific.yaml +4 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_module_config/hiera.yaml +7 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/data/common.yaml +4 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/data/specific.yaml +4 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/environment.conf +2 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/hiera.yaml +7 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/manifests/site.pp +1 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/one/data/common.yaml +6 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/one/hiera.yaml +5 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/one/manifests/init.pp +2 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/one/metadata.json +9 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/two/data/common.yaml +4 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/two/hiera.yaml +5 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/two/manifests/init.pp +3 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/two/metadata.json +9 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee/functions/usee_puppet.pp +3 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/{usee → modules/usee}/lib/puppet/functions/usee/callee.rb +0 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee/lib/puppet/functions/usee/usee_ruby.rb +6 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee/manifests/init.pp +6 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee2/lib/puppet/functions/usee2/callee.rb +5 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/functions/puppet_calling_puppet.pp +5 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/functions/puppet_calling_puppet_init.pp +5 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/functions/puppet_calling_ruby.pp +5 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/{user → modules/user}/lib/puppet/functions/user/caller.rb +0 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/lib/puppet/functions/user/caller2.rb +5 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/lib/puppet/functions/user/ruby_calling_puppet.rb +5 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/lib/puppet/functions/user/ruby_calling_puppet_init.rb +5 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/lib/puppet/functions/user/ruby_calling_ruby.rb +5 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/manifests/init.pp +81 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/{user → modules/user}/metadata.json +2 -1
- data/spec/integration/parser/collection_spec.rb +8 -0
- data/spec/integration/util/windows/principal_spec.rb +115 -0
- data/spec/{unit → integration}/util/windows/registry_spec.rb +91 -1
- data/spec/integration/util/windows/security_spec.rb +2 -2
- data/spec/unit/application/lookup_spec.rb +138 -28
- data/spec/unit/data_providers/hiera_data_provider_spec.rb +182 -5
- data/spec/unit/face/epp_face_spec.rb +2 -2
- data/spec/unit/functions/epp_spec.rb +6 -6
- data/spec/unit/functions/inline_epp_spec.rb +4 -4
- data/spec/unit/functions/lookup_spec.rb +30 -3
- data/spec/unit/functions4_spec.rb +1 -1
- data/spec/unit/hiera/scope_spec.rb +5 -2
- data/spec/unit/indirector/json_spec.rb +1 -1
- data/spec/unit/node_spec.rb +8 -0
- data/spec/unit/parser/compiler_spec.rb +0 -18
- data/spec/unit/pops/evaluator/access_ops_spec.rb +4 -4
- data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +1 -1
- data/spec/unit/pops/loaders/loaders_spec.rb +84 -2
- data/spec/unit/pops/parser/lexer2_spec.rb +6 -0
- data/spec/unit/pops/parser/parser_rspec_helper.rb +5 -0
- data/spec/unit/pops/types/type_calculator_spec.rb +0 -17
- data/spec/unit/pops/validator/validator_spec.rb +87 -0
- data/spec/unit/provider/group/windows_adsi_spec.rb +8 -8
- data/spec/unit/provider/package/pip_spec.rb +41 -13
- data/spec/unit/provider/package/rpm_spec.rb +2 -25
- data/spec/unit/provider/package/yum_spec.rb +1 -1
- data/spec/unit/provider/service/debian_spec.rb +6 -24
- data/spec/unit/provider/service/init_spec.rb +11 -1
- data/spec/unit/provider/service/launchd_spec.rb +11 -0
- data/spec/unit/provider/service/systemd_spec.rb +18 -12
- data/spec/unit/provider/service/upstart_spec.rb +57 -0
- data/spec/unit/provider/user/windows_adsi_spec.rb +5 -5
- data/spec/unit/provider/yumrepo/inifile_spec.rb +16 -0
- data/spec/unit/resource_spec.rb +12 -2
- data/spec/unit/util/windows/adsi_spec.rb +44 -36
- data/spec/unit/util/windows/sid_spec.rb +47 -10
- metadata +77 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e088919c39d3ed288f44eb7d2ff4521f5edd2278
|
4
|
+
data.tar.gz: b5b1c5564ac30f47e6f2971893ac2c402708f3c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c1b5c7200ef7c8a28ed2de5df046b4802461f15c774da5218fd959c22beabf9a19da9b74e1bb5c5842929883034f7e9aa9c6c73c0a996ec4b458f8095885e2a
|
7
|
+
data.tar.gz: 22b393ad4aa9ab172384619e83e8c218dd902427781ffbfdb79cb796d8140b58f7e5571f83c04594009c4da798194411186f5fa3b97e9f18ac84d1e016fc3fb4
|
data/ext/build_defaults.yaml
CHANGED
@@ -14,7 +14,7 @@ build_dmg: FALSE
|
|
14
14
|
sign_tar: FALSE
|
15
15
|
yum_host: 'yum.puppetlabs.com'
|
16
16
|
yum_repo_path: '/opt/repository/yum/'
|
17
|
-
|
17
|
+
apt_signing_server: 'apt.puppetlabs.com'
|
18
18
|
apt_repo_url: 'http://apt.puppetlabs.com'
|
19
19
|
apt_repo_path: '/opt/repository/incoming'
|
20
20
|
tar_host: 'downloads.puppetlabs.com'
|
data/lib/hiera/scope.rb
CHANGED
@@ -12,11 +12,7 @@ class Puppet::Application::Lookup < Puppet::Application
|
|
12
12
|
|
13
13
|
# Options for lookup
|
14
14
|
option('--merge TYPE') do |arg|
|
15
|
-
|
16
|
-
options[:merge] = arg
|
17
|
-
else
|
18
|
-
raise "The --merge option only accepts 'unique', 'hash', or 'deep'.\n#{RUN_HELP}"
|
19
|
-
end
|
15
|
+
options[:merge] = arg
|
20
16
|
end
|
21
17
|
|
22
18
|
option('--debug', '-d')
|
@@ -31,6 +27,8 @@ class Puppet::Application::Lookup < Puppet::Application
|
|
31
27
|
options[:type] = arg
|
32
28
|
end
|
33
29
|
|
30
|
+
option('--compile', '-c')
|
31
|
+
|
34
32
|
option('--knock-out-prefix PREFIX_STRING') do |arg|
|
35
33
|
options[:prefix] = arg
|
36
34
|
end
|
@@ -45,6 +43,8 @@ class Puppet::Application::Lookup < Puppet::Application
|
|
45
43
|
|
46
44
|
option('--explain')
|
47
45
|
|
46
|
+
option('--explain-options')
|
47
|
+
|
48
48
|
option('--default VALUE') do |arg|
|
49
49
|
options[:default_value] = arg
|
50
50
|
end
|
@@ -96,31 +96,6 @@ class Puppet::Application::Lookup < Puppet::Application
|
|
96
96
|
Puppet::FileBucket::File.indirection.terminus_class = :file
|
97
97
|
end
|
98
98
|
|
99
|
-
def setup_ssl
|
100
|
-
# Configure all of the SSL stuff.
|
101
|
-
if Puppet::SSL::CertificateAuthority.ca?
|
102
|
-
Puppet::SSL::Host.ca_location = :local
|
103
|
-
Puppet.settings.use :ca
|
104
|
-
Puppet::SSL::CertificateAuthority.instance
|
105
|
-
else
|
106
|
-
Puppet::SSL::Host.ca_location = :none
|
107
|
-
end
|
108
|
-
# These lines are not on stable (seems like a copy was made from master)
|
109
|
-
#
|
110
|
-
# Puppet::SSL::Oids.register_puppet_oids
|
111
|
-
# Puppet::SSL::Oids.load_custom_oid_file(Puppet[:trusted_oid_mapping_file])
|
112
|
-
end
|
113
|
-
|
114
|
-
# Sets up a special node cache "write only yaml" that collects and stores node data in yaml
|
115
|
-
# but never finds or reads anything (this since a real cache causes stale data to be served
|
116
|
-
# in circumstances when the cache can not be cleared).
|
117
|
-
# @see puppet issue 16753
|
118
|
-
# @see Puppet::Node::WriteOnlyYaml
|
119
|
-
# @return [void]
|
120
|
-
def setup_node_cache
|
121
|
-
Puppet::Node.indirection.cache_class = Puppet[:node_cache_terminus]
|
122
|
-
end
|
123
|
-
|
124
99
|
def setup
|
125
100
|
setup_logs
|
126
101
|
|
@@ -129,11 +104,6 @@ class Puppet::Application::Lookup < Puppet::Application
|
|
129
104
|
Puppet.settings.use :main, :master, :ssl, :metrics
|
130
105
|
|
131
106
|
setup_terminuses
|
132
|
-
|
133
|
-
# TODO: Do we need this in lookup? It sets up a write only cache
|
134
|
-
setup_node_cache
|
135
|
-
|
136
|
-
setup_ssl
|
137
107
|
end
|
138
108
|
|
139
109
|
def help
|
@@ -156,6 +126,7 @@ puppet lookup [--help] [--type <TYPESTRING>] [--merge unique|hash|deep]
|
|
156
126
|
[--knock-out-prefix <PREFIX-STRING>] [--sort-merged-arrays]
|
157
127
|
[--unpack-arrays <STRING-VALUE>] [--merge-hash-arrays] [--explain]
|
158
128
|
[--default <VALUE>] [--node <NODE-NAME>] [--facts <FILE>]
|
129
|
+
[--compile]
|
159
130
|
[--render-as s|json|yaml|binary|msgpack] <keys>
|
160
131
|
|
161
132
|
DESCRIPTION
|
@@ -214,6 +185,10 @@ the puppet lookup function linked to above.
|
|
214
185
|
than the value returned for the key. The explaination will describe how
|
215
186
|
the result was obtained or why lookup failed to obtain the result.
|
216
187
|
|
188
|
+
* --explain-options
|
189
|
+
Explain if a lookup_options hash will be used and how it was assembled
|
190
|
+
when performing a lookup.
|
191
|
+
|
217
192
|
* --default <VALUE>
|
218
193
|
A value produced if no value was found in the lookup.
|
219
194
|
|
@@ -227,6 +202,11 @@ the puppet lookup function linked to above.
|
|
227
202
|
override the facts for the current node. Any facts not specified by the
|
228
203
|
user will maintain their original value.
|
229
204
|
|
205
|
+
* --compile
|
206
|
+
Perform a full catalog compilation prior to the lookup. This is meaningful when
|
207
|
+
the catalog changes global variables that are referenced in interpolated values.
|
208
|
+
No catalog compilation takes place unless this flag is given.
|
209
|
+
|
230
210
|
* --render-as s|json|yaml|binary|msgpack
|
231
211
|
Determines how the results will be rendered to the standard output where
|
232
212
|
s means plain text. The default when lookup is producing a value is yaml
|
@@ -266,7 +246,6 @@ Copyright (c) 2015 Puppet Labs, LLC Licensed under the Apache 2.0 License
|
|
266
246
|
|
267
247
|
def main
|
268
248
|
keys = command_line.args
|
269
|
-
raise 'No keys were given to lookup.' if keys.empty?
|
270
249
|
|
271
250
|
#unless options[:node]
|
272
251
|
# raise "No node was given via the '--node' flag for the scope of the lookup.\n#{RUN_HELP}"
|
@@ -279,8 +258,15 @@ Copyright (c) 2015 Puppet Labs, LLC Licensed under the Apache 2.0 License
|
|
279
258
|
use_default_value = !options[:default_value].nil?
|
280
259
|
merge_options = nil
|
281
260
|
|
282
|
-
|
283
|
-
|
261
|
+
merge = options[:merge]
|
262
|
+
unless merge.nil?
|
263
|
+
strategies = Puppet::Pops::MergeStrategy.strategy_keys
|
264
|
+
unless strategies.include?(merge.to_sym)
|
265
|
+
strategies = strategies.map {|k| "'#{k}'"}
|
266
|
+
raise "The --merge option only accepts #{strategies[0...-1].join(', ')}, or #{strategies.last}\n#{RUN_HELP}"
|
267
|
+
end
|
268
|
+
|
269
|
+
if merge == 'deep'
|
284
270
|
merge_options = {'strategy' => 'deep',
|
285
271
|
'sort_merge_arrays' => !options[:sort_merge_arrays].nil?,
|
286
272
|
'merge_hash_arrays' => !options[:merge_hash_arrays].nil?}
|
@@ -294,11 +280,22 @@ Copyright (c) 2015 Puppet Labs, LLC Licensed under the Apache 2.0 License
|
|
294
280
|
end
|
295
281
|
|
296
282
|
else
|
297
|
-
merge_options = {'strategy' =>
|
283
|
+
merge_options = {'strategy' => merge}
|
298
284
|
end
|
299
285
|
end
|
300
286
|
|
301
|
-
|
287
|
+
explain_data = !!options[:explain]
|
288
|
+
explain_options = !!options[:explain_options]
|
289
|
+
only_explain_options = explain_options && !explain_data
|
290
|
+
if keys.empty?
|
291
|
+
if only_explain_options
|
292
|
+
# Explain lookup_options for lookup of an unqualified value.
|
293
|
+
keys = Puppet::Pops::Lookup::GLOBAL
|
294
|
+
else
|
295
|
+
raise 'No keys were given to lookup.'
|
296
|
+
end
|
297
|
+
end
|
298
|
+
explain = explain_data || explain_options
|
302
299
|
|
303
300
|
# Format defaults to text (:s) when producing an explanation and :yaml when producing the value
|
304
301
|
format = options[:render_as] || (explain ? :s : :yaml)
|
@@ -308,7 +305,7 @@ Copyright (c) 2015 Puppet Labs, LLC Licensed under the Apache 2.0 License
|
|
308
305
|
type = options.include?(:type) ? Puppet::Pops::Types::TypeParser.new.parse(options[:type]) : nil
|
309
306
|
|
310
307
|
generate_scope do |scope|
|
311
|
-
lookup_invocation = Puppet::Pops::Lookup::Invocation.new(scope, {}, {}, explain)
|
308
|
+
lookup_invocation = Puppet::Pops::Lookup::Invocation.new(scope, {}, {}, explain ? Puppet::Pops::Lookup::Explainer.new(explain_options, only_explain_options) : nil)
|
312
309
|
begin
|
313
310
|
result = Puppet::Pops::Lookup.lookup(keys, type, options[:default_value], use_default_value, merge_options, lookup_invocation)
|
314
311
|
puts renderer.render(result) unless explain
|
@@ -336,7 +333,7 @@ Copyright (c) 2015 Puppet Labs, LLC Licensed under the Apache 2.0 License
|
|
336
333
|
fact_file = options[:fact_file]
|
337
334
|
|
338
335
|
if fact_file
|
339
|
-
original_facts = node.
|
336
|
+
original_facts = node.parameters
|
340
337
|
if fact_file.end_with?("json")
|
341
338
|
given_facts = JSON.parse(File.read(fact_file))
|
342
339
|
else
|
@@ -347,9 +344,10 @@ Copyright (c) 2015 Puppet Labs, LLC Licensed under the Apache 2.0 License
|
|
347
344
|
raise "Incorrect formatted data in #{fact_file} given via the --facts flag"
|
348
345
|
end
|
349
346
|
|
350
|
-
node.
|
347
|
+
node.parameters = original_facts.merge(given_facts)
|
351
348
|
end
|
352
349
|
|
350
|
+
Puppet[:code] = 'undef' unless options[:compile]
|
353
351
|
compiler = Puppet::Parser::Compiler.new(node)
|
354
352
|
compiler.compile { |catalog| yield(compiler.topscope); catalog }
|
355
353
|
end
|
@@ -3,7 +3,9 @@
|
|
3
3
|
#
|
4
4
|
class Puppet::DataProviders::LookupAdapter < Puppet::DataProviders::DataAdapter
|
5
5
|
|
6
|
-
LOOKUP_OPTIONS =
|
6
|
+
LOOKUP_OPTIONS = Puppet::Pops::Lookup::LOOKUP_OPTIONS
|
7
|
+
LOOKUP_OPTIONS_PREFIX = LOOKUP_OPTIONS + '.'
|
8
|
+
LOOKUP_OPTIONS_PREFIX.freeze
|
7
9
|
HASH = 'hash'.freeze
|
8
10
|
MERGE = 'merge'.freeze
|
9
11
|
|
@@ -29,12 +31,43 @@ class Puppet::DataProviders::LookupAdapter < Puppet::DataProviders::DataAdapter
|
|
29
31
|
# @throws :no_such_key if the given key is not found
|
30
32
|
#
|
31
33
|
def lookup(key, lookup_invocation, merge)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
# The 'lookup_options' key is reserved and not found as normal data
|
35
|
+
if key == LOOKUP_OPTIONS || key.start_with?(LOOKUP_OPTIONS_PREFIX)
|
36
|
+
lookup_invocation.with(:invalid_key, LOOKUP_OPTIONS) do
|
37
|
+
throw :no_such_key
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
lookup_invocation.top_key ||= key
|
42
|
+
merge_explained = false
|
43
|
+
if lookup_invocation.explain_options?
|
44
|
+
catch(:no_such_key) do
|
45
|
+
module_name = extract_module_name(key) unless key == Puppet::Pops::Lookup::GLOBAL
|
46
|
+
lookup_invocation.module_name = module_name
|
47
|
+
if lookup_invocation.only_explain_options?
|
48
|
+
do_lookup(LOOKUP_OPTIONS, lookup_invocation, HASH)
|
49
|
+
return nil
|
50
|
+
end
|
51
|
+
|
52
|
+
# Bypass cache and do a "normal" lookup of the lookup_options
|
53
|
+
lookup_invocation.with(:meta, LOOKUP_OPTIONS) do
|
54
|
+
key_options = do_lookup(LOOKUP_OPTIONS, lookup_invocation, HASH)[key]
|
55
|
+
merge = key_options[MERGE] unless key_options.nil?
|
56
|
+
merge_explained = true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
elsif merge.nil?
|
60
|
+
# Used cached lookup_options
|
61
|
+
merge = lookup_merge_options(key, lookup_invocation)
|
62
|
+
lookup_invocation.report_merge_source('lookup_options') unless merge.nil?
|
63
|
+
end
|
64
|
+
|
65
|
+
if merge_explained
|
66
|
+
# Merge lookup is explained in detail so we need to explain the data in a section
|
67
|
+
# on the same level to avoid confusion
|
68
|
+
lookup_invocation.with(:data, key) { do_lookup(key, lookup_invocation, merge) }
|
69
|
+
else
|
70
|
+
do_lookup(key, lookup_invocation, merge)
|
38
71
|
end
|
39
72
|
end
|
40
73
|
|
@@ -44,13 +77,15 @@ class Puppet::DataProviders::LookupAdapter < Puppet::DataProviders::DataAdapter
|
|
44
77
|
lookup_invocation.with(:global, terminus) do
|
45
78
|
catch(:no_such_key) do
|
46
79
|
return lookup_invocation.report_found(name, Puppet::DataBinding.indirection.find(name,
|
47
|
-
{ :environment => @env
|
80
|
+
{ :environment => @env, :variables => lookup_invocation.scope, :merge => merge_strategy }))
|
48
81
|
end
|
49
82
|
lookup_invocation.report_not_found(name)
|
50
83
|
throw :no_such_key
|
51
84
|
end
|
52
|
-
rescue Puppet::DataBinding::LookupError =>
|
53
|
-
|
85
|
+
rescue Puppet::DataBinding::LookupError => detail
|
86
|
+
error = Puppet::Error.new("Lookup of key '#{lookup_invocation.top_key}' failed: #{detail.message}")
|
87
|
+
error.set_backtrace(detail.backtrace)
|
88
|
+
raise error
|
54
89
|
end
|
55
90
|
|
56
91
|
# @api private
|
@@ -60,7 +95,7 @@ class Puppet::DataProviders::LookupAdapter < Puppet::DataProviders::DataAdapter
|
|
60
95
|
|
61
96
|
# @api private
|
62
97
|
def lookup_in_module(name, lookup_invocation, merge_strategy)
|
63
|
-
module_name = extract_module_name(name)
|
98
|
+
module_name = lookup_invocation.module_name || extract_module_name(name)
|
64
99
|
|
65
100
|
# Do not attempt to do a lookup in a module unless the name is qualified.
|
66
101
|
throw :no_such_key if module_name.nil?
|
@@ -95,41 +130,52 @@ class Puppet::DataProviders::LookupAdapter < Puppet::DataProviders::DataAdapter
|
|
95
130
|
module_name = extract_module_name(name)
|
96
131
|
|
97
132
|
# Retrieve the options for the module. We use nil as a key in case we have none
|
98
|
-
|
99
|
-
if options.nil? && !@lookup_options.include?(module_name)
|
133
|
+
if !@lookup_options.include?(module_name)
|
100
134
|
options = retrieve_lookup_options(module_name, lookup_invocation, Puppet::Pops::MergeStrategy.strategy(HASH))
|
101
135
|
raise Puppet::DataBinding::LookupError.new("value of #{LOOKUP_OPTIONS} must be a hash") unless options.nil? || options.is_a?(Hash)
|
102
136
|
@lookup_options[module_name] = options
|
137
|
+
else
|
138
|
+
options = @lookup_options[module_name]
|
103
139
|
end
|
104
140
|
options.nil? ? nil : options[name]
|
105
141
|
end
|
106
142
|
|
107
143
|
private
|
108
144
|
|
145
|
+
def do_lookup(key, lookup_invocation, merge)
|
146
|
+
merge_strategy = Puppet::Pops::MergeStrategy.strategy(merge)
|
147
|
+
lookup_invocation.with(:merge, merge_strategy) do
|
148
|
+
result = merge_strategy.merge_lookup([:lookup_global, :lookup_in_environment, :lookup_in_module]) { |m| send(m, key, lookup_invocation, merge_strategy) }
|
149
|
+
lookup_invocation.report_result(result)
|
150
|
+
result
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
109
154
|
# Retrieve lookup options that applies when using a specific module (i.e. a merge of the pre-cached
|
110
155
|
# `env_lookup_options` and the module specific data)
|
111
156
|
def retrieve_lookup_options(module_name, lookup_invocation, merge_strategy)
|
112
|
-
lookup_invocation.
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
157
|
+
meta_invocation = Puppet::Pops::Lookup::Invocation.new(lookup_invocation.scope)
|
158
|
+
meta_invocation.top_key = lookup_invocation.top_key
|
159
|
+
env_opts = env_lookup_options(meta_invocation, merge_strategy)
|
160
|
+
unless module_name.nil? || @env.module(module_name).nil?
|
161
|
+
catch(:no_such_key) do
|
162
|
+
meta_invocation.module_name = module_name
|
163
|
+
options = module_provider(module_name).lookup(LOOKUP_OPTIONS, meta_invocation, merge_strategy)
|
164
|
+
options = merge_strategy.merge(env_opts, options) unless env_opts.nil?
|
165
|
+
return options
|
120
166
|
end
|
121
|
-
options.nil? ? env_opts : options
|
122
167
|
end
|
168
|
+
env_opts
|
123
169
|
end
|
124
170
|
|
125
171
|
# Retrieve and cache lookup options specific to the environment that this adapter is attached to (i.e. a merge
|
126
172
|
# of global and environment lookup options).
|
127
|
-
def env_lookup_options(
|
128
|
-
|
173
|
+
def env_lookup_options(meta_invocation, merge_strategy)
|
174
|
+
if !instance_variable_defined?(:@env_lookup_options)
|
129
175
|
@env_lookup_options = nil
|
130
176
|
catch(:no_such_key) do
|
131
177
|
@env_lookup_options = merge_strategy.merge_lookup([:lookup_global, :lookup_in_environment]) do |m|
|
132
|
-
send(m, LOOKUP_OPTIONS,
|
178
|
+
send(m, LOOKUP_OPTIONS, meta_invocation, merge_strategy)
|
133
179
|
end
|
134
180
|
end
|
135
181
|
end
|
@@ -170,7 +216,8 @@ class Puppet::DataProviders::LookupAdapter < Puppet::DataProviders::DataAdapter
|
|
170
216
|
unless provider
|
171
217
|
raise Puppet::Error.new("Environment '#{@env.name}', cannot find module_data_provider '#{provider_name}'")
|
172
218
|
end
|
173
|
-
|
219
|
+
# Provider is configured per module but cached using environment life cycle so it must be cloned
|
220
|
+
provider.clone
|
174
221
|
end
|
175
222
|
|
176
223
|
def initialize_env_provider
|
@@ -1,153 +1,129 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
# lookup
|
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
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
#
|
62
|
-
#
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
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
|
-
#
|
98
|
-
#
|
99
|
-
#
|
100
|
-
#
|
101
|
-
#
|
102
|
-
#
|
103
|
-
#
|
104
|
-
#
|
105
|
-
#
|
106
|
-
#
|
107
|
-
#
|
108
|
-
#
|
109
|
-
#
|
110
|
-
#
|
111
|
-
#
|
112
|
-
#
|
113
|
-
#
|
114
|
-
#
|
115
|
-
#
|
116
|
-
#
|
117
|
-
#
|
118
|
-
#
|
119
|
-
#
|
120
|
-
#
|
121
|
-
#
|
122
|
-
#
|
123
|
-
#
|
124
|
-
#
|
125
|
-
#
|
126
|
-
#
|
127
|
-
# lookup('the_name', Array[String], 'unique', [Fred])
|
128
|
-
#
|
129
|
-
# Using a lambda to provide a default value by calling a function:
|
130
|
-
#
|
131
|
-
# lookup('the_size', Integer[1,100]) |$name| {
|
132
|
-
# obtain_size_default()
|
133
|
-
# }
|
134
|
-
#
|
135
|
-
# There are two ways to make lookup return undef when no matching key was found instead of raising an error.
|
136
|
-
# Either call it with four arguments (the `merge` argument must be present even when using the default strategy
|
137
|
-
# to ensure that the four argument variant is used):
|
138
|
-
#
|
139
|
-
# $are_you_there = lookup('peekaboo', Optional[String], undef, undef)
|
140
|
-
#
|
141
|
-
# or call it using an options hash:
|
142
|
-
#
|
143
|
-
# $are_you_there = lookup('peekaboo', { 'default_value' => undef })
|
144
|
-
# $are_you_there = lookup({ 'name' => 'peekaboo', 'default_value' => undef })
|
145
|
-
#
|
146
|
-
# or with a block that produces an undef value:
|
147
|
-
#
|
148
|
-
# $are_you_there = lookup('peekaboo', Optional[String]) |$name| { undef }
|
149
|
-
#
|
150
|
-
# - Since 4.0.0
|
1
|
+
# Uses the Puppet lookup system to retrieve a value for a given key. By default,
|
2
|
+
# this returns the first value found (and fails compilation if no values are
|
3
|
+
# available), but you can configure it to merge multiple values into one, fail
|
4
|
+
# gracefully, and more.
|
5
|
+
#
|
6
|
+
# When looking up a key, Puppet will search up to three tiers of data, in the
|
7
|
+
# following order:
|
8
|
+
#
|
9
|
+
# 1. Hiera.
|
10
|
+
# 2. The current environment's data provider.
|
11
|
+
# 3. The indicated module's data provider, if the key is of the form
|
12
|
+
# `<MODULE NAME>::<SOMETHING>`.
|
13
|
+
#
|
14
|
+
# #### Arguments
|
15
|
+
#
|
16
|
+
# You must provide the name of a key to look up, and can optionally provide other
|
17
|
+
# arguments. You can combine these arguments in the following ways:
|
18
|
+
#
|
19
|
+
# * `lookup( <NAME>, [<VALUE TYPE>], [<MERGE BEHAVIOR>], [<DEFAULT VALUE>] )`
|
20
|
+
# * `lookup( [<NAME>], <OPTIONS HASH> )`
|
21
|
+
# * `lookup( as above ) |$key| { # lambda returns a default value }`
|
22
|
+
#
|
23
|
+
# Arguments in `[square brackets]` are optional.
|
24
|
+
#
|
25
|
+
# The arguments accepted by `lookup` are as follows:
|
26
|
+
#
|
27
|
+
# 1. `<NAME>` (string or array) --- The name of the key to look up.
|
28
|
+
# * This can also be an array of keys. If Puppet doesn't find anything for the
|
29
|
+
# first key, it will try again with the subsequent ones, only resorting to a
|
30
|
+
# default value if none of them succeed.
|
31
|
+
# 2. `<VALUE TYPE>` (data type) --- A
|
32
|
+
# [data type](https://docs.puppetlabs.com/puppet/latest/reference/lang_data_type.html)
|
33
|
+
# that must match the retrieved value; if not, the lookup (and catalog
|
34
|
+
# compilation) will fail. Defaults to `Data` (accepts any normal value).
|
35
|
+
# 3. `<MERGE BEHAVIOR>` (string or hash; see **"Merge Behaviors"** below) ---
|
36
|
+
# Whether (and how) to combine multiple values. If present, this overrides any
|
37
|
+
# merge behavior specified in the data sources. Defaults to no value; Puppet will
|
38
|
+
# use merge behavior from the data sources if present, and will otherwise do a
|
39
|
+
# first-found lookup.
|
40
|
+
# 4. `<DEFAULT VALUE>` (any normal value) --- If present, `lookup` returns this
|
41
|
+
# when it can't find a normal value. Default values are never merged with found
|
42
|
+
# values. Like a normal value, the default must match the value type. Defaults to
|
43
|
+
# no value; if Puppet can't find a normal value, the lookup (and compilation) will
|
44
|
+
# fail.
|
45
|
+
# 5. `<OPTIONS HASH>` (hash) --- Alternate way to set the arguments above, plus
|
46
|
+
# some less-common extra options. If you pass an options hash, you can't combine
|
47
|
+
# it with any regular arguments (except `<NAME>`). An options hash can have the
|
48
|
+
# following keys:
|
49
|
+
# * `'name'` --- Same as `<NAME>` (argument 1). You can pass this as an
|
50
|
+
# argument or in the hash, but not both.
|
51
|
+
# * `'value_type'` --- Same as `<VALUE TYPE>` (argument 2).
|
52
|
+
# * `'merge'` --- Same as `<MERGE BEHAVIOR>` (argument 3).
|
53
|
+
# * `'default_value'` --- Same as `<DEFAULT VALUE>` (argument 4).
|
54
|
+
# * `'default_values_hash'` (hash) --- A hash of lookup keys and default
|
55
|
+
# values. If Puppet can't find a normal value, it will check this hash for the
|
56
|
+
# requested key before giving up. You can combine this with `default_value` or
|
57
|
+
# a lambda, which will be used if the key isn't present in this hash. Defaults
|
58
|
+
# to an empty hash.
|
59
|
+
# * `'override'` (hash) --- A hash of lookup keys and override values. Puppet
|
60
|
+
# will check for the requested key in the overrides hash _first;_ if found, it
|
61
|
+
# returns that value as the _final_ value, ignoring merge behavior. Defaults
|
62
|
+
# to an empty hash.
|
63
|
+
#
|
64
|
+
# Finally, `lookup` can take a lambda, which must accept a single parameter.
|
65
|
+
# This is yet another way to set a default value for the lookup; if no results are
|
66
|
+
# found, Puppet will pass the requested key to the lambda and use its result as
|
67
|
+
# the default value.
|
68
|
+
#
|
69
|
+
# #### Merge Behaviors
|
70
|
+
#
|
71
|
+
# Puppet lookup uses a hierarchy of data sources, and a given key might have
|
72
|
+
# values in multiple sources. By default, Puppet returns the first value it finds,
|
73
|
+
# but it can also continue searching and merge all the values together.
|
74
|
+
#
|
75
|
+
# > **Note:** Data sources can use the special `lookup_options` metadata key to
|
76
|
+
# request a specific merge behavior for a key. The `lookup` function will use that
|
77
|
+
# requested behavior unless you explicitly specify one.
|
78
|
+
#
|
79
|
+
# The valid merge behaviors are:
|
80
|
+
#
|
81
|
+
# * `'first'` --- Returns the first value found, with no merging. Puppet lookup's
|
82
|
+
# default behavior.
|
83
|
+
# * `'unique'` (called "array merge" in classic Hiera) --- Combines any number of
|
84
|
+
# arrays and scalar values to return a merged, flattened array with all duplicate
|
85
|
+
# values removed. The lookup will fail if any hash values are found.
|
86
|
+
# * `'hash'` --- Combines the keys and values of any number of hashes to return a
|
87
|
+
# merged hash. If the same key exists in multiple source hashes, Puppet will use
|
88
|
+
# the value from the highest-priority data source; it won't recursively merge the
|
89
|
+
# values.
|
90
|
+
# * `'deep'` --- Combines the keys and values of any number of hashes to return a
|
91
|
+
# merged hash. If the same key exists in multiple source hashes, Puppet will
|
92
|
+
# recursively merge hash or array values (with duplicate values removed from
|
93
|
+
# arrays). For conflicting scalar values, the highest-priority value will win.
|
94
|
+
# * `{'strategy' => 'first|unique|hash'}` --- Same as the string versions of these
|
95
|
+
# merge behaviors.
|
96
|
+
# * `{'strategy' => 'deep', <DEEP OPTION> => <VALUE>, ...}` --- Same as `'deep'`,
|
97
|
+
# but can adjust the merge with additional options. The available options are:
|
98
|
+
# * `'knockout_prefix'` (string or undef) --- A string prefix to indicate a
|
99
|
+
# value should be _removed_ from the final result. Defaults to `undef`, which
|
100
|
+
# disables this feature.
|
101
|
+
# * `'sort_merged_arrays'` (boolean) --- Whether to sort all arrays that are
|
102
|
+
# merged together. Defaults to `false`.
|
103
|
+
# * `'unpack_arrays'` (string or undef) --- A delimiter string; Puppet will
|
104
|
+
# join merged arrays with this delimiter, then split them again. Defaults to
|
105
|
+
# `undef`, which disables this feature.
|
106
|
+
# * `'merge_hash_arrays'` (boolean) --- Whether to merge hashes within arrays.
|
107
|
+
# Defaults to `false`.
|
108
|
+
#
|
109
|
+
# @example Look up a key and return the first value found
|
110
|
+
#
|
111
|
+
# lookup('ntp::service_name')
|
112
|
+
#
|
113
|
+
# @example Do a unique merge lookup of class names, then add all of those classes to the catalog (like `hiera_include`)
|
114
|
+
#
|
115
|
+
# lookup('classes', Array[String], 'unique').include
|
116
|
+
#
|
117
|
+
# @example Do a deep hash merge lookup of user data, but let higher priority sources remove values by prefixing them with `--`
|
118
|
+
#
|
119
|
+
# lookup( { 'name' => 'users',
|
120
|
+
# 'merge' => {
|
121
|
+
# 'strategy' => 'deep',
|
122
|
+
# 'knockout_prefix' => '--',
|
123
|
+
# },
|
124
|
+
# })
|
125
|
+
#
|
126
|
+
# @since 4.0.0
|
151
127
|
Puppet::Functions.create_function(:lookup, Puppet::Functions::InternalFunction) do
|
152
128
|
name_t = 'Variant[String,Array[String]]'
|
153
129
|
value_type_t = 'Type'
|