bolt 0.20.3 → 0.20.5

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 (256) hide show
  1. checksums.yaml +4 -4
  2. data/bolt-modules/boltlib/lib/puppet/functions/run_task.rb +3 -3
  3. data/bolt-modules/boltlib/lib/puppet/functions/set_feature.rb +33 -0
  4. data/lib/bolt/inventory.rb +19 -1
  5. data/lib/bolt/target.rb +15 -0
  6. data/lib/bolt/transport/local.rb +6 -1
  7. data/lib/bolt/transport/orch.rb +2 -0
  8. data/lib/bolt/transport/ssh.rb +7 -2
  9. data/lib/bolt/transport/winrm.rb +6 -1
  10. data/lib/bolt/version.rb +1 -1
  11. data/modules/facts/plans/retrieve.pp +2 -26
  12. data/modules/facts/tasks/init.json +9 -0
  13. data/vendored/puppet/lib/hiera/puppet_function.rb +1 -1
  14. data/vendored/puppet/lib/hiera/scope.rb +24 -2
  15. data/vendored/puppet/lib/puppet.rb +4 -13
  16. data/vendored/puppet/lib/puppet/application.rb +2 -2
  17. data/vendored/puppet/lib/puppet/application/agent.rb +1 -1
  18. data/vendored/puppet/lib/puppet/application/apply.rb +1 -1
  19. data/vendored/puppet/lib/puppet/application/cert.rb +1 -1
  20. data/vendored/puppet/lib/puppet/application/device.rb +8 -8
  21. data/vendored/puppet/lib/puppet/application/face_base.rb +1 -1
  22. data/vendored/puppet/lib/puppet/application/lookup.rb +2 -2
  23. data/vendored/puppet/lib/puppet/application/resource.rb +2 -2
  24. data/vendored/puppet/lib/puppet/application/script.rb +1 -1
  25. data/vendored/puppet/lib/puppet/configurer.rb +47 -24
  26. data/vendored/puppet/lib/puppet/confine.rb +4 -1
  27. data/vendored/puppet/lib/puppet/context.rb +1 -1
  28. data/vendored/puppet/lib/puppet/defaults.rb +32 -44
  29. data/vendored/puppet/lib/puppet/error.rb +14 -7
  30. data/vendored/puppet/lib/puppet/external/dot.rb +23 -17
  31. data/vendored/puppet/lib/puppet/face/config.rb +58 -3
  32. data/vendored/puppet/lib/puppet/face/epp.rb +1 -1
  33. data/vendored/puppet/lib/puppet/face/module/build.rb +3 -3
  34. data/vendored/puppet/lib/puppet/face/module/install.rb +0 -4
  35. data/vendored/puppet/lib/puppet/face/module/list.rb +0 -5
  36. data/vendored/puppet/lib/puppet/face/module/search.rb +1 -1
  37. data/vendored/puppet/lib/puppet/face/module/uninstall.rb +0 -4
  38. data/vendored/puppet/lib/puppet/face/module/upgrade.rb +0 -4
  39. data/vendored/puppet/lib/puppet/face/status.rb +2 -2
  40. data/vendored/puppet/lib/puppet/file_serving/base.rb +5 -5
  41. data/vendored/puppet/lib/puppet/file_serving/metadata.rb +2 -1
  42. data/vendored/puppet/lib/puppet/forge.rb +7 -8
  43. data/vendored/puppet/lib/puppet/forge/errors.rb +3 -3
  44. data/vendored/puppet/lib/puppet/functions/abs.rb +61 -0
  45. data/vendored/puppet/lib/puppet/functions/all.rb +2 -2
  46. data/vendored/puppet/lib/puppet/functions/any.rb +2 -2
  47. data/vendored/puppet/lib/puppet/functions/assert_type.rb +3 -3
  48. data/vendored/puppet/lib/puppet/functions/break.rb +3 -7
  49. data/vendored/puppet/lib/puppet/functions/camelcase.rb +62 -0
  50. data/vendored/puppet/lib/puppet/functions/capitalize.rb +61 -0
  51. data/vendored/puppet/lib/puppet/functions/ceiling.rb +37 -0
  52. data/vendored/puppet/lib/puppet/functions/chomp.rb +57 -0
  53. data/vendored/puppet/lib/puppet/functions/chop.rb +67 -0
  54. data/vendored/puppet/lib/puppet/functions/compare.rb +125 -0
  55. data/vendored/puppet/lib/puppet/functions/convert_to.rb +3 -2
  56. data/vendored/puppet/lib/puppet/functions/dig.rb +21 -1
  57. data/vendored/puppet/lib/puppet/functions/downcase.rb +89 -0
  58. data/vendored/puppet/lib/puppet/functions/each.rb +2 -2
  59. data/vendored/puppet/lib/puppet/functions/empty.rb +1 -3
  60. data/vendored/puppet/lib/puppet/functions/eyaml_lookup_key.rb +4 -2
  61. data/vendored/puppet/lib/puppet/functions/filter.rb +2 -2
  62. data/vendored/puppet/lib/puppet/functions/floor.rb +37 -0
  63. data/vendored/puppet/lib/puppet/functions/get.rb +150 -0
  64. data/vendored/puppet/lib/puppet/functions/getvar.rb +87 -0
  65. data/vendored/puppet/lib/puppet/functions/hiera.rb +5 -5
  66. data/vendored/puppet/lib/puppet/functions/hiera_array.rb +5 -5
  67. data/vendored/puppet/lib/puppet/functions/hiera_hash.rb +6 -6
  68. data/vendored/puppet/lib/puppet/functions/hiera_include.rb +7 -7
  69. data/vendored/puppet/lib/puppet/functions/hocon_data.rb +1 -1
  70. data/vendored/puppet/lib/puppet/functions/json_data.rb +3 -3
  71. data/vendored/puppet/lib/puppet/functions/lest.rb +1 -1
  72. data/vendored/puppet/lib/puppet/functions/lookup.rb +3 -2
  73. data/vendored/puppet/lib/puppet/functions/lstrip.rb +58 -0
  74. data/vendored/puppet/lib/puppet/functions/map.rb +1 -1
  75. data/vendored/puppet/lib/puppet/functions/match.rb +11 -0
  76. data/vendored/puppet/lib/puppet/functions/max.rb +183 -0
  77. data/vendored/puppet/lib/puppet/functions/min.rb +182 -0
  78. data/vendored/puppet/lib/puppet/functions/next.rb +1 -8
  79. data/vendored/puppet/lib/puppet/functions/reduce.rb +1 -1
  80. data/vendored/puppet/lib/puppet/functions/return.rb +1 -8
  81. data/vendored/puppet/lib/puppet/functions/reverse_each.rb +1 -1
  82. data/vendored/puppet/lib/puppet/functions/round.rb +24 -0
  83. data/vendored/puppet/lib/puppet/functions/rstrip.rb +58 -0
  84. data/vendored/puppet/lib/puppet/functions/size.rb +15 -0
  85. data/vendored/puppet/lib/puppet/functions/sort.rb +74 -0
  86. data/vendored/puppet/lib/puppet/functions/step.rb +1 -1
  87. data/vendored/puppet/lib/puppet/functions/strftime.rb +1 -7
  88. data/vendored/puppet/lib/puppet/functions/strip.rb +58 -0
  89. data/vendored/puppet/lib/puppet/functions/then.rb +1 -1
  90. data/vendored/puppet/lib/puppet/functions/tree_each.rb +7 -7
  91. data/vendored/puppet/lib/puppet/functions/upcase.rb +89 -0
  92. data/vendored/puppet/lib/puppet/functions/with.rb +4 -4
  93. data/vendored/puppet/lib/puppet/functions/yaml_data.rb +4 -2
  94. data/vendored/puppet/lib/puppet/graph/simple_graph.rb +9 -5
  95. data/vendored/puppet/lib/puppet/indirector/certificate_revocation_list/rest.rb +0 -11
  96. data/vendored/puppet/lib/puppet/indirector/indirection.rb +8 -12
  97. data/vendored/puppet/lib/puppet/indirector/node/exec.rb +1 -1
  98. data/vendored/puppet/lib/puppet/indirector/node/ldap.rb +1 -1
  99. data/vendored/puppet/lib/puppet/indirector/request.rb +11 -11
  100. data/vendored/puppet/lib/puppet/indirector/rest.rb +11 -11
  101. data/vendored/puppet/lib/puppet/interface/action.rb +2 -5
  102. data/vendored/puppet/lib/puppet/metatype/manager.rb +0 -2
  103. data/vendored/puppet/lib/puppet/module.rb +7 -33
  104. data/vendored/puppet/lib/puppet/module/task.rb +0 -1
  105. data/vendored/puppet/lib/puppet/module_tool.rb +2 -5
  106. data/vendored/puppet/lib/puppet/module_tool/applications/application.rb +5 -5
  107. data/vendored/puppet/lib/puppet/module_tool/applications/builder.rb +2 -2
  108. data/vendored/puppet/lib/puppet/module_tool/applications/checksummer.rb +3 -3
  109. data/vendored/puppet/lib/puppet/module_tool/applications/installer.rb +6 -7
  110. data/vendored/puppet/lib/puppet/module_tool/applications/uninstaller.rb +1 -2
  111. data/vendored/puppet/lib/puppet/module_tool/applications/unpacker.rb +2 -2
  112. data/vendored/puppet/lib/puppet/module_tool/applications/upgrader.rb +5 -6
  113. data/vendored/puppet/lib/puppet/module_tool/dependency.rb +1 -1
  114. data/vendored/puppet/lib/puppet/module_tool/installed_modules.rb +2 -2
  115. data/vendored/puppet/lib/puppet/module_tool/local_tarball.rb +3 -3
  116. data/vendored/puppet/lib/puppet/module_tool/metadata.rb +3 -4
  117. data/vendored/puppet/lib/puppet/module_tool/shared_behaviors.rb +2 -2
  118. data/vendored/puppet/lib/puppet/network/authconfig.rb +0 -13
  119. data/vendored/puppet/lib/puppet/network/format_support.rb +1 -1
  120. data/vendored/puppet/lib/puppet/network/formats.rb +5 -7
  121. data/vendored/puppet/lib/puppet/network/http.rb +0 -2
  122. data/vendored/puppet/lib/puppet/network/http/api.rb +1 -10
  123. data/vendored/puppet/lib/puppet/network/http/api/master/v3/environment.rb +2 -2
  124. data/vendored/puppet/lib/puppet/network/http/api/master/v3/environments.rb +2 -2
  125. data/vendored/puppet/lib/puppet/network/http/compression.rb +1 -1
  126. data/vendored/puppet/lib/puppet/network/http/connection.rb +11 -3
  127. data/vendored/puppet/lib/puppet/network/http/error.rb +3 -3
  128. data/vendored/puppet/lib/puppet/network/http/factory.rb +3 -0
  129. data/vendored/puppet/lib/puppet/network/http/handler.rb +59 -27
  130. data/vendored/puppet/lib/puppet/network/resolver.rb +140 -67
  131. data/vendored/puppet/lib/puppet/node/environment.rb +2 -19
  132. data/vendored/puppet/lib/puppet/parameter.rb +12 -7
  133. data/vendored/puppet/lib/puppet/parser/ast.rb +4 -8
  134. data/vendored/puppet/lib/puppet/parser/ast/branch.rb +3 -3
  135. data/vendored/puppet/lib/puppet/parser/ast/leaf.rb +5 -0
  136. data/vendored/puppet/lib/puppet/parser/ast/pops_bridge.rb +18 -0
  137. data/vendored/puppet/lib/puppet/parser/compiler.rb +3 -4
  138. data/vendored/puppet/lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb +9 -2
  139. data/vendored/puppet/lib/puppet/parser/functions.rb +1 -1
  140. data/vendored/puppet/lib/puppet/parser/functions/assert_type.rb +3 -3
  141. data/vendored/puppet/lib/puppet/parser/functions/create_resources.rb +1 -7
  142. data/vendored/puppet/lib/puppet/parser/functions/each.rb +2 -2
  143. data/vendored/puppet/lib/puppet/parser/functions/filter.rb +1 -1
  144. data/vendored/puppet/lib/puppet/parser/functions/hiera.rb +4 -4
  145. data/vendored/puppet/lib/puppet/parser/functions/hiera_array.rb +5 -5
  146. data/vendored/puppet/lib/puppet/parser/functions/hiera_hash.rb +6 -6
  147. data/vendored/puppet/lib/puppet/parser/functions/hiera_include.rb +10 -11
  148. data/vendored/puppet/lib/puppet/parser/functions/inline_template.rb +1 -1
  149. data/vendored/puppet/lib/puppet/parser/functions/lest.rb +1 -1
  150. data/vendored/puppet/lib/puppet/parser/functions/lookup.rb +1 -1
  151. data/vendored/puppet/lib/puppet/parser/functions/map.rb +1 -1
  152. data/vendored/puppet/lib/puppet/parser/functions/reduce.rb +1 -1
  153. data/vendored/puppet/lib/puppet/parser/functions/return.rb +22 -1
  154. data/vendored/puppet/lib/puppet/parser/functions/reverse_each.rb +1 -1
  155. data/vendored/puppet/lib/puppet/parser/functions/step.rb +1 -1
  156. data/vendored/puppet/lib/puppet/parser/functions/then.rb +1 -1
  157. data/vendored/puppet/lib/puppet/parser/functions/with.rb +4 -4
  158. data/vendored/puppet/lib/puppet/parser/resource.rb +0 -1
  159. data/vendored/puppet/lib/puppet/parser/resource/param.rb +12 -5
  160. data/vendored/puppet/lib/puppet/parser/scope.rb +5 -7
  161. data/vendored/puppet/lib/puppet/pops/evaluator/compare_operator.rb +3 -1
  162. data/vendored/puppet/lib/puppet/pops/evaluator/runtime3_support.rb +2 -7
  163. data/vendored/puppet/lib/puppet/pops/issues.rb +4 -0
  164. data/vendored/puppet/lib/puppet/pops/loader/loader_paths.rb +2 -2
  165. data/vendored/puppet/lib/puppet/pops/loader/module_loaders.rb +17 -12
  166. data/vendored/puppet/lib/puppet/pops/loader/task_instantiator.rb +73 -45
  167. data/vendored/puppet/lib/puppet/pops/lookup/lookup_adapter.rb +55 -6
  168. data/vendored/puppet/lib/puppet/pops/model/model_label_provider.rb +2 -0
  169. data/vendored/puppet/lib/puppet/pops/parser/epp_parser.rb +1 -1
  170. data/vendored/puppet/lib/puppet/pops/parser/epp_support.rb +6 -2
  171. data/vendored/puppet/lib/puppet/pops/parser/lexer2.rb +1 -1
  172. data/vendored/puppet/lib/puppet/pops/pcore.rb +7 -7
  173. data/vendored/puppet/lib/puppet/pops/puppet_stack.rb +15 -1
  174. data/vendored/puppet/lib/puppet/pops/serialization.rb +2 -2
  175. data/vendored/puppet/lib/puppet/pops/serialization/from_data_converter.rb +2 -2
  176. data/vendored/puppet/lib/puppet/pops/serialization/json.rb +7 -7
  177. data/vendored/puppet/lib/puppet/pops/serialization/to_data_converter.rb +5 -5
  178. data/vendored/puppet/lib/puppet/pops/types/types.rb +8 -4
  179. data/vendored/puppet/lib/puppet/pops/validation/checker4_0.rb +73 -0
  180. data/vendored/puppet/lib/puppet/pops/validation/validator_factory_4_0.rb +4 -3
  181. data/vendored/puppet/lib/puppet/provider/augeas/augeas.rb +7 -0
  182. data/vendored/puppet/lib/puppet/provider/service/systemd.rb +1 -1
  183. data/vendored/puppet/lib/puppet/provider/user/aix.rb +2 -2
  184. data/vendored/puppet/lib/puppet/provider/yumrepo/inifile.rb +21 -9
  185. data/vendored/puppet/lib/puppet/reference/providers.rb +1 -1
  186. data/vendored/puppet/lib/puppet/reference/report.rb +1 -1
  187. data/vendored/puppet/lib/puppet/resource.rb +1 -1
  188. data/vendored/puppet/lib/puppet/resource/capability_finder.rb +4 -4
  189. data/vendored/puppet/lib/puppet/resource/catalog.rb +6 -3
  190. data/vendored/puppet/lib/puppet/resource/type.rb +6 -2
  191. data/vendored/puppet/lib/puppet/rest/client.rb +79 -0
  192. data/vendored/puppet/lib/puppet/rest/errors.rb +14 -0
  193. data/vendored/puppet/lib/puppet/rest/response.rb +29 -0
  194. data/vendored/puppet/lib/puppet/rest/route.rb +102 -0
  195. data/vendored/puppet/lib/puppet/rest/routes.rb +31 -0
  196. data/vendored/puppet/lib/puppet/settings.rb +9 -5
  197. data/vendored/puppet/lib/puppet/settings/config_file.rb +1 -1
  198. data/vendored/puppet/lib/puppet/settings/environment_conf.rb +10 -1
  199. data/vendored/puppet/lib/puppet/ssl.rb +0 -1
  200. data/vendored/puppet/lib/puppet/ssl/certificate.rb +6 -2
  201. data/vendored/puppet/lib/puppet/ssl/certificate_authority.rb +3 -3
  202. data/vendored/puppet/lib/puppet/ssl/host.rb +258 -19
  203. data/vendored/puppet/lib/puppet/ssl/validator/default_validator.rb +33 -19
  204. data/vendored/puppet/lib/puppet/syntax_checkers/json.rb +1 -1
  205. data/vendored/puppet/lib/puppet/transaction/event.rb +34 -7
  206. data/vendored/puppet/lib/puppet/transaction/report.rb +17 -14
  207. data/vendored/puppet/lib/puppet/type.rb +20 -12
  208. data/vendored/puppet/lib/puppet/type/file.rb +1 -1
  209. data/vendored/puppet/lib/puppet/type/file/content.rb +15 -2
  210. data/vendored/puppet/lib/puppet/type/file/ensure.rb +1 -1
  211. data/vendored/puppet/lib/puppet/type/schedule.rb +1 -1
  212. data/vendored/puppet/lib/puppet/type/stage.rb +1 -1
  213. data/vendored/puppet/lib/puppet/type/tidy.rb +5 -1
  214. data/vendored/puppet/lib/puppet/type/user.rb +35 -18
  215. data/vendored/puppet/lib/puppet/type/yumrepo.rb +8 -17
  216. data/vendored/puppet/lib/puppet/util.rb +0 -1
  217. data/vendored/puppet/lib/puppet/util/autoload.rb +1 -6
  218. data/vendored/puppet/lib/puppet/util/checksums.rb +0 -2
  219. data/vendored/puppet/lib/puppet/util/classgen.rb +0 -6
  220. data/vendored/puppet/lib/puppet/util/fileparsing.rb +27 -5
  221. data/vendored/puppet/lib/puppet/util/instance_loader.rb +3 -3
  222. data/vendored/puppet/lib/puppet/util/json.rb +77 -0
  223. data/vendored/puppet/lib/puppet/util/json_lockfile.rb +3 -3
  224. data/vendored/puppet/lib/puppet/util/ldap/connection.rb +7 -7
  225. data/vendored/puppet/lib/puppet/util/log/destinations.rb +2 -2
  226. data/vendored/puppet/lib/puppet/util/logging.rb +1 -1
  227. data/vendored/puppet/lib/puppet/util/plist.rb +1 -1
  228. data/vendored/puppet/lib/puppet/util/provider_features.rb +2 -5
  229. data/vendored/puppet/lib/puppet/util/reference.rb +5 -4
  230. data/vendored/puppet/lib/puppet/util/tagging.rb +16 -3
  231. data/vendored/puppet/lib/puppet/version.rb +1 -1
  232. metadata +44 -26
  233. data/vendored/puppet/lib/puppet/application/master.rb +0 -317
  234. data/vendored/puppet/lib/puppet/feature/rack.rb +0 -19
  235. data/vendored/puppet/lib/puppet/network/http/api/ca.rb +0 -2
  236. data/vendored/puppet/lib/puppet/network/http/api/ca/v1.rb +0 -11
  237. data/vendored/puppet/lib/puppet/network/http/rack.rb +0 -33
  238. data/vendored/puppet/lib/puppet/network/http/rack/rest.rb +0 -162
  239. data/vendored/puppet/lib/puppet/network/http/webrick.rb +0 -124
  240. data/vendored/puppet/lib/puppet/network/http/webrick/rest.rb +0 -114
  241. data/vendored/puppet/lib/puppet/network/server.rb +0 -39
  242. data/vendored/puppet/lib/puppet/ssl/configuration.rb +0 -61
  243. data/vendored/puppet/lib/puppet/util/methodhelper.rb +0 -32
  244. data/vendored/puppet/lib/puppet/vendor/load_semantic.rb +0 -1
  245. data/vendored/puppet/lib/puppet/vendor/load_semantic_puppet.rb +0 -1
  246. data/vendored/puppet/lib/puppet/vendor/semantic/lib/semantic.rb +0 -5
  247. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet.rb +0 -11
  248. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency.rb +0 -181
  249. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/graph.rb +0 -60
  250. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/graph_node.rb +0 -117
  251. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/module_release.rb +0 -58
  252. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/source.rb +0 -25
  253. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/unsatisfiable_graph.rb +0 -31
  254. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/gem_version.rb +0 -3
  255. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/version.rb +0 -203
  256. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/version_range.rb +0 -758
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'puppet/util/json'
2
2
  require 'puppet/error'
