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.

Files changed (192) hide show
  1. checksums.yaml +4 -4
  2. data/bolt-modules/boltlib/lib/puppet/functions/apply_prep.rb +5 -2
  3. data/bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb +5 -1
  4. data/bolt-modules/boltlib/lib/puppet/functions/run_task.rb +5 -8
  5. data/lib/bolt/applicator.rb +11 -8
  6. data/lib/bolt/boltdir.rb +13 -5
  7. data/lib/bolt/catalog.rb +22 -47
  8. data/lib/bolt/config.rb +1 -26
  9. data/lib/bolt/executor.rb +1 -1
  10. data/lib/bolt/outputter.rb +0 -9
  11. data/lib/bolt/outputter/human.rb +29 -14
  12. data/lib/bolt/outputter/json.rb +12 -1
  13. data/lib/bolt/pal.rb +12 -10
  14. data/lib/bolt/target.rb +0 -6
  15. data/lib/bolt/task.rb +53 -10
  16. data/lib/bolt/transport/base.rb +1 -6
  17. data/lib/bolt/transport/local.rb +11 -13
  18. data/lib/bolt/transport/local/shell.rb +2 -2
  19. data/lib/bolt/transport/ssh.rb +16 -11
  20. data/lib/bolt/transport/winrm.rb +8 -11
  21. data/lib/bolt/version.rb +1 -1
  22. data/lib/bolt_ext/schemas/task.json +12 -5
  23. data/libexec/apply_catalog.rb +3 -1
  24. data/libexec/bolt_catalog +4 -0
  25. data/vendored/puppet/lib/puppet.rb +2 -1
  26. data/vendored/puppet/lib/puppet/application/agent.rb +2 -6
  27. data/vendored/puppet/lib/puppet/application/apply.rb +100 -60
  28. data/vendored/puppet/lib/puppet/application/cert.rb +26 -291
  29. data/vendored/puppet/lib/puppet/application/device.rb +0 -5
  30. data/vendored/puppet/lib/puppet/application/lookup.rb +1 -1
  31. data/vendored/puppet/lib/puppet/application/ssl.rb +133 -0
  32. data/vendored/puppet/lib/puppet/application_support.rb +1 -2
  33. data/vendored/puppet/lib/puppet/configurer.rb +34 -50
  34. data/vendored/puppet/lib/puppet/configurer/downloader.rb +1 -1
  35. data/vendored/puppet/lib/puppet/configurer/plugin_handler.rb +1 -1
  36. data/vendored/puppet/lib/puppet/daemon.rb +1 -1
  37. data/vendored/puppet/lib/puppet/defaults.rb +40 -117
  38. data/vendored/puppet/lib/puppet/face/epp.rb +2 -2
  39. data/vendored/puppet/lib/puppet/face/help.rb +21 -7
  40. data/vendored/puppet/lib/puppet/face/node/clean.rb +14 -10
  41. data/vendored/puppet/lib/puppet/feature/base.rb +7 -23
  42. data/vendored/puppet/lib/puppet/feature/eventlog.rb +1 -1
  43. data/vendored/puppet/lib/puppet/file_serving/base.rb +2 -2
  44. data/vendored/puppet/lib/puppet/file_serving/fileset.rb +1 -1
  45. data/vendored/puppet/lib/puppet/file_serving/metadata.rb +2 -2
  46. data/vendored/puppet/lib/puppet/functions.rb +133 -0
  47. data/vendored/puppet/lib/puppet/functions/eyaml_lookup_key.rb +4 -5
  48. data/vendored/puppet/lib/puppet/functions/filter.rb +7 -6
  49. data/vendored/puppet/lib/puppet/functions/new.rb +37 -53
  50. data/vendored/puppet/lib/puppet/functions/warning.rb +1 -1
  51. data/vendored/puppet/lib/puppet/functions/yaml_data.rb +4 -5
  52. data/vendored/puppet/lib/puppet/gettext/config.rb +1 -1
  53. data/vendored/puppet/lib/puppet/graph.rb +0 -2
  54. data/vendored/puppet/lib/puppet/indirector/catalog/json.rb +14 -3
  55. data/vendored/puppet/lib/puppet/indirector/catalog/yaml.rb +0 -16
  56. data/vendored/puppet/lib/puppet/indirector/certificate/file.rb +0 -1
  57. data/vendored/puppet/lib/puppet/indirector/facts/yaml.rb +4 -2
  58. data/vendored/puppet/lib/puppet/indirector/key/file.rb +1 -6
  59. data/vendored/puppet/lib/puppet/indirector/node/exec.rb +1 -3
  60. data/vendored/puppet/lib/puppet/indirector/node/yaml.rb +0 -6
  61. data/vendored/puppet/lib/puppet/indirector/request.rb +1 -1
  62. data/vendored/puppet/lib/puppet/indirector/ssl_file.rb +3 -44
  63. data/vendored/puppet/lib/puppet/indirector/yaml.rb +4 -4
  64. data/vendored/puppet/lib/puppet/info_service/task_information_service.rb +7 -3
  65. data/vendored/puppet/lib/puppet/loaders.rb +1 -0
  66. data/vendored/puppet/lib/puppet/module/task.rb +198 -29
  67. data/vendored/puppet/lib/puppet/module_tool/applications/unpacker.rb +1 -1
  68. data/vendored/puppet/lib/puppet/network/format_support.rb +13 -8
  69. data/vendored/puppet/lib/puppet/network/formats.rb +93 -2
  70. data/vendored/puppet/lib/puppet/network/http/api/indirected_routes.rb +10 -3
  71. data/vendored/puppet/lib/puppet/node/facts.rb +11 -1
  72. data/vendored/puppet/lib/puppet/parser/catalog_compiler.rb +56 -0
  73. data/vendored/puppet/lib/puppet/parser/compiler.rb +3 -1
  74. data/vendored/puppet/lib/puppet/parser/functions.rb +3 -1
  75. data/vendored/puppet/lib/puppet/parser/functions/filter.rb +1 -1
  76. data/vendored/puppet/lib/puppet/parser/functions/generate.rb +1 -1
  77. data/vendored/puppet/lib/puppet/parser/functions/sprintf.rb +12 -1
  78. data/vendored/puppet/lib/puppet/parser/functions/tagged.rb +1 -4
  79. data/vendored/puppet/lib/puppet/parser/scope.rb +1 -1
  80. data/vendored/puppet/lib/puppet/parser/script_compiler.rb +7 -2
  81. data/vendored/puppet/lib/puppet/pops/evaluator/deferred_resolver.rb +5 -3
  82. data/vendored/puppet/lib/puppet/pops/evaluator/runtime3_converter.rb +23 -4
  83. data/vendored/puppet/lib/puppet/pops/evaluator/runtime3_support.rb +3 -4
  84. data/vendored/puppet/lib/puppet/pops/functions/dispatch.rb +4 -0
  85. data/vendored/puppet/lib/puppet/pops/issues.rb +8 -0
  86. data/vendored/puppet/lib/puppet/pops/loader/loader.rb +2 -2
  87. data/vendored/puppet/lib/puppet/pops/loader/loader_paths.rb +3 -1
  88. data/vendored/puppet/lib/puppet/pops/loader/module_loaders.rb +30 -9
  89. data/vendored/puppet/lib/puppet/pops/loader/ruby_legacy_function_instantiator.rb +62 -0
  90. data/vendored/puppet/lib/puppet/pops/loader/static_loader.rb +0 -1
  91. data/vendored/puppet/lib/puppet/pops/loader/task_instantiator.rb +13 -70
  92. data/vendored/puppet/lib/puppet/pops/loaders.rb +19 -29
  93. data/vendored/puppet/lib/puppet/pops/lookup/hiera_config.rb +1 -1
  94. data/vendored/puppet/lib/puppet/pops/model/model_label_provider.rb +4 -1
  95. data/vendored/puppet/lib/puppet/pops/pcore.rb +10 -33
  96. data/vendored/puppet/lib/puppet/pops/serialization.rb +2 -0
  97. data/vendored/puppet/lib/puppet/pops/serialization/from_data_converter.rb +2 -1
  98. data/vendored/puppet/lib/puppet/pops/serialization/to_data_converter.rb +11 -3
  99. data/vendored/puppet/lib/puppet/pops/serialization/to_stringified_converter.rb +226 -0
  100. data/vendored/puppet/lib/puppet/pops/types/p_object_type.rb +3 -0
  101. data/vendored/puppet/lib/puppet/pops/validation/checker4_0.rb +97 -47
  102. data/vendored/puppet/lib/puppet/pops/validation/validator_factory_4_0.rb +7 -8
  103. data/vendored/puppet/lib/puppet/property/keyvalue.rb +70 -8
  104. data/vendored/puppet/lib/puppet/provider/aix_object.rb +483 -0
  105. data/vendored/puppet/lib/puppet/provider/file/windows.rb +1 -1
  106. data/vendored/puppet/lib/puppet/provider/group/aix.rb +51 -112
  107. data/vendored/puppet/lib/puppet/provider/package/gem.rb +1 -1
  108. data/vendored/puppet/lib/puppet/provider/package/pip.rb +1 -1
  109. data/vendored/puppet/lib/puppet/provider/package/puppet_gem.rb +1 -1
  110. data/vendored/puppet/lib/puppet/provider/package/rpm.rb +1 -1
  111. data/vendored/puppet/lib/puppet/provider/package/windows/package.rb +1 -1
  112. data/vendored/puppet/lib/puppet/provider/package/zypper.rb +1 -1
  113. data/vendored/puppet/lib/puppet/provider/service/systemd.rb +1 -1
  114. data/vendored/puppet/lib/puppet/provider/service/windows.rb +37 -40
  115. data/vendored/puppet/lib/puppet/provider/user/aix.rb +142 -254
  116. data/vendored/puppet/lib/puppet/resource.rb +20 -3
  117. data/vendored/puppet/lib/puppet/resource/catalog.rb +2 -12
  118. data/vendored/puppet/lib/puppet/rest/routes.rb +97 -34
  119. data/vendored/puppet/lib/puppet/settings.rb +1 -1
  120. data/vendored/puppet/lib/puppet/settings/file_setting.rb +1 -1
  121. data/vendored/puppet/lib/puppet/ssl/base.rb +1 -9
  122. data/vendored/puppet/lib/puppet/ssl/certificate_request.rb +1 -13
  123. data/vendored/puppet/lib/puppet/ssl/certificate_request_attributes.rb +1 -1
  124. data/vendored/puppet/lib/puppet/ssl/host.rb +114 -232
  125. data/vendored/puppet/lib/puppet/ssl/key.rb +1 -5
  126. data/vendored/puppet/lib/puppet/ssl/oids.rb +1 -1
  127. data/vendored/puppet/lib/puppet/test/test_helper.rb +0 -4
  128. data/vendored/puppet/lib/puppet/transaction/event.rb +3 -7
  129. data/vendored/puppet/lib/puppet/transaction/persistence.rb +1 -1
  130. data/vendored/puppet/lib/puppet/type/exec.rb +18 -16
  131. data/vendored/puppet/lib/puppet/type/file.rb +3 -3
  132. data/vendored/puppet/lib/puppet/type/file/source.rb +20 -7
  133. data/vendored/puppet/lib/puppet/type/group.rb +3 -5
  134. data/vendored/puppet/lib/puppet/type/notify.rb +1 -1
  135. data/vendored/puppet/lib/puppet/type/package.rb +2 -5
  136. data/vendored/puppet/lib/puppet/type/schedule.rb +1 -1
  137. data/vendored/puppet/lib/puppet/type/service.rb +3 -6
  138. data/vendored/puppet/lib/puppet/type/tidy.rb +1 -1
  139. data/vendored/puppet/lib/puppet/type/user.rb +13 -20
  140. data/vendored/puppet/lib/puppet/util.rb +8 -9
  141. data/vendored/puppet/lib/puppet/util/execution.rb +3 -3
  142. data/vendored/puppet/lib/puppet/util/feature.rb +61 -39
  143. data/vendored/puppet/lib/puppet/util/log/destinations.rb +1 -1
  144. data/vendored/puppet/lib/puppet/util/rdoc.rb +1 -1
  145. data/vendored/puppet/lib/puppet/util/run_mode.rb +1 -1
  146. data/vendored/puppet/lib/puppet/util/storage.rb +1 -1
  147. data/vendored/puppet/lib/puppet/util/suidmanager.rb +7 -5
  148. data/vendored/puppet/lib/puppet/util/tag_set.rb +1 -1
  149. data/vendored/puppet/lib/puppet/util/tagging.rb +1 -1
  150. data/vendored/puppet/lib/puppet/util/windows.rb +18 -2
  151. data/vendored/puppet/lib/puppet/util/windows/adsi.rb +154 -205
  152. data/vendored/puppet/lib/puppet/util/windows/service.rb +770 -0
  153. data/vendored/puppet/lib/puppet/util/yaml.rb +41 -5
  154. data/vendored/puppet/lib/puppet/version.rb +1 -1
  155. data/vendored/puppet/lib/puppet_pal.rb +280 -24
  156. metadata +8 -38
  157. data/lib/bolt/catalog/compiler.rb +0 -48
  158. data/lib/bolt/catalog/loaders.rb +0 -19
  159. data/vendored/puppet/lib/puppet/application/ca.rb +0 -11
  160. data/vendored/puppet/lib/puppet/application/certificate.rb +0 -17
  161. data/vendored/puppet/lib/puppet/application/certificate_request.rb +0 -7
  162. data/vendored/puppet/lib/puppet/application/certificate_revocation_list.rb +0 -7
  163. data/vendored/puppet/lib/puppet/face/ca.rb +0 -266
  164. data/vendored/puppet/lib/puppet/face/certificate.rb +0 -167
  165. data/vendored/puppet/lib/puppet/face/certificate_request.rb +0 -56
  166. data/vendored/puppet/lib/puppet/face/certificate_revocation_list.rb +0 -56
  167. data/vendored/puppet/lib/puppet/graph/random_prioritizer.rb +0 -16
  168. data/vendored/puppet/lib/puppet/graph/title_hash_prioritizer.rb +0 -16
  169. data/vendored/puppet/lib/puppet/indirector/certificate/ca.rb +0 -9
  170. data/vendored/puppet/lib/puppet/indirector/certificate/disabled_ca.rb +0 -22
  171. data/vendored/puppet/lib/puppet/indirector/certificate_request/ca.rb +0 -22
  172. data/vendored/puppet/lib/puppet/indirector/certificate_request/disabled_ca.rb +0 -22
  173. data/vendored/puppet/lib/puppet/indirector/certificate_revocation_list/ca.rb +0 -8
  174. data/vendored/puppet/lib/puppet/indirector/certificate_revocation_list/disabled_ca.rb +0 -22
  175. data/vendored/puppet/lib/puppet/indirector/certificate_revocation_list/file.rb +0 -8
  176. data/vendored/puppet/lib/puppet/indirector/certificate_revocation_list/rest.rb +0 -11
  177. data/vendored/puppet/lib/puppet/indirector/certificate_status.rb +0 -4
  178. data/vendored/puppet/lib/puppet/indirector/certificate_status/file.rb +0 -91
  179. data/vendored/puppet/lib/puppet/indirector/certificate_status/rest.rb +0 -11
  180. data/vendored/puppet/lib/puppet/indirector/key/ca.rb +0 -16
  181. data/vendored/puppet/lib/puppet/indirector/key/disabled_ca.rb +0 -22
  182. data/vendored/puppet/lib/puppet/indirector/ldap.rb +0 -86
  183. data/vendored/puppet/lib/puppet/indirector/node/ldap.rb +0 -275
  184. data/vendored/puppet/lib/puppet/provider/aixobject.rb +0 -392
  185. data/vendored/puppet/lib/puppet/provider/cron/crontab.rb +0 -297
  186. data/vendored/puppet/lib/puppet/ssl/certificate_authority.rb +0 -475
  187. data/vendored/puppet/lib/puppet/ssl/certificate_authority/autosign_command.rb +0 -45
  188. data/vendored/puppet/lib/puppet/ssl/certificate_authority/interface.rb +0 -324
  189. data/vendored/puppet/lib/puppet/ssl/certificate_factory.rb +0 -219
  190. data/vendored/puppet/lib/puppet/ssl/certificate_revocation_list.rb +0 -111
  191. data/vendored/puppet/lib/puppet/ssl/inventory.rb +0 -55
  192. data/vendored/puppet/lib/puppet/type/cron.rb +0 -480
