puppet 6.17.0-x86-mingw32 → 6.18.0-x86-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.

Files changed (189) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +6 -5
  3. data/lib/puppet/application/apply.rb +18 -20
  4. data/lib/puppet/application/lookup.rb +16 -4
  5. data/lib/puppet/configurer/downloader.rb +31 -10
  6. data/lib/puppet/confine.rb +1 -1
  7. data/lib/puppet/confine/any.rb +1 -1
  8. data/lib/puppet/defaults.rb +21 -3
  9. data/lib/puppet/feature/base.rb +1 -1
  10. data/lib/puppet/file_serving/mount/locales.rb +1 -2
  11. data/lib/puppet/file_serving/mount/pluginfacts.rb +1 -2
  12. data/lib/puppet/file_serving/mount/plugins.rb +1 -2
  13. data/lib/puppet/file_system/file_impl.rb +3 -3
  14. data/lib/puppet/functions/lstrip.rb +4 -4
  15. data/lib/puppet/functions/reverse_each.rb +1 -1
  16. data/lib/puppet/functions/rstrip.rb +4 -4
  17. data/lib/puppet/functions/step.rb +1 -1
  18. data/lib/puppet/functions/strip.rb +4 -4
  19. data/lib/puppet/gettext/config.rb +5 -5
  20. data/lib/puppet/gettext/module_translations.rb +4 -4
  21. data/lib/puppet/indirector/exec.rb +1 -1
  22. data/lib/puppet/indirector/facts/facter.rb +3 -3
  23. data/lib/puppet/indirector/file_metadata/http.rb +1 -0
  24. data/lib/puppet/indirector/hiera.rb +4 -0
  25. data/lib/puppet/indirector/indirection.rb +1 -1
  26. data/lib/puppet/indirector/report/processor.rb +2 -2
  27. data/lib/puppet/module.rb +1 -2
  28. data/lib/puppet/network/format_support.rb +2 -2
  29. data/lib/puppet/network/http/route.rb +2 -2
  30. data/lib/puppet/node/environment.rb +12 -5
  31. data/lib/puppet/pal/pal_impl.rb +27 -3
  32. data/lib/puppet/parameter.rb +1 -1
  33. data/lib/puppet/parser/functions.rb +21 -17
  34. data/lib/puppet/parser/functions/create_resources.rb +11 -7
  35. data/lib/puppet/parser/type_loader.rb +2 -2
  36. data/lib/puppet/pops/adaptable.rb +7 -13
  37. data/lib/puppet/pops/adapters.rb +8 -4
  38. data/lib/puppet/pops/loader/runtime3_type_loader.rb +4 -2
  39. data/lib/puppet/pops/loaders.rb +18 -11
  40. data/lib/puppet/pops/lookup/context.rb +1 -1
  41. data/lib/puppet/pops/lookup/hiera_config.rb +14 -1
  42. data/lib/puppet/pops/types/iterable.rb +34 -8
  43. data/lib/puppet/pops/validation/checker4_0.rb +19 -15
  44. data/lib/puppet/provider/file/windows.rb +1 -1
  45. data/lib/puppet/provider/package/apt.rb +34 -0
  46. data/lib/puppet/provider/package/gem.rb +4 -2
  47. data/lib/puppet/provider/package/puppet_gem.rb +5 -0
  48. data/lib/puppet/provider/package/zypper.rb +3 -0
  49. data/lib/puppet/provider/user/aix.rb +1 -1
  50. data/lib/puppet/provider/user/user_role_add.rb +1 -1
  51. data/lib/puppet/provider/user/windows_adsi.rb +18 -1
  52. data/lib/puppet/settings.rb +1 -1
  53. data/lib/puppet/ssl/validator/default_validator.rb +1 -1
  54. data/lib/puppet/test/test_helper.rb +10 -3
  55. data/lib/puppet/transaction.rb +2 -2
  56. data/lib/puppet/transaction/persistence.rb +1 -1
  57. data/lib/puppet/transaction/report.rb +1 -1
  58. data/lib/puppet/trusted_external.rb +2 -2
  59. data/lib/puppet/type.rb +4 -3
  60. data/lib/puppet/type/file.rb +2 -2
  61. data/lib/puppet/type/file/source.rb +27 -7
  62. data/lib/puppet/type/notify.rb +2 -2
  63. data/lib/puppet/type/service.rb +4 -0
  64. data/lib/puppet/type/user.rb +18 -3
  65. data/lib/puppet/util.rb +26 -12
  66. data/lib/puppet/util/autoload.rb +9 -7
  67. data/lib/puppet/util/character_encoding.rb +9 -5
  68. data/lib/puppet/util/execution.rb +2 -2
  69. data/lib/puppet/util/windows.rb +1 -0
  70. data/lib/puppet/util/windows/api_types.rb +15 -1
  71. data/lib/puppet/util/windows/monkey_patches/dir.rb +40 -0
  72. data/lib/puppet/util/windows/security.rb +4 -4
  73. data/lib/puppet/util/windows/user.rb +219 -0
  74. data/lib/puppet/version.rb +1 -1
  75. data/locales/puppet.pot +78 -69
  76. data/man/man5/puppet.conf.5 +22 -3
  77. data/man/man8/puppet-agent.8 +1 -1
  78. data/man/man8/puppet-apply.8 +1 -1
  79. data/man/man8/puppet-catalog.8 +1 -1
  80. data/man/man8/puppet-config.8 +1 -1
  81. data/man/man8/puppet-describe.8 +1 -1
  82. data/man/man8/puppet-device.8 +1 -1
  83. data/man/man8/puppet-doc.8 +1 -1
  84. data/man/man8/puppet-epp.8 +1 -1
  85. data/man/man8/puppet-facts.8 +1 -1
  86. data/man/man8/puppet-filebucket.8 +1 -1
  87. data/man/man8/puppet-generate.8 +1 -1
  88. data/man/man8/puppet-help.8 +1 -1
  89. data/man/man8/puppet-key.8 +1 -1
  90. data/man/man8/puppet-lookup.8 +2 -2
  91. data/man/man8/puppet-man.8 +1 -1
  92. data/man/man8/puppet-module.8 +1 -1
  93. data/man/man8/puppet-node.8 +1 -1
  94. data/man/man8/puppet-parser.8 +1 -1
  95. data/man/man8/puppet-plugin.8 +1 -1
  96. data/man/man8/puppet-report.8 +1 -1
  97. data/man/man8/puppet-resource.8 +1 -1
  98. data/man/man8/puppet-script.8 +1 -1
  99. data/man/man8/puppet-ssl.8 +1 -1
  100. data/man/man8/puppet-status.8 +1 -1
  101. data/man/man8/puppet.8 +2 -2
  102. data/spec/fixtures/integration/application/apply/environments/spec/modules/amod/lib/puppet/provider/applytest/applytest.rb +2 -0
  103. data/spec/fixtures/integration/application/apply/environments/spec/modules/amod/lib/puppet/type/applytest.rb +25 -0
  104. data/spec/fixtures/unit/forge/bacula-releases.json +128 -0
  105. data/spec/fixtures/unit/forge/bacula.tar.gz +0 -0
  106. data/spec/integration/application/agent_spec.rb +29 -37
  107. data/spec/integration/application/apply_spec.rb +149 -149
  108. data/spec/integration/application/config_spec.rb +74 -0
  109. data/spec/integration/application/doc_spec.rb +16 -6
  110. data/spec/integration/application/filebucket_spec.rb +65 -16
  111. data/spec/integration/application/help_spec.rb +42 -0
  112. data/spec/integration/application/lookup_spec.rb +13 -0
  113. data/spec/integration/application/module_spec.rb +68 -0
  114. data/spec/integration/application/plugin_spec.rb +50 -0
  115. data/spec/integration/data_binding_spec.rb +82 -0
  116. data/spec/integration/directory_environments_spec.rb +17 -17
  117. data/spec/integration/indirector/facts/facter_spec.rb +8 -6
  118. data/spec/integration/node/environment_spec.rb +1 -1
  119. data/spec/integration/util/execution_spec.rb +22 -0
  120. data/spec/integration/util/windows/monkey_patches/dir_spec.rb +11 -0
  121. data/spec/integration/util/windows/process_spec.rb +26 -32
  122. data/spec/integration/util/windows/user_spec.rb +7 -0
  123. data/spec/integration/util_spec.rb +7 -33
  124. data/spec/lib/puppet_spec/matchers.rb +0 -80
  125. data/spec/lib/puppet_spec/puppetserver.rb +8 -0
  126. data/spec/unit/application/agent_spec.rb +3 -4
  127. data/spec/unit/application/face_base_spec.rb +6 -4
  128. data/spec/unit/application/facts_spec.rb +39 -10
  129. data/spec/unit/application/man_spec.rb +52 -0
  130. data/spec/unit/application/resource_spec.rb +3 -1
  131. data/spec/unit/application/ssl_spec.rb +15 -2
  132. data/spec/unit/configurer/downloader_spec.rb +10 -0
  133. data/spec/unit/configurer_spec.rb +47 -31
  134. data/spec/unit/confine_spec.rb +2 -1
  135. data/spec/unit/face/config_spec.rb +3 -1
  136. data/spec/unit/file_serving/mount/locales_spec.rb +2 -2
  137. data/spec/unit/file_serving/mount/pluginfacts_spec.rb +2 -2
  138. data/spec/unit/file_serving/mount/plugins_spec.rb +2 -2
  139. data/spec/unit/file_system/uniquefile_spec.rb +18 -0
  140. data/spec/unit/http/client_spec.rb +0 -1
  141. data/spec/unit/http/resolver_spec.rb +0 -1
  142. data/spec/unit/http/service/ca_spec.rb +0 -1
  143. data/spec/unit/http/service/compiler_spec.rb +0 -1
  144. data/spec/unit/http/service/file_server_spec.rb +0 -1
  145. data/spec/unit/http/service/report_spec.rb +0 -1
  146. data/spec/unit/http/service_spec.rb +0 -1
  147. data/spec/unit/http/session_spec.rb +0 -1
  148. data/spec/unit/module_tool/tar/mini_spec.rb +20 -0
  149. data/spec/unit/network/format_support_spec.rb +3 -2
  150. data/spec/unit/node/environment_spec.rb +18 -1
  151. data/spec/unit/pops/loaders/loaders_spec.rb +70 -0
  152. data/spec/unit/pops/lookup/lookup_spec.rb +25 -0
  153. data/spec/unit/provider/package/apt_spec.rb +77 -0
  154. data/spec/unit/provider/package/aptitude_spec.rb +1 -0
  155. data/spec/unit/provider/package/puppet_gem_spec.rb +4 -1
  156. data/spec/unit/provider/package/zypper_spec.rb +14 -0
  157. data/spec/unit/provider/service/init_spec.rb +41 -0
  158. data/spec/unit/provider/service/systemd_spec.rb +1 -6
  159. data/spec/unit/provider/service/windows_spec.rb +28 -0
  160. data/spec/unit/provider/user/windows_adsi_spec.rb +82 -0
  161. data/spec/unit/puppet_pal_2pec.rb +40 -0
  162. data/spec/unit/reports/store_spec.rb +17 -13
  163. data/spec/unit/transaction/persistence_spec.rb +15 -0
  164. data/spec/unit/type/service_spec.rb +35 -2
  165. data/spec/unit/type/user_spec.rb +31 -2
  166. data/spec/unit/util/character_encoding_spec.rb +4 -4
  167. data/spec/unit/util/command_line_spec.rb +11 -6
  168. metadata +21 -44
  169. data/spec/integration/faces/config_spec.rb +0 -91
  170. data/spec/integration/faces/documentation_spec.rb +0 -57
  171. data/spec/integration/file_bucket/file_spec.rb +0 -50
  172. data/spec/integration/file_serving/content_spec.rb +0 -7
  173. data/spec/integration/file_serving/fileset_spec.rb +0 -12
  174. data/spec/integration/file_serving/metadata_spec.rb +0 -8
  175. data/spec/integration/file_serving/terminus_helper_spec.rb +0 -20
  176. data/spec/integration/file_system/uniquefile_spec.rb +0 -26
  177. data/spec/integration/module_tool/forge_spec.rb +0 -51
  178. data/spec/integration/module_tool/tar/mini_spec.rb +0 -28
  179. data/spec/integration/provider/service/init_spec.rb +0 -48
  180. data/spec/integration/provider/service/systemd_spec.rb +0 -25
  181. data/spec/integration/provider/service/windows_spec.rb +0 -50
  182. data/spec/integration/reference/providers_spec.rb +0 -21
  183. data/spec/integration/reports_spec.rb +0 -13
  184. data/spec/integration/ssl/certificate_request_spec.rb +0 -44
  185. data/spec/integration/ssl/host_spec.rb +0 -72
  186. data/spec/integration/ssl/key_spec.rb +0 -99
  187. data/spec/shared_behaviours/file_serving_model.rb +0 -51
  188. data/spec/unit/face/man_spec.rb +0 -25
  189. data/spec/unit/man_spec.rb +0 -31