3
3
  require 'puppet/forge'
4
4
 
@@ -82,11 +82,11 @@ module Puppet::Forge::Errors
82
82
  @response = "#{response.code} #{response.message.strip}"
83
83
 
84
84
  begin
85
- body = JSON.parse(response.body)
85
+ body = Puppet::Util::Json.load(response.body)
86
86
  if body['message']
87
87
  @message ||= body['message'].strip
88
88
  end
89
- rescue JSON::ParserError
89
+ rescue Puppet::Util::Json::ParseError
90
90
  end
91
91
 
92
92
  message = if @message
@@ -0,0 +1,61 @@
1
+ # Returns the absolute value of a Numeric value, for example -34.56 becomes
2
+ # 34.56. Takes a single `Integer` or `Float` value as an argument.
3
+ #
4
+ # *Deprecated behavior*
5
+ #
6
+ # For backwards compatibility reasons this function also works when given a
7
+ # number in `String` format such that it first attempts to covert it to either a `Float` or
8
+ # an `Integer` and then taking the absolute value of the result. Only strings representing
9
+ # a number in decimal format is supported - an error is raised if
10
+ # value is not decimal (using base 10). Leading 0 chars in the string
11
+ # are ignored. A floating point value in string form can use some forms of
12
+ # scientific notation but not all.
13
+ #
14
+ # Callers should convert strings to `Numeric` before calling
15
+ # this function to have full control over the conversion.
16
+ #
17
+ # @example Converting to Numeric before calling
18
+ # ```puppet
19
+ # abs(Numeric($str_val))
20
+ # ```
21
+ #
22
+ # It is worth noting that `Numeric` can convert to absolute value
23
+ # directly as in the following examples:
24
+ #
25
+ # @example Absolute value and String to Numeric
26
+ # ```puppet
27
+ # Numeric($strval, true) # Converts to absolute Integer or Float
28
+ # Integer($strval, 10, true) # Converts to absolute Integer using base 10 (decimal)
29
+ # Integer($strval, 16, true) # Converts to absolute Integer using base 16 (hex)
30
+ # Float($strval, true) # Converts to absolute Float
31
+ # ```puppet
32
+ #
33
+ Puppet::Functions.create_function(:abs) do
34
+ dispatch :on_numeric do
35
+ param 'Numeric', :val
36
+ end
37
+
38
+ dispatch :on_string do
39
+ param 'String', :val
40
+ end
41
+
42
+ def on_numeric(x)
43
+ x.abs
44
+ end
45
+
46
+ def on_string(x)
47
+ Puppet.warn_once('deprecations', 'abs_function_numeric_coerce_string',
48
+ _("The abs() function's auto conversion of String to Numeric is deprecated - change to convert input before calling"))
49
+
50
+ # These patterns for conversion are backwards compatible with the stdlib
51
+ # version of this function.
52
+ #
53
+ if x =~ %r{^-?(?:\d+)(?:\.\d+){1}$}
54
+ x.to_f.abs
55
+ elsif x =~ %r{^-?\d+$}
56
+ x.to_i.abs
57
+ else
58
+ raise(ArgumentError, 'abs(): Requires float or integer to work with - was given non decimal string')
59
+ end
60
+ end
61
+ end
@@ -1,4 +1,4 @@
1
- # Runs a [lambda](http://docs.puppetlabs.com/puppet/latest/reference/lang_lambdas.html)
1
+ # Runs a [lambda](https://puppet.com/docs/puppet/latest/lang_lambdas.html)
2
2
  # repeatedly using each value in a data structure until the lambda returns a non "truthy" value which