@@ -14,7 +14,7 @@ module Puppet::ModuleTool
14
14
  end
15
15
 
16
16
  def self.harmonize_ownership(source, target)
17
- unless Puppet.features.microsoft_windows?
17
+ unless Puppet::Util::Platform.windows?
18
18
  source = Pathname.new(source) unless source.respond_to?(:stat)
19
19
  target = Pathname.new(target) unless target.respond_to?(:stat)
20
20
 
@@ -45,11 +45,9 @@ module Puppet::Network::FormatSupport
45
45
  end.sort do |a, b|
46
46
  # It's an inverse sort -- higher weight formats go first.
47
47
  b.weight <=> a.weight
48
- end.collect do |f|
49
- f.name
50
48
  end
51
49
 
52
- result = put_preferred_format_first(result)
50
+ result = put_preferred_format_first(result).map(&:name)
53
51
 
54
52
  Puppet.debug "#{friendly_name} supports formats: #{result.join(' ')}"
55
53
 
@@ -76,13 +74,20 @@ module Puppet::Network::FormatSupport
76
74
  end
77
75
 
78
76
  def put_preferred_format_first(list)
79
- preferred_format = Puppet.settings[:preferred_serialization_format].to_sym
80
- if list.include?(preferred_format)
81
- list.delete(preferred_format)
82
- list.unshift(preferred_format)
77
+ preferred_format = Puppet.settings[:preferred_serialization_format].to_s
78
+
79
+ preferred = list.select { |format|
80
+ format.mime.end_with?(preferred_format)
81
+ }
82
+
83
+ if preferred.empty?
84
+ Puppet.debug "Value of 'preferred_serialization_format' (#{preferred_format}) is invalid for #{friendly_name}, using default (#{list.first.name})"
83
85
  else