@@ -65,7 +65,7 @@ module Puppet::GettextConfig
65
65
  return if @gettext_disabled || !gettext_loaded?
66
66
  domain_name = domain_name.to_sym
67
67
 
68
- Puppet.debug "Reset text domain to #{domain_name.inspect}"
68
+ Puppet.debug { "Reset text domain to #{domain_name.inspect}" }
69
69
  FastGettext.add_text_domain(domain_name,
70
70
  type: :chain,
71
71
  chain: [],
@@ -115,10 +115,10 @@ module Puppet::GettextConfig
115
115
  domain_name = domain_name.to_sym
116
116
 
117
117
  if FastGettext.translation_repositories.include?(domain_name)
118
- Puppet.debug "Use text domain #{domain_name.inspect}"
118
+ Puppet.debug { "Use text domain #{domain_name.inspect}" }
119
119
  FastGettext.text_domain = domain_name
120
120
  else
121
- Puppet.debug "Requested unknown text domain #{domain_name.inspect}"
121
+ Puppet.debug { "Requested unknown text domain #{domain_name.inspect}" }
122
122
  end
123
123
  end
124
124
 
@@ -139,10 +139,10 @@ module Puppet::GettextConfig
139
139
 
140
140
  deleted = FastGettext.translation_repositories.delete(domain_name)
141
141
  if FastGettext.text_domain == domain_name
142
- Puppet.debug "Deleted current text domain #{domain_name.inspect}: #{!deleted.nil?}"
142
+ Puppet.debug { "Deleted current text domain #{domain_name.inspect}: #{!deleted.nil?}" }
143
143
  FastGettext.text_domain = nil
144
144
  else
145
- Puppet.debug "Deleted text domain #{domain_name.inspect}: #{!deleted.nil?}"
145
+ Puppet.debug { "Deleted text domain #{domain_name.inspect}: #{!deleted.nil?}" }
146
146
  end
147
147
  end
148
148
 
@@ -13,9 +13,9 @@ module Puppet::ModuleTranslations
13
13
 
14
14
  module_name = mod.forge_name.tr('/', '-')
15
15
  if Puppet::GettextConfig.load_translations(module_name, mod.locale_directory, :po)
16
- Puppet.debug "Loaded translations for #{module_name}."
16
+ Puppet.debug { "Loaded translations for #{module_name}." }
17
17
  elsif Puppet::GettextConfig.gettext_loaded?
18
- Puppet.debug "Could not find translation files for #{module_name} at #{mod.locale_directory}. Skipping translation initialization."
18
+ Puppet.debug { "Could not find translation files for #{module_name} at #{mod.locale_directory}. Skipping translation initialization." }
19
19
  else
20
20
  Puppet.warn_once("gettext_unavailable", "gettext_unavailable", "No gettext library found, skipping translation initialization.")
21
21
  end
@@ -31,9 +31,9 @@ module Puppet::ModuleTranslations
31
31
  Dir.glob("#{vardir}/locales/#{locale}/*.po") do |f|
32
32
  module_name = File.basename(f, ".po")
33
33
  if Puppet::GettextConfig.load_translations(module_name, File.join(vardir, "locales"), :po)
34
- Puppet.debug "Loaded translations for #{module_name}."
34
+ Puppet.debug { "Loaded translations for #{module_name}." }
35
35
  elsif Puppet::GettextConfig.gettext_loaded?
36
- Puppet.debug "Could not load translations for #{module_name}."
36
+ Puppet.debug { "Could not load translations for #{module_name}." }
37
37
  else
38
38
  Puppet.warn_once("gettext_unavailable", "gettext_unavailable", "No gettext library found, skipping translation initialization.")
39
39
  end
@@ -22,7 +22,7 @@ class Puppet::Indirector::Exec < Puppet::Indirector::Terminus
22
22
  end
23
23
 
24
24
  if output =~ /\A\s*\Z/ # all whitespace
25
- Puppet.debug "Empty response for #{name} from #{self.name} terminus"
25
+ Puppet.debug { "Empty response for #{name} from #{self.name} terminus" }
26
26
  return nil
27
27
  else
28
28
  return output
@@ -55,7 +55,7 @@ class Puppet::Node::Facts::Facter < Puppet::Indirector::Code
55
55
  if Puppet::Util::Log.sendlevel?(:info)
56
56
  Puppet.info _("Loading facts")
57
57
  Dir.glob("#{dir}/*.rb").each do |file|
58
- Puppet.debug "Loading facts from #{file}"
58
+ Puppet.debug { "Loading facts from #{file}" }
59
59
  end
60
60
  end
61
61
 
@@ -71,7 +71,7 @@ class Puppet::Node::Facts::Facter < Puppet::Indirector::Code
71
71
  request.environment.modules.each do |m|
72
72
  if m.has_external_facts?
73
73
  dir = m.plugin_fact_directory
74
- Puppet.debug "Loading external facts from #{dir}"
74
+ Puppet.debug { "Loading external facts from #{dir}" }
75
75
  dirs << dir
76
76
  end
77
77
  end
@@ -79,7 +79,7 @@ class Puppet::Node::Facts::Facter < Puppet::Indirector::Code
79
79
  # Add system external fact directory if it exists
80
80
  if FileTest.directory?(Puppet[:pluginfactdest])
81
81
  dir = Puppet[:pluginfactdest]
82
- Puppet.debug "Loading external facts from #{dir}"
82
+ Puppet.debug { "Loading external facts from #{dir}" }
83
83
  dirs << dir
84
84
  end
85
85
 
@@ -10,6 +10,7 @@ class Puppet::Indirector::FileMetadata::Http < Puppet::Indirector::GenericHttp
10
10
 
11
11
  def find(request)
12
12
  checksum_type = request.options[:checksum_type]
13
+ # See URL encoding comment in Puppet::Type::File::ParamSource#chunk_file_from_source
13
14
  uri = URI(request.uri)
14
15
  client = Puppet.runtime[:http]
15
16
  head = client.head(uri, options: {include_system_store: true})
@@ -1,6 +1,10 @@
1
1
  require 'puppet/indirector/terminus'
2
2
  require 'hiera/scope'
3
3
 
4
+ # This class can't be collapsed into Puppet::Indirector::DataBindings::Hiera
5
+ # because some community plugins rely on this class directly, see PUP-1843.
6
+ # This class is deprecated and will be deleted in a future release.
7
+ # Use `Puppet::DataBinding.indirection.terminus(:hiera)` instead.
4
8
  class Puppet::Indirector::Hiera < Puppet::Indirector::Terminus
5
9
  def initialize(*args)
6
10
  if ! Puppet.features.hiera?
@@ -269,7 +269,7 @@ class Puppet::Indirector::Indirection
269
269
  return nil
270
270
  end
271
271
 
272
- Puppet.debug "Using cached #{self.name} for #{request.key}"
272
+ Puppet.debug { "Using cached #{self.name} for #{request.key}" }
273
273
  cached
274
274
  rescue => detail
275
275
  Puppet.log_exception(detail, _("Cached %{indirection} for %{request} failed: %{detail}") % { indirection: self.name, request: request.key, detail: detail })
@@ -26,9 +26,9 @@ class Puppet::Transaction::Report::Processor < Puppet::Indirector::Code
26
26
  # LAK:NOTE This isn't necessarily the best design, but it's backward
27
27
  # compatible and that's good enough for now.
28
28
  def process(report)
29
- Puppet.debug "Received report to process from #{report.host}"
29
+ Puppet.debug { "Received report to process from #{report.host}" }
30
30
  processors do |mod|
31
- Puppet.debug "Processing report from #{report.host} with processor #{mod}"
31
+ Puppet.debug { "Processing report from #{report.host} with processor #{mod}" }
32
32
  # We have to use a dup because we're including a module in the
33
33
  # report.
34
34
  newrep = report.dup
@@ -107,8 +107,7 @@ class Puppet::Module
107
107
  define_method(type + '?') do
108
108
  type_subpath = subpath(location)
109
109
  unless Puppet::FileSystem.exist?(type_subpath)
110
- Puppet.debug("No #{type} found in subpath '#{type_subpath}' " +
111
- "(file / directory does not exist)")
110
+ Puppet.debug { "No #{type} found in subpath '#{type_subpath}' (file / directory does not exist)" }
112
111
  return false
113
112
  end
114
113
 
@@ -49,7 +49,7 @@ module Puppet::Network::FormatSupport
49
49
 
50
50
  result = put_preferred_format_first(result).map(&:name)
51
51
 
52
- Puppet.debug "#{friendly_name} supports formats: #{result.join(' ')}"
52
+ Puppet.debug { "#{friendly_name} supports formats: #{result.join(' ')}" }
53
53
 
54
54
  result
55
55
  end
@@ -81,7 +81,7 @@ module Puppet::Network::FormatSupport
81
81
  }
