puppet 5.3.7-x64-mingw32 → 5.4.0-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (454) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +42 -29
  3. data/README.md +8 -6
  4. data/ext/cert_inspector +2 -2
  5. data/ext/envpuppet +1 -1
  6. data/ext/gentoo/init.d/puppetmaster +4 -4
  7. data/ext/ips/puppet-agent +11 -11
  8. data/ext/ips/puppet-master +11 -11
  9. data/ext/puppet-test +1 -2
  10. data/ext/redhat/client.init +2 -2
  11. data/ext/redhat/logrotate +1 -1
  12. data/ext/solaris/smf/puppet +11 -11
  13. data/ext/solaris/smf/svc-puppetd +5 -5
  14. data/ext/solaris/smf/svc-puppetmasterd +5 -5
  15. data/ext/windows/service/daemon.rb +1 -1
  16. data/install.rb +2 -3
  17. data/lib/puppet/agent.rb +1 -1
  18. data/lib/puppet/application/cert.rb +1 -3
  19. data/lib/puppet/application/describe.rb +0 -1
  20. data/lib/puppet/application/device.rb +12 -99
  21. data/lib/puppet/application/filebucket.rb +32 -11
  22. data/lib/puppet/application/lookup.rb +1 -11
  23. data/lib/puppet/application/script.rb +261 -0
  24. data/lib/puppet/configurer.rb +3 -4
  25. data/lib/puppet/configurer/plugin_handler.rb +26 -9
  26. data/lib/puppet/context.rb +1 -1
  27. data/lib/puppet/datatypes.rb +213 -0
  28. data/lib/puppet/datatypes/error.rb +21 -0
  29. data/lib/puppet/datatypes/impl/error.rb +40 -0
  30. data/lib/puppet/defaults.rb +51 -20
  31. data/lib/puppet/environments.rb +17 -0
  32. data/lib/puppet/error.rb +17 -0
  33. data/lib/puppet/etc.rb +2 -2
  34. data/lib/puppet/external/pson/pure/generator.rb +1 -1
  35. data/lib/puppet/external/pson/pure/parser.rb +1 -1
  36. data/lib/puppet/face/config.rb +45 -0
  37. data/lib/puppet/face/epp.rb +3 -3
  38. data/lib/puppet/face/help/action.erb +3 -0
  39. data/lib/puppet/face/module/build.rb +1 -0
  40. data/lib/puppet/face/module/generate.rb +5 -0
  41. data/lib/puppet/face/module/install.rb +1 -0
  42. data/lib/puppet/face/module/search.rb +6 -2
  43. data/lib/puppet/face/module/uninstall.rb +1 -0
  44. data/lib/puppet/face/module/upgrade.rb +1 -0
  45. data/lib/puppet/face/parser.rb +0 -1
  46. data/lib/puppet/face/plugin.rb +1 -3
  47. data/lib/puppet/feature/base.rb +1 -1
  48. data/lib/puppet/feature/bolt.rb +3 -0
  49. data/lib/puppet/file_bucket/dipper.rb +1 -2
  50. data/lib/puppet/file_serving/http_metadata.rb +1 -1
  51. data/lib/puppet/file_system/uniquefile.rb +2 -2
  52. data/lib/puppet/forge.rb +6 -0
  53. data/lib/puppet/functions.rb +70 -88
  54. data/lib/puppet/functions/all.rb +6 -2
  55. data/lib/puppet/functions/annotate.rb +1 -1
  56. data/lib/puppet/functions/any.rb +7 -3
  57. data/lib/puppet/functions/contain.rb +6 -0
  58. data/lib/puppet/functions/convert_to.rb +32 -0
  59. data/lib/puppet/functions/defined.rb +0 -3
  60. data/lib/puppet/functions/each.rb +10 -6
  61. data/lib/puppet/functions/filter.rb +16 -10
  62. data/lib/puppet/functions/find_file.rb +0 -1
  63. data/lib/puppet/functions/include.rb +6 -0
  64. data/lib/puppet/functions/map.rb +12 -9
  65. data/lib/puppet/functions/module_directory.rb +41 -0
  66. data/lib/puppet/functions/new.rb +1 -4
  67. data/lib/puppet/functions/regsubst.rb +1 -1
  68. data/lib/puppet/functions/require.rb +6 -0
  69. data/lib/puppet/generate/type.rb +1 -1
  70. data/lib/puppet/gettext/config.rb +2 -2
  71. data/lib/puppet/gettext/stubs.rb +1 -1
  72. data/lib/puppet/indirector/catalog/compiler.rb +0 -1
  73. data/lib/puppet/indirector/file_bucket_file/file.rb +6 -2
  74. data/lib/puppet/indirector/file_server.rb +1 -1
  75. data/lib/puppet/indirector/node/ldap.rb +19 -3
  76. data/lib/puppet/indirector/request.rb +10 -6
  77. data/lib/puppet/indirector/rest.rb +11 -12
  78. data/lib/puppet/info_service/class_information_service.rb +1 -1
  79. data/lib/puppet/interface/action.rb +11 -0
  80. data/lib/puppet/interface/action_builder.rb +8 -0
  81. data/lib/puppet/interface/option_manager.rb +1 -1
  82. data/lib/puppet/loaders.rb +2 -0
  83. data/lib/puppet/module.rb +6 -2
  84. data/lib/puppet/module_tool/applications/builder.rb +4 -0
  85. data/lib/puppet/module_tool/applications/installer.rb +3 -0
  86. data/lib/puppet/module_tool/applications/uninstaller.rb +3 -0
  87. data/lib/puppet/module_tool/applications/unpacker.rb +1 -1
  88. data/lib/puppet/module_tool/applications/upgrader.rb +3 -0
  89. data/lib/puppet/module_tool/installed_modules.rb +1 -1
  90. data/lib/puppet/module_tool/metadata.rb +0 -1
  91. data/lib/puppet/network/authstore.rb +1 -1
  92. data/lib/puppet/network/http/api/indirected_routes.rb +1 -1
  93. data/lib/puppet/network/http/connection.rb +1 -9
  94. data/lib/puppet/network/http/factory.rb +0 -3
  95. data/lib/puppet/network/http/webrick.rb +1 -0
  96. data/lib/puppet/network/rights.rb +1 -1
  97. data/lib/puppet/node.rb +53 -0
  98. data/lib/puppet/node/environment.rb +1 -1
  99. data/lib/puppet/parameter/boolean.rb +1 -1
  100. data/lib/puppet/parser.rb +1 -0
  101. data/lib/puppet/parser/abstract_compiler.rb +36 -0
  102. data/lib/puppet/parser/ast/branch.rb +1 -1
  103. data/lib/puppet/parser/ast/pops_bridge.rb +8 -52
  104. data/lib/puppet/parser/compiler.rb +4 -54
  105. data/lib/puppet/parser/functions.rb +0 -1
  106. data/lib/puppet/parser/functions/create_resources.rb +6 -0
  107. data/lib/puppet/parser/functions/fqdn_rand.rb +6 -2
  108. data/lib/puppet/parser/functions/inline_template.rb +6 -0
  109. data/lib/puppet/parser/functions/new.rb +47 -32
  110. data/lib/puppet/parser/functions/realize.rb +6 -0
  111. data/lib/puppet/parser/functions/return.rb +1 -22
  112. data/lib/puppet/parser/functions/reverse_each.rb +1 -1
  113. data/lib/puppet/parser/functions/scanf.rb +1 -1
  114. data/lib/puppet/parser/functions/sha256.rb +5 -0
  115. data/lib/puppet/parser/functions/tag.rb +6 -0
  116. data/lib/puppet/parser/functions/tagged.rb +6 -0
  117. data/lib/puppet/parser/functions/template.rb +5 -0
  118. data/lib/puppet/parser/scope.rb +28 -4
  119. data/lib/puppet/parser/script_compiler.rb +118 -0
  120. data/lib/puppet/parser/type_loader.rb +1 -1
  121. data/lib/puppet/pops.rb +1 -1
  122. data/lib/puppet/pops/evaluator/access_operator.rb +38 -4
  123. data/lib/puppet/pops/evaluator/closure.rb +12 -4
  124. data/lib/puppet/pops/evaluator/compare_operator.rb +4 -4
  125. data/lib/puppet/pops/evaluator/epp_evaluator.rb +13 -0
  126. data/lib/puppet/pops/evaluator/evaluator_impl.rb +38 -10
  127. data/lib/puppet/pops/evaluator/literal_evaluator.rb +1 -1
  128. data/lib/puppet/pops/evaluator/runtime3_converter.rb +1 -1
  129. data/lib/puppet/pops/evaluator/runtime3_support.rb +2 -3
  130. data/lib/puppet/pops/functions/dispatch.rb +6 -5
  131. data/lib/puppet/pops/functions/function.rb +2 -2
  132. data/lib/puppet/pops/issues.rb +34 -2
  133. data/lib/puppet/pops/loader/base_loader.rb +10 -0
  134. data/lib/puppet/pops/loader/dependency_loader.rb +7 -0
  135. data/lib/puppet/pops/loader/loader.rb +21 -2
  136. data/lib/puppet/pops/loader/loader_paths.rb +180 -30
  137. data/lib/puppet/pops/loader/module_loaders.rb +202 -33
  138. data/lib/puppet/pops/loader/puppet_plan_instantiator.rb +84 -0
  139. data/lib/puppet/pops/loader/puppet_resource_type_impl_instantiator.rb +9 -9
  140. data/lib/puppet/pops/loader/ruby_data_type_instantiator.rb +40 -0
  141. data/lib/puppet/pops/loader/runtime3_type_loader.rb +6 -1
  142. data/lib/puppet/pops/loader/static_loader.rb +23 -8
  143. data/lib/puppet/pops/loader/task_instantiator.rb +69 -0
  144. data/lib/puppet/pops/loader/type_definition_instantiator.rb +4 -0
  145. data/lib/puppet/pops/loaders.rb +122 -11
  146. data/lib/puppet/pops/lookup/data_dig_function_provider.rb +1 -1
  147. data/lib/puppet/pops/lookup/interpolation.rb +1 -1
  148. data/lib/puppet/pops/lookup/lookup_adapter.rb +0 -1
  149. data/lib/puppet/pops/model/ast.pp +3 -0
  150. data/lib/puppet/pops/model/ast.rb +34 -1
  151. data/lib/puppet/pops/model/factory.rb +30 -3
  152. data/lib/puppet/pops/model/model_label_provider.rb +1 -0
  153. data/lib/puppet/pops/model/model_tree_dumper.rb +12 -1
  154. data/lib/puppet/pops/model/tree_dumper.rb +1 -1
  155. data/lib/puppet/pops/parser/code_merger.rb +2 -2
  156. data/lib/puppet/pops/parser/egrammar.ra +44 -15
  157. data/lib/puppet/pops/parser/eparser.rb +1687 -1571
  158. data/lib/puppet/pops/parser/epp_support.rb +1 -3
  159. data/lib/puppet/pops/parser/evaluating_parser.rb +1 -1
  160. data/lib/puppet/pops/parser/interpolation_support.rb +2 -2
  161. data/lib/puppet/pops/parser/lexer2.rb +4 -4
  162. data/lib/puppet/pops/parser/lexer_support.rb +2 -2
  163. data/lib/puppet/pops/parser/locatable.rb +1 -1
  164. data/lib/puppet/pops/parser/locator.rb +7 -13
  165. data/lib/puppet/pops/parser/parser_support.rb +3 -3
  166. data/lib/puppet/pops/parser/slurp_support.rb +0 -3
  167. data/lib/puppet/pops/pcore.rb +45 -0
  168. data/lib/puppet/pops/resource/param.rb +1 -1
  169. data/lib/puppet/pops/resource/resource_type_impl.rb +1 -1
  170. data/lib/puppet/pops/serialization/abstract_reader.rb +4 -0
  171. data/lib/puppet/pops/serialization/abstract_writer.rb +6 -0
  172. data/lib/puppet/pops/serialization/extension.rb +1 -0
  173. data/lib/puppet/pops/serialization/from_data_converter.rb +64 -10
  174. data/lib/puppet/pops/serialization/json_path.rb +2 -1
  175. data/lib/puppet/pops/serialization/object.rb +3 -4
  176. data/lib/puppet/pops/serialization/serializer.rb +2 -1
  177. data/lib/puppet/pops/serialization/to_data_converter.rb +7 -3
  178. data/lib/puppet/pops/time/timespan.rb +1 -1
  179. data/lib/puppet/pops/types/iterable.rb +38 -9
  180. data/lib/puppet/pops/types/p_init_type.rb +1 -1
  181. data/lib/puppet/pops/types/p_meta_type.rb +4 -0
  182. data/lib/puppet/pops/types/p_object_type.rb +146 -14
  183. data/lib/puppet/pops/types/p_object_type_extension.rb +218 -0
  184. data/lib/puppet/pops/types/p_sem_ver_range_type.rb +0 -1
  185. data/lib/puppet/pops/types/p_sem_ver_type.rb +10 -2
  186. data/lib/puppet/pops/types/p_type_set_type.rb +0 -1
  187. data/lib/puppet/pops/types/p_uri_type.rb +190 -0
  188. data/lib/puppet/pops/types/puppet_object.rb +15 -1
  189. data/lib/puppet/pops/types/ruby_generator.rb +46 -54
  190. data/lib/puppet/pops/types/string_converter.rb +22 -1
  191. data/lib/puppet/pops/types/type_acceptor.rb +1 -1
  192. data/lib/puppet/pops/types/type_calculator.rb +13 -4
  193. data/lib/puppet/pops/types/type_factory.rb +29 -5
  194. data/lib/puppet/pops/types/type_formatter.rb +67 -4
  195. data/lib/puppet/pops/types/type_parser.rb +92 -4
  196. data/lib/puppet/pops/types/type_with_members.rb +43 -0
  197. data/lib/puppet/pops/types/types.rb +212 -80
  198. data/lib/puppet/pops/validation/checker4_0.rb +10 -6
  199. data/lib/puppet/pops/validation/tasks_checker.rb +60 -0
  200. data/lib/puppet/pops/validation/validator_factory_4_0.rb +6 -1
  201. data/lib/puppet/property.rb +1 -1
  202. data/lib/puppet/provider.rb +18 -8
  203. data/lib/puppet/provider/augeas/augeas.rb +3 -4
  204. data/lib/puppet/provider/exec.rb +0 -2
  205. data/lib/puppet/provider/group/groupadd.rb +25 -1
  206. data/lib/puppet/provider/group/windows_adsi.rb +7 -4
  207. data/lib/puppet/provider/mount.rb +25 -8
  208. data/lib/puppet/provider/nameservice.rb +9 -4
  209. data/lib/puppet/provider/nameservice/directoryservice.rb +3 -3
  210. data/lib/puppet/provider/nameservice/objectadd.rb +13 -24
  211. data/lib/puppet/provider/nameservice/pw.rb +14 -14
  212. data/lib/puppet/provider/package/appdmg.rb +0 -1
  213. data/lib/puppet/provider/package/apple.rb +0 -1
  214. data/lib/puppet/provider/package/gem.rb +2 -2
  215. data/lib/puppet/provider/package/macports.rb +2 -2
  216. data/lib/puppet/provider/package/pkg.rb +3 -0
  217. data/lib/puppet/provider/package/pkgdmg.rb +0 -1
  218. data/lib/puppet/provider/package/portage.rb +0 -1
  219. data/lib/puppet/provider/package/yum.rb +23 -8
  220. data/lib/puppet/provider/package/zypper.rb +2 -2
  221. data/lib/puppet/provider/scheduled_task/win32_taskscheduler.rb +2 -2
  222. data/lib/puppet/provider/service/init.rb +1 -0
  223. data/lib/puppet/provider/service/launchd.rb +6 -7
  224. data/lib/puppet/provider/service/redhat.rb +3 -2
  225. data/lib/puppet/provider/service/systemd.rb +2 -2
  226. data/lib/puppet/provider/ssh_authorized_key/parsed.rb +1 -1
  227. data/lib/puppet/provider/user/aix.rb +3 -2
  228. data/lib/puppet/provider/user/openbsd.rb +1 -1
  229. data/lib/puppet/provider/user/pw.rb +1 -1
  230. data/lib/puppet/provider/user/user_role_add.rb +7 -1
  231. data/lib/puppet/provider/user/useradd.rb +36 -6
  232. data/lib/puppet/provider/user/windows_adsi.rb +1 -1
  233. data/lib/puppet/provider/yumrepo/inifile.rb +2 -4
  234. data/lib/puppet/provider/zfs/zfs.rb +23 -3
  235. data/lib/puppet/provider/zpool/zpool.rb +1 -1
  236. data/lib/puppet/reference/configuration.rb +0 -2
  237. data/lib/puppet/reference/type.rb +0 -1
  238. data/lib/puppet/resource.rb +1 -2
  239. data/lib/puppet/resource/catalog.rb +1 -1
  240. data/lib/puppet/resource/status.rb +0 -1
  241. data/lib/puppet/resource/type.rb +4 -4
  242. data/lib/puppet/resource/type_collection.rb +1 -1
  243. data/lib/puppet/settings/base_setting.rb +1 -1
  244. data/lib/puppet/settings/environment_conf.rb +0 -1
  245. data/lib/puppet/settings/ini_file.rb +66 -12
  246. data/lib/puppet/ssl/certificate_authority.rb +1 -1
  247. data/lib/puppet/ssl/certificate_request.rb +2 -2
  248. data/lib/puppet/ssl/certificate_revocation_list.rb +2 -1
  249. data/lib/puppet/ssl/certificate_signer.rb +11 -0
  250. data/lib/puppet/ssl/host.rb +2 -2
  251. data/lib/puppet/syntax_checkers/base64.rb +1 -1
  252. data/lib/puppet/transaction.rb +37 -14
  253. data/lib/puppet/transaction/report.rb +3 -1
  254. data/lib/puppet/type.rb +17 -4
  255. data/lib/puppet/type/cron.rb +1 -1
  256. data/lib/puppet/type/exec.rb +5 -4
  257. data/lib/puppet/type/file.rb +3 -3
  258. data/lib/puppet/type/file/checksum.rb +7 -1
  259. data/lib/puppet/type/file/checksum_value.rb +4 -3
  260. data/lib/puppet/type/group.rb +3 -0
  261. data/lib/puppet/type/k5login.rb +101 -0
  262. data/lib/puppet/type/macauthorization.rb +1 -1
  263. data/lib/puppet/type/mount.rb +6 -2
  264. data/lib/puppet/type/tidy.rb +6 -4
  265. data/lib/puppet/type/user.rb +26 -39
  266. data/lib/puppet/type/yumrepo.rb +9 -0
  267. data/lib/puppet/type/zfs.rb +4 -0
  268. data/lib/puppet/util.rb +8 -15
  269. data/lib/puppet/util/character_encoding.rb +2 -2
  270. data/lib/puppet/util/checksums.rb +82 -1
  271. data/lib/puppet/util/errors.rb +0 -2
  272. data/lib/puppet/util/filetype.rb +2 -2
  273. data/lib/puppet/util/json_lockfile.rb +1 -1
  274. data/lib/puppet/util/log.rb +1 -1
  275. data/lib/puppet/util/log/destinations.rb +10 -1
  276. data/lib/puppet/util/monkey_patches.rb +1 -1
  277. data/lib/puppet/util/network_device/cisco/device.rb +5 -5
  278. data/lib/puppet/util/network_device/config.rb +2 -3
  279. data/lib/puppet/util/platform.rb +13 -0
  280. data/lib/puppet/util/plist.rb +4 -4
  281. data/lib/puppet/util/rdoc/generators/puppet_generator.rb +2 -2
  282. data/lib/puppet/util/rdoc/parser/puppet_parser_rdoc2.rb +1 -1
  283. data/lib/puppet/util/reference.rb +8 -1
  284. data/lib/puppet/util/windows/adsi.rb +18 -15
  285. data/lib/puppet/util/windows/principal.rb +6 -7
  286. data/lib/puppet/util/windows/process.rb +1 -1
  287. data/lib/puppet/util/windows/registry.rb +2 -2
  288. data/lib/puppet/util/windows/sid.rb +7 -62
  289. data/lib/puppet/vendor/deep_merge/README.md +2 -2
  290. data/lib/puppet/vendor/pathspec/lib/pathspec/gitignorespec.rb +18 -18
  291. data/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/version.rb +2 -2
  292. data/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/version_range.rb +5 -5
  293. data/lib/puppet/vendor/semantic_puppet/locales/config.yaml +1 -1
  294. data/lib/puppet/version.rb +1 -1
  295. data/lib/puppet_pal.rb +874 -0
  296. data/locales/ja/puppet.po +140 -163
  297. data/locales/puppet.pot +940 -597
  298. data/man/man5/puppet.conf.5 +16 -91
  299. data/man/man8/puppet-agent.8 +2 -6
  300. data/man/man8/puppet-apply.8 +2 -2
  301. data/man/man8/puppet-ca.8 +1 -1
  302. data/man/man8/puppet-catalog.8 +1 -1
  303. data/man/man8/puppet-cert.8 +1 -1
  304. data/man/man8/puppet-certificate.8 +1 -1
  305. data/man/man8/puppet-certificate_request.8 +1 -1
  306. data/man/man8/puppet-certificate_revocation_list.8 +1 -1
  307. data/man/man8/puppet-config.8 +1 -1
  308. data/man/man8/puppet-describe.8 +1 -1
  309. data/man/man8/puppet-device.8 +11 -33
  310. data/man/man8/puppet-doc.8 +1 -1
  311. data/man/man8/puppet-epp.8 +1 -1
  312. data/man/man8/puppet-facts.8 +1 -1
  313. data/man/man8/puppet-filebucket.8 +4 -22
  314. data/man/man8/puppet-generate.8 +1 -1
  315. data/man/man8/puppet-help.8 +1 -1
  316. data/man/man8/puppet-key.8 +1 -1
  317. data/man/man8/puppet-lookup.8 +1 -1
  318. data/man/man8/puppet-man.8 +1 -1
  319. data/man/man8/puppet-master.8 +1 -1
  320. data/man/man8/puppet-module.8 +2 -11
  321. data/man/man8/puppet-node.8 +1 -1
  322. data/man/man8/puppet-parser.8 +1 -1
  323. data/man/man8/puppet-plugin.8 +1 -1
  324. data/man/man8/puppet-report.8 +1 -1
  325. data/man/man8/puppet-resource.8 +1 -1
  326. data/man/man8/puppet-status.8 +1 -1
  327. data/man/man8/puppet.8 +2 -2
  328. data/spec/integration/application/lookup_spec.rb +0 -21
  329. data/spec/integration/parser/compiler_spec.rb +18 -0
  330. data/spec/integration/parser/script_compiler_spec.rb +113 -0
  331. data/spec/integration/provider/mount_spec.rb +2 -0
  332. data/spec/integration/type/file_spec.rb +11 -3
  333. data/spec/integration/util/windows/adsi_spec.rb +1 -86
  334. data/spec/integration/util/windows/principal_spec.rb +1 -10
  335. data/spec/shared_contexts/checksum.rb +4 -1
  336. data/spec/shared_contexts/digests.rb +46 -1
  337. data/spec/shared_contexts/types_setup.rb +8 -3
  338. data/spec/unit/agent_spec.rb +2 -2
  339. data/spec/unit/application/cert_spec.rb +5 -17
  340. data/spec/unit/application/device_spec.rb +2 -96
  341. data/spec/unit/application/filebucket_spec.rb +18 -4
  342. data/spec/unit/configurer/plugin_handler_spec.rb +5 -32
  343. data/spec/unit/configurer_spec.rb +3 -3
  344. data/spec/unit/datatypes_spec.rb +304 -0
  345. data/spec/unit/defaults_spec.rb +41 -20
  346. data/spec/unit/face/config_spec.rb +46 -1
  347. data/spec/unit/face/epp_face_spec.rb +7 -3
  348. data/spec/unit/face/module/search_spec.rb +11 -0
  349. data/spec/unit/face/parser_spec.rb +2 -2
  350. data/spec/unit/file_bucket/dipper_spec.rb +12 -1
  351. data/spec/unit/forge/module_release_spec.rb +70 -0
  352. data/spec/unit/functions/break_spec.rb +34 -2
  353. data/spec/unit/functions/contain_spec.rb +1 -0
  354. data/spec/unit/functions/convert_to_spec.rb +22 -0
  355. data/spec/unit/functions/epp_spec.rb +5 -0
  356. data/spec/unit/functions/include_spec.rb +15 -0
  357. data/spec/unit/functions/module_directory_spec.rb +43 -0
  358. data/spec/unit/functions/new_spec.rb +14 -14
  359. data/spec/unit/functions/require_spec.rb +2 -0
  360. data/spec/unit/functions/shared.rb +12 -0
  361. data/spec/unit/functions/step_spec.rb +1 -1
  362. data/spec/unit/functions4_spec.rb +49 -4
  363. data/spec/unit/indirector/catalog/compiler_spec.rb +3 -3
  364. data/spec/unit/indirector/file_bucket_file/file_spec.rb +148 -94
  365. data/spec/unit/indirector/node/ldap_spec.rb +15 -12
  366. data/spec/unit/indirector/rest_spec.rb +0 -43
  367. data/spec/unit/interface/action_spec.rb +33 -0
  368. data/spec/unit/module_tool/applications/builder_spec.rb +7 -0
  369. data/spec/unit/module_tool/applications/installer_spec.rb +8 -0
  370. data/spec/unit/module_tool/applications/uninstaller_spec.rb +8 -0
  371. data/spec/unit/module_tool/applications/upgrader_spec.rb +6 -0
  372. data/spec/unit/network/http/connection_spec.rb +1 -1
  373. data/spec/unit/network/http/factory_spec.rb +28 -35
  374. data/spec/unit/parser/compiler_spec.rb +0 -8
  375. data/spec/unit/parser/environment_compiler_spec.rb +36 -0
  376. data/spec/unit/parser/functions/create_resources_spec.rb +9 -0
  377. data/spec/unit/parser/functions/inline_template_spec.rb +7 -0
  378. data/spec/unit/parser/functions/realize_spec.rb +9 -0
  379. data/spec/unit/parser/functions/tag_spec.rb +7 -0
  380. data/spec/unit/parser/functions/tagged_spec.rb +25 -0
  381. data/spec/unit/parser/functions/template_spec.rb +8 -0
  382. data/spec/unit/parser/scope_spec.rb +19 -0
  383. data/spec/unit/pops/evaluator/conditionals_spec.rb +1 -1
  384. data/spec/unit/pops/loaders/loader_spec.rb +516 -0
  385. data/spec/unit/pops/loaders/loaders_spec.rb +11 -0
  386. data/spec/unit/pops/loaders/module_loaders_spec.rb +43 -0
  387. data/spec/unit/pops/loaders/static_loader_spec.rb +15 -7
  388. data/spec/unit/pops/model/model_spec.rb +5 -0
  389. data/spec/unit/pops/parser/lexer2_spec.rb +15 -0
  390. data/spec/unit/pops/parser/locator_spec.rb +20 -0
  391. data/spec/unit/pops/parser/parse_basic_expressions_spec.rb +33 -0
  392. data/spec/unit/pops/parser/parse_calls_spec.rb +28 -0
  393. data/spec/unit/pops/parser/parse_conditionals_spec.rb +12 -0
  394. data/spec/unit/pops/parser/parse_plan_spec.rb +48 -0
  395. data/spec/unit/pops/serialization/packer_spec.rb +8 -0
  396. data/spec/unit/pops/serialization/serialization_spec.rb +30 -0
  397. data/spec/unit/pops/serialization/to_from_hr_spec.rb +31 -0
  398. data/spec/unit/pops/types/error_spec.rb +207 -0
  399. data/spec/unit/pops/types/p_init_type_spec.rb +98 -0
  400. data/spec/unit/pops/types/p_object_type_spec.rb +275 -10
  401. data/spec/unit/pops/types/p_uri_type_spec.rb +191 -0
  402. data/spec/unit/pops/types/ruby_generator_spec.rb +82 -44
  403. data/spec/unit/pops/types/task_spec.rb +353 -0
  404. data/spec/unit/pops/types/type_calculator_spec.rb +76 -5
  405. data/spec/unit/pops/types/type_formatter_spec.rb +31 -13
  406. data/spec/unit/pops/types/type_parser_spec.rb +13 -1
  407. data/spec/unit/pops/types/types_spec.rb +60 -0
  408. data/spec/unit/pops/validator/validator_spec.rb +76 -0
  409. data/spec/unit/provider/group/groupadd_spec.rb +77 -1
  410. data/spec/unit/provider/group/pw_spec.rb +4 -4
  411. data/spec/unit/provider/group/windows_adsi_spec.rb +22 -79
  412. data/spec/unit/provider/mount_spec.rb +18 -5
  413. data/spec/unit/provider/nameservice_spec.rb +5 -5
  414. data/spec/unit/provider/package/dnf_spec.rb +2 -2
  415. data/spec/unit/provider/package/gem_spec.rb +1 -1
  416. data/spec/unit/provider/package/pkg_spec.rb +3 -0
  417. data/spec/unit/provider/package/yum_spec.rb +40 -0
  418. data/spec/unit/provider/service/launchd_spec.rb +2 -1
  419. data/spec/unit/provider/service/redhat_spec.rb +5 -0
  420. data/spec/unit/provider/service/systemd_spec.rb +1 -1
  421. data/spec/unit/provider/user/hpux_spec.rb +2 -2
  422. data/spec/unit/provider/user/openbsd_spec.rb +2 -2
  423. data/spec/unit/provider/user/pw_spec.rb +14 -14
  424. data/spec/unit/provider/user/user_role_add_spec.rb +19 -2
  425. data/spec/unit/provider/user/useradd_spec.rb +188 -22
  426. data/spec/unit/provider/user/windows_adsi_spec.rb +4 -4
  427. data/spec/unit/provider/zfs/zfs_spec.rb +55 -1
  428. data/spec/unit/provider_spec.rb +48 -0
  429. data/spec/unit/puppet_pal_2pec.rb +1005 -0
  430. data/spec/unit/puppet_pal_spec.rb +11 -0
  431. data/spec/unit/settings/ini_file_spec.rb +313 -2
  432. data/spec/unit/ssl/certificate_request_spec.rb +42 -1
  433. data/spec/unit/ssl/certificate_revocation_list_spec.rb +2 -1
  434. data/spec/unit/transaction/report_spec.rb +1 -0
  435. data/spec/unit/transaction_spec.rb +112 -21
  436. data/spec/unit/type/file/checksum_spec.rb +20 -0
  437. data/spec/unit/type/file_spec.rb +8 -0
  438. data/spec/unit/type/group_spec.rb +8 -0
  439. data/spec/unit/type/k5login_spec.rb +22 -1
  440. data/spec/unit/type/scheduled_task_spec.rb +15 -0
  441. data/spec/unit/type/user_spec.rb +11 -1
  442. data/spec/unit/type/yumrepo_spec.rb +5 -0
  443. data/spec/unit/util/checksums_spec.rb +3 -3
  444. data/spec/unit/util/log/destinations_spec.rb +14 -0
  445. data/spec/unit/util/network_device/cisco/device_spec.rb +1 -1
  446. data/spec/unit/util/plist_spec.rb +3 -3
  447. data/spec/unit/util/windows/adsi_spec.rb +27 -31
  448. data/spec/unit/util/windows/sid_spec.rb +15 -86
  449. data/spec/unit/util_spec.rb +17 -3
  450. data/tasks/manpages.rake +1 -1
  451. metadata +220 -182
  452. data/lib/puppet/bindings.rb +0 -148
  453. data/lib/puppet/configurer/downloader_factory.rb +0 -44
  454. data/spec/unit/configurer/downloader_factory_spec.rb +0 -129