3
3
  # makes the function return `false`, or if the end of the iteration is reached, `true` is returned.
4
4
  #
@@ -54,7 +54,7 @@
54
54
  # Would notice true.
55
55
  #
56
56
  # For an general examples that demonstrates iteration, see the Puppet
57
- # [iteration](https://docs.puppetlabs.com/puppet/latest/reference/lang_iteration.html)
57
+ # [iteration](https://puppet.com/docs/puppet/latest/lang_iteration.html)
58
58
  # documentation.
59
59
  #
60
60
  # @since 5.2.0
@@ -1,4 +1,4 @@
1
- # Runs a [lambda](http://docs.puppetlabs.com/puppet/latest/reference/lang_lambdas.html)
1
+ # Runs a [lambda](https://puppet.com/docs/puppet/latest/lang_lambdas.html)
2
2
  # repeatedly using each value in a data structure until the lambda returns a "truthy" value which
3
3
  # makes the function return `true`, or if the end of the iteration is reached, false is returned.
4
4
  #
@@ -59,7 +59,7 @@
59
59
  # Would notice true as the index `2` is even and not a `String`
60
60
  #
61
61
  # For an general examples that demonstrates iteration, see the Puppet
62
- # [iteration](https://docs.puppetlabs.com/puppet/latest/reference/lang_iteration.html)
62
+ # [iteration](https://puppet.com/docs/puppet/latest/lang_iteration.html)
63
63
  # documentation.