82
82
 
83
83
  if preferred.empty?
84
- Puppet.debug "Value of 'preferred_serialization_format' (#{preferred_format}) is invalid for #{friendly_name}, using default (#{list.first.name})"
84
+ Puppet.debug { "Value of 'preferred_serialization_format' (#{preferred_format}) is invalid for #{friendly_name}, using default (#{list.first.name})" }
85
85
  else
86
86
  list = preferred + list.reject { |format|
87
87
  format.mime.end_with?(preferred_format)
@@ -67,11 +67,11 @@ class Puppet::Network::HTTP::Route
67
67
  end
68
68
 
69
69
  def matches?(request)
70
- Puppet.debug("Evaluating match for #{self.inspect}")
70
+ Puppet.debug { "Evaluating match for #{self.inspect}" }
71
71
  if match(request.routing_path)
72
72
  return true
73
73
  else
74
- Puppet.debug("Did not match path (#{request.routing_path.inspect})")
74
+ Puppet.debug { "Did not match path (#{request.routing_path.inspect})" }
75
75
  end
76
76
  return false
77
77
  end
@@ -266,7 +266,7 @@ class Puppet::Node::Environment
266
266
  # @param name [String] The module name
267
267
  # @return [Puppet::Module, nil] The module if found, else nil
268
268
  def module(name)
269
- modules.find {|mod| mod.name == name}
269
+ modules_by_name[name]
270
270
  end
271
271
 
272
272
  # Locate a module instance by the full forge name (EG authorname/module)
@@ -298,7 +298,7 @@ class Puppet::Node::Environment
298
298
  if @modules.nil?
299
299
  module_references = []
300
300
  project = Puppet.lookup(:bolt_project) { nil }
301
- seen_modules = if project
301
+ seen_modules = if project && project.load_as_module?
302
302
  module_references << project.to_h
303
303
  { project.name => true }
304
304
  else
@@ -327,6 +327,12 @@ class Puppet::Node::Environment
327
327
  @modules
328
328
  end
329
329
 
330
+ # @api private
331
+ def modules_by_name
332
+ @modules_by_name ||= Hash[modules.map { |mod| [mod.name, mod] }]
333
+ end
334
+ private :modules_by_name
335
+
330
336
  # Generate a warning if the given directory in a module path entry is named `lib`.
331
337
  #
332
338
  # @api private
@@ -335,9 +341,10 @@ class Puppet::Node::Environment
335
341
  # @param name [String] The directory name
336
342
  def warn_about_mistaken_path(path, name)
337
343
  if name == "lib"
338
- Puppet.debug("Warning: Found directory named 'lib' in module path ('#{path}/lib'); unless " +
339
- "you are expecting to load a module named 'lib', your module path may be set " +
340
- "incorrectly.")
344
+ Puppet.debug {
345
+ "Warning: Found directory named 'lib' in module path ('#{path}/lib'); unless you \
346
+ are expecting to load a module named 'lib', your module path may be set incorrectly."
347
+ }
341
348
  end
342
349
  end
343
350
 
@@ -49,6 +49,7 @@ module Pal
49
49
  # If given at the environment level, the facts given here are merged with higher priority.
50
50
  # @param variables [Hash] optional map of fully qualified variable name to value. If given at the environment level, the variables
51
51
  # given here are merged with higher priority.
52
+ # @param set_local_facts [Boolean] when true, the $facts, $server_facts, and $trusted variables are set for the scope.
52
53
  # @param block [Proc] the block performing operations on compiler
53
54
  # @return [Object] what the block returns
54
55
  # @yieldparam [Puppet::Pal::ScriptCompiler] compiler, a ScriptCompiler to perform operations on.
@@ -59,6 +60,7 @@ module Pal
59
60
  code_string: nil,
60
61
  facts: nil,
61
62
  variables: nil,
63
+ set_local_facts: true,
62
64
  &block
63
65
  )