@@ -0,0 +1,43 @@
1
+ module Puppet::Pops
2
+ module Types
3
+
4
+ # Interface implemented by a type that has InvocableMembers
5
+ module TypeWithMembers
6
+ # @return [InvocableMember,nil] An invocable member if it exists, or `nil`
7
+ def [](member_name)
8
+ raise NotImplementedError, "'#{self.class.name}' should implement #[]"
9
+ end
10
+ end
11
+
12
+ # Interface implemented by attribute and function members
13
+ module InvocableMember
14
+ # Performs type checking of arguments and invokes the method that corresponds to this
15
+ # method. The result of the invocation is returned
16
+ #
17
+ # @param receiver [Object] The receiver of the call
18
+ # @param scope [Puppet::Parser::Scope] The caller scope
19
+ # @param args [Array] Array of arguments.
20
+ # @return [Object] The result returned by the member function or attribute
21
+ #
22
+ # @api private
23
+ def invoke(receiver, scope, args, &block)
24
+ raise NotImplementedError, "'#{self.class.name}' should implement #invoke"
25
+ end
26
+ end
27
+
28
+ # Plays the same role as an PAttribute in the PObjectType. Provides
29
+ # access to known attr_readers and plain reader methods.
30
+ class AttrReader
31
+ include InvocableMember
32
+
33
+ def initialize(message)
34
+ @message = message.to_sym
35
+ end
36
+
37
+ def invoke(receiver, scope, args, &block)
38
+ receiver.send(@message)
39
+ end
40
+ end
41
+ end
42
+ end
43
+
@@ -57,7 +57,7 @@ class TypedModelObject < Object
57
57
  def self.register_ptypes(loader, ir)
