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
@@ -405,7 +405,7 @@ Puppet::Face.define(:epp, '0.0.1') do
405
405
  if values_file = options[:values_file]
406
406
  begin
407
407
  if values_file =~ /\.yaml$/
408
- template_values = YAML.load_file(values_file)
408
+ template_values = Puppet::Util::Yaml.safe_load_file(values_file, [Symbol])
409
409
  elsif values_file =~ /\.pp$/
410
410
  evaluating_parser = Puppet::Pops::Parser::EvaluatingParser.new
411
411
  template_values = evaluating_parser.evaluate_file(compiler.topscope, values_file)
@@ -511,7 +511,7 @@ Puppet::Face.define(:epp, '0.0.1') do
511
511
  elsif fact_file.end_with?("json")
512
512
  given_facts = Puppet::Util::Json.load(Puppet::FileSystem.read(fact_file, :encoding => 'utf-8'))
513
513
  else
514
- given_facts = YAML.load(Puppet::FileSystem.read(fact_file, :encoding => 'utf-8'))
514
+ given_facts = Puppet::Util::Yaml.safe_load_file(fact_file)
515
515
  end
516
516
 
517
517
  unless given_facts.instance_of?(Hash)
@@ -132,19 +132,21 @@ Puppet::Face.define(:help, '0.0.1') do
132
132
  # element in the outer array is a pair whose first element is a String containing the application
133
133
  # name, and whose second element is a String containing the summary for that application.
134
134
  def all_application_summaries()
135
- Puppet::Application.available_application_names.sort.inject([]) do |result, appname|
135
+ available_application_names_special_sort().inject([]) do |result, appname|
136
136
  next result if exclude_from_docs?(appname)
137
137
 
138
- if (is_face_app?(appname))
138
+ if (appname == COMMON || appname == SPECIALIZED || appname == BLANK)
139
+ result << appname
140
+ elsif (is_face_app?(appname))
139
141
  begin
140
142
  face = Puppet::Face[appname, :current]
141
143
  # Add deprecation message to summary if the face is deprecated
142
144
  summary = face.deprecated? ? face.summary + ' ' + _("(Deprecated)") : face.summary
143
- result << [appname, summary]
145
+ result << [appname, summary, ' ']
144
146
  rescue StandardError, LoadError
145
147
  error_message = _("!%{sub_command}! Subcommand unavailable due to error.") % { sub_command: appname }
146
148
  error_message += ' ' + _("Check error logs.")
147
- result << [ error_message ]
149
+ result << [ error_message, '', ' ' ]
148
150
  end
149
151
  else
150
152
  begin
@@ -152,16 +154,28 @@ Puppet::Face.define(:help, '0.0.1') do
152
154
  if summary.empty?
153
155
  summary = horribly_extract_summary_from(appname)
154
156
  end
155
- result << [appname, summary]
157
+ result << [appname, summary, ' ']
156
158
  rescue StandardError, LoadError
157
159
  error_message = _("!%{sub_command}! Subcommand unavailable due to error.") % { sub_command: appname }
158
160
  error_message += ' ' + _("Check error logs.")
159
- result << [ error_message ]
161
+ result << [ error_message, '', ' ' ]
160
162
  end
161
163
  end
162
164
  end
163
165
  end
164
166
 
167
+ COMMON = 'Common:'.freeze
168
+ SPECIALIZED = 'Specialized:'.freeze
169
+ BLANK = "\n".freeze
170
+ def available_application_names_special_sort()
171
+ full_list = Puppet::Application.available_application_names
172
+ a_list = full_list & %w{apply agent config help lookup module resource}
173
+ a_list = a_list.sort
174
+ also_ran = full_list - a_list
175
+ also_ran = also_ran.sort
176
+ [[COMMON], a_list, [BLANK], [SPECIALIZED], also_ran].flatten(1)
177
+ end
178
+
165
179
  def horribly_extract_summary_from(appname)
166
180
  help = Puppet::Application[appname].help.split("\n")
167
181
  # Now we find the line with our summary, extract it, and return it. This
@@ -181,7 +195,7 @@ Puppet::Face.define(:help, '0.0.1') do
181
195
  #private :horribly_extract_summary_from
182
196
 
183
197
  def exclude_from_docs?(appname)
184
- %w{face_base indirection_base}.include? appname
198
+ %w{face_base indirection_base cert key man plugin report status}.include? appname
185
199
  end