84
- Puppet.debug "Value of 'preferred_serialization_format' (#{preferred_format}) is invalid for #{friendly_name}, using default (#{list.first})"
86
+ list = preferred + list.reject { |format|
87
+ format.mime.end_with?(preferred_format)
88
+ }
85
89
  end
90
+
86
91
  list
87
92
  end
88
93
  end
@@ -23,13 +23,25 @@ Puppet::Network::FormatHandler.create_serialized_formats(:msgpack, :weight => 20
23
23
  end
24
24
 
25
25
  Puppet::Network::FormatHandler.create_serialized_formats(:yaml) do
26
+ def allowed_yaml_classes
27
+ @allowed_yaml_classes ||= [
28
+ Puppet::Node::Facts,
29
+ Puppet::Node,
30
+ Puppet::Transaction::Report,
31
+ Puppet::Resource,
32
+ Puppet::Resource::Catalog
33
+ ]
34
+ end
35
+
26
36
  def intern(klass, text)
27
- data = YAML.load(text)
37
+ data = Puppet::Util::Yaml.safe_load(text, allowed_yaml_classes)
28
38
  data_to_instance(klass, data)
39
+ rescue Puppet::Util::Yaml::YamlLoadError => e
40
+ raise Puppet::Network::FormatHandler::FormatError, _("Serialized YAML did not contain a valid instance of %{klass}: %{message}") % { klass: klass, message: e.message }
29
41
  end
30
42
 
31
43
  def intern_multiple(klass, text)
32
- data = YAML.load(text)
44
+ data = Puppet::Util::Yaml.safe_load(text, allowed_yaml_classes)
33
45
  unless data.respond_to?(:collect)
34
46
  raise Puppet::Network::FormatHandler::FormatError, _("Serialized YAML did not contain a collection of instances when calling intern_multiple")
35
47
  end
@@ -37,6 +49,8 @@ Puppet::Network::FormatHandler.create_serialized_formats(:yaml) do
37
49
  data.collect do |datum|
38
50
  data_to_instance(klass, datum)
39
51
  end
52
+ rescue Puppet::Util::Yaml::YamlLoadError => e
53
+ raise Puppet::Network::FormatHandler::FormatError, _("Serialized YAML did not contain a valid instance of %{klass}: %{message}") % { klass: klass, message: e.message }
40
54
  end
41
55
 
42
56
  def data_to_instance(klass, data)
@@ -167,3 +181,80 @@ Puppet::Network::FormatHandler.create(:console,
167
181
  data.collect(&:render).join("\n")
168
182
  end
169
183
  end
184
+
185
+ Puppet::Network::FormatHandler.create(:rich_data_json, mime: 'application/vnd.puppet.rich+json', charset: Encoding::UTF_8, weight: 30) do
186
+ def intern(klass, text)
187
+ Puppet.override({:rich_data => true}) do
188
+ data_to_instance(klass, Puppet::Util::Json.load(text))
189
+ end
190
+ end
191
+
192
+ def intern_multiple(klass, text)
193
+ Puppet.override({:rich_data => true}) do
194
+ Puppet::Util::Json.load(text).collect do |data|
195
+ data_to_instance(klass, data)
196
+ end
197
+ end
198
+ end
199
+
200
+ def render(instance)
201
+ Puppet.override({:rich_data => true}) do
202
+ instance.to_json
203
+ end
204
+ end
205
+
206
+ def render_multiple(instances)
207
+ Puppet.override({:rich_data => true}) do
208
+ Puppet::Util::Json.dump(instances)
209
+ end
210
+ end
211
+
212
+ def data_to_instance(klass, data)
213
+ Puppet.override({:rich_data => true}) do
214
+ return data if data.is_a?(klass)
215
+ klass.from_data_hash(data)
216
+ end
217
+ end
218
+
219
+ def supported?(klass)
220
+ klass == Puppet::Resource::Catalog &&
221
+ Puppet.lookup(:current_environment).rich_data?
222
+ end
223
+ end
224
+
225
+ Puppet::Network::FormatHandler.create_serialized_formats(:rich_data_msgpack, mime: "application/vnd.puppet.rich+msgpack", weight: 35) do
226
+ confine :feature => :msgpack
227
+
228
+ def intern(klass, text)
229
+ Puppet.override(rich_data: true) do
230
+ data = MessagePack.unpack(text)
231
+ return data if data.is_a?(klass)
232
+ klass.from_data_hash(data)
233
+ end
234
+ end
235
+
236
+ def intern_multiple(klass, text)
237
+ Puppet.override(rich_data: true) do
238
+ MessagePack.unpack(text).collect do |data|
239
+ klass.from_data_hash(data)
240
+ end
241
+ end
242
+ end
243
+
244
+ def render_multiple(instances)
245
+ Puppet.override(rich_data: true) do
246
+ instances.to_msgpack
247
+ end
248
+ end
249
+
250
+ def render(instance)
251
+ Puppet.override(rich_data: true) do
252
+ instance.to_msgpack
253
+ end
254
+ end
255
+
256
+ def supported?(klass)
257
+ klass == Puppet::Resource::Catalog &&
258
+ Puppet.lookup(:current_environment).rich_data?
259
+ end
260
+ end
@@ -43,8 +43,14 @@ class Puppet::Network::HTTP::API::IndirectedRoutes
43
43
  raise Puppet::Network::HTTP::Error::HTTPNotFoundError.new(_("No handler for %{indirection}") % { indirection: indirection.name }, :NO_INDIRECTION_REMOTE_REQUESTS)
44
44
  end
45
45
 
46
- trusted = Puppet::Context::TrustedInformation.remote(params[:authenticated], params[:node], certificate)
47
- Puppet.override(:trusted_information => trusted) do
46
+ overrides = {
47
+ trusted_information: Puppet::Context::TrustedInformation.remote(params[:authenticated], params[:node], certificate),
48
+ }
49
+ if params[:environment]
50
+ overrides[:current_environment] = params[:environment]
51
+ end
52
+
53
+ Puppet.override(overrides) do
48
54
  send("do_#{method}", indirection, key, params, request, response)
49
55
  end
50
56
  end
@@ -191,7 +197,8 @@ class Puppet::Network::HTTP::API::IndirectedRoutes
191
197
  begin
192
198
  yield format
193
199
  true
194
- rescue Puppet::Network::FormatHandler::FormatError
200
+ rescue Puppet::Network::FormatHandler::FormatError => err
201
+ Puppet.log_exception(err, err.message, level: :debug)
195
202
  false
196
203
  end
197
204
  end
@@ -131,7 +131,17 @@ class Puppet::Node::Facts
131
131
  or fact.is_a? String
132
132
  fact
133
133
  else
134
- fact.to_s
134
+ result = fact.to_s
135
+ # The result may be ascii-8bit encoded without being a binary (low level object.inspect returns ascii-8bit string)
136
+ if result.encoding == Encoding::ASCII_8BIT
137
+ begin
138
+ result = result.encode(Encoding::UTF_8)
139
+ rescue
140
+ # return the ascii-8bit - it will be taken as a binary
141
+ result
142
+ end
143
+ end
144
+ result
135
145
  end
136
146
  end
137
147
  end
@@ -0,0 +1,56 @@
1
+ require 'puppet/loaders'
2
+ require 'puppet/pops'
3
+
4
+ # A Catalog "compiler" that is like the regular compiler but with an API
5
+ # that is harmonized with the ScriptCompiler
6
+ #
7
+ # The Script compiler is "one shot" - it does not support rechecking if underlying source has changed or
8
+ # deal with possible errors in a cached environment.
9
+ #
10
+ class Puppet::Parser::CatalogCompiler < Puppet::Parser::Compiler
11
+
12
+ # Evaluates the configured setup for a script + code in an environment with modules
13
+ #
14
+ def compile
15
+ Puppet[:strict_variables] = true
16
+ Puppet[:strict] = :error
17
+
18
+ Puppet.override(rich_data: true) do
19
+ super
20
+ end
21
+
22
+ rescue Puppet::ParseErrorWithIssue => detail
23
+ detail.node = node.name
24
+ Puppet.log_exception(detail)
25
+ raise
26
+ rescue => detail
27
+ message = "#{detail} on node #{node.name}"
28
+ Puppet.log_exception(detail, message)
29
+ raise Puppet::Error, message, detail.backtrace
30
+ end
31
+
32
+ # Evaluates all added constructs, and validates the resulting catalog.
33
+ # This can be called whenever a series of evaluation of puppet code strings
34
+ # have reached a stable state (essentially that there are no relationships to
35
+ # non-existing resources).
36
+ #
37
+ # Raises an error if validation fails.
38
+ #
39
+ def compile_additions
40
+ evaluate_additions
41
+ validate
42
+ end
43
+
44
+ # Evaluates added constructs that are lazily evaluated until all of them have been evaluated.
45
+ #
46
+ def evaluate_additions
47
+ evaluate_generators
48
+ finish
49
+ end
50
+
51
+ # Validates the current state of the catalog.
52
+ # Does not cause evaluation of lazy constructs.
53
+ def validate
54
+ validate_catalog(CatalogValidator::FINAL)
55
+ end
56
+ end
@@ -577,6 +577,7 @@ class Puppet::Parser::Compiler
577
577
  end
578
578
  end
579
579
  end
580
+ protected :evaluate_generators
580
581
 
581
582
  # Find and evaluate our main object, if possible.
582
583
  def evaluate_main
@@ -641,6 +642,7 @@ class Puppet::Parser::Compiler
641
642
 
642
643
  add_resource_metaparams
643
644
  end
645
+ protected :finish
644
646
 
645
647
  def add_resource_metaparams
646
648
  unless main = catalog.resource(:class, :main)
@@ -780,8 +782,8 @@ class Puppet::Parser::Compiler
780
782
  settings_resource = Puppet::Parser::Resource.new('class', SETTINGS, :scope => @topscope)
781
783
 
782
784
  @catalog.add_resource(settings_resource)
783
-
784
785
  settings_type.evaluate_code(settings_resource)
786
+ settings_resource.instance_variable_set(:@evaluated, true) # Prevents settings from being reevaluated
785
787
 
786
788
  scope = @topscope.class_scope(settings_type)
787
789
  scope.merge_settings(environment.name)
@@ -203,7 +203,9 @@ module Puppet::Parser::Functions
203
203
  elsif arity < 0 and args[0].size < (arity+1).abs
204
204
  raise ArgumentError, _("%{name}(): Wrong number of arguments given (%{arg_count} for minimum %{min_arg_count})") % { name: name, arg_count: args[0].size, min_arg_count: (arity+1).abs }
205
205
  end
206
- self.send(real_fname, args[0])
206
+ r = Puppet::Pops::Evaluator::Runtime3FunctionArgumentConverter.convert_return(self.send(real_fname, args[0]))
207
+ # avoid leaking aribtrary value if not being an rvalue function
208
+ options[:type] == :rvalue ? r : nil
207
209
  else
208
210
  raise ArgumentError, _("custom functions must be called with a single array that contains the arguments. For example, function_example([1]) instead of function_example(1)")
209
211
  end
@@ -5,7 +5,7 @@ Puppet::Parser::Functions::newfunction(
5
5
  :doc => <<-DOC
6
6
  Applies a [lambda](https://puppet.com/docs/puppet/latest/lang_lambdas.html)
7
7
  to every value in a data structure and returns an array or hash containing any elements
8
- for which the lambda evaluates to `true`.
8
+ for which the lambda evaluates to a truthy value (not `false` or `undef`).
9
9
 
10
10
  This function takes two mandatory arguments, in this order:
11
11
 
@@ -14,7 +14,7 @@ Puppet::Parser::Functions::newfunction(:generate, :arity => -2, :type => :rvalue
14
14
  #TRANSLATORS "fully qualified" refers to a fully qualified file system path
15
15
  raise Puppet::ParseError, _("Generators must be fully qualified") unless Puppet::Util.absolute_path?(args[0])
16
16
 
17
- if Puppet.features.microsoft_windows?
17
+ if Puppet::Util::Platform.windows?
18
18
  valid = args[0] =~ /^[a-z]:(?:[\/\\][-.~\w]+)+$/i
19
19
  else
20
20
  valid = args[0] =~ /^[-\/\w.+]+$/
@@ -30,7 +30,18 @@ Puppet::Parser::Functions::newfunction(
30
30
  :doc => "Perform printf-style formatting of text.
31
31
 
32
32
  The first parameter is format string describing how the rest of the parameters should be formatted.
33
- See the documentation for the `Kernel::sprintf` function in Ruby for all the details."
33
+ See the documentation for the [`Kernel::sprintf` function](https://ruby-doc.org/core/Kernel.html)
34
+ in Ruby for details.
35
+
36
+ To use [named format](https://idiosyncratic-ruby.com/49-what-the-format.html) arguments, provide a
37
+ hash containing the target string values as the argument to be formatted. For example:
38
+
39
+ ```puppet
40
+ notice sprintf(\"%<x>s : %<y>d\", { 'x' => 'value is', 'y' => 42 })
41
+ ```
42
+
43
+ This statement produces a notice of `value is : 42`."
44
+
34
45
  ) do |args|
35
46
  fmt = args[0]
36
47
  args = args[1..-1]
@@ -9,12 +9,9 @@ Puppet::Parser::Functions::newfunction(:tagged, :type => :rvalue, :arity => -2,
9
9
  {:operation => 'tagged'})
10
10
  end
11
11
 
12
- configtags = compiler.catalog.tags
13
- resourcetags = resource.tags
14
-
15
12
  retval = true
16
13
  vals.each do |val|
17
- unless configtags.include?(val) or resourcetags.include?(val)
14
+ unless compiler.catalog.tagged?(val) or resource.tagged?(val)
18
15
  retval = false
19
16
  break
20
17
  end
@@ -814,7 +814,7 @@ class Puppet::Parser::Scope
814
814
  end
815
815
 
816
816
  # Deeply freezes the given object. The object and its content must be of the types:
817
- # Array, Hash, Numeric, Boolean, Symbol, Regexp, NilClass, or String. All other types raises an Error.
817
+ # Array, Hash, Numeric, Boolean, Regexp, NilClass, or String. All other types raises an Error.
818
818
  # (i.e. if they are assignable to Puppet::Pops::Types::Data type).
819
819
  #
820
820
  def deep_freeze(object)
@@ -66,13 +66,14 @@ class Puppet::Parser::ScriptCompiler
66
66
  :current_environment => environment,
67
67
  :global_scope => @topscope, # 4x placeholder for new global scope
68
68
  :loaders => @loaders, # 4x loaders
69
+ :rich_data => true,
69
70
  }
70
71
  end
71
72
 
72
73
  # Create a script compiler for the given environment where errors are logged as coming
73
74
  # from the given node_name
74
75
  #
75
- def initialize(environment, node_name)
76
+ def initialize(environment, node_name, for_agent=false)
76
77
  @environment = environment
77
78
  @node_name = node_name
78
79
 
@@ -80,7 +81,11 @@ class Puppet::Parser::ScriptCompiler
80
81
  @topscope = Puppet::Parser::Scope.new(self)
81
82
 
82
83
  # Initialize loaders and Pcore
83
- @loaders = Puppet::Pops::Loaders.new(environment)
84
+ if for_agent
85
+ @loaders = Puppet::Pops::Loaders.new(environment, true)
86
+ else
87
+ @loaders = Puppet::Pops::Loaders.new(environment)
88
+ end
84
89
 
85
90
  # Need to compute overrides here, and remember them, because we are about to
86
91
  # Expensive entries in the context are bound lazily.
@@ -14,13 +14,12 @@ class DeferredResolver
14
14
  # Deferred values inside of custom Object instances are not resolved as this
15
15
  # is expected to be done by such objects.
16
16
  #
17
- # @param node [Puppet::Node] the node for the catalog
18
17
  # @param facts [Puppet::Node::Facts] the facts object for the node
19
18
  # @param catalog [Puppet::Resource::Catalog] the catalog where all deferred values should be replaced
20
19
  # @return [nil] does not return anything - the catalog is modified as a side effect
21
20
  #
22
- def self.resolve_and_replace(node, facts, catalog)
23
- compiler = Puppet::Parser::ScriptCompiler.new(node.environment, node.name)
21
+ def self.resolve_and_replace(facts, catalog)
22
+ compiler = Puppet::Parser::ScriptCompiler.new(catalog.environment_instance, catalog.name, true)
24
23
  resolver = new(compiler)
25
24
  resolver.set_facts_variable(facts)
26
25
  # TODO:
@@ -97,6 +96,9 @@ class DeferredResolver
97
96
  elsif x.is_a?(Puppet::Pops::Types::PSensitiveType::Sensitive)
98
97
  # rewrap in a new Sensitive after resolving any nested deferred values
99
98
  Puppet::Pops::Types::PSensitiveType::Sensitive.new(resolve(x.unwrap))
99
+ elsif x.is_a?(Puppet::Pops::Types::PBinaryType::Binary)
100
+ # use the ASCII-8BIT string that it wraps
101
+ x.binary_buffer
100
102
  else
101
103
  x
102
104
  end
@@ -61,7 +61,7 @@ class Runtime3Converter
61
61
  end
62
62
 
63
63
  def convert_NilClass(o, scope, undef_value)
64
- @inner ? :undef : undef_value
64
+ @inner ? nil : undef_value
65
65
  end
66
66
 
67
67
  def convert_Integer(o, scope, undef_value)
@@ -78,8 +78,10 @@ class Runtime3Converter
78
78
  end
79
79
 
80
80
  def convert_String(o, scope, undef_value)
81
- # although wasteful, needed because user code may mutate these strings in Resources
82
- o.frozen? ? o.dup : o
81
+ # Although wasteful, a dup is needed because user code may mutate these strings when applying
82
+ # Resources. This does not happen when in master mode since it only uses Resources that are
83
+ # in puppet core and those are all safe.
84
+ o.frozen? && !Puppet.run_mode.master? ? o.dup : o
83
85
  end
84
86
 
85
87
  def convert_Object(o, scope, undef_value)
@@ -103,7 +105,8 @@ class Runtime3Converter
103
105
  end
104
106
 
105
107
  def convert_Symbol(o, scope, undef_value)
106
- o == :undef && !@inner ? undef_value : o
108
+ o == :undef ? undef_value : o
109
+ #o == :undef && !@inner ? undef_value : o
107
110
  end
108
111
 
109
112
  def convert_PAnyType(o, scope, undef_value)
@@ -196,6 +199,22 @@ class Runtime3FunctionArgumentConverter < Runtime3Converter
196
199
  o.to_s
197
200
  end
198
201
 
202
+ # Converts result back to 4.x by replacing :undef with nil in Array and Hash objects
203
+ #
204
+ def self.convert_return(val3x)
205
+ if val3x == :undef
206
+ nil
207
+ elsif val3x.is_a?(Array)
208
+ val3x.map {|v| convert_return(v) }
209
+ elsif val3x.is_a?(Hash)
210
+ hsh = {}
211
+ val3x.each_pair {|k,v| hsh[convert_return(k)] = convert_return(v)}
212
+ hsh
213
+ else
214
+ val3x
215
+ end
216
+ end
217
+
199
218
  @instance = self.new
200
219
  end
201
220