58
58
  types = [
59
59
  Annotation.register_ptype(loader, ir),
60
- RubyMethod.register_ptype(loader, ir)
60
+ RubyMethod.register_ptype(loader, ir),
61
61
  ]
62
62
  Types.constants.each do |c|
63
63
  next if c == :PType || c == :PHostClassType
@@ -129,8 +129,11 @@ class PAnyType < TypedModelObject
129
129
  assignable?(o.resolved_type, guard)
130
130
  end
131
131
  when PVariantType
132
- # Assignable if all contained types are assignable
133
- o.types.all? { |vt| assignable?(vt, guard) }
132
+ # Assignable if all contained types are assignable, or if this is exactly Any
133
+ return true if self.class == PAnyType
134
+ # An empty variant may be assignable to NotUndef[T] if T is assignable to empty variant
135
+ return _assignable?(o, guard) if is_a?(PNotUndefType) && o.types.empty?
136
+ !o.types.empty? && o.types.all? { |vt| assignable?(vt, guard) }
134
137
  when POptionalType
135
138
  # Assignable if undef and contained type is assignable
136
139
  assignable?(PUndefType::DEFAULT) && (o.type.nil? || assignable?(o.type))
@@ -343,7 +346,7 @@ class PAnyType < TypedModelObject
343
346
  # Answers the question if instances of this type can represent themselves as a string that