186
200
  # This should absolutely be a private method, but for some reason it appears
187
201
  # that you can't use the 'private' keyword inside of a Face definition.
@@ -14,6 +14,7 @@ Puppet::Face.define(:node, '0.0.1') do
14
14
 
15
15
  <Reports> - ($vardir/reports/node.domain)
16
16
 
17
+ NOTE: this action now cleans up certs via Puppet Server's CA API. A running server is required for certs to be cleaned.
17
18
  EOT
18
19
 
19
20
  when_invoked do |*args|
@@ -29,12 +30,6 @@ Puppet::Face.define(:node, '0.0.1') do
29
30
  # certificates correctly.
30
31
  Puppet.settings.preferred_run_mode = "master"
31
32
 
32
- if Puppet::SSL::CertificateAuthority.ca?
33
- Puppet::SSL::Host.ca_location = :local
34
- else
35
- Puppet::SSL::Host.ca_location = :none
36
- end
37
-
38
33
  Puppet::Node::Facts.indirection.terminus_class = :yaml
39
34
  Puppet::Node::Facts.indirection.cache_class = :yaml
40
35
  Puppet::Node.indirection.terminus_class = :yaml
@@ -51,12 +46,21 @@ Puppet::Face.define(:node, '0.0.1') do
51
46
  clean_reports(node)
52
47
  end
53
48
 
49
+ class LoggerIO
50
+ def err(message)
51
+ Puppet.err(message) unless message =~ /^\s*Error:\s*/
52
+ end
53
+
54
+ def inform(message)
55
+ Puppet.notice(message)
56
+ end
57
+ end
58
+
54
59
  # clean signed cert for +host+
55
60
  def clean_cert(node)
56
- if Puppet::SSL::CertificateAuthority.ca?
57
- Puppet::Face[:ca, :current].revoke(node)
58
- Puppet::Face[:ca, :current].destroy(node)
59
- Puppet.info _("%{node} certificates removed from ca") % { node: node }
61
+ if Puppet.features.puppetserver_ca?
62
+ require 'puppetserver/ca/action/clean'
63
+ Puppetserver::Ca::Action::Clean.new(LoggerIO.new).run({ 'certnames' => [node] })
60
64
  else
61
65
  Puppet.info _("Not managing %{node} certs as this host is not a CA") % { node: node }
62
66
  end
@@ -14,28 +14,7 @@ Puppet.features.add(:posix) do
14
14
  end
15
15
 
16
16
  # We can use Microsoft Windows functions
17
- Puppet.features.add(:microsoft_windows) do
18
- begin
19
- # ruby
20
- require 'Win32API' # case matters in this require!
21
-
22
- # Note: Setting codepage here globally ensures all strings returned via
23
- # WIN32OLE (Ruby's late-bound COM support) are encoded in Encoding::UTF_8
24
- #
25
- # Also, this does not modify the value of WIN32OLE.locale - which defaults
26
- # to 2048 (at least on US English Windows) and is not listed in the MS
27
- # locales table, here: https://msdn.microsoft.com/en-us/library/ms912047(v=winembedded.10).aspx
28
- require 'win32ole' ; WIN32OLE.codepage = WIN32OLE::CP_UTF8
29
- # gems
30
- require 'win32/process'
31
- require 'win32/dir'
32
- require 'win32/service'
33
- true
34
- rescue LoadError => err
35
- #TRANSLATORS "win32-process", "win32-dir", and "win32-service" are program names and should not be translated
36
- warn _("Cannot run on Microsoft Windows without the win32-process, win32-dir and win32-service gems: %{err}") % { err: err } unless Puppet.features.posix?
37
- end
38
- end
17
+ Puppet.features.add(:microsoft_windows) { Puppet::Util::Platform.windows? }
39
18
 
40
19
  raise Puppet::Error,_("Cannot determine basic system flavour") unless Puppet.features.posix? or Puppet.features.microsoft_windows?
41
20
 
@@ -49,7 +28,10 @@ Puppet.features.add(:usage, :libs => %w{rdoc/ri/ri_paths rdoc/usage})
49
28
  Puppet.features.add(:libshadow, :libs => ["shadow"])
50
29
 
51
30
  # We're running as root.
52
- Puppet.features.add(:root) { require 'puppet/util/suidmanager'; Puppet::Util::SUIDManager.root? }
31
+ Puppet.features.add(:root) do
32
+ require 'puppet/util/suidmanager'
33
+ Puppet::Util::SUIDManager.root?
34
+ end
53
35
 
