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
@@ -23,11 +23,12 @@ Puppet::Functions.create_function(:convert_to) do
23
23
  dispatch :convert_to do
24
24
  param 'Any', :value
25
25
  param 'Type', :type
26
+ optional_repeated_param 'Any', :args
26
27
  optional_block_param 'Callable[1,1]', :block
27
28
  end
28
29
 
29
- def convert_to(value, type, &block)
30
- result = call_function('new', type, value)
30
+ def convert_to(value, type, *args, &block)
31
+ result = call_function('new', type, value, *args)
31
32
  block_given? ? yield(result) : result
32
33
  end
33
34
  end
@@ -38,9 +38,29 @@ Puppet::Functions.create_function(:dig) do
38
38
  args.reduce(data) do | d, k |
39
39
  return nil if d.nil? || k.nil?
40
40
  if !(d.is_a?(Array) || d.is_a?(Hash))
41
- raise ArgumentError, _("The given data does not contain a Collection at %{walked_path}, got '%{klass}'") % { walked_path: walked_path, klass: d.class }
41
+ t = Puppet::Pops::Types::TypeCalculator.infer(d)
42
+ msg = _("The given data does not contain a Collection at %{walked_path}, got '%{type}'") % { walked_path: walked_path, type: t }
43
+ error_data = Puppet::DataTypes::Error.new(
44
+ msg,
45
+ 'SLICE_ERROR',
46
+ {'walked_path' => walked_path, 'value_type' => t},
47
+ 'EXPECTED_COLLECTION'
48
+ )
49
+ raise Puppet::ErrorWithData.new(error_data, msg)
42
50
  end
51
+
43
52
  walked_path << k
53
+ if d.is_a?(Array) && !k.is_a?(Integer)
54
+ t = Puppet::Pops::Types::TypeCalculator.infer(k)
55
+ msg = _("The given data requires an Integer index at %{walked_path}, got '%{type}'") % { walked_path: walked_path, type: t }
56
+ error_data = Puppet::DataTypes::Error.new(
57
+ msg,
58
+ 'SLICE_ERROR',
59
+ {'walked_path' => walked_path, 'index_type' => t},
60
+ 'EXPECTED_INTEGER_INDEX'
61
+ )
62
+ raise Puppet::ErrorWithData.new(error_data, msg)
63
+ end
44
64
  d[k]
45
65
  end
46
66
  end
