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
@@ -0,0 +1,182 @@
1
+ # Returns the lowest value among a variable number of arguments.
2
+ # Takes at least one argument.
3
+ #
4
+ # This function is (with one exception) compatible with the stdlib function
5
+ # with the same name and performs deprecated type conversion before
6
+ # comparison as follows:
7
+ #
8
+ # * If a value converted to String is an optionally '-' prefixed,
9
+ # string of digits, one optional decimal point, followed by optional
10
+ # decimal digits - then the comparison is performed on the values
11
+ # converted to floating point.
12
+ # * If a value is not considered convertible to float, it is converted
13
+ # to a `String` and the comparison is a lexical compare where min is
14
+ # the lexicographical earlier value.
15
+ # * A lexicographical compare is performed in a system locale - international
16
+ # characters may therefore not appear in what a user thinks is the correct order.
17
+ # * The conversion rules apply to values in pairs - the rule must hold for both
18
+ # values - a value may therefore be compared using different rules depending
19
+ # on the "other value".
20
+ # * The returned result found to be the "lowest" is the original unconverted value.
21
+ #
22
+ # The above rules have been deprecated in Puppet 6.0.0 as they produce strange results when
23
+ # given values of mixed data types. In general, either convert values to be
24
+ # all `String` or all `Numeric` values before calling the function, or call the
25
+ # function with a lambda that performs type conversion and comparison. This because one
26
+ # simply cannot compare `Boolean` with `Regexp` and with any arbitrary `Array`, `Hash` or
27
+ # `Object` and getting a meaningful result.
28
+ #
29
+ # The one change in the function's behavior is when the function is given a single
30
+ # array argument. The stdlib implementation would return that array as the result where
31
+ # it now instead returns the max value from that array.
32
+ #
33
+ # @example 'min of values - stdlib compatible'
34
+ #
35
+ # ```puppet
36
+ # notice(min(1)) # would notice 1
37
+ # notice(min(1,2)) # would notice 1
38
+ # notice(min("1", 2)) # would notice 1
39
+ # notice(min("0777", 512)) # would notice 512, since "0777" is not converted from octal form
40
+ # notice(min(0777, 512)) # would notice 511, since 0777 is decimal 511
41
+ # notice(min('aa', 'ab')) # would notice 'aa'
42
+ # notice(min(['a'], ['b'])) # would notice ['a'], since "['a']" is before "['b']"
43
+ # ```
44
+ #
45
+ # @example find 'min' value in an array
46
+ #
47
+ # ```puppet
48
+ # $x = [1,2,3,4]
49
+ # notice(min(*$x)) # would notice 1
50
+ # ```
51
+ #
52
+ # @example find 'min' value in an array directly - since Puppet 6.0.0
53
+ #
54
+ # ```puppet
55
+ # $x = [1,2,3,4]
56
+ # notice(min($x)) # would notice 1
57
+ # notice($x.min) # would notice 1
58
+ # ```
59
+ # This example shows that a single array argument is used as the set of values
60
+ # as opposed to being a single returned value.
61
+ #
62
+ # When calling with a lambda, it must accept two variables and it must return
63
+ # one of -1, 0, or 1 depending on if first argument is before/lower than, equal to,
64
+ # or higher/after the second argument.
65
+ #
66
+ # @example 'min of values using a lambda'
67
+ #
68
+ # ```puppet
69
+ # notice(min("2", "10", "100") |$a, $b| { compare($a, $b) })
70
+ # ```
71
+ #
72
+ # Would notice "10" as lower since it is lexicographically lower/before the other values. Without the
73
+ # lambda the stdlib compatible (deprecated) behavior would have been to return "2" since number conversion kicks in.
74
+ #
75
+ Puppet::Functions.create_function(:min) do
76
+ dispatch :on_numeric do
77
+ repeated_param 'Numeric', :values
78
+ end
79
+
80
+ dispatch :on_string do
81
+ repeated_param 'String', :values
82
+ end
83
+
84
+ dispatch :on_single_numeric_array do
85
+ param 'Array[Numeric]', :values
86
+ optional_block_param 'Callable[2,2]', :block
87
+ end
88
+
89
+ dispatch :on_single_string_array do
90
+ param 'Array[String]', :values
91
+ optional_block_param 'Callable[2,2]', :block
92
+ end
93
+
94
+ dispatch :on_single_any_array do
95
+ param 'Array', :values
96
+ optional_block_param 'Callable[2,2]', :block
97
+ end
98
+
99
+ dispatch :on_any_with_block do
100
+ repeated_param 'Any', :values
101
+ block_param 'Callable[2,2]', :block
102
+ end
103
+
104
+ dispatch :on_any do
105
+ repeated_param 'Any', :values
106
+ end
107
+
108
+
109
+ # All are Numeric - ok now, will be ok later
110
+ def on_numeric(*args)
111
+ assert_arg_count(args)
112
+ args.min
113
+ end
114
+
115
+ # All are String, may convert to numeric (which is deprecated)
116
+ def on_string(*args)
117
+ assert_arg_count(args)
118
+
119
+ args.min do|a,b|
120
+ if a.to_s =~ %r{\A^-?\d+([._eE]\d+)?\z} && b.to_s =~ %r{\A-?\d+([._eE]\d+)?\z}
121
+ Puppet.warn_once('deprecations', 'min_function_numeric_coerce_string',
122
+ _("The min() function's auto conversion of String to Numeric is deprecated - change to convert input before calling, or use lambda"))
123
+ a.to_f <=> b.to_f
124
+ else
125
+ # case sensitive as in the stdlib function
126
+ a <=> b
127
+ end
128
+ end
129
+ end
130
+
131
+ def on_any_with_block(*args, &block)
132
+ args.min {|x,y| block.call(x,y) }
133
+ end
134
+
135
+ def on_single_numeric_array(array, &block)
136
+ if block_given?
137
+ on_any_with_block(*array, &block)
138
+ else
139
+ on_numeric(*array)
140
+ end
141
+ end
142
+
143
+ def on_single_string_array(array, &block)
144
+ if block_given?
145
+ on_any_with_block(*array, &block)
146
+ else
147
+ on_string(*array)
148
+ end
149
+ end
150
+
151
+ def on_single_any_array(array, &block)
152
+ if block_given?
153
+ on_any_with_block(*array, &block)
154
+ else
155
+ on_any(*array)
156
+ end
157
+ end
158
+
159
+ # Mix of data types - while only some compares are actually bad it will deprecate
160
+ # the entire call
161
+ #
162
+ def on_any(*args)
163
+ assert_arg_count(args)
164
+ args.min do |a, b|
165
+ as = a.to_s
166
+ bs = b.to_s
167
+ if as =~ %r{\A^-?\d+([._eE]\d+)?\z} && bs =~ %r{\A-?\d+([._eE]\d+)?\z}
168
+ Puppet.warn_once('deprecations', 'min_function_numeric_coerce_string',
169
+ _("The min() function's auto conversion of String to Numeric is deprecated - change to convert input before calling, or use lambda"))
170
+ a.to_f <=> b.to_f
171
+ else
172
+ Puppet.warn_once('deprecations', 'min_function_string_coerce_any',
173
+ _("The min() function's auto conversion of Any to String is deprecated - change to convert input before calling, or use lambda"))
174
+ as <=> bs
175
+ end
176
+ end
177
+ end
178
+
179
+ def assert_arg_count(args)
180
+ raise(ArgumentError, 'min(): Wrong number of arguments need at least one') if args.empty?
181
+ end
182
+ end
@@ -9,14 +9,7 @@ Puppet::Functions.create_function(:next) do
9
9
  end