54
36
  # We have lcs diff
55
37
  Puppet.features.add :diff, :libs => %w{diff/lcs diff/lcs/hunk}
@@ -90,3 +72,5 @@ Puppet.features.add(:manages_symlinks) do
90
72
  WindowsSymlink.is_implemented
91
73
  end
92
74
  end
75
+
76
+ Puppet.features.add(:puppetserver_ca, libs: ['puppetserver/ca'])
@@ -1,5 +1,5 @@
1
1
  require 'puppet/util/feature'
2
2
 
3
- if Puppet.features.microsoft_windows?
3
+ if Puppet::Util::Platform.windows?
4
4
  Puppet.features.add(:eventlog)
5
5
  end
@@ -24,7 +24,7 @@ class Puppet::FileServing::Base
24
24
  full_path = File.join(path, relative_path)
25
25
  end
26
26
 
27
- if Puppet.features.microsoft_windows?
27
+ if Puppet::Util::Platform.windows?
28
28
  # Replace multiple slashes as long as they aren't at the beginning of a filename
29
29
  full_path.gsub(%r{(./)/+}, '\1')
30
30
  else
@@ -81,6 +81,6 @@ class Puppet::FileServing::Base
81
81
  end
82
82
 
83
83
  def self.absolute?(path)
84
- Puppet::Util.absolute_path?(path, :posix) or (Puppet.features.microsoft_windows? and Puppet::Util.absolute_path?(path, :windows))
84
+ Puppet::Util.absolute_path?(path, :posix) || (Puppet::Util::Platform.windows? && Puppet::Util.absolute_path?(path, :windows))
85
85
  end
86
86
  end
@@ -25,7 +25,7 @@ class Puppet::FileServing::Fileset
25
25
  end
26
26
 
27
27
  def initialize(path, options = {})
28
- if Puppet.features.microsoft_windows?
28
+ if Puppet::Util::Platform.windows?
29
29
  # REMIND: UNC path
30
30
  path = path.chomp(File::SEPARATOR) unless path =~ /^[A-Za-z]:\/$/
31
31
  else
@@ -65,7 +65,7 @@ class Puppet::FileServing::Metadata < Puppet::FileServing::Base
65
65
  end
66
66
 
67
67
  class WindowsStat < MetaStat
68
- if Puppet.features.microsoft_windows?
68
+ if Puppet::Util::Platform.windows?
69
69
  require 'puppet/util/windows/security'
70
70
  end
71
71
 
@@ -88,7 +88,7 @@ class Puppet::FileServing::Metadata < Puppet::FileServing::Base
88
88
  def collect_stat(path)
89
89
  stat = stat()
90
90
 
91
- if Puppet.features.microsoft_windows?
91
+ if Puppet::Util::Platform.windows?
92
92
  WindowsStat.new(stat, path, @source_permissions)
93
93
  else
94
94
  MetaStat.new(stat, @source_permissions)
@@ -385,6 +385,7 @@ module Puppet::Functions
385
385
  end
386
386
  end
387
387
 
388
+
388
389
  # Public api methods of the DispatcherBuilder are available within dispatch()
389
390
  # blocks declared in a Puppet::Function.create_function() call.
390
391
  #
@@ -679,6 +680,128 @@ module Puppet::Functions
679
680
  end
680
681
  end
681
682
 