@@ -0,0 +1,89 @@
1
+ # Converts a String, Array or Hash (recursively) into lower case.
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`, its lower case version is returned. This is done using Ruby system locale which handles some, but not all
7
+ # special international up-casing rules (for example German double-s ß is upcased to "SS", whereas upper case double-s
8
+ # is downcased to ß).
9
+ # * For `Array` and `Hash` the conversion to lower case is recursive and each key and value must be convertible by
10
+ # this function.
11
+ # * When a `Hash` is converted, some keys could result in the same key - in those cases, the
12
+ # latest key-value wins. For example if keys "aBC", and "abC" where both present, after downcase there would only be one
13
+ # key "abc".
14
+ # * If the value is `Numeric` it is simply returned (this is for backwards compatibility).
15
+ # * An error is raised for all other data types.
16
+ #
17
+ # Please note: This function relies directly on Ruby's String implementation and as such may not be entirely UTF8 compatible.
18
+ # To ensure best compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085.
19
+ #
20
+ # @example Converting a String to lower case
21
+ # ```puppet
22
+ # 'HELLO'.downcase()
23
+ # downcase('HEllO')
24
+ # ```
25
+ # Would both result in "hello"
26
+ #
27
+ # @example Converting an Array to lower case
28
+ # ```puppet
29
+ # ['A', 'B'].downcase()
30
+ # downcase(['A', 'B'])
31
+ # ```
32
+ # Would both result in ['a', 'b']
33
+ #
34
+ # @example Converting a Hash to lower case
35
+ # ```puppet
36
+ # {'A' => 'HEllO', 'B' => 'GOODBYE'}.downcase()
37
+ # ```
38
+ # Would result in `{'a' => 'hello', 'b' => 'goodbye'}`
39
+ #
40
+ # @example Converting a recursive structure
41
+ # ```puppet
42
+ # ['A', 'B', ['C', ['D']], {'X' => 'Y'}].downcase
43
+ # ```
44
+ # Would result in `['a', 'b', ['c', ['d']], {'x' => 'y'}]`
45
+ #
46
+ Puppet::Functions.create_function(:downcase) do
47
+ local_types do
48
+ type 'StringData = Variant[String, Numeric, Array[StringData], Hash[StringData, StringData]]'
49
+ end
50
+
51
+ dispatch :on_numeric do
52
+ param 'Numeric', :arg
53
+ end
54
+
55
+ dispatch :on_string do
56
+ param 'String', :arg
57
+ end
58
+
59
+ dispatch :on_array do
60
+ param 'Array[StringData]', :arg
61
+ end
62
+
63
+ dispatch :on_hash do
64
+ param 'Hash[StringData, StringData]', :arg
65
+ end
66
+
67
+ # unit function - since the old implementation skipped Numeric values
68
+ def on_numeric(n)
69
+ n
70
+ end
71
+
72
+ def on_string(s)
73
+ s.downcase
74
+ end
75
+
76
+ def on_array(a)
77
+ a.map {|x| do_downcase(x) }
78
+ end
79
+
80
+ def on_hash(h)
81
+ result = {}
82
+ h.each_pair {|k,v| result[do_downcase(k)] = do_downcase(v) }
83
+ result
84
+ end
85
+
86
+ def do_downcase(x)
87
+ x.is_a?(String) ? x.downcase : call_function('downcase', x)
88
+ end
89
+ end
@@ -1,4 +1,4 @@
1
- # Runs a [lambda](https://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, then returns the values unchanged.
3
3
  #
4
4
  # This function takes two mandatory arguments, in this order:
@@ -89,7 +89,7 @@
89
89
  #
90
90
  # For an example that demonstrates how to create multiple `file` resources using `each`,
91
91
  # see the Puppet
92
- # [iteration](https://docs.puppetlabs.com/puppet/latest/reference/lang_iteration.html)
92
+ # [iteration](https://puppet.com/docs/puppet/latest/lang_iteration.html)
93
93
  # documentation.
94
94
  #
95
95
  # @since 4.0.0
@@ -66,13 +66,11 @@ Puppet::Functions.create_function(:empty) do
66
66
  # (Yes, it is strange, but undef was passed as empty string in 3.x API)
67
67
  #
68
68
  def undef_empty(x)
69
- deprecation_warning_for('Undef')
70
69
  true
71
70
  end
72
71
 
73
72
  def deprecation_warning_for(arg_type)
74
- stacktrace = Puppet::Pops::PuppetStack.stacktrace()
75
- file, line = stacktrace[0] # defaults to nil
73
+ file, line = Puppet::Pops::PuppetStack.top_of_stack
76
74
  msg = _("Calling function empty() with %{arg_type} value is deprecated.") % { arg_type: arg_type }
77
75
  Puppet.warn_once('deprecations', "empty-from-#{file}-#{line}", msg, file, line)
78
76
  end
@@ -1,5 +1,5 @@
1
1
  # The `eyaml_lookup_key` is a hiera 5 `lookup_key` data provider function.
2
- # See [the configuration guide documentation](https://docs.puppet.com/puppet/latest/hiera_config_yaml_5.html#configuring-a-hierarchy-level-hiera-eyaml) for
2
+ # See [the configuration guide documentation](https://puppet.com/docs/puppet/latest/hiera_config_yaml_5.html#configuring-a-hierarchy-level-hiera-eyaml) for
3
3
  # how to use this function.
4
4
  #
5
5
  # @since 5.0.0
@@ -50,7 +50,9 @@ Puppet::Functions.create_function(:eyaml_lookup_key) do
50
50
  if data.is_a?(Hash)
51
51
  Puppet::Pops::Lookup::HieraConfig.symkeys_to_string(data)
52
52
  else