10
10
 
11
11
  def next_impl(value = nil)
12
- stacktrace = Puppet::Pops::PuppetStack.stacktrace()
13
- if stacktrace.size > 0
14
- file, line = stacktrace[0]
15
- else
16
- file = nil
17
- line = nil
18
- end
19
-
12
+ file, line = Puppet::Pops::PuppetStack.top_of_stack
20
13
  exc = Puppet::Pops::Evaluator::Next.new(value, file, line)
21
14
  raise exc
22
15
  end
@@ -1,4 +1,4 @@
1
- # Applies a [lambda](https://docs.puppetlabs.com/puppet/latest/reference/lang_lambdas.html)
1
+ # Applies a [lambda](https://puppet.com/docs/puppet/latest/lang_lambdas.html)
2
2
  # to every value in a data structure from the first argument, carrying over the returned
3
3
  # value of each iteration, and returns the result of the lambda's final iteration. This
4
4
  # lets you create a new value or data structure by combining values from the first
@@ -9,14 +9,7 @@ Puppet::Functions.create_function(:return, Puppet::Functions::InternalFunction)
9
9
  end
10
10
 
11
11
  def return_impl(value = nil)
12
- stacktrace = Puppet::Pops::PuppetStack.stacktrace()
13
- if stacktrace.size > 0
14
- file, line = stacktrace[0]
15
- else
16
- file = nil
17
- line = nil
18
- end
19
-
12
+ file, line = Puppet::Pops::PuppetStack.top_of_stack
20
13
  raise Puppet::Pops::Evaluator::Return.new(value, file, line)