683
+ class Function3x < InternalFunction
684
+
685
+ # Table of optimized parameter names - 0 to 5 parameters
686
+ PARAM_NAMES = [
687
+ [],
688
+ ['p0'.freeze].freeze,
689
+ ['p0'.freeze, 'p1'.freeze].freeze,
690
+ ['p0'.freeze, 'p1'.freeze, 'p2'.freeze].freeze,
691
+ ['p0'.freeze, 'p1'.freeze, 'p2'.freeze, 'p3'.freeze].freeze,
692
+ ['p0'.freeze, 'p1'.freeze, 'p2'.freeze, 'p3'.freeze, 'p4'.freeze].freeze,
693
+ ]
694
+
695
+ # Creates an anonymous Function3x class that wraps a 3x function
696
+ #
697
+ # @api private
698
+ def self.create_function(func_name, func_info, loader)
699
+ func_name = func_name.to_s
700
+
701
+ # Creates an anonymous class to represent the function
702
+ # The idea being that it is garbage collected when there are no more
703
+ # references to it.
704
+ #
705
+ # (Do not give the class the block here, as instance variables should be set first)
706
+ the_class = Class.new(Function3x)
707
+
708
+ unless loader.nil?
709
+ the_class.instance_variable_set(:'@loader', loader.private_loader)
710
+ end
711
+
712
+ the_class.instance_variable_set(:'@func_name', func_name)
713
+ the_class.instance_variable_set(:'@method3x', :"function_#{func_name}")
714
+
715
+ # Make the anonymous class appear to have the class-name <func_name>
716
+ # Even if this class is not bound to such a symbol in a global ruby scope and
717
+ # must be resolved via the loader.
718
+ # This also overrides any attempt to define a name method in the given block
719
+ # (Since it redefines it)
720
+ #
721
+ the_class.instance_eval do
722
+ def name
723
+ @func_name
724
+ end
725
+
726
+ def loader
727
+ @loader
728
+ end
729
+
730
+ def method3x
731
+ @method3x
732
+ end
733
+ end
734
+
735
+ # Add the method that is called - it simply delegates to
736
+ # the 3.x function by calling it via the calling scope using the @method3x symbol
737
+ # :"function_#{name}".
738
+ #
739
+ # When function is not an rvalue function, make sure it produces nil
740
+ #
741
+ the_class.class_eval do
742
+
743
+ # Bypasses making the call via the dispatcher to make sure errors
744
+ # are reported exactly the same way as in 3x. The dispatcher is still needed as it is
745
+ # used to support other features than calling.
746
+ #
747
+ def call(scope, *args, &block)
748
+ begin
749
+ result = catch(:return) do
750
+ mapped_args = Puppet::Pops::Evaluator::Runtime3FunctionArgumentConverter.map_args(args, scope, '')
751
+ # this is the scope.function_xxx(...) call
752
+ return scope.send(self.class.method3x, mapped_args)
753
+ end
754
+ return result.value
755
+ rescue Puppet::Pops::Evaluator::Next => jumper
756
+ begin
757
+ throw :next, jumper.value
758
+ rescue Puppet::Parser::Scope::UNCAUGHT_THROW_EXCEPTION
759
+ raise Puppet::ParseError.new("next() from context where this is illegal", jumper.file, jumper.line)
760
+ end
761
+ rescue Puppet::Pops::Evaluator::Return => jumper
762
+ begin
763
+ throw :return, jumper
764
+ rescue Puppet::Parser::Scope::UNCAUGHT_THROW_EXCEPTION
765
+ raise Puppet::ParseError.new("return() from context where this is illegal", jumper.file, jumper.line)
766
+ end
767
+ end
768
+ end
769
+ end
770
+
771
+ # Create a dispatcher based on func_info
772
+ type, names = Puppet::Functions.any_signature(*from_to_names(func_info))
773
+ last_captures_rest = (type.size_range[1] == Float::INFINITY)
774
+
775
+ # The method '3x_function' here is a dummy as the dispatcher is not used for calling, only for information.
776
+ the_class.dispatcher.add(Puppet::Pops::Functions::Dispatch.new(type, '3x_function', names, last_captures_rest))
777
+ # The function class is returned as the result of the create function method
778
+ the_class
779
+ end
780
+
781
+ # Compute min and max number of arguments and a list of constructed
782
+ # parameter names p0 - pn (since there are no parameter names in 3x functions).
783
+ #
784
+ # @api private
785
+ def self.from_to_names(func_info)
786
+ arity = func_info[:arity]
787
+ if arity.nil?
788
+ arity = -1
789
+ end
790
+ if arity < 0
791
+ from = -arity - 1 # arity -1 is 0 min param, -2 is min 1 param
792
+ to = :default # infinite range
793
+ count = -arity # the number of named parameters
794
+ else
795
+ count = from = to = arity
796
+ end
797
+ # Names of parameters, up to 5 are optimized and use frozen version
798
+ # Note that (0..count-1) produces expected empty array for count == 0, 0-n for count >= 1
799
+ names = count <= 5 ? PARAM_NAMES[count] : (0..count-1).map {|n| "p#{n}" }
800
+ [from, to, names]
801
+ end
802
+ end
803
+
804
+
682
805
  # Injection and Weaving of parameters
683
806
  # ---
684
807
  # It is possible to inject and weave a set of well known parameters into a call.