53
- Puppet.warning(_("%{path}: file does not contain a valid yaml hash") % { path: path })
53
+ msg = _("%{path}: file does not contain a valid yaml hash") % { path: path }
54
+ raise Puppet::DataBinding::LookupError, msg if Puppet[:strict] == :error && data != false
55
+ Puppet.warning(msg)
54
56
  {}
55
57
  end
56
58
  rescue YAML::SyntaxError => ex
@@ -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 and returns an array or hash containing any elements
3
3
  # for which the lambda evaluates to `true`.
4
4
  #
@@ -59,7 +59,7 @@
59
59
  # @example Using the `filter` function with a hash and a two-parameter lambda
60
60
  #
61
61
  # ```puppet
62
- # # For the hash $data, return a hash of all keys that both end with "berry" and have
62
+ # # For the hash $data, return a hash of all keys that both end with "berry" and have
63
63
  # # values less than or equal to 1
64
64
  # $data = { "orange" => 0, "blueberry" => 1, "raspberry" => 2 }
65
65
  # $filtered_data = $data.filter |$keys, $values| { $keys =~ /berry$/ and $values <= 1 }
@@ -0,0 +1,37 @@
1
+ # Returns the largest `Integer` less 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(:floor) 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.floor
23
+ end
24
+
25
+ def on_string(x)
26
+ Puppet.warn_once('deprecations', 'floor_function_numeric_coerce_string',
27
+ _("The floor() function's auto conversion of String to Float is deprecated - change to convert input before calling"))
28
+
29
+ begin
30
+ Float(x).floor
31
+ rescue TypeError, ArgumentError => _e
32
+ # TRANSLATORS: 'floor' is a name and should not be translated
33
+ raise(ArgumentError, _('floor(): cannot convert given value to a floating point value.'))
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,150 @@
1
+ # Digs into a value with dot notation to get a value from within a structure.
2
+ #
3
+ # **To dig into a given value**, call the function with (at least) two arguments:
4
+ #
5
+ # * The **first** argument must be an Array, or Hash. Value can also be `undef`
6
+ # (which also makes the result `undef` unless a _default value_ is given).
7
+ # * The **second** argument must be a _dot notation navigation string_.
8
+ # * The **optional third** argument can be any type of value and it is used
9
+ # as the _default value_ if the function would otherwise return `undef`.
10
+ # * An **optional lambda** for error handling taking one `Error` argument.
11
+ #
12
+ # **Dot notation navigation string** -
13
+ # The dot string consists of period `.` separated segments where each
14
+ # segment is either the index into an array or the value of a hash key.
15
+ # If a wanted key contains a period it must be quoted to avoid it being
16
+ # taken as a segment separator. Quoting can be done with either
17
+ # single quotes `'` or double quotes `"`. If a segment is
18
+ # a decimal number it is converted to an Integer index. This conversion
19
+ # can be prevented by quoting the value.
20
+ #
21
+ # @example Navigating into a value
22
+ # ```puppet
23
+ # #get($facts, 'os.family')
24
+ # $facts.get('os.family')
25
+ # ```
26
+ # Would both result in the value of $facts['os']['family']
27
+ #
28
+ # @example Getting the value from an expression
29
+ # ```puppet
30
+ # get([1,2,[{'name' =>'waldo'}]], '2.0.name')
31
+ # ```
32
+ # Would result in 'waldo'
33
+ #
34
+ # @example Using a default value
35
+ # ```puppet
36
+ # get([1,2,[{'name' =>'waldo'}]], '2.1.name', 'not waldo')
37
+ #
38
+ # ```
39
+ # Would result in 'not waldo'
40
+ #
41
+ # @example Quoting a key with period
42
+ # ```puppet
43
+ # $x = [1, 2, { 'readme.md' => "This is a readme."}]
44
+ # $x.get('2."readme.md"')
45
+ # ```
46
+ #
47
+ # @example Quoting a numeric string
48
+ # ```puppet
49
+ # $x = [1, 2, { '10' => "ten"}]
50
+ # $x.get('2."0"')
51
+ # ```
52
+ #
53
+ # **Error Handling** - There are two types of common errors that can
54
+ # be handled by giving the function a code block to execute.
55
+ # (A third kind or error; when the navigation string has syntax errors
56
+ # (for example an empty segment or unbalanced quotes) will always raise
57
+ # an error).
58
+ #
59
+ # The given block will be given an instance of the `Error` data type,
60
+ # and it has methods to extract `msg`, `issue_code`, `kind`, and
61
+ # `details`.
62
+ #
63
+ # The `msg` will be a preformatted message describing the error.
64
+ # This is the error message that would have surfaced if there was
65
+ # no block to handle the error.
66
+ #
67
+ # The `kind` is the string `'SLICE_ERROR'` for both kinds of errors,
68
+ # and the `issue_code` is either the string `'EXPECTED_INTEGER_INDEX'`
69
+ # for an attempt to index into an array with a String,
70
+ # or `'EXPECTED_COLLECTION'` for an attempt to index into something that
71
+ # is not a Collection.
72
+ #
73
+ # The `details` is a Hash that for both issue codes contain the
74
+ # entry `'walked_path'` which is an Array with each key in the
75
+ # progression of the dig up to the place where the error occurred.
76
+ #
77
+ # For an `EXPECTED_INTEGER_INDEX`-issue the detail `'index_type'` is
78
+ # set to the data type of the index value and for an
79
+ # `'EXPECTED_COLLECTION'`-issue the detail `'value_type'` is set
80
+ # to the type of the value.
81
+ #
82
+ # The logic in the error handling block can inspect the details,
83
+ # and either call `fail()` with a custom error message or produce
84
+ # the wanted value.
85
+ #
86
+ # If the block produces `undef` it will not be replaced with a
87
+ # given default value.
88
+ #
89
+ # @example Ensure `undef` result on error
90
+ # ```puppet
91
+ # $x = 'blue'
92
+ # $x.get('0.color', 'green') |$error| { undef } # result is undef
93
+ #
94
+ # $y = ['blue']
95
+ # $y.get('color', 'green') |$error| { undef } # result is undef
96
+ # ```
97
+ #
98
+ # @example Accessing information in the Error
99
+ # ```puppet
100
+ # $x = [1, 2, ['blue']]
101
+ # $x.get('2.color') |$error| {
102
+ # notice("Walked path is ${error.details['walked_path']}")
103
+ # }
104
+ # ```
105
+ # Would notice `Walked path is [2, color]`
106
+ #
107
+ # Also see:
108
+ # * `getvar()` that takes the first segment to be the name of a variable
109
+ # and then delegates to this function.
110
+ # * `dig()` function which is similar but uses an
111
+ # array of navigation values instead of a dot notation string.
112
+ #
113
+ # @since 6.0.0
114
+ #
115
+ Puppet::Functions.create_function(:get, Puppet::Functions::InternalFunction) do
116
+ dispatch :get_from_value do
117
+ param 'Any', :value
118
+ param 'String', :dotted_string
119
+ optional_param 'Any', :default_value
120
+ optional_block_param 'Callable[1,1]', :block
121
+ end
122
+
123
+ # Gets a result from given value and a navigation string
124
+ #
125
+ def get_from_value(value, navigation, default_value = nil, &block)
126
+ return default_value if value.nil?
127
+ return value if navigation.empty?
128
+
129
+ # Note: split_key always processes the initial segment as a string even if it could be an integer.
130
+ # This since it is designed for lookup keys. For a numeric first segment
131
+ # like '0.1' the wanted result is [0,1], not ["0", 1]. The workaround here is to
132
+ # prefix the navigation with "x." thus giving split_key a first segment that is a string.
133
+ # The fake segment is then dropped.
134
+ segments = split_key("x." + navigation) {|err| _("Syntax error in dotted-navigation string")}
135
+ segments.shift
136
+
137
+ begin
138
+ result = call_function('dig', value, *segments)
139
+ return result.nil? ? default_value : result
140
+ rescue Puppet::ErrorWithData => e
141
+ if block_given?
142
+ yield(e.error_data)
143
+ else
144
+ raise e
145
+ end
146
+ end
147
+ end
148
+ # reuse the split_key parser used also by lookup
149
+ include Puppet::Pops::Lookup::SubLookup
150
+ end
@@ -0,0 +1,87 @@
1
+ # Digs into a variable with dot notation to get a value from a structure.
2
+ #
3
+ # **To get the value from a variable** (that may or may not exist), call the function with
4
+ # one or two arguments:
5
+ #
6
+ # * The **first** argument must be a string, and must start with a variable name without leading `$`,
7
+ # for example `get('facts')`. The variable name can be followed
8
+ # by a _dot notation navigation string_ to dig out a value in the array or hash value
9
+ # of the variable.
10
+ # * The **optional second** argument can be any type of value and it is used as the
11
+ # _default value_ if the function would otherwise return `undef`.
12
+ # * An **optional lambda** for error handling taking one `Error` argument.
13
+ #
14
+ # **Dot notation navigation string** -
15
+ # The dot string consists of period `.` separated segments where each
16
+ # segment is either the index into an array or the value of a hash key.
17
+ # If a wanted key contains a period it must be quoted to avoid it being
18
+ # taken as a segment separator. Quoting can be done with either
19
+ # single quotes `'` or double quotes `"`. If a segment is
20
+ # a decimal number it is converted to an Integer index. This conversion
21
+ # can be prevented by quoting the value.
22
+ #
23
+ # @example Getting the value of a variable
24
+ # ```puppet
25
+ # getvar('facts') # results in the value of $facts
26
+ # ```
27
+ #
28
+ # @example Navigating into a variable
29
+ # ```puppet
30
+ # getvar('facts.os.family') # results in the value of $facts['os']['family']
31
+ # ```
32
+ #
33
+ # @example Using a default value
34
+ # ```puppet
35
+ # $x = [1,2,[{'name' =>'waldo'}]]
36
+ # getvar('x.2.1.name', 'not waldo')
37
+ # # results in 'not waldo'
38
+ # ```
39
+ #
40
+ # For further examples and how to perform error handling, see the `get()` function
41
+ # which this function delegates to after having resolved the variable value.
42
+ #
43
+ # @since 6.0.0 - the ability to dig into the variable's value with dot notation.
44
+ #
45
+ Puppet::Functions.create_function(:getvar, Puppet::Functions::InternalFunction) do
46
+ dispatch :get_from_navigation do
47
+ scope_param
48
+ param 'Pattern[/\A(?:::)?(?:[a-z]\w*::)*[a-z_]\w*(?:\.|\Z)/]', :get_string
49
+ optional_param 'Any', :default_value
50
+ optional_block_param 'Callable[1,1]', :block
51
+ end
52
+
53
+ argument_mismatch :invalid_variable_error do
54
+ param 'String', :get_string
55
+ optional_param 'Any', :default_value
56
+ optional_block_param 'Callable', :block
57
+ end
58
+
59
+ def invalid_variable_error(navigation, default_value=nil, &block)
60
+ _("The given string does not start with a valid variable name")
61
+ end
62
+
63
+ # Gets a result from a navigation string starting with $var
64
+ #
65
+ def get_from_navigation(scope, navigation, default_value = nil, &block)
66
+ # asserted to start with a valid variable name - dig out the variable
67
+ matches = navigation.match(/^((::)?(\w+::)*\w+)(.*)\z/)
68
+ navigation = matches[4]
69
+ if navigation[0] == '.'
70
+ navigation = navigation[1..-1]
71
+ else
72
+ unless navigation.empty?
73
+ raise ArgumentError, _("First character after var name in get string must be a '.' - got %{char}") % {char: navigation[0]}
74
+ end
75
+ end
76
+ get_from_var_name(scope, matches[1], navigation, default_value, &block)
77
+ end
78
+
79
+ # Gets a result from a $var name and a navigation string
80
+ #
81
+ def get_from_var_name(scope, var_string, navigation, default_value = nil, &block)
82
+ catch(:undefined_variable) do
83
+ return call_function_with_scope(scope,'get', scope.lookupvar(var_string), navigation, default_value, &block)
84
+ end
85
+ default_value
86
+ end
87
+ end