21
14
  end
22
15
  end
@@ -1,5 +1,5 @@
1
1
  # Reverses the order of the elements of something that is iterable and optionally runs a
2
- # [lambda](https://docs.puppetlabs.com/puppet/latest/reference/lang_lambdas.html) for each
2
+ # [lambda](https://puppet.com/docs/puppet/latest/lang_lambdas.html) for each
3
3
  # element.
4
4
  #
5
5
  # This function takes one to two arguments:
@@ -0,0 +1,24 @@
1
+ # Returns an `Integer` value rounded to the nearest value.
2
+ # Takes a single `Numeric` value as an argument.
3
+ #
4
+ # @example 'rounding a value'
5
+ #
6
+ # ```puppet
7
+ # notice(round(2.9)) # would notice 3
8
+ # notice(round(2.1)) # would notice 2
9
+ # notice(round(-2.9)) # would notice -3
10
+ # ```
11
+ #
12
+ Puppet::Functions.create_function(:round) do
13
+ dispatch :on_numeric do
14
+ param 'Numeric', :val
15
+ end
16
+
17
+ def on_numeric(x)
18
+ if x > 0
19
+ Integer(x + 0.5)
20
+ else
21
+ Integer(x - 0.5)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,58 @@
1
+ # Strips trailing spaces from 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 removes all trailing ASCII white space characters such as space, tab, newline, and return.
7
+ # It does not remove other space-like characters like hard space (Unicode U+00A0). (Tip, `/^[[:space:]]/` regular expression
8
+ # matches all space-like characters).
9
+ # * For an `Iterable[Variant[String, Numeric]]` (for example an `Array`) each value is processed 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
+ # @example Removing trailing space from a String
14
+ # ```puppet
15
+ # "hello\n\t".lstrip()
16
+ # camelcase("hello\n\t")
17
+ # ```
18
+ # Would both result in `"hello"`
19
+ #
20
+ # @example Removing trailing space from strings in an Array
21
+ # ```puppet
22
+ # ["hello\n\t", "hi\n\t"].lstrip()
23
+ # lstrip(["hello\n\t", "hi\n\t"])
24
+ # ```
25
+ # Would both result in `['hello', 'hi']`
26
+ #
27
+ Puppet::Functions.create_function(:rstrip) do
28
+
29
+ dispatch :on_numeric do
30
+ param 'Numeric', :arg
31
+ end
32
+
33
+ dispatch :on_string do
34
+ param 'String', :arg
35
+ end
36
+
37
+ dispatch :on_iterable do
38
+ param 'Iterable[Variant[String, Numeric]]', :arg
39
+ end
40
+
41
+ # unit function - since the old implementation skipped Numeric values
42
+ def on_numeric(n)
43
+ n
44
+ end
45
+
46
+ def on_string(s)
47
+ s.rstrip
48
+ end
49
+
50
+ def on_iterable(a)
51
+ a.map {|x| do_rstrip(x) }
52
+ end
53
+
54
+ def do_rstrip(x)
55
+ # x can only be a String or Numeric because type constraints have been automatically applied
56
+ x.is_a?(String) ? x.rstrip : x
57
+ end
58
+ end
@@ -0,0 +1,15 @@
1
+ # The same as length() - returns the size of an Array, Hash, String, or Binary value.
2
+ #
3
+ # @since 6.0.0 - also supporting Binary
4
+ #
5
+ Puppet::Functions.create_function(:size) do
6
+ dispatch :generic_size do
7
+ param 'Variant[Collection, String, Binary]', :arg
8
+ end
9
+
10
+
11
+ def generic_size(arg)
12
+ call_function('length', arg)
13
+ end
14
+
15
+ end
@@ -0,0 +1,74 @@
1
+ # Sorts an Array numerically or lexicographically or the characters of a String lexicographically.
2
+ # Please note: This function is based on Ruby String comparison and as such may not be entirely UTF8 compatible.
3
+ # To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085.
4
+ #
5
+ # This function is compatible with the function sort() in stdlib.
6
+ # * Comparison of characters in a string always uses a system locale and may not be what is expected for a particular locale
7
+ # * Sorting is based on Ruby's <=> operator unless a lambda is given that performs the comparison.
8
+ # * comparison of strings is case dependent (use lambda with `compare($a,$b)` to ignore case)
9
+ # * comparison of mixed data types raises an error (if there is the need to sort mixed data types use a lambda)
10
+ #
11
+ # Also see the `compare()` function for information about comparable data types in general.
12
+ #
13
+ # @example Sorting a String
14
+ #
15
+ # ```puppet
16
+ # notice(sort("xadb")) # notices 'abdx'
17
+ # ```
18
+ #
19
+ # @example Sorting an Array
20
+ #
21
+ # ```puppet
22
+ # notice(sort([3,6,2])) # notices [2, 3, 6]
23
+ # ```
24
+ #
25
+ # @example Sorting with a lambda
26
+ #
27
+ # ```puppet
28
+ # notice(sort([3,6,2]) |$a,$b| { compare($a, $b) }) # notices [2, 3, 6]
29
+ # notice(sort([3,6,2]) |$a,$b| { compare($b, $a) }) # notices [6, 3, 2]
30
+ # ```
31
+ #
32
+ # @example Case independent sorting with a lambda
33
+ #
34
+ # ```puppet
35
+ # notice(sort(['A','b','C'])) # notices ['A', 'C', 'b']
36
+ # notice(sort(['A','b','C']) |$a,$b| { compare($a, $b) }) # notices ['A', 'b', 'C']
37
+ # notice(sort(['A','b','C']) |$a,$b| { compare($a, $b, true) }) # notices ['A', 'b', 'C']
38
+ # notice(sort(['A','b','C']) |$a,$b| { compare($a, $b, false) }) # notices ['A','C', 'b']
39
+ # ```
40
+ #
41
+ # @example Sorting Array with Numeric and String so that numbers are before strings
42
+ #
43
+ # ```puppet
44
+ # notice(sort(['b', 3, 'a', 2]) |$a, $b| {
45
+ # case [$a, $b] {
46
+ # [String, Numeric] : { 1 }
47
+ # [Numeric, String] : { -1 }
48
+ # default: { compare($a, $b) }
49
+ # }
50
+ # })
51
+ # ```
52
+ # Would notice [2,3,'a','b']
53
+ #
54
+ # @since 6.0.0 - supporting a lambda to do compare
55
+ #
56
+ Puppet::Functions.create_function(:sort) do
57
+ dispatch :sort_string do
58
+ param 'String', :string_value
59
+ optional_block_param 'Callable[2,2]', :block
60
+ end
61
+
62
+ dispatch :sort_array do
63
+ param 'Array', :array_value
64
+ optional_block_param 'Callable[2,2]', :block
65
+ end
66
+
67
+ def sort_string(s, &block)
68
+ sort_array(s.split(''), &block).join('')
69
+ end
70
+
71
+ def sort_array(a, &block)
72
+ a.sort(&block)
73
+ end
74
+ end
@@ -1,5 +1,5 @@
1
1
  # Provides stepping with given interval over elements in an iterable and optionally runs a