64
66
  # TRANSLATORS: do not translate variable name strings in these assertions
@@ -91,7 +93,7 @@ module Pal
91
93
 
92
94
  # If manifest_file is nil, the #main method will use the env configured manifest
93
95
  # to do things in the block while a Script Compiler is in effect
94
- main(manifest_file, facts, variables, :script, &block)
96
+ main(manifest_file, facts, variables, :script, set_local_facts, &block)
95
97
  ensure
96
98
  Puppet[:tasks] = previous_tasks_value
97
99
  Puppet[:code] = previous_code_value
@@ -191,7 +193,7 @@ module Pal
191
193
 
192
194
  # If manifest_file is nil, the #main method will use the env configured manifest
193
195
  # to do things in the block while a Script Compiler is in effect
194
- main(manifest_file, facts, variables, :catalog, &block)
196
+ main(manifest_file, facts, variables, :catalog, false, &block)
195
197
  ensure
196
198
  # Clean up after ourselves
197
199
  Puppet[:tasks] = previous_tasks_value
@@ -379,7 +381,13 @@ module Pal
379
381
  # Picks up information from the puppet context and configures a script compiler which is given to
380
382
  # the provided block
381
383
  #
382
- def self.main(manifest, facts, variables, internal_compiler_class)
384
+ def self.main(
385
+ manifest,
386
+ facts,
387
+ variables,
388
+ internal_compiler_class,
389
+ set_local_facts
390
+ )
383
391
  # Configure the load path