344
347
  # can then be passed to the create method
345
348
  #
346
- # @return [Boolean] wether or not the instance has a canonical string representation
349
+ # @return [Boolean] whether or not the instance has a canonical string representation
347
350
  def roundtrip_with_string?
348
351
  false
349
352
  end
@@ -476,7 +479,7 @@ class PTypeType < PTypeWithContainedType
476
479
  def self.new_function(type)
477
480
  @new_function ||= Puppet::Functions.create_loaded_function(:new_type, type.loader) do
478
481
  dispatch :from_string do
479
- param 'String', :type_string
482
+ param 'String[1]', :type_string
480
483
  end
481
484
 
482
485
  def from_string(type_string)
@@ -649,7 +652,12 @@ class PUnitType < PAnyType
649
652
 
650
653
  DEFAULT = PUnitType.new
651
654
 
655
+ def assignable?(o, guard=nil)
656
+ true
657
+ end
658
+
652
659
  protected
660
+
653
661
  # @api private
654
662
  def _assignable?(o, guard)
655
663
  true
@@ -750,13 +758,20 @@ end
750
758
  #
751
759
  class PEnumType < PScalarDataType
752
760
  def self.register_ptype(loader, ir)
753
- create_ptype(loader, ir, 'ScalarDataType', 'values' => PArrayType.new(PStringType::NON_EMPTY))
761
+ create_ptype(loader, ir, 'ScalarDataType',
762
+ 'values' => PArrayType.new(PStringType::NON_EMPTY),
763
+ 'case_insensitive' => { 'type' => PBooleanType::DEFAULT, 'value' => false })
754
764
  end