2
- # [lambda](https://docs.puppetlabs.com/puppet/latest/reference/lang_lambdas.html) for each
2
+ # [lambda](https://puppet.com/docs/puppet/latest/lang_lambdas.html) for each
3
3
  # element.
4
4
  #
5
5
  # This function takes two to three arguments:
@@ -202,13 +202,7 @@ Puppet::Functions.create_function(:strftime) do
202
202
  end
203
203
 
204
204
  def legacy_strftime(format, timezone = nil)
205
- stacktrace = Puppet::Pops::PuppetStack.stacktrace()
206
- if stacktrace.size > 0
207
- file, line = stacktrace[0]
208
- else
209
- file = nil
210
- line = nil
211
- end
205
+ file, line = Puppet::Pops::PuppetStack.top_of_stack
212
206
  Puppet.warn_once('deprecations', 'legacy#strftime',
213
207
  _('The argument signature (String format, [String timezone]) is deprecated for #strftime. See #strftime documentation and Timespan type for more info'),
214
208
  file, line)
@@ -0,0 +1,58 @@
1
+ # Strips leading and trailing spaces from 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 removes all leading and trailing ASCII white space characters such as space, tab, newline, and return.
7
+ # It does not remove other space-like characters like hard space (Unicode U+00A0). (Tip, `/^[[:space:]]/` regular expression
8
+ # matches all space-like characters).
9
+ # * For an `Iterable[Variant[String, Numeric]]` (for example an `Array`) each value is processed 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
+ # @example Removing leading and trailing space from a String
14
+ # ```puppet
15
+ # " hello\n\t".lstrip()
16
+ # camelcase(" hello\n\t")
17
+ # ```
18
+ # Would both result in `"hello"`
19
+ #
20
+ # @example Removing trailing space from strings in an Array
21
+ # ```puppet
22
+ # [" hello\n\t", " hi\n\t"].lstrip()
23
+ # lstrip([" hello\n\t", " hi\n\t"])
24
+ # ```
25
+ # Would both result in `['hello', 'hi']`
26
+ #
27
+ Puppet::Functions.create_function(:strip) do
28
+
29
+ dispatch :on_numeric do
30
+ param 'Numeric', :arg
31
+ end
32
+
33
+ dispatch :on_string do
34
+ param 'String', :arg
35
+ end
36
+
37
+ dispatch :on_iterable do
38
+ param 'Iterable[Variant[String, Numeric]]', :arg
39
+ end
40
+
41
+ # unit function - since the old implementation skipped Numeric values
42
+ def on_numeric(n)
43
+ n
44
+ end
45
+
46
+ def on_string(s)
47
+ s.strip
48
+ end
49
+
50
+ def on_iterable(a)
51
+ a.map {|x| do_strip(x) }
52
+ end
53
+
54
+ def do_strip(x)
55
+ # x can only be a String or Numeric because type constraints have been automatically applied
56
+ x.is_a?(String) ? x.strip : x
57
+ end
58
+ end