384
392
  env = Puppet.lookup(:pal_env)
385
393
  env.each_plugin_directory do |dir|
@@ -434,6 +442,22 @@ module Pal
434
442
  overrides[:pal_catalog_compiler] = overrides[:pal_compiler] = pal_compiler
435
443
  end
436
444
 
445
+ # When scripting the trusted data are always local; default is to set them anyway
446
+ # When compiling for a catalog, the catalog compiler does this
447
+ if set_local_facts
448
+ compiler.topscope.set_trusted(node.trusted_data)
449
+
450
+ # Server facts are always about the local node's version etc.
451
+ compiler.topscope.set_server_facts(node.server_facts)
452
+
453
+ # Set $facts for the node running the script
454
+ facts_hash = node.facts.nil? ? {} : node.facts.values
455
+ compiler.topscope.set_facts(facts_hash)
456
+
457
+ # create the $settings:: variables
458
+ compiler.topscope.merge_settings(node.environment.name, false)
459
+ end
460
+
437
461
  # Make compiler available to Puppet#lookup and injection in functions
438
462
  # TODO: The compiler instances should be available under non PAL use as well!
439
463
  # TRANSLATORS: Do not translate, symbolic name
@@ -429,7 +429,7 @@ class Puppet::Parameter
429
429
  begin