755
765
 
756
- attr_reader :values
766
+ attr_reader :values, :case_insensitive
757
767
 
758
- def initialize(values)
768
+ def initialize(values, case_insensitive = false)
759
769
  @values = values.uniq.sort.freeze
770
+ @case_insensitive = case_insensitive
771
+ end
772
+
773
+ def case_insensitive?
774
+ @case_insensitive
760
775
  end
761
776
 
762
777
  # Returns Enumerator if no block is given, otherwise, calls the given
@@ -786,15 +801,19 @@ class PEnumType < PScalarDataType
786
801
  end
787
802
 
788
803
  def hash
789
- @values.hash
804
+ @values.hash ^ @case_insensitive.hash
790
805
  end
791
806
 
792
807
  def eql?(o)
793
- self.class == o.class && @values == o.values
808
+ self.class == o.class && @values == o.values && @case_insensitive == o.case_insensitive?
794
809
  end
795
810
 
796
811
  def instance?(o, guard = nil)
797
- o.is_a?(String) && @values.any? { |p| p == o }
812
+ if o.is_a?(String)
813
+ @case_insensitive ? @values.any? { |p| p.casecmp(o) == 0 } : @values.any? { |p| p == o }
814
+ else
815
+ false
816
+ end
798
817
  end
799
818
 
800
819
  DEFAULT = PEnumType.new(EMPTY_ARRAY)
@@ -813,13 +832,26 @@ class PEnumType < PScalarDataType
813
832
  # if the contained string is found in the set of enums
814
833
  instance?(o.value, guard)
815
834
  when PEnumType
816
- !o.values.empty? && o.values.all? { |s| instance?(s, guard) }
835
+ !o.values.empty? && (case_insensitive? || !o.case_insensitive?) && o.values.all? { |s| instance?(s, guard) }
817
836
  else
818
837
  false
819
838
  end
820
839
  end
821
840
  end
822
841
 