64
64
  #
65
65
  # @since 5.2.0
@@ -1,7 +1,7 @@
1
1
  # Returns the given value if it is of the given
2
- # [data type](https://docs.puppetlabs.com/puppet/latest/reference/lang_data.html), or
2
+ # [data type](https://puppet.com/docs/puppet/latest/lang_data.html), or
3
3
  # otherwise either raises an error or executes an optional two-parameter
4
- # [lambda](https://docs.puppetlabs.com/puppet/latest/reference/lang_lambdas.html).
4
+ # [lambda](https://puppet.com/docs/puppet/latest/lang_lambdas.html).
5
5
  #
6
6
  # The function takes two mandatory arguments, in this order:
7
7
  #
@@ -46,7 +46,7 @@
46
46
  # ```
47
47
  #
48
48
  # For more information about data types, see the
49
- # [documentation](https://docs.puppetlabs.com/puppet/latest/reference/lang_data.html).
49
+ # [documentation](https://puppet.com/docs/puppet/latest/lang_data.html).
50
50
  #
51
51
  # @since 4.0.0
52
52
  #
@@ -36,13 +36,9 @@ Puppet::Functions.create_function(:break) do
36
36
  end
37
37
 
38
38
  def break_impl()
39
- stacktrace = Puppet::Pops::PuppetStack.stacktrace()
40
- if stacktrace.size > 0
41
- file, line = stacktrace[0]
42
- else
43
- file = nil
44
- line = nil
45
- end
39
+ # get file, line if available, else they are set to nil
40
+ file, line = Puppet::Pops::PuppetStack.top_of_stack
41
+
46
42
  # PuppetStopIteration contains file and line and is a StopIteration exception