430
430
  ret = unsafe_munge(value)
431
431
  rescue Puppet::Error => detail
432
- Puppet.debug "Reraising #{detail}"
432
+ Puppet.debug { "Reraising #{detail}" }
433
433
  raise
434
434
  rescue => detail
435
435
  raise Puppet::DevError, _("Munging failed for value %{value} in class %{class_name}: %{detail}") % { value: value.inspect, class_name: self.name, detail: detail }, detail.backtrace
@@ -77,6 +77,26 @@ module Puppet::Parser::Functions
77
77
  # @api private
78
78
  class AnonymousModuleAdapter < Puppet::Pops::Adaptable::Adapter
79
79
  attr_accessor :module
80
+
81
+ def self.create_adapter(env)
82
+ adapter = super(env)
83
+ adapter.module = Module.new do
84
+ @metadata = {}
85
+
86
+ def self.all_function_info
87
+ @metadata
88
+ end
89
+
90
+ def self.get_function_info(name)
91
+ @metadata[name]
92
+ end
93
+
94
+ def self.add_function_info(name, info)
95
+ @metadata[name] = info
96
+ end
97
+ end
98
+ adapter
99
+ end
80
100
  end
81
101
 
82
102
  @environment_module_lock = Puppet::Concurrent::Lock.new