842
+ INTEGER_HEX = '(?:0[xX][0-9A-Fa-f]+)'
843
+ INTEGER_OCT = '(?:0[0-7]+)'
844
+ INTEGER_BIN = '(?:0[bB][01]+)'
845
+ INTEGER_DEC = '(?:0|[1-9]\d*)'
846
+ SIGN_PREFIX = '[+-]?\s*'
847
+
848
+ OPTIONAL_FRACTION = '(?:\.\d+)?'
849
+ OPTIONAL_EXPONENT = '(?:[eE]-?\d+)?'
850
+ FLOAT_DEC = '(?:' + INTEGER_DEC + OPTIONAL_FRACTION + OPTIONAL_EXPONENT + ')'
851
+
852
+ INTEGER_PATTERN = '\A' + SIGN_PREFIX + '(?:' + INTEGER_DEC + '|' + INTEGER_HEX + '|' + INTEGER_OCT + '|' + INTEGER_BIN + ')\z'
853
+ FLOAT_PATTERN = '\A' + SIGN_PREFIX + '(?:' + FLOAT_DEC + '|' + INTEGER_HEX + '|' + INTEGER_OCT + '|' + INTEGER_BIN + ')\z'
854
+
823
855
  # @api public
824
856
  #
825
857
  class PNumericType < PScalarDataType
@@ -833,7 +865,7 @@ class PNumericType < PScalarDataType
833
865
  def self.new_function(type)
834
866
  @new_function ||= Puppet::Functions.create_loaded_function(:new_numeric, type.loader) do
835
867
  local_types do
836
- type 'Convertible = Variant[Undef, Integer, Float, Boolean, String, Timespan, Timestamp]'
868
+ type "Convertible = Variant[Integer, Float, Boolean, Pattern[/#{FLOAT_PATTERN}/], Timespan, Timestamp]"
837
869
  type 'NamedArgs = Struct[{from => Convertible, Optional[abs] => Boolean}]'
838
870
  end
839
871
 
@@ -846,6 +878,11 @@ class PNumericType < PScalarDataType
846
878
  param 'NamedArgs', :hash_args
847
879
  end
848
880
 
881
+ argument_mismatch :on_error do
882
+ param 'Any', :from
883
+ optional_param 'Boolean', :abs
884
+ end
885
+
849
886
  def from_args(from, abs = false)
850
887
  result = from_convertible(from)
851
888
  abs ? result.abs : result
@@ -857,8 +894,6 @@ class PNumericType < PScalarDataType
857
894
 
858
895
  def from_convertible(from)
859
896
  case from
860
- when NilClass
861
- throw :undefined_value
862
897
  when Float
863
898
  from
864
899
  when Integer
@@ -869,7 +904,7 @@ class PNumericType < PScalarDataType
869
904
  1
870
905
  when FalseClass
871
906
  0
872
- when String
907
+ else
873
908
  begin
874
909
  if from[0] == '0' && (from[1].downcase == 'b' || from[1].downcase == 'x')
875
910
  Integer(from)
@@ -881,9 +916,15 @@ class PNumericType < PScalarDataType
881
916
  rescue ArgumentError => e
882
917
  raise TypeConversionError.new(e.message)
883
918
  end
919
+ end
920
+ end
921
+
922
+ def on_error(from, abs = false)
923
+ if from.is_a?(String)
924
+ _("The string '%{str}' cannot be converted to Numeric") % { str: from }
884
925
  else
885
- t = Puppet::Pops::Types::TypeCalculator.singleton.infer(from).generalize
886
- raise TypeConversionError.new("Value of type '#{t}' cannot be converted to Numeric")
926
+ t = TypeCalculator.singleton.infer(from).generalize
927
+ _("Value of type %{type} cannot be converted to Numeric") % { type: t }
887
928
  end
888
929
  end
889
930
  end
@@ -1044,7 +1085,7 @@ class PIntegerType < PNumericType
1044
1085
  @@new_function ||= Puppet::Functions.create_loaded_function(:new, loader) do
1045
1086
  local_types do
1046
1087
  type 'Radix = Variant[Default, Integer[2,2], Integer[8,8], Integer[10,10], Integer[16,16]]'
1047
- type 'Convertible = Variant[Undef, Numeric, Boolean, String, Timespan, Timestamp]'
1088
+ type "Convertible = Variant[Numeric, Boolean, Pattern[/#{INTEGER_PATTERN}/], Timespan, Timestamp]"
1048
1089
  type 'NamedArgs = Struct[{from => Convertible, Optional[radix] => Radix, Optional[abs] => Boolean}]'
1049
1090
  end
1050
1091
 
@@ -1058,6 +1099,16 @@ class PIntegerType < PNumericType
1058
1099
  param 'NamedArgs', :hash_args
1059
1100
  end
1060
1101
 
1102
+ argument_mismatch :on_error_hash do
1103
+ param 'Hash', :hash_args
1104
+ end
1105
+
1106
+ argument_mismatch :on_error do
1107
+ param 'Any', :from
1108
+ optional_param 'Integer', :radix
1109
+ optional_param 'Boolean', :abs
1110
+ end
1111
+
1061
1112
  def from_args(from, radix = :default, abs = false)
1062
1113
  result = from_convertible(from, radix)
1063
1114
  abs ? result.abs : result
@@ -1069,8 +1120,6 @@ class PIntegerType < PNumericType
1069
1120
 
1070
1121
  def from_convertible(from, radix)
1071
1122
  case from
1072
- when NilClass
1073
- throw :undefined_value
1074
1123
  when Float, Time::TimeData
1075
1124
  from.to_i
1076
1125
  when Integer
@@ -1079,9 +1128,9 @@ class PIntegerType < PNumericType
1079
1128
  1
1080
1129
  when FalseClass
1081
1130
  0
1082
- when String
1131
+ else
1083
1132
  begin
1084
- radix == :default ? Integer(from) : Integer(from, assert_radix(radix))
1133
+ radix == :default ? Integer(from) : Integer(from, radix)
1085
1134
  rescue TypeError => e
1086
1135
  raise TypeConversionError.new(e.message)
1087
1136
  rescue ArgumentError => e
@@ -1097,17 +1146,34 @@ class PIntegerType < PNumericType
1097
1146
  end
1098
1147
  raise TypeConversionError.new(e.message)
1099
1148
  end
1149
+ end
1150
+ end
1151
+
1152
+ def on_error_hash(args_hash)
1153
+ if args_hash.include?('from')
1154
+ from = args_hash['from']
1155
+ return on_error(from) unless loader.load(:type, 'convertible').instance?(from)
1156
+ end
1157
+ radix = args_hash['radix']
1158
+ assert_radix(radix) unless radix.nil? || radix == :default
1159
+ TypeAsserter.assert_instance_of('Integer.new', loader.load(:type, 'namedargs'), args_hash)
1160
+ end
1161
+
1162
+ def on_error(from, radix = :default, abs = nil)
1163
+ assert_radix(radix) unless radix == :default
1164
+ if from.is_a?(String)
1165
+ _("The string '%{str}' cannot be converted to Integer") % { str: from }
1100
1166
  else
1101
- t = Puppet::Pops::Types::TypeCalculator.singleton.infer(from).generalize
1102
- raise TypeConversionError.new("Value of type '#{t}' cannot be converted to an Integer")
1167
+ t = TypeCalculator.singleton.infer(from).generalize
1168
+ _("Value of type %{type} cannot be converted to Integer") % { type: t }
1103
1169
  end
1104
1170
  end
1105
1171
 
1106
1172
  def assert_radix(radix)
1107
1173
  case radix
1108
- when 2, 8, 10, 16, :default
1174
+ when 2, 8, 10, 16
1109
1175
  else
1110
- raise ArgumentError.new("Illegal radix: '#{radix}', expected 2, 8, 10, 16, or default")
1176
+ raise ArgumentError.new(_("Illegal radix: %{radix}, expected 2, 8, 10, 16, or default") % { radix: radix })
1111
1177
  end
1112
1178
  radix
1113
1179
  end
