bolt 0.23.0 → 0.24.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of bolt might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/bolt-modules/boltlib/lib/puppet/functions/apply_prep.rb +5 -2
- data/bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb +5 -1
- data/bolt-modules/boltlib/lib/puppet/functions/run_task.rb +5 -8
- data/lib/bolt/applicator.rb +11 -8
- data/lib/bolt/boltdir.rb +13 -5
- data/lib/bolt/catalog.rb +22 -47
- data/lib/bolt/config.rb +1 -26
- data/lib/bolt/executor.rb +1 -1
- data/lib/bolt/outputter.rb +0 -9
- data/lib/bolt/outputter/human.rb +29 -14
- data/lib/bolt/outputter/json.rb +12 -1
- data/lib/bolt/pal.rb +12 -10
- data/lib/bolt/target.rb +0 -6
- data/lib/bolt/task.rb +53 -10
- data/lib/bolt/transport/base.rb +1 -6
- data/lib/bolt/transport/local.rb +11 -13
- data/lib/bolt/transport/local/shell.rb +2 -2
- data/lib/bolt/transport/ssh.rb +16 -11
- data/lib/bolt/transport/winrm.rb +8 -11
- data/lib/bolt/version.rb +1 -1
- data/lib/bolt_ext/schemas/task.json +12 -5
- data/libexec/apply_catalog.rb +3 -1
- data/libexec/bolt_catalog +4 -0
- data/vendored/puppet/lib/puppet.rb +2 -1
- data/vendored/puppet/lib/puppet/application/agent.rb +2 -6
- data/vendored/puppet/lib/puppet/application/apply.rb +100 -60
- data/vendored/puppet/lib/puppet/application/cert.rb +26 -291
- data/vendored/puppet/lib/puppet/application/device.rb +0 -5
- data/vendored/puppet/lib/puppet/application/lookup.rb +1 -1
- data/vendored/puppet/lib/puppet/application/ssl.rb +133 -0
- data/vendored/puppet/lib/puppet/application_support.rb +1 -2
- data/vendored/puppet/lib/puppet/configurer.rb +34 -50
- data/vendored/puppet/lib/puppet/configurer/downloader.rb +1 -1
- data/vendored/puppet/lib/puppet/configurer/plugin_handler.rb +1 -1
- data/vendored/puppet/lib/puppet/daemon.rb +1 -1
- data/vendored/puppet/lib/puppet/defaults.rb +40 -117
- data/vendored/puppet/lib/puppet/face/epp.rb +2 -2
- data/vendored/puppet/lib/puppet/face/help.rb +21 -7
- data/vendored/puppet/lib/puppet/face/node/clean.rb +14 -10
- data/vendored/puppet/lib/puppet/feature/base.rb +7 -23
- data/vendored/puppet/lib/puppet/feature/eventlog.rb +1 -1
- data/vendored/puppet/lib/puppet/file_serving/base.rb +2 -2
- data/vendored/puppet/lib/puppet/file_serving/fileset.rb +1 -1
- data/vendored/puppet/lib/puppet/file_serving/metadata.rb +2 -2
- data/vendored/puppet/lib/puppet/functions.rb +133 -0
- data/vendored/puppet/lib/puppet/functions/eyaml_lookup_key.rb +4 -5
- data/vendored/puppet/lib/puppet/functions/filter.rb +7 -6
- data/vendored/puppet/lib/puppet/functions/new.rb +37 -53
- data/vendored/puppet/lib/puppet/functions/warning.rb +1 -1
- data/vendored/puppet/lib/puppet/functions/yaml_data.rb +4 -5
- data/vendored/puppet/lib/puppet/gettext/config.rb +1 -1
- data/vendored/puppet/lib/puppet/graph.rb +0 -2
- data/vendored/puppet/lib/puppet/indirector/catalog/json.rb +14 -3
- data/vendored/puppet/lib/puppet/indirector/catalog/yaml.rb +0 -16
- data/vendored/puppet/lib/puppet/indirector/certificate/file.rb +0 -1
- data/vendored/puppet/lib/puppet/indirector/facts/yaml.rb +4 -2
- data/vendored/puppet/lib/puppet/indirector/key/file.rb +1 -6
- data/vendored/puppet/lib/puppet/indirector/node/exec.rb +1 -3
- data/vendored/puppet/lib/puppet/indirector/node/yaml.rb +0 -6
- data/vendored/puppet/lib/puppet/indirector/request.rb +1 -1
- data/vendored/puppet/lib/puppet/indirector/ssl_file.rb +3 -44
- data/vendored/puppet/lib/puppet/indirector/yaml.rb +4 -4
- data/vendored/puppet/lib/puppet/info_service/task_information_service.rb +7 -3
- data/vendored/puppet/lib/puppet/loaders.rb +1 -0
- data/vendored/puppet/lib/puppet/module/task.rb +198 -29
- data/vendored/puppet/lib/puppet/module_tool/applications/unpacker.rb +1 -1
- data/vendored/puppet/lib/puppet/network/format_support.rb +13 -8
- data/vendored/puppet/lib/puppet/network/formats.rb +93 -2
- data/vendored/puppet/lib/puppet/network/http/api/indirected_routes.rb +10 -3
- data/vendored/puppet/lib/puppet/node/facts.rb +11 -1
- data/vendored/puppet/lib/puppet/parser/catalog_compiler.rb +56 -0
- data/vendored/puppet/lib/puppet/parser/compiler.rb +3 -1
- data/vendored/puppet/lib/puppet/parser/functions.rb +3 -1
- data/vendored/puppet/lib/puppet/parser/functions/filter.rb +1 -1
- data/vendored/puppet/lib/puppet/parser/functions/generate.rb +1 -1
- data/vendored/puppet/lib/puppet/parser/functions/sprintf.rb +12 -1
- data/vendored/puppet/lib/puppet/parser/functions/tagged.rb +1 -4
- data/vendored/puppet/lib/puppet/parser/scope.rb +1 -1
- data/vendored/puppet/lib/puppet/parser/script_compiler.rb +7 -2
- data/vendored/puppet/lib/puppet/pops/evaluator/deferred_resolver.rb +5 -3
- data/vendored/puppet/lib/puppet/pops/evaluator/runtime3_converter.rb +23 -4
- data/vendored/puppet/lib/puppet/pops/evaluator/runtime3_support.rb +3 -4
- data/vendored/puppet/lib/puppet/pops/functions/dispatch.rb +4 -0
- data/vendored/puppet/lib/puppet/pops/issues.rb +8 -0
- data/vendored/puppet/lib/puppet/pops/loader/loader.rb +2 -2
- data/vendored/puppet/lib/puppet/pops/loader/loader_paths.rb +3 -1
- data/vendored/puppet/lib/puppet/pops/loader/module_loaders.rb +30 -9
- data/vendored/puppet/lib/puppet/pops/loader/ruby_legacy_function_instantiator.rb +62 -0
- data/vendored/puppet/lib/puppet/pops/loader/static_loader.rb +0 -1
- data/vendored/puppet/lib/puppet/pops/loader/task_instantiator.rb +13 -70
- data/vendored/puppet/lib/puppet/pops/loaders.rb +19 -29
- data/vendored/puppet/lib/puppet/pops/lookup/hiera_config.rb +1 -1
- data/vendored/puppet/lib/puppet/pops/model/model_label_provider.rb +4 -1
- data/vendored/puppet/lib/puppet/pops/pcore.rb +10 -33
- data/vendored/puppet/lib/puppet/pops/serialization.rb +2 -0
- data/vendored/puppet/lib/puppet/pops/serialization/from_data_converter.rb +2 -1
- data/vendored/puppet/lib/puppet/pops/serialization/to_data_converter.rb +11 -3
- data/vendored/puppet/lib/puppet/pops/serialization/to_stringified_converter.rb +226 -0
- data/vendored/puppet/lib/puppet/pops/types/p_object_type.rb +3 -0
- data/vendored/puppet/lib/puppet/pops/validation/checker4_0.rb +97 -47
- data/vendored/puppet/lib/puppet/pops/validation/validator_factory_4_0.rb +7 -8
- data/vendored/puppet/lib/puppet/property/keyvalue.rb +70 -8
- data/vendored/puppet/lib/puppet/provider/aix_object.rb +483 -0
- data/vendored/puppet/lib/puppet/provider/file/windows.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/group/aix.rb +51 -112
- data/vendored/puppet/lib/puppet/provider/package/gem.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/package/pip.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/package/puppet_gem.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/package/rpm.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/package/windows/package.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/package/zypper.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/service/systemd.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/service/windows.rb +37 -40
- data/vendored/puppet/lib/puppet/provider/user/aix.rb +142 -254
- data/vendored/puppet/lib/puppet/resource.rb +20 -3
- data/vendored/puppet/lib/puppet/resource/catalog.rb +2 -12
- data/vendored/puppet/lib/puppet/rest/routes.rb +97 -34
- data/vendored/puppet/lib/puppet/settings.rb +1 -1
- data/vendored/puppet/lib/puppet/settings/file_setting.rb +1 -1
- data/vendored/puppet/lib/puppet/ssl/base.rb +1 -9
- data/vendored/puppet/lib/puppet/ssl/certificate_request.rb +1 -13
- data/vendored/puppet/lib/puppet/ssl/certificate_request_attributes.rb +1 -1
- data/vendored/puppet/lib/puppet/ssl/host.rb +114 -232
- data/vendored/puppet/lib/puppet/ssl/key.rb +1 -5
- data/vendored/puppet/lib/puppet/ssl/oids.rb +1 -1
- data/vendored/puppet/lib/puppet/test/test_helper.rb +0 -4
- data/vendored/puppet/lib/puppet/transaction/event.rb +3 -7
- data/vendored/puppet/lib/puppet/transaction/persistence.rb +1 -1
- data/vendored/puppet/lib/puppet/type/exec.rb +18 -16
- data/vendored/puppet/lib/puppet/type/file.rb +3 -3
- data/vendored/puppet/lib/puppet/type/file/source.rb +20 -7
- data/vendored/puppet/lib/puppet/type/group.rb +3 -5
- data/vendored/puppet/lib/puppet/type/notify.rb +1 -1
- data/vendored/puppet/lib/puppet/type/package.rb +2 -5
- data/vendored/puppet/lib/puppet/type/schedule.rb +1 -1
- data/vendored/puppet/lib/puppet/type/service.rb +3 -6
- data/vendored/puppet/lib/puppet/type/tidy.rb +1 -1
- data/vendored/puppet/lib/puppet/type/user.rb +13 -20
- data/vendored/puppet/lib/puppet/util.rb +8 -9
- data/vendored/puppet/lib/puppet/util/execution.rb +3 -3
- data/vendored/puppet/lib/puppet/util/feature.rb +61 -39
- data/vendored/puppet/lib/puppet/util/log/destinations.rb +1 -1
- data/vendored/puppet/lib/puppet/util/rdoc.rb +1 -1
- data/vendored/puppet/lib/puppet/util/run_mode.rb +1 -1
- data/vendored/puppet/lib/puppet/util/storage.rb +1 -1
- data/vendored/puppet/lib/puppet/util/suidmanager.rb +7 -5
- data/vendored/puppet/lib/puppet/util/tag_set.rb +1 -1
- data/vendored/puppet/lib/puppet/util/tagging.rb +1 -1
- data/vendored/puppet/lib/puppet/util/windows.rb +18 -2
- data/vendored/puppet/lib/puppet/util/windows/adsi.rb +154 -205
- data/vendored/puppet/lib/puppet/util/windows/service.rb +770 -0
- data/vendored/puppet/lib/puppet/util/yaml.rb +41 -5
- data/vendored/puppet/lib/puppet/version.rb +1 -1
- data/vendored/puppet/lib/puppet_pal.rb +280 -24
- metadata +8 -38
- data/lib/bolt/catalog/compiler.rb +0 -48
- data/lib/bolt/catalog/loaders.rb +0 -19
- data/vendored/puppet/lib/puppet/application/ca.rb +0 -11
- data/vendored/puppet/lib/puppet/application/certificate.rb +0 -17
- data/vendored/puppet/lib/puppet/application/certificate_request.rb +0 -7
- data/vendored/puppet/lib/puppet/application/certificate_revocation_list.rb +0 -7
- data/vendored/puppet/lib/puppet/face/ca.rb +0 -266
- data/vendored/puppet/lib/puppet/face/certificate.rb +0 -167
- data/vendored/puppet/lib/puppet/face/certificate_request.rb +0 -56
- data/vendored/puppet/lib/puppet/face/certificate_revocation_list.rb +0 -56
- data/vendored/puppet/lib/puppet/graph/random_prioritizer.rb +0 -16
- data/vendored/puppet/lib/puppet/graph/title_hash_prioritizer.rb +0 -16
- data/vendored/puppet/lib/puppet/indirector/certificate/ca.rb +0 -9
- data/vendored/puppet/lib/puppet/indirector/certificate/disabled_ca.rb +0 -22
- data/vendored/puppet/lib/puppet/indirector/certificate_request/ca.rb +0 -22
- data/vendored/puppet/lib/puppet/indirector/certificate_request/disabled_ca.rb +0 -22
- data/vendored/puppet/lib/puppet/indirector/certificate_revocation_list/ca.rb +0 -8
- data/vendored/puppet/lib/puppet/indirector/certificate_revocation_list/disabled_ca.rb +0 -22
- data/vendored/puppet/lib/puppet/indirector/certificate_revocation_list/file.rb +0 -8
- data/vendored/puppet/lib/puppet/indirector/certificate_revocation_list/rest.rb +0 -11
- data/vendored/puppet/lib/puppet/indirector/certificate_status.rb +0 -4
- data/vendored/puppet/lib/puppet/indirector/certificate_status/file.rb +0 -91
- data/vendored/puppet/lib/puppet/indirector/certificate_status/rest.rb +0 -11
- data/vendored/puppet/lib/puppet/indirector/key/ca.rb +0 -16
- data/vendored/puppet/lib/puppet/indirector/key/disabled_ca.rb +0 -22
- data/vendored/puppet/lib/puppet/indirector/ldap.rb +0 -86
- data/vendored/puppet/lib/puppet/indirector/node/ldap.rb +0 -275
- data/vendored/puppet/lib/puppet/provider/aixobject.rb +0 -392
- data/vendored/puppet/lib/puppet/provider/cron/crontab.rb +0 -297
- data/vendored/puppet/lib/puppet/ssl/certificate_authority.rb +0 -475
- data/vendored/puppet/lib/puppet/ssl/certificate_authority/autosign_command.rb +0 -45
- data/vendored/puppet/lib/puppet/ssl/certificate_authority/interface.rb +0 -324
- data/vendored/puppet/lib/puppet/ssl/certificate_factory.rb +0 -219
- data/vendored/puppet/lib/puppet/ssl/certificate_revocation_list.rb +0 -111
- data/vendored/puppet/lib/puppet/ssl/inventory.rb +0 -55
- data/vendored/puppet/lib/puppet/type/cron.rb +0 -480
@@ -305,15 +305,14 @@ module Runtime3Support
|
|
305
305
|
return Kernel.eval('_func.call(scope, *args, &block)'.freeze, Kernel.binding, file || '', line)
|
306
306
|
end
|
307
307
|
end
|
308
|
-
# Call via 3x API if function exists there
|
308
|
+
# Call via 3x API if function exists there without having been autoloaded
|
309
309
|
fail(Issues::UNKNOWN_FUNCTION, o, {:name => name}) unless Puppet::Parser::Functions.function(name)
|
310
310
|
|
311
311
|
# Arguments must be mapped since functions are unaware of the new and magical creatures in 4x.
|
312
312
|
# NOTE: Passing an empty string last converts nil/:undef to empty string
|
313
313
|
mapped_args = Runtime3FunctionArgumentConverter.map_args(args, scope, '')
|
314
|
-
|
315
|
-
|
316
|
-
Puppet::Parser::Functions.rvalue?(name) ? result : nil
|
314
|
+
# The 3x function performs return value mapping and returns nil if it is not of rvalue type
|
315
|
+
Puppet::Pops::PuppetStack.stack(file, line, scope, "function_#{name}", [mapped_args], &block)
|
317
316
|
end
|
318
317
|
|
319
318
|
# The o is used for source reference
|
@@ -81,6 +81,10 @@ class Dispatch < Evaluator::CallableSignature
|
|
81
81
|
Puppet.lookup(:pal_script_compiler)
|
82
82
|
when :cache
|
83
83
|
Puppet::Pops::Adapters::ObjectIdCacheAdapter.adapt(scope.compiler)
|
84
|
+
when :pal_catalog_compiler
|
85
|
+
Puppet.lookup(:pal_catalog_compiler)
|
86
|
+
when :pal_compiler
|
87
|
+
Puppet.lookup(:pal_compiler)
|
84
88
|
else
|
85
89
|
raise ArgumentError, _("Unknown injection %{injection_name}") % { injection_name: injection_name }
|
86
90
|
end
|
@@ -490,6 +490,14 @@ module Issues
|
|
490
490
|
_("Unacceptable location. The name '%{name}' is unacceptable in file '%{file}'") % { name: name, file: file }
|
491
491
|
end
|
492
492
|
|
493
|
+
ILLEGAL_TOP_CONSTRUCT_LOCATION = issue :ILLEGAL_TOP_CONSTRUCT_LOCATION do
|
494
|
+
if semantic.is_a?(Puppet::Pops::Model::NamedDefinition)
|
495
|
+
_("The %{value} '%{name}' is unacceptable as a top level construct in this location") % { name: semantic.name, value: label(semantic) }
|
496
|
+
else
|
497
|
+
_("This %{value} is unacceptable as a top level construct in this location") % { value: label(semantic) }
|
498
|
+
end
|
499
|
+
end
|
500
|
+
|
493
501
|
CAPTURES_REST_NOT_LAST = hard_issue :CAPTURES_REST_NOT_LAST, :param_name do
|
494
502
|
_("Parameter $%{param} is not last, and has 'captures rest'") % { param: param_name }
|
495
503
|
end
|
@@ -29,7 +29,7 @@ class Loader
|
|
29
29
|
attr_reader :loader_name
|
30
30
|
|
31
31
|
# Describes the kinds of things that loaders can load
|
32
|
-
LOADABLE_KINDS = [:func_4x, :func_4xpp, :datatype, :type_pp, :resource_type_pp, :plan, :task].freeze
|
32
|
+
LOADABLE_KINDS = [:func_4x, :func_4xpp, :func_3x, :datatype, :type_pp, :resource_type_pp, :plan, :task].freeze
|
33
33
|
|
34
34
|
# @param [String] name the name of the loader. Must be unique among all loaders maintained by a {Loader} instance
|
35
35
|
def initialize(loader_name)
|
@@ -107,7 +107,7 @@ class Loader
|
|
107
107
|
#
|
108
108
|
# @api private
|
109
109
|
#
|
110
|
-
def []
|
110
|
+
def [](typed_name)
|
111
111
|
if found = get_entry(typed_name)
|
112
112
|
found.value
|
113
113
|
else
|
@@ -25,7 +25,9 @@ module LoaderPaths
|
|
25
25
|
if loader.loadables.include?(:func_4xpp)
|
26
26
|
result << FunctionPathPP.new(loader)
|
27
27
|
end
|
28
|
-
|
28
|
+
if loader.loadables.include?(:func_3x)
|
29
|
+
result << FunctionPath3x.new(loader)
|
30
|
+
end
|
29
31
|
when :plan
|
30
32
|
result << PlanPathPP.new(loader)
|
31
33
|
when :task
|
@@ -19,6 +19,24 @@ module Loader
|
|
19
19
|
# @api private
|
20
20
|
#
|
21
21
|
module ModuleLoaders
|
22
|
+
|
23
|
+
# Wildcard module name for module loaders, makes loading possible from any namespace.
|
24
|
+
NAMESPACE_WILDCARD = '*'.freeze
|
25
|
+
|
26
|
+
# This is exactly the same as the #system_loader_from method, but the argument for path is changed to
|
27
|
+
# location where pluginsync stores functions. It also accepts definitions in any namespace since pluginsync
|
28
|
+
# places all of them in the same directory.
|
29
|
+
#
|
30
|
+
def self.cached_loader_from(parent_loader, loaders)
|
31
|
+
LibRootedFileBased.new(parent_loader,
|
32
|
+
loaders,
|
33
|
+
NAMESPACE_WILDCARD,
|
34
|
+
Puppet[:libdir],
|
35
|
+
'cached_puppet_lib',
|
36
|
+
[:func_4x, :datatype]
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
22
40
|
def self.system_loader_from(parent_loader, loaders)
|
23
41
|
# Puppet system may be installed in a fixed location via RPM, installed as a Gem, via source etc.
|
24
42
|
# The only way to find this across the different ways puppet can be installed is
|
@@ -31,7 +49,7 @@ module ModuleLoaders
|
|
31
49
|
nil,
|
32
50
|
puppet_lib, # may or may not have a 'lib' above 'puppet'
|
33
51
|
'puppet_system',
|
34
|
-
[:func_4x, :datatype] # only load ruby functions and types from "puppet"
|
52
|
+
[:func_4x, :func_3x, :datatype] # only load ruby functions and types from "puppet"
|
35
53
|
)
|
36
54
|
end
|
37
55
|
|
@@ -82,9 +100,10 @@ module ModuleLoaders
|
|
82
100
|
|
83
101
|
class AbstractPathBasedModuleLoader < BaseLoader
|
84
102
|
|
85
|
-
# The name of the module, or nil, if this is a global "component"
|
103
|
+
# The name of the module, or nil, if this is a global "component", or "any module" if set to the `NAMESPACE_WILDCARD` (*)
|
86
104
|
attr_reader :module_name
|
87
105
|
|
106
|
+
|
88
107
|
# The path to the location of the module/component - semantics determined by subclass
|
89
108
|
attr_reader :path
|
90
109
|
|
@@ -169,10 +188,12 @@ module ModuleLoaders
|
|
169
188
|
# The name is in a name space.
|
170
189
|
|
171
190
|
# Then entity cannot possible be in this module unless the name starts with the module name.
|
172
|
-
# Note:
|
173
|
-
#
|
191
|
+
# Note:
|
192
|
+
# * If "module" represents a "global component", the module_name is nil and cannot match which is
|
193
|
+
# ok since such a "module" cannot have namespaced content).
|
194
|
+
# * If this loader is allowed to have namespaced content, the module_name can be set to NAMESPACE_WILDCARD `*`
|
174
195
|
#
|
175
|
-
return nil unless name_parts[0] == module_name
|
196
|
+
return nil unless name_parts[0] == module_name || module_name == NAMESPACE_WILDCARD
|
176
197
|
else
|
177
198
|
# The name is in the global name space.
|
178
199
|
|
@@ -203,7 +224,7 @@ module ModuleLoaders
|
|
203
224
|
when :type
|
204
225
|
if !global?
|
205
226
|
# Global name must be the name of the module
|
206
|
-
unless name_parts[0] == module_name
|
227
|
+
unless name_parts[0] == module_name || module_name == NAMESPACE_WILDCARD
|
207
228
|
# Check for ruby defined data type in global namespace before giving up
|
208
229
|
origin, smart_path = find_existing_path(typed_name)
|
209
230
|
return smart_path.is_a?(LoaderPaths::DataTypePath) ? instantiate(smart_path, typed_name, origin) : nil
|
@@ -219,9 +240,9 @@ module ModuleLoaders
|
|
219
240
|
return set_entry(typed_name, value, origin)
|
220
241
|
end
|
221
242
|
|
222
|
-
#TRANSLATORS 'TypeSet' should not be translated
|
243
|
+
# TRANSLATORS 'TypeSet' should not be translated
|
223
244
|
raise ArgumentError, _("The code loaded from %{origin} does not define the TypeSet '%{module_name}'") %
|
224
|
-
{ origin: origin, module_name:
|
245
|
+
{ origin: origin, module_name: name_parts[0].capitalize }
|
225
246
|
end
|
226
247
|
else
|
227
248
|
# anything else cannot possibly be in this module
|
@@ -325,7 +346,7 @@ module ModuleLoaders
|
|
325
346
|
# @return [Boolean] `true` if this loader represents a global component
|
326
347
|
#
|
327
348
|
def global?
|
328
|
-
module_name.nil? || module_name == ENVIRONMENT
|
349
|
+
module_name.nil? || module_name == NAMESPACE_WILDCARD || module_name == ENVIRONMENT
|
329
350
|
end
|
330
351
|
|
331
352
|
# Answers `true` if the loader used by this instance is rooted beneath 'lib'. This is
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# The RubyLegacyFunctionInstantiator instantiates a Puppet::Functions::Function given the ruby source
|
2
|
+
# that calls Puppet::Functions.create_function.
|
3
|
+
#
|
4
|
+
class Puppet::Pops::Loader::RubyLegacyFunctionInstantiator
|
5
|
+
# Produces an instance of the Function class with the given typed_name, or fails with an error if the
|
6
|
+
# given ruby source does not produce this instance when evaluated.
|
7
|
+
#
|
8
|
+
# @param loader [Puppet::Pops::Loader::Loader] The loader the function is associated with
|
9
|
+
# @param typed_name [Puppet::Pops::Loader::TypedName] the type / name of the function to load
|
10
|
+
# @param source_ref [URI, String] a reference to the source / origin of the ruby code to evaluate
|
11
|
+
# @param ruby_code_string [String] ruby code in a string
|
12
|
+
#
|
13
|
+
# @return [Puppet::Pops::Functions.Function] - an instantiated function with global scope closure associated with the given loader
|
14
|
+
#
|
15
|
+
def self.create(loader, typed_name, source_ref, ruby_code_string)
|
16
|
+
unless ruby_code_string.is_a?(String) && ruby_code_string =~ /Puppet\:\:Parser\:\:Functions.*newfunction/m
|
17
|
+
raise ArgumentError, _("The code loaded from %{source_ref} does not seem to be a Puppet 3x API function - no 'newfunction' call.") % { source_ref: source_ref }
|
18
|
+
end
|
19
|
+
# make the private loader available in a binding to allow it to be passed on
|
20
|
+
loader_for_function = loader.private_loader
|
21
|
+
here = get_binding(loader_for_function)
|
22
|
+
|
23
|
+
# Avoid reloading the function if already loaded via one of the APIs that trigger 3x function loading
|
24
|
+
# Check if function is already loaded the 3x way (and obviously not the 4x way since we would not be here in the
|
25
|
+
# first place.
|
26
|
+
environment = Puppet.lookup(:current_environment)
|
27
|
+
func_info = Puppet::Parser::Functions.environment_module(environment).get_function_info(typed_name.name.to_sym)
|
28
|
+
if func_info.nil?
|
29
|
+
# This will to do the 3x loading and define the "function_<name>" and "real_function_<name>" methods
|
30
|
+
# in the anonymous module used to hold function definitions.
|
31
|
+
#
|
32
|
+
func_info = eval(ruby_code_string, here, source_ref, 1)
|
33
|
+
|
34
|
+
# Validate what was loaded
|
35
|
+
unless func_info.is_a?(Hash)
|
36
|
+
raise ArgumentError, _("The code loaded from %{source_ref} did not produce the expected 3x function info Hash when evaluated. Got '%{klass}'") % { source_ref: source_ref, klass: created.class }
|
37
|
+
end
|
38
|
+
unless func_info[:name] == "function_#{typed_name.name()}"
|
39
|
+
raise ArgumentError, _("The code loaded from %{source_ref} produced mis-matched name, expected 'function_%{type_name}', got %{created_name}") % {
|
40
|
+
source_ref: source_ref, type_name: typed_name.name, created_name: func_info[:name] }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
created = Puppet::Functions::Function3x.create_function(typed_name.name(), func_info, loader_for_function)
|
45
|
+
|
46
|
+
# create the function instance - it needs closure (scope), and loader (i.e. where it should start searching for things
|
47
|
+
# when calling functions etc.
|
48
|
+
# It should be bound to global scope
|
49
|
+
|
50
|
+
# Sets closure scope to nil, to let it be picked up at runtime from Puppet.lookup(:global_scope)
|
51
|
+
# If function definition used the loader from the binding to create a new loader, that loader wins
|
52
|
+
created.new(nil, loader_for_function)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Produces a binding where the given loader is bound as a local variable (loader_injected_arg). This variable can be used in loaded
|
56
|
+
# ruby code - e.g. to call Puppet::Function.create_loaded_function(:name, loader,...)
|
57
|
+
#
|
58
|
+
def self.get_binding(loader_injected_arg)
|
59
|
+
binding
|
60
|
+
end
|
61
|
+
private_class_method :get_binding
|
62
|
+
end
|
@@ -1,58 +1,9 @@
|
|
1
1
|
# The TypeDefinitionInstantiator instantiates a type alias or a type definition
|
2
2
|
#
|
3
|
+
require 'puppet/module/task'
|
3
4
|
module Puppet::Pops
|
4
5
|
module Loader
|
5
6
|
class TaskInstantiator
|
6
|
-
def self.load_metadata(loader, metadata)
|
7
|
-
if metadata.nil?
|
8
|
-
EMPTY_HASH
|
9
|
-
else
|
10
|
-
json_text = loader.get_contents(metadata)
|
11
|
-
begin
|
12
|
-
Puppet::Util::Json.load(json_text).freeze || EMPTY_HASH
|
13
|
-
rescue Puppet::Util::Json::ParseError => ex
|
14
|
-
raise Puppet::ParseError.new(ex.message, metadata)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.validate_implementations(typed_name, directory, metadata, executables)
|
20
|
-
name = typed_name.name
|
21
|
-
basename = typed_name.name_parts[1] || 'init'
|
22
|
-
# If 'implementations' is defined, it needs to mention at least one
|
23
|
-
# implementation, and everything it mentions must exist.
|
24
|
-
if metadata.key?('implementations')
|
25
|
-
if metadata['implementations'].is_a?(Array)
|
26
|
-
metadata['implementations'].map do |impl|
|
27
|
-
path = executables.find { |real_impl| File.basename(real_impl) == impl['name'] }
|
28
|
-
if path
|
29
|
-
{ "name" => impl['name'], "requirements" => impl.fetch('requirements', []), "path" => path }
|
30
|
-
else
|
31
|
-
raise ArgumentError, _("Task metadata for task %{name} specifies missing implementation %{implementation}") %
|
32
|
-
{ name: name, implementation: impl['name'] }
|
33
|
-
end
|
34
|
-
end
|
35
|
-
else
|
36
|
-
# If 'implementations' is the wrong type, we just pass it through and
|
37
|
-
# let the task type definition reject it.
|
38
|
-
metadata['implementations']
|
39
|
-
end
|
40
|
-
# If implementations isn't defined, then we use executables matching the
|
41
|
-
# task name, and only one may exist.
|
42
|
-
else
|
43
|
-
implementations = executables.select { |impl| File.basename(impl, '.*') == basename }
|
44
|
-
if implementations.empty?
|
45
|
-
raise ArgumentError, _('No source besides task metadata was found in directory %{directory} for task %{name}') %
|
46
|
-
{ name: name, directory: directory }
|
47
|
-
elsif implementations.length > 1
|
48
|
-
raise ArgumentError, _("Multiple executables were found in directory %{directory} for task %{name}; define 'implementations' in metadata to differentiate between them") %
|
49
|
-
{ name: name, directory: implementations[0] }
|
50
|
-
end
|
51
|
-
|
52
|
-
[{ "name" => File.basename(implementations.first), "path" => implementations.first, "requirements" => [] }]
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
7
|
def self.create(loader, typed_name, source_refs)
|
57
8
|
name = typed_name.name
|
58
9
|
basename = typed_name.name_parts[1] || 'init'
|
@@ -60,31 +11,16 @@ class TaskInstantiator
|
|
60
11
|
metadata_files, executables = source_refs.partition { |source_ref| source_ref.end_with?('.json') }
|
61
12
|
metadata_file = metadata_files.find { |source_ref| File.basename(source_ref, '.json') == basename }
|
62
13
|
|
63
|
-
metadata =
|
14
|
+
metadata = Puppet::Module::Task.read_metadata(metadata_file) || {}
|
64
15
|
|
65
|
-
|
16
|
+
files = Puppet::Module::Task.find_files(name, dirname, metadata, executables)
|
66
17
|
|
67
|
-
|
68
|
-
'name' => name,
|
69
|
-
'implementations' => implementation_metadata
|
70
|
-
}
|
18
|
+
task = { 'name' => name, 'metadata' => metadata, 'files' => files }
|
71
19
|
|
72
20
|
begin
|
73
|
-
|
74
|
-
if %w[parameters output].include?(key)
|
75
|
-
ps = {}
|
76
|
-
value.each_pair do |k, v|
|
77
|
-
pd = v.dup
|
78
|
-
t = v['type']
|
79
|
-
pd['type'] = t.nil? ? Types::TypeFactory.data : Types::TypeParser.singleton.parse(t)
|
80
|
-
ps[k] = pd
|
81
|
-
end
|
82
|
-
value = ps
|
83
|
-
end
|
84
|
-
arguments[key] = value unless arguments.key?(key)
|
85
|
-
end
|
21
|
+
task['parameters'] = convert_types(metadata['parameters'])
|
86
22
|
|
87
|
-
Types::TypeFactory.task.from_hash(
|
23
|
+
Types::TypeFactory.task.from_hash(task)
|
88
24
|
rescue Types::TypeAssertionError => ex
|
89
25
|
# Not strictly a parser error but from the users perspective, the file content didn't parse properly. The
|
90
26
|
# ParserError also conveys file info (even though line is unknown)
|
@@ -92,6 +28,13 @@ class TaskInstantiator
|
|
92
28
|
raise Puppet::ParseError.new(msg, metadata_file)
|
93
29
|
end
|
94
30
|
end
|
31
|
+
|
32
|
+
def self.convert_types(args)
|
33
|
+
args.each_with_object({}) do |(k, v), hsh|
|
34
|
+
hsh[k] = v['type'].nil? ? Types::TypeFactory.data : Types::TypeParser.singleton.parse(v['type'])
|
35
|
+
end if args
|
36
|
+
end
|
37
|
+
private_class_method :convert_types
|
95
38
|
end
|
96
39
|
end
|
97
40
|
end
|
@@ -13,6 +13,7 @@ class Loaders
|
|
13
13
|
|
14
14
|
attr_reader :static_loader
|
15
15
|
attr_reader :puppet_system_loader
|
16
|
+
attr_reader :puppet_cache_loader
|
16
17
|
attr_reader :public_environment_loader
|
17
18
|
attr_reader :private_environment_loader
|
18
19
|
attr_reader :environment
|
@@ -43,20 +44,21 @@ class Loaders
|
|
43
44
|
#
|
44
45
|
@puppet_system_loader = create_puppet_system_loader()
|
45
46
|
|
46
|
-
# 2.
|
47
|
+
# 2. Cache loader(optional) - i.e. what puppet stores on disk via pluginsync; gate behind the for_agent flag.
|
48
|
+
# 3. Environment loader - i.e. what is bound across the environment, may change for each setup
|
47
49
|
# TODO: loaders need to work when also running in an agent doing catalog application. There is no
|
48
50
|
# concept of environment the same way as when running as a master (except when doing apply).
|
49
51
|
# The creation mechanisms should probably differ between the two.
|
50
|
-
#
|
51
52
|
@private_environment_loader = if for_agent
|
52
|
-
|
53
|
+
@puppet_cache_loader = create_puppet_cache_loader()
|
54
|
+
create_environment_loader(environment, @puppet_cache_loader)
|
53
55
|
else
|
54
|
-
create_environment_loader(environment)
|
56
|
+
create_environment_loader(environment, @puppet_system_loader)
|
55
57
|
end
|
56
58
|
|
57
59
|
Pcore.init_env(@private_environment_loader)
|
58
60
|
|
59
|
-
#
|
61
|
+
# 4. module loaders are set up from the create_environment_loader, they register themselves
|
60
62
|
end
|
61
63
|
|
62
64
|
# Called after loader has been added to Puppet Context as :loaders so that dynamic types can
|
@@ -354,7 +356,11 @@ class Loaders
|
|
354
356
|
Loader::ModuleLoaders.system_loader_from(static_loader, self)
|
355
357
|
end
|
356
358
|
|
357
|
-
def
|
359
|
+
def create_puppet_cache_loader()
|
360
|
+
Loader::ModuleLoaders.cached_loader_from(puppet_system_loader, self)
|
361
|
+
end
|
362
|
+
|
363
|
+
def create_environment_loader(environment, parent_loader)
|
358
364
|
# This defines where to start parsing/evaluating - the "initial import" (to use 3x terminology)
|
359
365
|
# Is either a reference to a single .pp file, or a directory of manifests. If the environment becomes
|
360
366
|
# a module and can hold functions, types etc. then these are available across all other modules without
|
@@ -375,11 +381,11 @@ class Loaders
|
|
375
381
|
env_path = env_conf.nil? || !env_conf.is_a?(Puppet::Settings::EnvironmentConf) ? nil : env_conf.path_to_env
|
376
382
|
|
377
383
|
if Puppet[:tasks]
|
378
|
-
loader = Loader::ModuleLoaders.environment_loader_from(
|
384
|
+
loader = Loader::ModuleLoaders.environment_loader_from(parent_loader, self, env_path)
|
379
385
|
else
|
380
386
|
# Create the 3.x resource type loader
|
381
387
|
static_loader.runtime_3_init
|
382
|
-
@runtime3_type_loader = add_loader_by_name(Loader::Runtime3TypeLoader.new(
|
388
|
+
@runtime3_type_loader = add_loader_by_name(Loader::Runtime3TypeLoader.new(parent_loader, self, environment, env_conf.nil? ? nil : env_path))
|
383
389
|
|
384
390
|
if env_path.nil?
|
385
391
|
# Not a real directory environment, cannot work as a module TODO: Drop when legacy env are dropped?
|
@@ -503,8 +509,8 @@ class Loaders
|
|
503
509
|
nil
|
504
510
|
else
|
505
511
|
module_data.private_loader =
|
506
|
-
if module_data.restrict_to_dependencies?
|
507
|
-
|
512
|
+
if module_data.restrict_to_dependencies?
|
513
|
+
create_loader_with_dependencies_first(module_data)
|
508
514
|
else
|
509
515
|
create_loader_with_all_modules_visible(module_data)
|
510
516
|
end
|
@@ -514,29 +520,13 @@ class Loaders
|
|
514
520
|
private
|
515
521
|
|
516
522
|
def create_loader_with_all_modules_visible(from_module_data)
|
517
|
-
Puppet.debug{"ModuleLoader: module '#{from_module_data.name}' has unknown dependencies - it will have all other modules visible"}
|
518
|
-
|
519
523
|
@loaders.add_loader_by_name(Loader::DependencyLoader.new(from_module_data.public_loader, "#{from_module_data.name} private", all_module_loaders()))
|
520
524
|
end
|
521
525
|
|
522
|
-
def
|
523
|
-
if from_module_data.unmet_dependencies?
|
524
|
-
if Puppet[:strict] != :off
|
525
|
-
msg = "ModuleLoader: module '#{from_module_data.name}' has unresolved dependencies" \
|
526
|
-
" - it will only see those that are resolved." \
|
527
|
-
" Use 'puppet module list --tree' to see information about modules"
|
528
|
-
case Puppet[:strict]
|
529
|
-
when :error
|
530
|
-
raise LoaderError.new(msg)
|
531
|
-
when :warning
|
532
|
-
Puppet.warn_once(:unresolved_module_dependencies,
|
533
|
-
"unresolved_dependencies_for_module_#{from_module_data.name}",
|
534
|
-
msg)
|
535
|
-
end
|
536
|
-
end
|
537
|
-
end
|
526
|
+
def create_loader_with_dependencies_first(from_module_data)
|
538
527
|
dependency_loaders = from_module_data.dependency_names.collect { |name| @index[name].public_loader }
|
539
|
-
|
528
|
+
visible_loaders = dependency_loaders + (all_module_loaders() - dependency_loaders)
|
529
|
+
@loaders.add_loader_by_name(Loader::DependencyLoader.new(from_module_data.public_loader, "#{from_module_data.name} private", visible_loaders))
|
540
530
|
end
|
541
531
|
end
|
542
532
|
end
|