@@ -87,23 +107,7 @@ module Puppet::Parser::Functions
87
107
  # @api private
88
108
  def self.environment_module(env)
89
109
  @environment_module_lock.synchronize do
90
- AnonymousModuleAdapter.adapt(env) do |a|
91
- a.module ||= Module.new do
92
- @metadata = {}
93
-
94
- def self.all_function_info
95
- @metadata
96
- end
97
-
98
- def self.get_function_info(name)
99
- @metadata[name]
100
- end
101
-
102
- def self.add_function_info(name, info)
103
- @metadata[name] = info
104
- end
105
- end
106
- end.module
110
+ AnonymousModuleAdapter.adapt(env).module
107
111
  end
108
112
  end
109
113
 
@@ -1,5 +1,9 @@
1
1
  Puppet::Parser::Functions::newfunction(:create_resources, :arity => -3, :doc => <<-'ENDHEREDOC') do |args|
2
2
  Converts a hash into a set of resources and adds them to the catalog.
3
+
4
+ **Note**: Use this function selectively. It's generally better to write resources in
5
+ [Puppet](https://puppet.com/docs/puppet/latest/lang_resources.html), as
6
+ resources created with `create_resource` are difficult to read and troubleshoot.
3
7
 
4
8
  This function takes two mandatory arguments: a resource type, and a hash describing
5
9
  a set of resources. The hash should be in the form `{title => {parameters} }`:
@@ -33,7 +37,7 @@ Puppet::Parser::Functions::newfunction(:create_resources, :arity => -3, :doc =>
33
37
  as native resources.
34
38
 
35
39
  Virtual and Exported resources may be created by prefixing the type name
36
- with @ or @@ respectively. For example, the $myusers hash may be exported
40
+ with @ or @@ respectively. For example, the $myusers hash may be exported
37
41
  in the following manner:
38
42
 
39
43
  create_resources("@@user", $myusers)
@@ -42,9 +46,9 @@ Puppet::Parser::Functions::newfunction(:create_resources, :arity => -3, :doc =>
42
46
 
43
47
  create_resources("@user", $myusers)
44
48
 
45
- Note that `create_resources` will filter out parameter values that are `undef` so that normal
46
- data binding and puppet default value expressions are considered (in that order) for the
47
- final value of a parameter (just as when setting a parameter to `undef` in a puppet language
49
+ Note that `create_resources` filters out parameter values that are `undef` so that normal
50
+ data binding and Puppet default value expressions are considered (in that order) for the
51
+ final value of a parameter (just as when setting a parameter to `undef` in a Puppet language
48
52
  resource declaration).
49
53
  ENDHEREDOC
50
54
  if Puppet[:tasks]
@@ -63,9 +67,9 @@ Puppet::Parser::Functions::newfunction(:create_resources, :arity => -3, :doc =>
63
67
  defaults ||= {}
64
68
  type_name = type.sub(/^@{1,2}/, '').downcase
65
69
 
66
- # Get file/line information from the puppet stack (where call comes from in puppet source)
67
- # If relayed via other puppet functions in ruby that do not nest their calls, the source position
68
- # will be in the original puppet source.
70
+ # Get file/line information from the Puppet stack (where call comes from in Puppet source)
71
+ # If relayed via other Puppet functions in ruby that do not nest their calls, the source position
72
+ # will be in the original Puppet source.
69
73
  #
70
74
  file, line = Puppet::Pops::PuppetStack.top_of_stack
71
75
 
@@ -81,7 +81,7 @@ class Puppet::Parser::TypeLoader
81
81
  end
82
82
 
83
83
  def parse_file(file)
84
- Puppet.debug("importing '#{file}' in environment #{environment}")
84
+ Puppet.debug { "importing '#{file}' in environment #{environment}" }
85
85
  parser = Puppet::Parser::ParserFactory.parser
86
86
  parser.file = file
87
87
  return parser.parse
@@ -118,7 +118,7 @@ class Puppet::Parser::TypeLoader
118
118
  # still be parsed. Mark this file as loaded so that
119
119
  # it would not be parsed next time (handle it as if
120
120
  # it was successfully parsed).
121
- Puppet.debug("Unable to parse '#{file}': #{e.message}")
121
+ Puppet.debug { "Unable to parse '#{file}': #{e.message}" }
122
122
  end
123
123
  else
124
124
  loaded_asts << parse_file(file)
@@ -69,11 +69,7 @@ module Adaptable
69
69
  #
70
70
  def self.get(o)
71
71
  attr_name = self_attr_name
72
- if o.instance_variable_defined?(attr_name)
73
- o.instance_variable_get(attr_name)
74
- else
75
- nil
76
- end
72
+ o.instance_variable_get(attr_name)
77
73
  end
78
74
 
79
75
  # Returns an existing adapter for the given object, or creates a new adapter if the
@@ -94,14 +90,13 @@ module Adaptable
94
90
  #
95
91
  def self.adapt(o, &block)
96
92
  attr_name = self_attr_name
97
- value = o.instance_variable_get(attr_name) if o.instance_variable_defined?(attr_name)
93
+ value = o.instance_variable_get(attr_name)
98
94
  adapter = value || associate_adapter(create_adapter(o), o)
99
95
  if block_given?
100
- case block.arity
101
- when 1
102
- block.call(adapter)
103
- else
104
- block.call(adapter, o)
96
+ if block.arity == 1
97
+ block.call(adapter)
98
+ else
99
+ block.call(adapter, o)
105
100
  end
106
101
  end
107
102
  adapter
@@ -127,8 +122,7 @@ module Adaptable
127
122
  def self.adapt_new(o, &block)
128
123
  adapter = associate_adapter(create_adapter(o), o)
129
124
  if block_given?
130
- case block.arity
131
- when 1
125
+ if block.arity == 1
132
126
  block.call(adapter)
133
127
  else
134
128
  block.call(adapter, o)