@@ -1154,7 +1220,7 @@ class PFloatType < PNumericType
1154
1220
  def self.new_function(type)
1155
1221
  @new_function ||= Puppet::Functions.create_loaded_function(:new_float, type.loader) do
1156
1222
  local_types do
1157
- type 'Convertible = Variant[Undef, Numeric, Boolean, String, Timespan, Timestamp]'
1223
+ type "Convertible = Variant[Numeric, Boolean, Pattern[/#{FLOAT_PATTERN}/], Timespan, Timestamp]"
1158
1224
  type 'NamedArgs = Struct[{from => Convertible, Optional[abs] => Boolean}]'
1159
1225
  end
1160
1226
 
@@ -1167,6 +1233,11 @@ class PFloatType < PNumericType
1167
1233
  param 'NamedArgs', :hash_args
1168
1234
  end
1169
1235
 
1236
+ argument_mismatch :on_error do
1237
+ param 'Any', :from
1238
+ optional_param 'Boolean', :abs
1239
+ end
1240
+
1170
1241
  def from_args(from, abs = false)
1171
1242
  result = from_convertible(from)
1172
1243
  abs ? result.abs : result
@@ -1178,8 +1249,6 @@ class PFloatType < PNumericType
1178
1249
 
1179
1250
  def from_convertible(from)
1180
1251
  case from
1181
- when NilClass
1182
- throw :undefined_value
1183
1252
  when Float
1184
1253
  from
1185
1254
  when Integer
@@ -1190,7 +1259,7 @@ class PFloatType < PNumericType
1190
1259
  1.0
1191
1260
  when FalseClass
1192
1261
  0.0
1193
- when String
1262
+ else
1194
1263
  begin
1195
1264
  # support a binary as float
1196
1265
  if from[0] == '0' && from[1].downcase == 'b'
@@ -1212,9 +1281,15 @@ class PFloatType < PNumericType
1212
1281
  end
1213
1282
  raise TypeConversionError.new(e.message)
1214
1283
  end
1284
+ end
1285
+ end
1286
+
1287
+ def on_error(from, _ = false)
1288
+ if from.is_a?(String)
1289
+ _("The string '%{str}' cannot be converted to Float") % { str: from }
1215
1290
  else
1216
- t = Puppet::Pops::Types::TypeCalculator.singleton.infer(from).generalize
1217
- raise TypeConversionError.new("Value of type '#{t}' cannot be converted to Float")
1291
+ t = TypeCalculator.singleton.infer(from).generalize
1292
+ _("Value of type %{type} cannot be converted to Float") % { type: t }
1218
1293
  end
1219
1294
  end
1220
1295
  end
@@ -1238,7 +1313,7 @@ class PCollectionType < PAnyType
1238
1313
  attr_reader :size_type
1239
1314
 
1240
1315
  def initialize(size_type)
1241
- @size_type = size_type
1316
+ @size_type = size_type.nil? ? nil : size_type.to_size
1242
1317
  end
1243
1318
 
1244
1319
  def accept(visitor, guard)
@@ -1435,7 +1510,7 @@ class PStringType < PScalarDataType
1435
1510
  end
1436
1511
  size_type_or_value = deprecated_multi_args[0]
1437
1512
  end
1438
- @size_type_or_value = size_type_or_value
1513
+ @size_type_or_value = size_type_or_value.is_a?(PIntegerType) ? size_type_or_value.to_size : size_type_or_value
1439
1514
  end
1440
1515
 
1441
1516
  def accept(visitor, guard)
@@ -1576,7 +1651,7 @@ class PStringType < PScalarDataType
1576
1651
  # Must match exactly when value is a string
1577
1652
  @size_type_or_value.nil? || @size_type_or_value == o.size_type_or_value
1578
1653
  when PEnumType
1579
- @size_type_or_value.nil? ? true : o.values.size == 1 && @size_type_or_value == o.values[0]
1654
+ @size_type_or_value.nil? ? true : o.values.size == 1 && !o.case_insensitive? && o.values[0]
1580
1655
  when PPatternType
1581
1656
  @size_type_or_value.nil?
1582
1657
  else
@@ -1785,46 +1860,73 @@ class PBooleanType < PScalarDataType
1785
1860
  create_ptype(loader, ir, 'ScalarDataType')
1786
1861
  end
1787
1862
 
1863
+ attr_reader :value
1864
+
1865
+ def initialize(value = nil)
1866
+ @value = value
1867
+ end
1868
+
1869
+ def eql?(o)
1870
+ o.is_a?(PBooleanType) && @value == o.value
1871
+ end
1872
+
1873
+ def generalize
1874
+ PBooleanType::DEFAULT
1875
+ end
1876
+
1877
+ def hash
1878
+ 31 ^ @value.hash
1879
+ end
1880
+
1788
1881
  def instance?(o, guard = nil)
1789
- o == true || o == false
1882
+ (o == true || o == false) && (@value.nil? || value == o)
1790
1883
  end
1791
1884
 
1792
1885
  def self.new_function(type)
1793
1886
  @new_function ||= Puppet::Functions.create_loaded_function(:new_boolean, type.loader) do
1794
1887
  dispatch :from_args do
1795
- param 'Variant[Undef, Integer, Float, Boolean, String]', :from
1888
+ param "Variant[Integer, Float, Boolean, Enum['false','true','yes','no','y','n',true]]", :from
1889
+ end
1890
+
1891
+ argument_mismatch :on_error do
1892
+ param 'Any', :from
1796
1893
  end
1797
1894
 
1798
1895
  def from_args(from)
1799
1896
  from = from.downcase if from.is_a?(String)
1800
1897
  case from
1801
- when NilClass
1802
- throw :undefined_value
1803
1898
  when Float
1804
1899
  from != 0.0
1805
1900
  when Integer
1806
1901
  from != 0
1807
- when true, false
1808
- from
1809
- when 'false', 'no', 'n'
1902
+ when false, 'false', 'no', 'n'
1810
1903
  false
1811
- when 'true', 'yes', 'y'
1904
+ else
1812
1905
  true
1906
+ end
1907
+ end
1908
+
1909
+ def on_error(from)
1910
+ if from.is_a?(String)
1911
+ _("The string '%{str}' cannot be converted to Boolean") % { str: from }
1813
1912
  else
1814
- raise TypeConversionError.new("Value '#{from}' of type '#{from.class}' cannot be converted to Boolean")
1913
+ t = TypeCalculator.singleton.infer(from).generalize
1914
+ _("Value of type %{type} cannot be converted to Boolean") % { type: t }
1815
1915
  end
1816
1916
  end
1817
1917
  end
1818
1918
  end
1819
1919
 
1820
1920
  DEFAULT = PBooleanType.new
1921
+ TRUE = PBooleanType.new(true)
1922
+ FALSE = PBooleanType.new(false)
1821
1923
 
1822
1924
  protected
1823
1925
 
1824
1926
  # @api private
1825
1927
  #
1826
1928
  def _assignable?(o, guard)
1827
- o.is_a?(PBooleanType)
1929
+ o.is_a?(PBooleanType) && (@value.nil? || @value == o.value)
1828
1930
  end
1829
1931
  end
1830
1932
 
@@ -1956,7 +2058,6 @@ class PStructType < PAnyType
1956
2058
  if self == DEFAULT
1957
2059
  PIterableType.new(PHashType::DEFAULT_KEY_PAIR_TUPLE)
1958
2060
  else