@@ -719,6 +842,16 @@ module Puppet::Functions
719
842
  inject(:cache)
720
843
  end
721
844
 
845
+ # Inject parameter for `Puppet::Pal::CatalogCompiler`
846
+ def compiler_param
847
+ inject(:pal_catalog_compiler)
848
+ end
849
+
850
+ # Inject parameter for either `Puppet::Pal::CatalogCompiler` or `Puppet::Pal::ScriptCompiler`
851
+ def pal_compiler_param
852
+ inject(:pal_compiler)
853
+ end
854
+
722
855
  private
723
856
 
724
857
  def inject(injection_name)
@@ -46,7 +46,7 @@ Puppet::Functions.create_function(:eyaml_lookup_key) do
46
46
  path = options['path']
47
47
  context.cached_file_data(path) do |content|
48
48
  begin
49
- data = YAML.load(content, path)
49
+ data = Puppet::Util::Yaml.safe_load(content, [Symbol], path)
50
50
  if data.is_a?(Hash)
51
51
  Puppet::Pops::Lookup::HieraConfig.symkeys_to_string(data)
52
52
  else
@@ -55,10 +55,9 @@ Puppet::Functions.create_function(:eyaml_lookup_key) do
55
55
  Puppet.warning(msg)
56
56
  {}
57
57
  end
58
- rescue YAML::SyntaxError => ex
59
- # Psych errors includes the absolute path to the file, so no need to add that
60
- # to the message
61
- raise Puppet::DataBinding::LookupError, "Unable to parse #{ex.message}"
58
+ rescue Puppet::Util::Yaml::YamlLoadError => ex
59
+ # YamlLoadErrors include the absolute path to the file, so no need to add that
60
+ raise Puppet::DataBinding::LookupError, _("Unable to parse %{message}") % { message: ex.message }
62
61
  end
63
62
  end
64
63
  end
@@ -1,6 +1,6 @@
1
1
  # Applies a [lambda](https://puppet.com/docs/puppet/latest/lang_lambdas.html)
2
2
  # to every value in a data structure and returns an array or hash containing any elements
3
- # for which the lambda evaluates to `true`.
3
+ # for which the lambda evaluates to a truthy value (not `false` or `undef`).
4
4
  #
5
5
  # This function takes two mandatory arguments, in this order:
6
6
  #
@@ -67,6 +67,7 @@
67
67
  # ```
68
68
  #
69
69
  # @since 4.0.0
70
+ # @since 6.0.0 does not filter if truthy value is returned from block
70
71
  #
71
72
  Puppet::Functions.create_function(:filter) do
72
73
  dispatch :filter_Hash_2 do
@@ -90,14 +91,14 @@ Puppet::Functions.create_function(:filter) do
90
91
  end
91
92
 
92
93
  def filter_Hash_1(hash)
93
- result = hash.select {|x, y| yield([x, y]) == true }
94
+ result = hash.select {|x, y| yield([x, y]) }
94
95
  # Ruby 1.8.7 returns Array
95
96
  result = Hash[result] unless result.is_a? Hash
96
97
  result
97
98
  end
98
99
 
99
100
  def filter_Hash_2(hash)
100
- result = hash.select {|x, y| yield(x, y) == true }
101
+ result = hash.select {|x, y| yield(x, y) }
101
102
  # Ruby 1.8.7 returns Array
102
103
  result = Hash[result] unless result.is_a? Hash
103
104
  result
@@ -109,7 +110,7 @@ Puppet::Functions.create_function(:filter) do
109
110
  begin
110
111
  loop do
111
112
  it = enum.next
112
- if yield(it) == true
113
+ if yield(it)
113
114
  result << it
114
115
  end
115
116
  end
@@ -122,7 +123,7 @@ Puppet::Functions.create_function(:filter) do
122
123
  enum = Puppet::Pops::Types::Iterable.asserted_iterable(self, enumerable)
123
124
  if enum.hash_style?
124
125
  result = {}
125
- enum.each { |k, v| result[k] = v if yield(k, v) == true }
126
+ enum.each { |k, v| result[k] = v if yield(k, v) }
126
127
  result
127
128
  else
128
129
  result = []
@@ -130,7 +131,7 @@ Puppet::Functions.create_function(:filter) do
130
131
  index = 0
131
132
  loop do
132
133
  it = enum.next
133
- if yield(index, it) == true
134
+ if yield(index, it)
134
135
  result << it
135
136
  end
136
137
  index += 1