47
43
  # so it can break a Ruby Kernel#loop or enumeration
48
44
  #
@@ -0,0 +1,62 @@
1
+ # Creates a Camel Case version of a String
2
+ #
3
+ # This function is compatible with the stdlib function with the same name.
4
+ #
5
+ # The function does the following:
6
+ # * For a `String` the conversion replaces all combinations of *_<char>* with an upcased version of the
7
+ # character following the _. This is done using Ruby system locale which handles some, but not all
8
+ # special international up-casing rules (for example German double-s ß is upcased to "Ss").
9
+ # * For an `Iterable[Variant[String, Numeric]]` (for example an `Array`) each value is capitalized and the conversion is not recursive.
10
+ # * If the value is `Numeric` it is simply returned (this is for backwards compatibility).
11
+ # * An error is raised for all other data types.
12
+ # * The result will not contain any underscore characters.
13
+ #
14
+ # Please note: This function relies directly on Ruby's String implementation and as such may not be entirely UTF8 compatible.
15
+ # To ensure best compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085.
16
+ #
17
+ # @example Camelcase a String
18
+ # ```puppet
19
+ # 'hello_friend'.camelcase()
20
+ # camelcase('hello_friend')
21
+ # ```
22
+ # Would both result in `"HelloFriend"`
23
+ #
24
+ # @example Camelcase of strings in an Array
25
+ # ```puppet
26
+ # ['abc_def', 'bcd_xyz'].capitalize()
27
+ # capitalize(['abc_def', 'bcd_xyz'])
28
+ # ```
29
+ # Would both result in `['AbcDef', 'BcdXyz']`
30
+ #
31
+ Puppet::Functions.create_function(:camelcase) do
32
+
33
+ dispatch :on_numeric do
34
+ param 'Numeric', :arg
35
+ end
36
+
37
+ dispatch :on_string do
38
+ param 'String', :arg
39
+ end
40
+
41
+ dispatch :on_iterable do
42
+ param 'Iterable[Variant[String, Numeric]]', :arg
43
+ end
44
+
45
+ # unit function - since the old implementation skipped Numeric values
46
+ def on_numeric(n)
47
+ n
48
+ end
49
+
50
+ def on_string(s)
51
+ s.split('_').map {|x| x.capitalize }.join('')
52
+ end
53
+
54
+ def on_iterable(a)
55
+ a.map {|x| do_camelcase(x) }
56
+ end
57
+
58
+ def do_camelcase(x)
59
+ # x can only be a String or Numeric because type constraints have been automatically applied
60
+ x.is_a?(String) ? on_string(x) : x
61
+ end
62
+ end
@@ -0,0 +1,61 @@
1
+ # Capitalizes the first character of a String, or the first character of every String in an Iterable value (such as an Array).
2
+ #
3
+ # This function is compatible with the stdlib function with the same name.
4
+ #
5
+ # The function does the following:
6
+ # * For a `String`, a string with its first character in upper case version is returned.
7
+ # This is done using Ruby system locale which handles some, but not all
8
+ # special international up-casing rules (for example German double-s ß is capitalized to "Ss").
9
+ # * For an `Iterable[Variant[String, Numeric]]` (for example an `Array`) each value is capitalized and the conversion is not recursive.
10
+ # * If the value is `Numeric` it is simply returned (this is for backwards compatibility).
11
+ # * An error is raised for all other data types.
12
+ #
13
+ # Please note: This function relies directly on Ruby's String implementation and as such may not be entirely UTF8 compatible.
14
+ # To ensure best compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085.
15
+ #
16
+ # @example Capitalizing a String
17
+ # ```puppet
18
+ # 'hello'.capitalize()
19
+ # upcase('hello')
20
+ # ```
21
+ # Would both result in "Hello"
22
+ #
23
+ # @example Capitalizing strings in an Array
24
+ # ```puppet
25
+ # ['abc', 'bcd'].capitalize()
26
+ # capitalize(['abc', 'bcd'])
27
+ # ```
28
+ # Would both result in ['Abc', 'Bcd']
29
+ #
30
+ Puppet::Functions.create_function(:capitalize) do
31
+
32
+ dispatch :on_numeric do
33
+ param 'Numeric', :arg
34
+ end
35
+
36
+ dispatch :on_string do
37
+ param 'String', :arg
38
+ end
39
+
40
+ dispatch :on_iterable do
41
+ param 'Iterable[Variant[String, Numeric]]', :arg
42
+ end
43
+
44
+ # unit function - since the old implementation skipped Numeric values
45
+ def on_numeric(n)
46
+ n
47
+ end
48
+
49
+ def on_string(s)
50
+ s.capitalize
51
+ end
52
+
53
+ def on_iterable(a)
54
+ a.map {|x| do_capitalize(x) }
55
+ end
56
+
57
+ def do_capitalize(x)
58
+ # x can only be a String or Numeric because type constraints have been automatically applied
59
+ x.is_a?(String) ? x.capitalize : x
60
+ end
61
+ end
@@ -0,0 +1,37 @@
1
+ # Returns the smallest `Integer` greater or equal to the argument.
2
+ # Takes a single numeric value as an argument.
3
+ #
4
+ # This function is backwards compatible with the same function in stdlib
5
+ # and accepts a `Numeric` value. A `String` that can be converted
6
+ # to a floating point number can also be used in this version - but this
7
+ # is deprecated.
8
+ #
9
+ # In general convert string input to `Numeric` before calling this function
10
+ # to have full control over how the conversion is done.
11
+ #
12
+ Puppet::Functions.create_function(:ceiling) do
13
+ dispatch :on_numeric do
14
+ param 'Numeric', :val
15
+ end
16
+
17
+ dispatch :on_string do
18
+ param 'String', :val
19
+ end
20
+
21
+ def on_numeric(x)
22
+ x.ceil
23
+ end
24
+
25
+ def on_string(x)
26
+ Puppet.warn_once('deprecations', 'ceiling_function_numeric_coerce_string',
27
+ _("The ceiling() function's auto conversion of String to Float is deprecated - change to convert input before calling"))
28
+
29
+ begin
30
+ Float(x).ceil
31
+ rescue TypeError, ArgumentError => _e
32
+ # TRANSLATORS: 'ceiling' is a name and should not be translated
33
+ raise(ArgumentError, _('ceiling(): cannot convert given value to a floating point value.'))
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,57 @@
1
+ # Returns a new string with the record separator character(s) removed.
2
+ # The record separator is the line ending characters `\r` and `\n`.
3
+ #
4
+ # This function is compatible with the stdlib function with the same name.
5
+ #
6
+ # The function does the following:
7
+ # * For a `String` the conversion removes `\r\n`, `\n` or `\r` from the end of a string.
8
+ # * For an `Iterable[Variant[String, Numeric]]` (for example an `Array`) each value is processed and the conversion is not recursive.
9
+ # * If the value is `Numeric` it is simply returned (this is for backwards compatibility).
10
+ # * An error is raised for all other data types.
11
+ #
12
+ # @example Removing line endings
13
+ # ```puppet
14
+ # "hello\r\n".chomp()
15
+ # chomp("hello\r\n")
16
+ # ```
17
+ # Would both result in `"hello"`
18
+ #
19
+ # @example Removing line endings in an array
20
+ # ```puppet
21
+ # ["hello\r\n", "hi\r\n"].chomp()
22
+ # chomp(["hello\r\n", "hi\r\n"])
23
+ # ```
24
+ # Would both result in `['hello', 'hi']`
25
+ #
26
+ Puppet::Functions.create_function(:chomp) do
27
+
28
+ dispatch :on_numeric do
29
+ param 'Numeric', :arg
30
+ end
31
+
32
+ dispatch :on_string do
33
+ param 'String', :arg
34
+ end
35
+
36
+ dispatch :on_iterable do
37
+ param 'Iterable[Variant[String, Numeric]]', :arg
38
+ end
39
+
40
+ # unit function - since the old implementation skipped Numeric values
41
+ def on_numeric(n)
42
+ n
43
+ end
44
+
45
+ def on_string(s)
46
+ s.chomp
47
+ end
48
+
49
+ def on_iterable(a)
50
+ a.map {|x| do_chomp(x) }
51
+ end
52
+
53
+ def do_chomp(x)
54
+ # x can only be a String or Numeric because type constraints have been automatically applied
55
+ x.is_a?(String) ? x.chomp : x
56
+ end
57
+ end
@@ -0,0 +1,67 @@
1
+ # Returns a new string with the last character removed.
2
+ # If the string ends with `\r\n`, both characters are removed. Applying chop to an empty
3
+ # string returns an empty string. If you wish to merely remove record
4
+ # separators then you should use the `chomp` function.
5
+ #
6
+ # This function is compatible with the stdlib function with the same name.
7
+ #
8
+ # The function does the following:
9
+ # * For a `String` the conversion removes the last character, or if it ends with \r\n` it removes both. If String is empty
10
+ # an empty string is returned.
11
+ # * For an `Iterable[Variant[String, Numeric]]` (for example an `Array`) each value is processed and the conversion is not recursive.
12
+ # * If the value is `Numeric` it is simply returned (this is for backwards compatibility).
13
+ # * An error is raised for all other data types.
14
+ #
15
+ # @example Removing line endings
16
+ # ```puppet
17
+ # "hello\r\n".chop()
18
+ # chop("hello\r\n")
19
+ # ```
20
+ # Would both result in `"hello"`
21
+ #
22
+ # @example Removing last char
23
+ # ```puppet
24
+ # "hello".chop()
25
+ # chop("hello")
26
+ # ```
27
+ # Would both result in `"hell"`
28
+ #
29
+ # @example Removing last char in an array
30
+ # ```puppet
31
+ # ["hello\r\n", "hi\r\n"].chop()
32
+ # chop(["hello\r\n", "hi\r\n"])
33
+ # ```
34
+ # Would both result in `['hello', 'hi']`
35
+ #
36
+ Puppet::Functions.create_function(:chop) do
37
+
38
+ dispatch :on_numeric do
39
+ param 'Numeric', :arg
40
+ end
41
+
42
+ dispatch :on_string do
43
+ param 'String', :arg
44
+ end
45
+
46
+ dispatch :on_iterable do
47
+ param 'Iterable[Variant[String, Numeric]]', :arg
48
+ end
49
+
50
+ # unit function - since the old implementation skipped Numeric values
51
+ def on_numeric(n)
52
+ n
53
+ end
54
+
55
+ def on_string(s)
56
+ s.chop
57
+ end
58
+
59
+ def on_iterable(a)
60
+ a.map {|x| do_chop(x) }
61
+ end
62
+
63
+ def do_chop(x)
64
+ # x can only be a String or Numeric because type constraints have been automatically applied
65
+ x.is_a?(String) ? x.chop : x
66
+ end
67
+ end
@@ -0,0 +1,125 @@
1
+ # Compares two values and returns -1, 0 or 1 if first value is smaller, equal or larger than the second value.
2
+ # The compare function accepts arguments of the data types `String`, `Numeric`, `Timespan`, `Timestamp`, and `Semver`,
3
+ # such that:
4
+ #
5
+ # * two of the same data type can be compared
6
+ # * `Timespan` and `Timestamp` can be compared with each other and with `Numeric`
7
+ #
8
+ # When comparing two `String` values the comparison can be made to consider case by passing a third (optional)
9
+ # boolean `false` value - the default is `true` which ignores case as the comparison operators
10
+ # in the Puppet Language.
11
+ #
12
+ Puppet::Functions.create_function(:compare) do
13
+ local_types do
14
+ type 'TimeComparable = Variant[Numeric, Timespan, Timestamp]'
15
+ type 'Comparable = Variant[String, Semver, TimeComparable]'
16
+ end
17
+
18
+ dispatch :on_numeric do
19
+ param 'Numeric', :a
20
+ param 'Numeric', :b
21
+ end
22
+
23
+ dispatch :on_string do
24
+ param 'String', :a
25
+ param 'String', :b
26
+ optional_param 'Boolean', :ignore_case
27
+ end
28
+
29
+ dispatch :on_version do
30
+ param 'Semver', :a
31
+ param 'Semver', :b
32
+ end
33
+
34
+ dispatch :on_time_num_first do
35
+ param 'Numeric', :a
36
+ param 'Variant[Timespan, Timestamp]', :b
37
+ end
38
+
39
+ dispatch :on_timestamp do
40
+ param 'Timestamp', :a
41
+ param 'Variant[Timestamp, Numeric]', :b
42
+ end
43
+
44
+ dispatch :on_timespan do
45
+ param 'Timespan', :a
46
+ param 'Variant[Timespan, Numeric]', :b
47
+ end
48
+
49
+ argument_mismatch :on_error do
50
+ param 'Comparable', :a
51
+ param 'Comparable', :b
52
+ repeated_param 'Any', :ignore_case
53
+ end
54
+
55
+ argument_mismatch :on_not_comparable do
56
+ param 'Any', :a
57
+ param 'Any', :b
58
+ repeated_param 'Any', :ignore_case
59
+ end
60
+
61
+ def on_numeric(a, b)
62
+ a <=> b
63
+ end
64
+
65
+ def on_string(a, b, ignore_case = true)
66
+ if ignore_case
67
+ a.casecmp(b)
68
+ else
69
+ a <=> b
70
+ end
71
+ end
72
+
73
+ def on_version(a, b)
74
+ a <=> b
75
+ end
76
+
77
+ def on_time_num_first(a, b)
78
+ # Time data types can compare against Numeric but not the other way around
79
+ # the comparison is therefore done in reverse and the answer is inverted.
80
+ -(b <=> a)
81
+ end
82
+
83
+ def on_timespan(a, b)
84
+ a <=> b
85
+ end
86
+
87
+ def on_timestamp(a, b)
88
+ a <=> b
89
+ end
90
+
91
+ def on_not_comparable(a, b, *ignore_case)
92
+ # TRANSLATORS 'compare' is a name
93
+ _("compare(): Non comparable type. Only values of the types Numeric, String, Semver, Timestamp and Timestamp can be compared. Got %{type_a} and %{type_b}") % {
94
+ type_a: type_label(a), type_b: type_label(b)
95
+ }
96
+ end
97
+
98
+ def on_error(a, b, *ignore_case)
99
+ if !ignore_case.empty?
100
+ unless a.is_a?(String) && b.is_a?(String)
101
+ # TRANSLATORS 'compare' is a name
102
+ return _("compare(): The third argument (ignore case) can only be used when comparing strings")
103
+ end
104
+ unless ignore_case.size == 1
105
+ # TRANSLATORS 'compare' is a name
106
+ return _("compare(): Accepts at most 3 arguments, got %{actual_number}") % {actual_number: 2 + ignore_case.size}
107
+ end
108
+ unless ignore_case[0].is_a?(Boolean)
109
+ # TRANSLATORS 'compare' is a name
110
+ return _("compare(): The third argument (ignore case) must be a Boolean. Got %{type}") % { type: type_label(ignore_case[0]) }
111
+ end
112
+ end
113
+
114
+ if a.class != b.class
115
+ # TRANSLATORS 'compare' is a name
116
+ return _("compare(): Can only compare values of the same type (or for Timestamp/Timespan also against Numeric). Got %{type_a} and %{type_b}") % {
117
+ type_a: type_label(a), type_b: type_label(b)
118
+ }
119
+ end
120
+ end
121
+
122
+ def type_label(x)
123
+ Puppet::Pops::Model::ModelLabelProvider.new.label(x)
124
+ end
125
+ end