1959
- tc = TypeCalculator.singleton
1960
2061
  PIterableType.new(
1961
2062
  PTupleType.new([
1962
2063
  PVariantType.maybe_create(@elements.map {|se| se.key_type }),
@@ -2260,11 +2361,11 @@ class PCallableType < PAnyType
2260
2361
  def self.register_ptype(loader, ir)
2261
2362
  create_ptype(loader, ir, 'AnyType',
2262
2363
  'param_types' => {
2263
- KEY_TYPE => POptionalType.new(PTupleType::DEFAULT),
2364
+ KEY_TYPE => POptionalType.new(PTypeType.new(PTupleType::DEFAULT)),
2264
2365
  KEY_VALUE => nil
2265
2366
  },
2266
2367
  'block_type' => {
2267
- KEY_TYPE => POptionalType.new(PCallableType::DEFAULT),
2368
+ KEY_TYPE => POptionalType.new(PTypeType.new(PCallableType::DEFAULT)),
2268
2369
  KEY_VALUE => nil
2269
2370
  },
2270
2371
  'return_type' => {
@@ -2346,7 +2447,7 @@ class PCallableType < PAnyType
2346
2447
 
2347
2448
  # @api private
2348
2449
  def callable_args?(required_callable_t, guard)
2349
- # If the required callable is euqal or more specific than self, self is acceptable arguments
2450
+ # If the required callable is equal or more specific than self, self is acceptable arguments
2350
2451
  required_callable_t.assignable?(self, guard)
2351
2452
  end
2352
2453
 
@@ -2503,41 +2604,43 @@ class PArrayType < PCollectionType
2503
2604
  def self.new_function(type)
2504
2605
  @new_function ||= Puppet::Functions.create_loaded_function(:new_array, type.loader) do
2505
2606
 
2506
- dispatch :from_args do
2507
- param 'Any', :from
2508
- optional_param 'Boolean', :wrap
2607
+ dispatch :to_array do
2608
+ param 'Variant[Array,Hash,Binary,Iterable]', :from
2609
+ optional_param 'Boolean[false]', :wrap
2610
+ end
2611
+
2612
+ dispatch :wrapped do
2613
+ param 'Any', :from
2614
+ param 'Boolean[true]', :wrap
2509
2615
  end
2510
2616
 
2511
- def from_args(from, wrap = false)
2617
+ argument_mismatch :on_error do
2618
+ param 'Any', :from
2619
+ optional_param 'Boolean', :wrap
2620
+ end
2621
+
2622
+ def wrapped(from, _)
2623
+ from.is_a?(Array) ? from : [from]
2624
+ end
2625
+
2626
+ def to_array(from, _ = false)
2512
2627
  case from
2513
- when NilClass
2514
- if wrap
2515
- [nil]
2516
- else
2517
- throw :undefined_value
2518
- end
2519
2628
  when Array
2520
2629
  from
2521
2630
  when Hash
2522
- wrap ? [from] : from.to_a
2523
-
2631
+ from.to_a
2524
2632
  when PBinaryType::Binary
2525
2633
  # For older rubies, the #bytes method returns an Enumerator that must be rolled out
2526
- wrap ? [from] : from.binary_buffer.bytes.to_a
2527
-
2634
+ from.binary_buffer.bytes.to_a
2528
2635
  else
2529
- if wrap
2530
- [from]
2531
- else
2532
- if PIterableType::DEFAULT.instance?(from)
2533
- Iterable.on(from).to_a
2534
- else
2535
- t = Puppet::Pops::Types::TypeCalculator.singleton.infer(from).generalize
2536
- raise TypeConversionError.new("Value of type '#{t}' cannot be converted to Array")
2537
- end
2538
- end
2636
+ Iterable.on(from).to_a
2539
2637
  end
2540
2638
  end
2639
+
2640
+ def on_error(from, _ = false)
2641
+ t = TypeCalculator.singleton.infer(from).generalize
2642
+ _("Value of type %{type} cannot be converted to Array") % { type: t }
2643
+ end
2541
2644
  end
2542
2645
  end
2543
2646
 
@@ -2738,14 +2841,12 @@ class PHashType < PCollectionType
2738
2841
 
2739
2842
  def from_array(from)
2740
2843
  case from
2741
- when NilClass
2742
- throw :undefined_value
2743
2844
  when Array
2744
2845
  if from.size == 0
2745
2846
  {}
2746
2847
  else
2747
2848
  unless from.size % 2 == 0
2748
- raise TypeConversionError.new("odd number of arguments for Hash")
2849
+ raise TypeConversionError.new(_('odd number of arguments for Hash'))
2749
2850
  end
2750
2851
  Hash[*from]
2751
2852
  end
@@ -2755,8 +2856,8 @@ class PHashType < PCollectionType
2755
2856
  if PIterableType::DEFAULT.instance?(from)
2756
2857
  Hash[*Iterable.on(from).to_a]
2757
2858
  else
2758
- t = Puppet::Pops::Types::TypeCalculator.singleton.infer(from).generalize
2759
- raise TypeConversionError.new("Value of type '#{t}' cannot be converted to Hash")
2859
+ t = TypeCalculator.singleton.infer(from).generalize
2860
+ raise TypeConversionError.new(_("Value of type %{type} cannot be converted to Hash") % { type: t })
2760
2861
  end
2761
2862
  end
2762
2863
  end
@@ -2924,6 +3025,20 @@ class PVariantType < PAnyType
2924
3025
 
2925
3026
  DEFAULT = PVariantType.new(EMPTY_ARRAY)
2926
3027
 
3028
+ def assignable?(o, guard = nil)
3029
+ # an empty Variant does not match Undef (it is void - not even undef)
3030
+ if o.is_a?(PUndefType) && types.empty?
3031
+ return false
3032
+ end
3033
+
3034
+ return super unless o.is_a?(PVariantType)
3035
+ # If empty, all Variant types match irrespective of the types they hold (including being empty)
3036
+ return true if types.empty?
3037
+ # Since this variant is not empty, an empty Variant cannot match, because it matches nothing
3038
+ # otherwise all types in o must be assignable to this
3039
+ !o.types.empty? && o.types.all? { |vt| super(vt, guard) }
3040
+ end
3041
+
2927
3042
  protected
2928
3043
 
2929
3044
  # @api private
@@ -2948,8 +3063,9 @@ class PVariantType < PAnyType
2948
3063
 
2949
3064
  # @api private
2950
3065
  def merge_enums(array)
3066
+ # Merge case sensitive enums and strings
2951
3067
  if array.size > 1
2952
- parts = array.partition {|t| t.is_a?(PEnumType) && !t.values.empty? || t.is_a?(PStringType) && !t.value.nil? }
3068
+ parts = array.partition {|t| t.is_a?(PEnumType) && !t.values.empty? && !t.case_insensitive? || t.is_a?(PStringType) && !t.value.nil? }
2953
3069
  enums = parts[0]
2954
3070
  if enums.size > 1
2955
3071
  others = parts[1]
@@ -2957,6 +3073,20 @@ class PVariantType < PAnyType
2957
3073
  array = others
2958
3074
  end
2959
3075
  end
3076
+
3077
+ # Merge case insensitive enums
3078
+ if array.size > 1
3079
+ parts = array.partition {|t| t.is_a?(PEnumType) && !t.values.empty? && t.case_insensitive? }
3080
+ enums = parts[0]
3081
+ if enums.size > 1
3082
+ others = parts[1]
3083
+ values = []
3084
+ enums.each { |enum| enum.values.each { |value| values << value.downcase }}
3085
+ values.uniq!
3086
+ others << PEnumType.new(values, true)
3087
+ array = others
3088
+ end
3089
+ end
2960
3090
  array
2961
3091
  end
2962
3092
 
@@ -3513,6 +3643,8 @@ require_relative 'p_timespan_type'
3513
3643
  require_relative 'p_timestamp_type'
3514
3644
  require_relative 'p_binary_type'
3515
3645
  require_relative 'p_init_type'
3646
+ require_relative 'p_object_type_extension'
3647
+ require_relative 'p_uri_type'
3516
3648
  require_relative 'type_set_reference'
3517
3649
  require_relative 'implementation_registry'
3518
3650
  require_relative 'tree_iterators'