bolt 0.0.1 → 0.5.0

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

Potentially problematic release.


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

Files changed (1291) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +33 -0
  3. data/.gitmodules +12 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +61 -0
  6. data/.travis.yml +18 -0
  7. data/Gemfile +9 -0
  8. data/INSTALL.md +70 -0
  9. data/LICENSE +201 -0
  10. data/README.md +372 -0
  11. data/Rakefile +27 -0
  12. data/Vagrantfile +13 -0
  13. data/appveyor.yml +29 -0
  14. data/bolt.gemspec +50 -0
  15. data/docs/writing_tasks_and_plans.pdf +0 -0
  16. data/exe/bolt +15 -0
  17. data/lib/bolt.rb +13 -0
  18. data/lib/bolt/cli.rb +409 -0
  19. data/lib/bolt/executor.rb +71 -0
  20. data/lib/bolt/node.rb +79 -0
  21. data/lib/bolt/node/formatter.rb +15 -0
  22. data/lib/bolt/node/orch.rb +118 -0
  23. data/lib/bolt/node/result.rb +110 -0
  24. data/lib/bolt/node/ssh.rb +145 -0
  25. data/lib/bolt/node/winrm.rb +237 -0
  26. data/lib/bolt/node_uri.rb +42 -0
  27. data/lib/bolt/result.rb +139 -0
  28. data/lib/bolt/version.rb +3 -0
  29. data/metadata.json +13 -0
  30. data/tasks/init.json +3 -0
  31. data/tasks/init.rb +44 -0
  32. data/ux/bolt-CLI-spec.md +186 -0
  33. data/vendored/facter/lib/facter.rb +261 -0
  34. data/vendored/facter/lib/facter/Cfkey.rb +42 -0
  35. data/vendored/facter/lib/facter/application.rb +206 -0
  36. data/vendored/facter/lib/facter/architecture.rb +50 -0
  37. data/vendored/facter/lib/facter/augeasversion.rb +28 -0
  38. data/vendored/facter/lib/facter/blockdevices.rb +105 -0
  39. data/vendored/facter/lib/facter/core/aggregate.rb +220 -0
  40. data/vendored/facter/lib/facter/core/directed_graph.rb +46 -0
  41. data/vendored/facter/lib/facter/core/execution.rb +123 -0
  42. data/vendored/facter/lib/facter/core/execution/base.rb +81 -0
  43. data/vendored/facter/lib/facter/core/execution/posix.rb +50 -0
  44. data/vendored/facter/lib/facter/core/execution/windows.rb +57 -0
  45. data/vendored/facter/lib/facter/core/logging.rb +197 -0
  46. data/vendored/facter/lib/facter/core/resolvable.rb +94 -0
  47. data/vendored/facter/lib/facter/core/suitable.rb +113 -0
  48. data/vendored/facter/lib/facter/dhcp_servers.rb +45 -0
  49. data/vendored/facter/lib/facter/domain.rb +99 -0
  50. data/vendored/facter/lib/facter/ec2.rb +68 -0
  51. data/vendored/facter/lib/facter/ec2/rest.rb +137 -0
  52. data/vendored/facter/lib/facter/facterversion.rb +15 -0
  53. data/vendored/facter/lib/facter/filesystems.rb +45 -0
  54. data/vendored/facter/lib/facter/fqdn.rb +24 -0
  55. data/vendored/facter/lib/facter/gce.rb +16 -0
  56. data/vendored/facter/lib/facter/gce/metadata.rb +87 -0
  57. data/vendored/facter/lib/facter/gid.rb +25 -0
  58. data/vendored/facter/lib/facter/hardwareisa.rb +20 -0
  59. data/vendored/facter/lib/facter/hardwaremodel.rb +67 -0
  60. data/vendored/facter/lib/facter/hostname.rb +31 -0
  61. data/vendored/facter/lib/facter/id.rb +21 -0
  62. data/vendored/facter/lib/facter/interfaces.rb +58 -0
  63. data/vendored/facter/lib/facter/ipaddress.rb +169 -0
  64. data/vendored/facter/lib/facter/ipaddress6.rb +82 -0
  65. data/vendored/facter/lib/facter/iphostnumber.rb +29 -0
  66. data/vendored/facter/lib/facter/kernel.rb +22 -0
  67. data/vendored/facter/lib/facter/kernelmajversion.rb +23 -0
  68. data/vendored/facter/lib/facter/kernelrelease.rb +45 -0
  69. data/vendored/facter/lib/facter/kernelversion.rb +22 -0
  70. data/vendored/facter/lib/facter/ldom.rb +51 -0
  71. data/vendored/facter/lib/facter/lsbdistcodename.rb +20 -0
  72. data/vendored/facter/lib/facter/lsbdistdescription.rb +21 -0
  73. data/vendored/facter/lib/facter/lsbdistid.rb +20 -0
  74. data/vendored/facter/lib/facter/lsbdistrelease.rb +20 -0
  75. data/vendored/facter/lib/facter/lsbmajdistrelease.rb +22 -0
  76. data/vendored/facter/lib/facter/lsbminordistrelease.rb +22 -0
  77. data/vendored/facter/lib/facter/lsbrelease.rb +20 -0
  78. data/vendored/facter/lib/facter/macaddress.rb +99 -0
  79. data/vendored/facter/lib/facter/macosx.rb +56 -0
  80. data/vendored/facter/lib/facter/manufacturer.rb +68 -0
  81. data/vendored/facter/lib/facter/memory.rb +168 -0
  82. data/vendored/facter/lib/facter/netmask.rb +43 -0
  83. data/vendored/facter/lib/facter/network.rb +20 -0
  84. data/vendored/facter/lib/facter/operatingsystem.rb +24 -0
  85. data/vendored/facter/lib/facter/operatingsystem/base.rb +61 -0
  86. data/vendored/facter/lib/facter/operatingsystem/cumuluslinux.rb +27 -0
  87. data/vendored/facter/lib/facter/operatingsystem/implementation.rb +33 -0
  88. data/vendored/facter/lib/facter/operatingsystem/linux.rb +484 -0
  89. data/vendored/facter/lib/facter/operatingsystem/osreleaselinux.rb +28 -0
  90. data/vendored/facter/lib/facter/operatingsystem/sunos.rb +54 -0
  91. data/vendored/facter/lib/facter/operatingsystem/vmkernel.rb +11 -0
  92. data/vendored/facter/lib/facter/operatingsystem/windows.rb +43 -0
  93. data/vendored/facter/lib/facter/operatingsystemmajrelease.rb +31 -0
  94. data/vendored/facter/lib/facter/operatingsystemrelease.rb +29 -0
  95. data/vendored/facter/lib/facter/os.rb +98 -0
  96. data/vendored/facter/lib/facter/osfamily.rb +18 -0
  97. data/vendored/facter/lib/facter/partitions.rb +39 -0
  98. data/vendored/facter/lib/facter/path.rb +14 -0
  99. data/vendored/facter/lib/facter/physicalprocessorcount.rb +27 -0
  100. data/vendored/facter/lib/facter/processor.rb +52 -0
  101. data/vendored/facter/lib/facter/processors.rb +66 -0
  102. data/vendored/facter/lib/facter/processors/os.rb +244 -0
  103. data/vendored/facter/lib/facter/ps.rb +31 -0
  104. data/vendored/facter/lib/facter/puppetversion.rb +20 -0
  105. data/vendored/facter/lib/facter/rackspace.rb +37 -0
  106. data/vendored/facter/lib/facter/rubyplatform.rb +12 -0
  107. data/vendored/facter/lib/facter/rubysitedir.rb +15 -0
  108. data/vendored/facter/lib/facter/rubyversion.rb +12 -0
  109. data/vendored/facter/lib/facter/selinux.rb +154 -0
  110. data/vendored/facter/lib/facter/ssh.rb +73 -0
  111. data/vendored/facter/lib/facter/system32.rb +21 -0
  112. data/vendored/facter/lib/facter/system_uptime.rb +44 -0
  113. data/vendored/facter/lib/facter/timezone.rb +14 -0
  114. data/vendored/facter/lib/facter/uniqueid.rb +4 -0
  115. data/vendored/facter/lib/facter/uptime.rb +16 -0
  116. data/vendored/facter/lib/facter/uptime_days.rb +13 -0
  117. data/vendored/facter/lib/facter/uptime_hours.rb +13 -0
  118. data/vendored/facter/lib/facter/uptime_seconds.rb +20 -0
  119. data/vendored/facter/lib/facter/util/architecture.rb +19 -0
  120. data/vendored/facter/lib/facter/util/collection.rb +161 -0
  121. data/vendored/facter/lib/facter/util/composite_loader.rb +12 -0
  122. data/vendored/facter/lib/facter/util/config.rb +88 -0
  123. data/vendored/facter/lib/facter/util/confine.rb +66 -0
  124. data/vendored/facter/lib/facter/util/dhcp_servers.rb +58 -0
  125. data/vendored/facter/lib/facter/util/directory_loader.rb +88 -0
  126. data/vendored/facter/lib/facter/util/ec2.rb +106 -0
  127. data/vendored/facter/lib/facter/util/fact.rb +204 -0
  128. data/vendored/facter/lib/facter/util/file_read.rb +37 -0
  129. data/vendored/facter/lib/facter/util/formatter.rb +39 -0
  130. data/vendored/facter/lib/facter/util/ip.rb +340 -0
  131. data/vendored/facter/lib/facter/util/ip/windows.rb +215 -0
  132. data/vendored/facter/lib/facter/util/loader.rb +155 -0
  133. data/vendored/facter/lib/facter/util/macaddress.rb +43 -0
  134. data/vendored/facter/lib/facter/util/macosx.rb +73 -0
  135. data/vendored/facter/lib/facter/util/manufacturer.rb +99 -0
  136. data/vendored/facter/lib/facter/util/memory.rb +228 -0
  137. data/vendored/facter/lib/facter/util/netmask.rb +40 -0
  138. data/vendored/facter/lib/facter/util/normalization.rb +94 -0
  139. data/vendored/facter/lib/facter/util/nothing_loader.rb +12 -0
  140. data/vendored/facter/lib/facter/util/operatingsystem.rb +21 -0
  141. data/vendored/facter/lib/facter/util/parser.rb +168 -0
  142. data/vendored/facter/lib/facter/util/partitions.rb +47 -0
  143. data/vendored/facter/lib/facter/util/partitions/linux.rb +71 -0
  144. data/vendored/facter/lib/facter/util/partitions/openbsd.rb +40 -0
  145. data/vendored/facter/lib/facter/util/plist.rb +24 -0
  146. data/vendored/facter/lib/facter/util/plist/generator.rb +228 -0
  147. data/vendored/facter/lib/facter/util/plist/parser.rb +226 -0
  148. data/vendored/facter/lib/facter/util/posix.rb +16 -0
  149. data/vendored/facter/lib/facter/util/processor.rb +289 -0
  150. data/vendored/facter/lib/facter/util/registry.rb +11 -0
  151. data/vendored/facter/lib/facter/util/resolution.rb +160 -0
  152. data/vendored/facter/lib/facter/util/solaris_zones.rb +158 -0
  153. data/vendored/facter/lib/facter/util/unix_root.rb +5 -0
  154. data/vendored/facter/lib/facter/util/uptime.rb +83 -0
  155. data/vendored/facter/lib/facter/util/values.rb +109 -0
  156. data/vendored/facter/lib/facter/util/virtual.rb +212 -0
  157. data/vendored/facter/lib/facter/util/vlans.rb +21 -0
  158. data/vendored/facter/lib/facter/util/windows.rb +10 -0
  159. data/vendored/facter/lib/facter/util/windows/api_types.rb +135 -0
  160. data/vendored/facter/lib/facter/util/windows/dir.rb +43 -0
  161. data/vendored/facter/lib/facter/util/windows/error.rb +87 -0
  162. data/vendored/facter/lib/facter/util/windows/process.rb +294 -0
  163. data/vendored/facter/lib/facter/util/windows/user.rb +186 -0
  164. data/vendored/facter/lib/facter/util/windows_root.rb +7 -0
  165. data/vendored/facter/lib/facter/util/wmi.rb +49 -0
  166. data/vendored/facter/lib/facter/util/xendomains.rb +28 -0
  167. data/vendored/facter/lib/facter/version.rb +86 -0
  168. data/vendored/facter/lib/facter/virtual.rb +328 -0
  169. data/vendored/facter/lib/facter/vlans.rb +17 -0
  170. data/vendored/facter/lib/facter/xendomains.rb +20 -0
  171. data/vendored/facter/lib/facter/zfs_version.rb +14 -0
  172. data/vendored/facter/lib/facter/zonename.rb +6 -0
  173. data/vendored/facter/lib/facter/zones.rb +18 -0
  174. data/vendored/facter/lib/facter/zpool_version.rb +10 -0
  175. data/vendored/hiera/lib/hiera.rb +119 -0
  176. data/vendored/hiera/lib/hiera/backend.rb +360 -0
  177. data/vendored/hiera/lib/hiera/backend/json_backend.rb +58 -0
  178. data/vendored/hiera/lib/hiera/backend/yaml_backend.rb +63 -0
  179. data/vendored/hiera/lib/hiera/config.rb +97 -0
  180. data/vendored/hiera/lib/hiera/console_logger.rb +13 -0
  181. data/vendored/hiera/lib/hiera/error.rb +4 -0
  182. data/vendored/hiera/lib/hiera/fallback_logger.rb +41 -0
  183. data/vendored/hiera/lib/hiera/filecache.rb +86 -0
  184. data/vendored/hiera/lib/hiera/interpolate.rb +121 -0
  185. data/vendored/hiera/lib/hiera/noop_logger.rb +8 -0
  186. data/vendored/hiera/lib/hiera/puppet_logger.rb +17 -0
  187. data/vendored/hiera/lib/hiera/recursive_guard.rb +20 -0
  188. data/vendored/hiera/lib/hiera/util.rb +65 -0
  189. data/vendored/hiera/lib/hiera/util/win32.rb +40 -0
  190. data/vendored/hiera/lib/hiera/version.rb +89 -0
  191. data/vendored/puppet/lib/hiera/puppet_function.rb +81 -0
  192. data/vendored/puppet/lib/hiera/scope.rb +61 -0
  193. data/vendored/puppet/lib/hiera_puppet.rb +79 -0
  194. data/vendored/puppet/lib/puppet.rb +311 -0
  195. data/vendored/puppet/lib/puppet/agent.rb +114 -0
  196. data/vendored/puppet/lib/puppet/agent/disabler.rb +53 -0
  197. data/vendored/puppet/lib/puppet/agent/locker.rb +52 -0
  198. data/vendored/puppet/lib/puppet/application.rb +485 -0
  199. data/vendored/puppet/lib/puppet/application/agent.rb +468 -0
  200. data/vendored/puppet/lib/puppet/application/apply.rb +358 -0
  201. data/vendored/puppet/lib/puppet/application/ca.rb +11 -0
  202. data/vendored/puppet/lib/puppet/application/catalog.rb +4 -0
  203. data/vendored/puppet/lib/puppet/application/cert.rb +334 -0
  204. data/vendored/puppet/lib/puppet/application/certificate.rb +17 -0
  205. data/vendored/puppet/lib/puppet/application/certificate_request.rb +7 -0
  206. data/vendored/puppet/lib/puppet/application/certificate_revocation_list.rb +7 -0
  207. data/vendored/puppet/lib/puppet/application/config.rb +4 -0
  208. data/vendored/puppet/lib/puppet/application/describe.rb +258 -0
  209. data/vendored/puppet/lib/puppet/application/device.rb +292 -0
  210. data/vendored/puppet/lib/puppet/application/doc.rb +230 -0
  211. data/vendored/puppet/lib/puppet/application/epp.rb +5 -0
  212. data/vendored/puppet/lib/puppet/application/face_base.rb +268 -0
  213. data/vendored/puppet/lib/puppet/application/facts.rb +4 -0
  214. data/vendored/puppet/lib/puppet/application/filebucket.rb +262 -0
  215. data/vendored/puppet/lib/puppet/application/generate.rb +5 -0
  216. data/vendored/puppet/lib/puppet/application/help.rb +4 -0
  217. data/vendored/puppet/lib/puppet/application/indirection_base.rb +4 -0
  218. data/vendored/puppet/lib/puppet/application/key.rb +4 -0
  219. data/vendored/puppet/lib/puppet/application/lookup.rb +361 -0
  220. data/vendored/puppet/lib/puppet/application/man.rb +4 -0
  221. data/vendored/puppet/lib/puppet/application/master.rb +317 -0
  222. data/vendored/puppet/lib/puppet/application/module.rb +4 -0
  223. data/vendored/puppet/lib/puppet/application/node.rb +4 -0
  224. data/vendored/puppet/lib/puppet/application/parser.rb +5 -0
  225. data/vendored/puppet/lib/puppet/application/plugin.rb +3 -0
  226. data/vendored/puppet/lib/puppet/application/report.rb +4 -0
  227. data/vendored/puppet/lib/puppet/application/resource.rb +231 -0
  228. data/vendored/puppet/lib/puppet/application/script.rb +255 -0
  229. data/vendored/puppet/lib/puppet/application/status.rb +4 -0
  230. data/vendored/puppet/lib/puppet/application_support.rb +57 -0
  231. data/vendored/puppet/lib/puppet/bindings.rb +147 -0
  232. data/vendored/puppet/lib/puppet/coercion.rb +40 -0
  233. data/vendored/puppet/lib/puppet/compilable_resource_type.rb +15 -0
  234. data/vendored/puppet/lib/puppet/configurer.rb +447 -0
  235. data/vendored/puppet/lib/puppet/configurer/downloader.rb +67 -0
  236. data/vendored/puppet/lib/puppet/configurer/downloader_factory.rb +34 -0
  237. data/vendored/puppet/lib/puppet/configurer/fact_handler.rb +46 -0
  238. data/vendored/puppet/lib/puppet/configurer/plugin_handler.rb +25 -0
  239. data/vendored/puppet/lib/puppet/confine.rb +80 -0
  240. data/vendored/puppet/lib/puppet/confine/any.rb +26 -0
  241. data/vendored/puppet/lib/puppet/confine/exists.rb +19 -0
  242. data/vendored/puppet/lib/puppet/confine/false.rb +19 -0
  243. data/vendored/puppet/lib/puppet/confine/feature.rb +17 -0
  244. data/vendored/puppet/lib/puppet/confine/true.rb +20 -0
  245. data/vendored/puppet/lib/puppet/confine/variable.rb +59 -0
  246. data/vendored/puppet/lib/puppet/confine_collection.rb +50 -0
  247. data/vendored/puppet/lib/puppet/confiner.rb +46 -0
  248. data/vendored/puppet/lib/puppet/context.rb +116 -0
  249. data/vendored/puppet/lib/puppet/context/trusted_information.rb +76 -0
  250. data/vendored/puppet/lib/puppet/daemon.rb +195 -0
  251. data/vendored/puppet/lib/puppet/data_binding.rb +14 -0
  252. data/vendored/puppet/lib/puppet/defaults.rb +1957 -0
  253. data/vendored/puppet/lib/puppet/environments.rb +509 -0
  254. data/vendored/puppet/lib/puppet/error.rb +117 -0
  255. data/vendored/puppet/lib/puppet/etc.rb +161 -0
  256. data/vendored/puppet/lib/puppet/external/dot.rb +326 -0
  257. data/vendored/puppet/lib/puppet/external/nagios.rb +46 -0
  258. data/vendored/puppet/lib/puppet/external/nagios/base.rb +472 -0
  259. data/vendored/puppet/lib/puppet/external/nagios/grammar.ry +248 -0
  260. data/vendored/puppet/lib/puppet/external/nagios/makefile +9 -0
  261. data/vendored/puppet/lib/puppet/external/nagios/parser.rb +400 -0
  262. data/vendored/puppet/lib/puppet/external/pson/common.rb +374 -0
  263. data/vendored/puppet/lib/puppet/external/pson/pure.rb +15 -0
  264. data/vendored/puppet/lib/puppet/external/pson/pure/generator.rb +395 -0
  265. data/vendored/puppet/lib/puppet/external/pson/pure/parser.rb +307 -0
  266. data/vendored/puppet/lib/puppet/external/pson/version.rb +8 -0
  267. data/vendored/puppet/lib/puppet/face.rb +12 -0
  268. data/vendored/puppet/lib/puppet/face/ca.rb +266 -0
  269. data/vendored/puppet/lib/puppet/face/catalog.rb +130 -0
  270. data/vendored/puppet/lib/puppet/face/catalog/select.rb +49 -0
  271. data/vendored/puppet/lib/puppet/face/certificate.rb +165 -0
  272. data/vendored/puppet/lib/puppet/face/certificate_request.rb +56 -0
  273. data/vendored/puppet/lib/puppet/face/certificate_revocation_list.rb +56 -0
  274. data/vendored/puppet/lib/puppet/face/config.rb +119 -0
  275. data/vendored/puppet/lib/puppet/face/epp.rb +527 -0
  276. data/vendored/puppet/lib/puppet/face/facts.rb +38 -0
  277. data/vendored/puppet/lib/puppet/face/generate.rb +64 -0
  278. data/vendored/puppet/lib/puppet/face/help.rb +205 -0
  279. data/vendored/puppet/lib/puppet/face/help/action.erb +86 -0
  280. data/vendored/puppet/lib/puppet/face/help/face.erb +114 -0
  281. data/vendored/puppet/lib/puppet/face/help/global.erb +16 -0
  282. data/vendored/puppet/lib/puppet/face/help/man.erb +152 -0
  283. data/vendored/puppet/lib/puppet/face/key.rb +16 -0
  284. data/vendored/puppet/lib/puppet/face/man.rb +101 -0
  285. data/vendored/puppet/lib/puppet/face/module.rb +19 -0
  286. data/vendored/puppet/lib/puppet/face/module/build.rb +63 -0
  287. data/vendored/puppet/lib/puppet/face/module/changes.rb +42 -0
  288. data/vendored/puppet/lib/puppet/face/module/generate.rb +251 -0
  289. data/vendored/puppet/lib/puppet/face/module/install.rb +149 -0
  290. data/vendored/puppet/lib/puppet/face/module/list.rb +279 -0
  291. data/vendored/puppet/lib/puppet/face/module/search.rb +94 -0
  292. data/vendored/puppet/lib/puppet/face/module/uninstall.rb +81 -0
  293. data/vendored/puppet/lib/puppet/face/module/upgrade.rb +90 -0
  294. data/vendored/puppet/lib/puppet/face/node.rb +42 -0
  295. data/vendored/puppet/lib/puppet/face/node/clean.rb +96 -0
  296. data/vendored/puppet/lib/puppet/face/parser.rb +161 -0
  297. data/vendored/puppet/lib/puppet/face/plugin.rb +58 -0
  298. data/vendored/puppet/lib/puppet/face/report.rb +54 -0
  299. data/vendored/puppet/lib/puppet/face/resource.rb +53 -0
  300. data/vendored/puppet/lib/puppet/face/status.rb +50 -0
  301. data/vendored/puppet/lib/puppet/feature/base.rb +95 -0
  302. data/vendored/puppet/lib/puppet/feature/bolt.rb +3 -0
  303. data/vendored/puppet/lib/puppet/feature/cfpropertylist.rb +3 -0
  304. data/vendored/puppet/lib/puppet/feature/eventlog.rb +5 -0
  305. data/vendored/puppet/lib/puppet/feature/hiera_eyaml.rb +3 -0
  306. data/vendored/puppet/lib/puppet/feature/hocon.rb +3 -0
  307. data/vendored/puppet/lib/puppet/feature/libuser.rb +8 -0
  308. data/vendored/puppet/lib/puppet/feature/msgpack.rb +3 -0
  309. data/vendored/puppet/lib/puppet/feature/pe_license.rb +4 -0
  310. data/vendored/puppet/lib/puppet/feature/rack.rb +19 -0
  311. data/vendored/puppet/lib/puppet/feature/selinux.rb +3 -0
  312. data/vendored/puppet/lib/puppet/feature/ssh.rb +3 -0
  313. data/vendored/puppet/lib/puppet/feature/telnet.rb +9 -0
  314. data/vendored/puppet/lib/puppet/feature/zlib.rb +5 -0
  315. data/vendored/puppet/lib/puppet/file_bucket.rb +4 -0
  316. data/vendored/puppet/lib/puppet/file_bucket/dipper.rb +174 -0
  317. data/vendored/puppet/lib/puppet/file_bucket/file.rb +131 -0
  318. data/vendored/puppet/lib/puppet/file_serving.rb +3 -0
  319. data/vendored/puppet/lib/puppet/file_serving/base.rb +85 -0
  320. data/vendored/puppet/lib/puppet/file_serving/configuration.rb +112 -0
  321. data/vendored/puppet/lib/puppet/file_serving/configuration/parser.rb +123 -0
  322. data/vendored/puppet/lib/puppet/file_serving/content.rb +43 -0
  323. data/vendored/puppet/lib/puppet/file_serving/fileset.rb +174 -0
  324. data/vendored/puppet/lib/puppet/file_serving/http_metadata.rb +46 -0
  325. data/vendored/puppet/lib/puppet/file_serving/metadata.rb +163 -0
  326. data/vendored/puppet/lib/puppet/file_serving/mount.rb +39 -0
  327. data/vendored/puppet/lib/puppet/file_serving/mount/file.rb +121 -0
  328. data/vendored/puppet/lib/puppet/file_serving/mount/modules.rb +24 -0
  329. data/vendored/puppet/lib/puppet/file_serving/mount/pluginfacts.rb +35 -0
  330. data/vendored/puppet/lib/puppet/file_serving/mount/plugins.rb +35 -0
  331. data/vendored/puppet/lib/puppet/file_serving/mount/tasks.rb +21 -0
  332. data/vendored/puppet/lib/puppet/file_serving/terminus_helper.rb +31 -0
  333. data/vendored/puppet/lib/puppet/file_serving/terminus_selector.rb +32 -0
  334. data/vendored/puppet/lib/puppet/file_system.rb +404 -0
  335. data/vendored/puppet/lib/puppet/file_system/file_impl.rb +154 -0
  336. data/vendored/puppet/lib/puppet/file_system/memory_file.rb +66 -0
  337. data/vendored/puppet/lib/puppet/file_system/memory_impl.rb +86 -0
  338. data/vendored/puppet/lib/puppet/file_system/path_pattern.rb +98 -0
  339. data/vendored/puppet/lib/puppet/file_system/posix.rb +46 -0
  340. data/vendored/puppet/lib/puppet/file_system/uniquefile.rb +190 -0
  341. data/vendored/puppet/lib/puppet/file_system/windows.rb +130 -0
  342. data/vendored/puppet/lib/puppet/forge.rb +229 -0
  343. data/vendored/puppet/lib/puppet/forge/cache.rb +60 -0
  344. data/vendored/puppet/lib/puppet/forge/errors.rb +112 -0
  345. data/vendored/puppet/lib/puppet/forge/repository.rb +155 -0
  346. data/vendored/puppet/lib/puppet/functions.rb +745 -0
  347. data/vendored/puppet/lib/puppet/functions/alert.rb +14 -0
  348. data/vendored/puppet/lib/puppet/functions/all.rb +104 -0
  349. data/vendored/puppet/lib/puppet/functions/annotate.rb +108 -0
  350. data/vendored/puppet/lib/puppet/functions/any.rb +109 -0
  351. data/vendored/puppet/lib/puppet/functions/assert_type.rb +93 -0
  352. data/vendored/puppet/lib/puppet/functions/binary_file.rb +19 -0
  353. data/vendored/puppet/lib/puppet/functions/break.rb +22 -0
  354. data/vendored/puppet/lib/puppet/functions/call.rb +42 -0
  355. data/vendored/puppet/lib/puppet/functions/contain.rb +39 -0
  356. data/vendored/puppet/lib/puppet/functions/crit.rb +14 -0
  357. data/vendored/puppet/lib/puppet/functions/debug.rb +14 -0
  358. data/vendored/puppet/lib/puppet/functions/defined.rb +160 -0
  359. data/vendored/puppet/lib/puppet/functions/dig.rb +23 -0
  360. data/vendored/puppet/lib/puppet/functions/each.rb +163 -0
  361. data/vendored/puppet/lib/puppet/functions/emerg.rb +14 -0
  362. data/vendored/puppet/lib/puppet/functions/epp.rb +48 -0
  363. data/vendored/puppet/lib/puppet/functions/err.rb +14 -0
  364. data/vendored/puppet/lib/puppet/functions/eyaml_lookup_key.rb +94 -0
  365. data/vendored/puppet/lib/puppet/functions/file_upload.rb +48 -0
  366. data/vendored/puppet/lib/puppet/functions/filter.rb +143 -0
  367. data/vendored/puppet/lib/puppet/functions/find_file.rb +31 -0
  368. data/vendored/puppet/lib/puppet/functions/hiera.rb +88 -0
  369. data/vendored/puppet/lib/puppet/functions/hiera_array.rb +81 -0
  370. data/vendored/puppet/lib/puppet/functions/hiera_hash.rb +92 -0
  371. data/vendored/puppet/lib/puppet/functions/hiera_include.rb +104 -0
  372. data/vendored/puppet/lib/puppet/functions/hocon_data.rb +41 -0
  373. data/vendored/puppet/lib/puppet/functions/import.rb +7 -0
  374. data/vendored/puppet/lib/puppet/functions/include.rb +27 -0
  375. data/vendored/puppet/lib/puppet/functions/info.rb +14 -0
  376. data/vendored/puppet/lib/puppet/functions/inline_epp.rb +59 -0
  377. data/vendored/puppet/lib/puppet/functions/json_data.rb +33 -0
  378. data/vendored/puppet/lib/puppet/functions/lest.rb +17 -0
  379. data/vendored/puppet/lib/puppet/functions/lookup.rb +223 -0
  380. data/vendored/puppet/lib/puppet/functions/map.rb +126 -0
  381. data/vendored/puppet/lib/puppet/functions/match.rb +120 -0
  382. data/vendored/puppet/lib/puppet/functions/new.rb +32 -0
  383. data/vendored/puppet/lib/puppet/functions/next.rb +23 -0
  384. data/vendored/puppet/lib/puppet/functions/notice.rb +14 -0
  385. data/vendored/puppet/lib/puppet/functions/reduce.rb +164 -0
  386. data/vendored/puppet/lib/puppet/functions/regsubst.rb +76 -0
  387. data/vendored/puppet/lib/puppet/functions/require.rb +43 -0
  388. data/vendored/puppet/lib/puppet/functions/return.rb +22 -0
  389. data/vendored/puppet/lib/puppet/functions/reverse_each.rb +25 -0
  390. data/vendored/puppet/lib/puppet/functions/run_command.rb +41 -0
  391. data/vendored/puppet/lib/puppet/functions/run_plan.rb +40 -0
  392. data/vendored/puppet/lib/puppet/functions/run_script.rb +50 -0
  393. data/vendored/puppet/lib/puppet/functions/run_task.rb +73 -0
  394. data/vendored/puppet/lib/puppet/functions/scanf.rb +44 -0
  395. data/vendored/puppet/lib/puppet/functions/slice.rb +111 -0
  396. data/vendored/puppet/lib/puppet/functions/split.rb +47 -0
  397. data/vendored/puppet/lib/puppet/functions/step.rb +26 -0
  398. data/vendored/puppet/lib/puppet/functions/strftime.rb +43 -0
  399. data/vendored/puppet/lib/puppet/functions/then.rb +14 -0
  400. data/vendored/puppet/lib/puppet/functions/tree_each.rb +200 -0
  401. data/vendored/puppet/lib/puppet/functions/type.rb +31 -0
  402. data/vendored/puppet/lib/puppet/functions/unique.rb +132 -0
  403. data/vendored/puppet/lib/puppet/functions/unwrap.rb +40 -0
  404. data/vendored/puppet/lib/puppet/functions/versioncmp.rb +36 -0
  405. data/vendored/puppet/lib/puppet/functions/warning.rb +14 -0
  406. data/vendored/puppet/lib/puppet/functions/with.rb +30 -0
  407. data/vendored/puppet/lib/puppet/functions/yaml_data.rb +42 -0
  408. data/vendored/puppet/lib/puppet/generate/models/type/property.rb +70 -0
  409. data/vendored/puppet/lib/puppet/generate/models/type/type.rb +62 -0
  410. data/vendored/puppet/lib/puppet/generate/templates/type/pcore.erb +42 -0
  411. data/vendored/puppet/lib/puppet/generate/type.rb +239 -0
  412. data/vendored/puppet/lib/puppet/gettext/config.rb +70 -0
  413. data/vendored/puppet/lib/puppet/gettext/stubs.rb +11 -0
  414. data/vendored/puppet/lib/puppet/graph.rb +11 -0
  415. data/vendored/puppet/lib/puppet/graph/key.rb +26 -0
  416. data/vendored/puppet/lib/puppet/graph/prioritizer.rb +29 -0
  417. data/vendored/puppet/lib/puppet/graph/random_prioritizer.rb +16 -0
  418. data/vendored/puppet/lib/puppet/graph/rb_tree_map.rb +388 -0
  419. data/vendored/puppet/lib/puppet/graph/relationship_graph.rb +277 -0
  420. data/vendored/puppet/lib/puppet/graph/sequential_prioritizer.rb +31 -0
  421. data/vendored/puppet/lib/puppet/graph/simple_graph.rb +539 -0
  422. data/vendored/puppet/lib/puppet/graph/title_hash_prioritizer.rb +16 -0
  423. data/vendored/puppet/lib/puppet/indirector.rb +61 -0
  424. data/vendored/puppet/lib/puppet/indirector/catalog/compiler.rb +384 -0
  425. data/vendored/puppet/lib/puppet/indirector/catalog/json.rb +24 -0
  426. data/vendored/puppet/lib/puppet/indirector/catalog/msgpack.rb +6 -0
  427. data/vendored/puppet/lib/puppet/indirector/catalog/rest.rb +6 -0
  428. data/vendored/puppet/lib/puppet/indirector/catalog/store_configs.rb +8 -0
  429. data/vendored/puppet/lib/puppet/indirector/catalog/yaml.rb +22 -0
  430. data/vendored/puppet/lib/puppet/indirector/certificate/ca.rb +9 -0
  431. data/vendored/puppet/lib/puppet/indirector/certificate/disabled_ca.rb +22 -0
  432. data/vendored/puppet/lib/puppet/indirector/certificate/file.rb +9 -0
  433. data/vendored/puppet/lib/puppet/indirector/certificate/rest.rb +16 -0
  434. data/vendored/puppet/lib/puppet/indirector/certificate_request/ca.rb +22 -0
  435. data/vendored/puppet/lib/puppet/indirector/certificate_request/disabled_ca.rb +22 -0
  436. data/vendored/puppet/lib/puppet/indirector/certificate_request/file.rb +8 -0
  437. data/vendored/puppet/lib/puppet/indirector/certificate_request/memory.rb +6 -0
  438. data/vendored/puppet/lib/puppet/indirector/certificate_request/rest.rb +10 -0
  439. data/vendored/puppet/lib/puppet/indirector/certificate_revocation_list/ca.rb +8 -0
  440. data/vendored/puppet/lib/puppet/indirector/certificate_revocation_list/disabled_ca.rb +22 -0
  441. data/vendored/puppet/lib/puppet/indirector/certificate_revocation_list/file.rb +8 -0
  442. data/vendored/puppet/lib/puppet/indirector/certificate_revocation_list/rest.rb +22 -0
  443. data/vendored/puppet/lib/puppet/indirector/certificate_status.rb +4 -0
  444. data/vendored/puppet/lib/puppet/indirector/certificate_status/file.rb +91 -0
  445. data/vendored/puppet/lib/puppet/indirector/certificate_status/rest.rb +11 -0
  446. data/vendored/puppet/lib/puppet/indirector/code.rb +6 -0
  447. data/vendored/puppet/lib/puppet/indirector/data_binding/hiera.rb +7 -0
  448. data/vendored/puppet/lib/puppet/indirector/data_binding/none.rb +8 -0
  449. data/vendored/puppet/lib/puppet/indirector/direct_file_server.rb +17 -0
  450. data/vendored/puppet/lib/puppet/indirector/envelope.rb +11 -0
  451. data/vendored/puppet/lib/puppet/indirector/errors.rb +5 -0
  452. data/vendored/puppet/lib/puppet/indirector/exec.rb +38 -0
  453. data/vendored/puppet/lib/puppet/indirector/face.rb +153 -0
  454. data/vendored/puppet/lib/puppet/indirector/facts/facter.rb +90 -0
  455. data/vendored/puppet/lib/puppet/indirector/facts/memory.rb +9 -0
  456. data/vendored/puppet/lib/puppet/indirector/facts/network_device.rb +27 -0
  457. data/vendored/puppet/lib/puppet/indirector/facts/store_configs.rb +11 -0
  458. data/vendored/puppet/lib/puppet/indirector/facts/yaml.rb +86 -0
  459. data/vendored/puppet/lib/puppet/indirector/file_bucket_file/file.rb +255 -0
  460. data/vendored/puppet/lib/puppet/indirector/file_bucket_file/rest.rb +8 -0
  461. data/vendored/puppet/lib/puppet/indirector/file_bucket_file/selector.rb +53 -0
  462. data/vendored/puppet/lib/puppet/indirector/file_content.rb +5 -0
  463. data/vendored/puppet/lib/puppet/indirector/file_content/file.rb +7 -0
  464. data/vendored/puppet/lib/puppet/indirector/file_content/file_server.rb +7 -0
  465. data/vendored/puppet/lib/puppet/indirector/file_content/http.rb +15 -0
  466. data/vendored/puppet/lib/puppet/indirector/file_content/rest.rb +9 -0
  467. data/vendored/puppet/lib/puppet/indirector/file_content/selector.rb +30 -0
  468. data/vendored/puppet/lib/puppet/indirector/file_metadata.rb +5 -0
  469. data/vendored/puppet/lib/puppet/indirector/file_metadata/file.rb +7 -0
  470. data/vendored/puppet/lib/puppet/indirector/file_metadata/file_server.rb +7 -0
  471. data/vendored/puppet/lib/puppet/indirector/file_metadata/http.rb +27 -0
  472. data/vendored/puppet/lib/puppet/indirector/file_metadata/rest.rb +9 -0
  473. data/vendored/puppet/lib/puppet/indirector/file_metadata/selector.rb +30 -0
  474. data/vendored/puppet/lib/puppet/indirector/file_server.rb +59 -0
  475. data/vendored/puppet/lib/puppet/indirector/generic_http.rb +16 -0
  476. data/vendored/puppet/lib/puppet/indirector/hiera.rb +94 -0
  477. data/vendored/puppet/lib/puppet/indirector/indirection.rb +336 -0
  478. data/vendored/puppet/lib/puppet/indirector/json.rb +75 -0
  479. data/vendored/puppet/lib/puppet/indirector/key/ca.rb +16 -0
  480. data/vendored/puppet/lib/puppet/indirector/key/disabled_ca.rb +22 -0
  481. data/vendored/puppet/lib/puppet/indirector/key/file.rb +50 -0
  482. data/vendored/puppet/lib/puppet/indirector/key/memory.rb +6 -0
  483. data/vendored/puppet/lib/puppet/indirector/ldap.rb +80 -0
  484. data/vendored/puppet/lib/puppet/indirector/memory.rb +34 -0
  485. data/vendored/puppet/lib/puppet/indirector/msgpack.rb +83 -0
  486. data/vendored/puppet/lib/puppet/indirector/node/exec.rb +71 -0
  487. data/vendored/puppet/lib/puppet/indirector/node/ldap.rb +259 -0
  488. data/vendored/puppet/lib/puppet/indirector/node/memory.rb +10 -0
  489. data/vendored/puppet/lib/puppet/indirector/node/msgpack.rb +7 -0
  490. data/vendored/puppet/lib/puppet/indirector/node/plain.rb +21 -0
  491. data/vendored/puppet/lib/puppet/indirector/node/rest.rb +7 -0
  492. data/vendored/puppet/lib/puppet/indirector/node/store_configs.rb +8 -0
  493. data/vendored/puppet/lib/puppet/indirector/node/write_only_yaml.rb +37 -0
  494. data/vendored/puppet/lib/puppet/indirector/node/yaml.rb +13 -0
  495. data/vendored/puppet/lib/puppet/indirector/none.rb +9 -0
  496. data/vendored/puppet/lib/puppet/indirector/plain.rb +9 -0
  497. data/vendored/puppet/lib/puppet/indirector/report/msgpack.rb +11 -0
  498. data/vendored/puppet/lib/puppet/indirector/report/processor.rb +59 -0
  499. data/vendored/puppet/lib/puppet/indirector/report/rest.rb +28 -0
  500. data/vendored/puppet/lib/puppet/indirector/report/yaml.rb +11 -0
  501. data/vendored/puppet/lib/puppet/indirector/request.rb +274 -0
  502. data/vendored/puppet/lib/puppet/indirector/resource/ral.rb +63 -0
  503. data/vendored/puppet/lib/puppet/indirector/resource/store_configs.rb +12 -0
  504. data/vendored/puppet/lib/puppet/indirector/resource/validator.rb +8 -0
  505. data/vendored/puppet/lib/puppet/indirector/rest.rb +348 -0
  506. data/vendored/puppet/lib/puppet/indirector/ssl_file.rb +201 -0
  507. data/vendored/puppet/lib/puppet/indirector/status.rb +3 -0
  508. data/vendored/puppet/lib/puppet/indirector/status/local.rb +12 -0
  509. data/vendored/puppet/lib/puppet/indirector/status/rest.rb +9 -0
  510. data/vendored/puppet/lib/puppet/indirector/store_configs.rb +30 -0
  511. data/vendored/puppet/lib/puppet/indirector/terminus.rb +169 -0
  512. data/vendored/puppet/lib/puppet/indirector/yaml.rb +63 -0
  513. data/vendored/puppet/lib/puppet/info_service.rb +17 -0
  514. data/vendored/puppet/lib/puppet/info_service/class_information_service.rb +110 -0
  515. data/vendored/puppet/lib/puppet/info_service/task_information_service.rb +32 -0
  516. data/vendored/puppet/lib/puppet/interface.rb +236 -0
  517. data/vendored/puppet/lib/puppet/interface/action.rb +374 -0
  518. data/vendored/puppet/lib/puppet/interface/action_builder.rb +149 -0
  519. data/vendored/puppet/lib/puppet/interface/action_manager.rb +97 -0
  520. data/vendored/puppet/lib/puppet/interface/documentation.rb +342 -0
  521. data/vendored/puppet/lib/puppet/interface/face_collection.rb +130 -0
  522. data/vendored/puppet/lib/puppet/interface/option.rb +150 -0
  523. data/vendored/puppet/lib/puppet/interface/option_builder.rb +91 -0
  524. data/vendored/puppet/lib/puppet/interface/option_manager.rb +99 -0
  525. data/vendored/puppet/lib/puppet/loaders.rb +26 -0
  526. data/vendored/puppet/lib/puppet/metatype/manager.rb +195 -0
  527. data/vendored/puppet/lib/puppet/module.rb +473 -0
  528. data/vendored/puppet/lib/puppet/module/task.rb +90 -0
  529. data/vendored/puppet/lib/puppet/module_tool.rb +196 -0
  530. data/vendored/puppet/lib/puppet/module_tool/applications.rb +14 -0
  531. data/vendored/puppet/lib/puppet/module_tool/applications/application.rb +90 -0
  532. data/vendored/puppet/lib/puppet/module_tool/applications/builder.rb +148 -0
  533. data/vendored/puppet/lib/puppet/module_tool/applications/checksummer.rb +62 -0
  534. data/vendored/puppet/lib/puppet/module_tool/applications/installer.rb +352 -0
  535. data/vendored/puppet/lib/puppet/module_tool/applications/searcher.rb +29 -0
  536. data/vendored/puppet/lib/puppet/module_tool/applications/uninstaller.rb +118 -0
  537. data/vendored/puppet/lib/puppet/module_tool/applications/unpacker.rb +100 -0
  538. data/vendored/puppet/lib/puppet/module_tool/applications/upgrader.rb +278 -0
  539. data/vendored/puppet/lib/puppet/module_tool/checksums.rb +49 -0
  540. data/vendored/puppet/lib/puppet/module_tool/contents_description.rb +88 -0
  541. data/vendored/puppet/lib/puppet/module_tool/dependency.rb +41 -0
  542. data/vendored/puppet/lib/puppet/module_tool/errors.rb +11 -0
  543. data/vendored/puppet/lib/puppet/module_tool/errors/base.rb +15 -0
  544. data/vendored/puppet/lib/puppet/module_tool/errors/installer.rb +95 -0
  545. data/vendored/puppet/lib/puppet/module_tool/errors/shared.rb +190 -0
  546. data/vendored/puppet/lib/puppet/module_tool/errors/uninstaller.rb +49 -0
  547. data/vendored/puppet/lib/puppet/module_tool/errors/upgrader.rb +63 -0
  548. data/vendored/puppet/lib/puppet/module_tool/install_directory.rb +45 -0
  549. data/vendored/puppet/lib/puppet/module_tool/installed_modules.rb +96 -0
  550. data/vendored/puppet/lib/puppet/module_tool/local_tarball.rb +90 -0
  551. data/vendored/puppet/lib/puppet/module_tool/metadata.rb +224 -0
  552. data/vendored/puppet/lib/puppet/module_tool/shared_behaviors.rb +180 -0
  553. data/vendored/puppet/lib/puppet/module_tool/skeleton/templates/generator/.fixtures.yml.erb +7 -0
  554. data/vendored/puppet/lib/puppet/module_tool/skeleton/templates/generator/.gitignore +18 -0
  555. data/vendored/puppet/lib/puppet/module_tool/skeleton/templates/generator/.rubocop.yml +42 -0
  556. data/vendored/puppet/lib/puppet/module_tool/skeleton/templates/generator/.yardopts +1 -0
  557. data/vendored/puppet/lib/puppet/module_tool/skeleton/templates/generator/Gemfile +18 -0
  558. data/vendored/puppet/lib/puppet/module_tool/skeleton/templates/generator/README.md.erb +89 -0
  559. data/vendored/puppet/lib/puppet/module_tool/skeleton/templates/generator/Rakefile +32 -0
  560. data/vendored/puppet/lib/puppet/module_tool/skeleton/templates/generator/examples/init.pp.erb +12 -0
  561. data/vendored/puppet/lib/puppet/module_tool/skeleton/templates/generator/manifests/init.pp.erb +48 -0
  562. data/vendored/puppet/lib/puppet/module_tool/skeleton/templates/generator/metadata.json.erb +1 -0
  563. data/vendored/puppet/lib/puppet/module_tool/skeleton/templates/generator/spec/classes/init_spec.rb.erb +6 -0
  564. data/vendored/puppet/lib/puppet/module_tool/skeleton/templates/generator/spec/spec_helper.rb +1 -0
  565. data/vendored/puppet/lib/puppet/module_tool/tar.rb +18 -0
  566. data/vendored/puppet/lib/puppet/module_tool/tar/gnu.rb +19 -0
  567. data/vendored/puppet/lib/puppet/module_tool/tar/mini.rb +53 -0
  568. data/vendored/puppet/lib/puppet/network.rb +3 -0
  569. data/vendored/puppet/lib/puppet/network/auth_config_parser.rb +85 -0
  570. data/vendored/puppet/lib/puppet/network/authconfig.rb +112 -0
  571. data/vendored/puppet/lib/puppet/network/authorization.rb +41 -0
  572. data/vendored/puppet/lib/puppet/network/authstore.rb +282 -0
  573. data/vendored/puppet/lib/puppet/network/client_request.rb +29 -0
  574. data/vendored/puppet/lib/puppet/network/format.rb +110 -0
  575. data/vendored/puppet/lib/puppet/network/format_handler.rb +108 -0
  576. data/vendored/puppet/lib/puppet/network/format_support.rb +134 -0
  577. data/vendored/puppet/lib/puppet/network/formats.rb +171 -0
  578. data/vendored/puppet/lib/puppet/network/http.rb +30 -0
  579. data/vendored/puppet/lib/puppet/network/http/api.rb +44 -0
  580. data/vendored/puppet/lib/puppet/network/http/api/ca.rb +2 -0
  581. data/vendored/puppet/lib/puppet/network/http/api/ca/v1.rb +11 -0
  582. data/vendored/puppet/lib/puppet/network/http/api/indirected_routes.rb +278 -0
  583. data/vendored/puppet/lib/puppet/network/http/api/indirection_type.rb +32 -0
  584. data/vendored/puppet/lib/puppet/network/http/api/master.rb +2 -0
  585. data/vendored/puppet/lib/puppet/network/http/api/master/v3.rb +28 -0
  586. data/vendored/puppet/lib/puppet/network/http/api/master/v3/authorization.rb +18 -0
  587. data/vendored/puppet/lib/puppet/network/http/api/master/v3/environment.rb +82 -0
  588. data/vendored/puppet/lib/puppet/network/http/api/master/v3/environments.rb +35 -0
  589. data/vendored/puppet/lib/puppet/network/http/compression.rb +120 -0
  590. data/vendored/puppet/lib/puppet/network/http/connection.rb +332 -0
  591. data/vendored/puppet/lib/puppet/network/http/error.rb +73 -0
  592. data/vendored/puppet/lib/puppet/network/http/factory.rb +47 -0
  593. data/vendored/puppet/lib/puppet/network/http/handler.rb +183 -0
  594. data/vendored/puppet/lib/puppet/network/http/issues.rb +12 -0
  595. data/vendored/puppet/lib/puppet/network/http/memory_response.rb +13 -0
  596. data/vendored/puppet/lib/puppet/network/http/nocache_pool.rb +21 -0
  597. data/vendored/puppet/lib/puppet/network/http/pool.rb +129 -0
  598. data/vendored/puppet/lib/puppet/network/http/rack.rb +33 -0
  599. data/vendored/puppet/lib/puppet/network/http/rack/rest.rb +162 -0
  600. data/vendored/puppet/lib/puppet/network/http/request.rb +70 -0
  601. data/vendored/puppet/lib/puppet/network/http/response.rb +23 -0
  602. data/vendored/puppet/lib/puppet/network/http/route.rb +100 -0
  603. data/vendored/puppet/lib/puppet/network/http/session.rb +17 -0
  604. data/vendored/puppet/lib/puppet/network/http/site.rb +39 -0
  605. data/vendored/puppet/lib/puppet/network/http/webrick.rb +125 -0
  606. data/vendored/puppet/lib/puppet/network/http/webrick/rest.rb +114 -0
  607. data/vendored/puppet/lib/puppet/network/http_pool.rb +61 -0
  608. data/vendored/puppet/lib/puppet/network/resolver.rb +86 -0
  609. data/vendored/puppet/lib/puppet/network/rest_controller.rb +2 -0
  610. data/vendored/puppet/lib/puppet/network/rights.rb +209 -0
  611. data/vendored/puppet/lib/puppet/network/server.rb +39 -0
  612. data/vendored/puppet/lib/puppet/node.rb +262 -0
  613. data/vendored/puppet/lib/puppet/node/environment.rb +572 -0
  614. data/vendored/puppet/lib/puppet/node/facts.rb +128 -0
  615. data/vendored/puppet/lib/puppet/parameter.rb +567 -0
  616. data/vendored/puppet/lib/puppet/parameter/boolean.rb +15 -0
  617. data/vendored/puppet/lib/puppet/parameter/package_options.rb +31 -0
  618. data/vendored/puppet/lib/puppet/parameter/path.rb +57 -0
  619. data/vendored/puppet/lib/puppet/parameter/value.rb +91 -0
  620. data/vendored/puppet/lib/puppet/parameter/value_collection.rb +212 -0
  621. data/vendored/puppet/lib/puppet/parser.rb +20 -0
  622. data/vendored/puppet/lib/puppet/parser/abstract_compiler.rb +36 -0
  623. data/vendored/puppet/lib/puppet/parser/ast.rb +65 -0
  624. data/vendored/puppet/lib/puppet/parser/ast/block_expression.rb +15 -0
  625. data/vendored/puppet/lib/puppet/parser/ast/branch.rb +19 -0
  626. data/vendored/puppet/lib/puppet/parser/ast/hostclass.rb +27 -0
  627. data/vendored/puppet/lib/puppet/parser/ast/leaf.rb +75 -0
  628. data/vendored/puppet/lib/puppet/parser/ast/node.rb +17 -0
  629. data/vendored/puppet/lib/puppet/parser/ast/pops_bridge.rb +273 -0
  630. data/vendored/puppet/lib/puppet/parser/ast/resource.rb +66 -0
  631. data/vendored/puppet/lib/puppet/parser/ast/resource_instance.rb +10 -0
  632. data/vendored/puppet/lib/puppet/parser/ast/resourceparam.rb +31 -0
  633. data/vendored/puppet/lib/puppet/parser/ast/top_level_construct.rb +4 -0
  634. data/vendored/puppet/lib/puppet/parser/compiler.rb +788 -0
  635. data/vendored/puppet/lib/puppet/parser/compiler/catalog_validator.rb +33 -0
  636. data/vendored/puppet/lib/puppet/parser/compiler/catalog_validator/env_relationship_validator.rb +64 -0
  637. data/vendored/puppet/lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb +57 -0
  638. data/vendored/puppet/lib/puppet/parser/compiler/catalog_validator/site_validator.rb +20 -0
  639. data/vendored/puppet/lib/puppet/parser/e4_parser_adapter.rb +60 -0
  640. data/vendored/puppet/lib/puppet/parser/environment_compiler.rb +199 -0
  641. data/vendored/puppet/lib/puppet/parser/files.rb +92 -0
  642. data/vendored/puppet/lib/puppet/parser/functions.rb +278 -0
  643. data/vendored/puppet/lib/puppet/parser/functions/assert_type.rb +60 -0
  644. data/vendored/puppet/lib/puppet/parser/functions/binary_file.rb +24 -0
  645. data/vendored/puppet/lib/puppet/parser/functions/break.rb +39 -0
  646. data/vendored/puppet/lib/puppet/parser/functions/contain.rb +30 -0
  647. data/vendored/puppet/lib/puppet/parser/functions/create_resources.rb +112 -0
  648. data/vendored/puppet/lib/puppet/parser/functions/defined.rb +107 -0
  649. data/vendored/puppet/lib/puppet/parser/functions/dig.rb +38 -0
  650. data/vendored/puppet/lib/puppet/parser/functions/digest.rb +5 -0
  651. data/vendored/puppet/lib/puppet/parser/functions/each.rb +104 -0
  652. data/vendored/puppet/lib/puppet/parser/functions/epp.rb +39 -0
  653. data/vendored/puppet/lib/puppet/parser/functions/fail.rb +4 -0
  654. data/vendored/puppet/lib/puppet/parser/functions/file.rb +33 -0
  655. data/vendored/puppet/lib/puppet/parser/functions/filter.rb +78 -0
  656. data/vendored/puppet/lib/puppet/parser/functions/find_file.rb +28 -0
  657. data/vendored/puppet/lib/puppet/parser/functions/fqdn_rand.rb +21 -0
  658. data/vendored/puppet/lib/puppet/parser/functions/generate.rb +38 -0
  659. data/vendored/puppet/lib/puppet/parser/functions/hiera.rb +103 -0
  660. data/vendored/puppet/lib/puppet/parser/functions/hiera_array.rb +92 -0
  661. data/vendored/puppet/lib/puppet/parser/functions/hiera_hash.rb +102 -0
  662. data/vendored/puppet/lib/puppet/parser/functions/hiera_include.rb +102 -0
  663. data/vendored/puppet/lib/puppet/parser/functions/include.rb +34 -0
  664. data/vendored/puppet/lib/puppet/parser/functions/inline_epp.rb +51 -0
  665. data/vendored/puppet/lib/puppet/parser/functions/inline_template.rb +27 -0
  666. data/vendored/puppet/lib/puppet/parser/functions/lest.rb +49 -0
  667. data/vendored/puppet/lib/puppet/parser/functions/lookup.rb +132 -0
  668. data/vendored/puppet/lib/puppet/parser/functions/map.rb +76 -0
  669. data/vendored/puppet/lib/puppet/parser/functions/match.rb +43 -0
  670. data/vendored/puppet/lib/puppet/parser/functions/md5.rb +5 -0
  671. data/vendored/puppet/lib/puppet/parser/functions/new.rb +1006 -0
  672. data/vendored/puppet/lib/puppet/parser/functions/next.rb +38 -0
  673. data/vendored/puppet/lib/puppet/parser/functions/realize.rb +20 -0
  674. data/vendored/puppet/lib/puppet/parser/functions/reduce.rb +137 -0
  675. data/vendored/puppet/lib/puppet/parser/functions/regsubst.rb +62 -0
  676. data/vendored/puppet/lib/puppet/parser/functions/require.rb +40 -0
  677. data/vendored/puppet/lib/puppet/parser/functions/return.rb +71 -0
  678. data/vendored/puppet/lib/puppet/parser/functions/reverse_each.rb +83 -0
  679. data/vendored/puppet/lib/puppet/parser/functions/scanf.rb +38 -0
  680. data/vendored/puppet/lib/puppet/parser/functions/sha1.rb +5 -0
  681. data/vendored/puppet/lib/puppet/parser/functions/shellquote.rb +61 -0
  682. data/vendored/puppet/lib/puppet/parser/functions/slice.rb +39 -0
  683. data/vendored/puppet/lib/puppet/parser/functions/split.rb +28 -0
  684. data/vendored/puppet/lib/puppet/parser/functions/sprintf.rb +36 -0
  685. data/vendored/puppet/lib/puppet/parser/functions/step.rb +84 -0
  686. data/vendored/puppet/lib/puppet/parser/functions/strftime.rb +185 -0
  687. data/vendored/puppet/lib/puppet/parser/functions/tag.rb +12 -0
  688. data/vendored/puppet/lib/puppet/parser/functions/tagged.rb +24 -0
  689. data/vendored/puppet/lib/puppet/parser/functions/template.rb +35 -0
  690. data/vendored/puppet/lib/puppet/parser/functions/then.rb +73 -0
  691. data/vendored/puppet/lib/puppet/parser/functions/type.rb +53 -0
  692. data/vendored/puppet/lib/puppet/parser/functions/versioncmp.rb +30 -0
  693. data/vendored/puppet/lib/puppet/parser/functions/with.rb +28 -0
  694. data/vendored/puppet/lib/puppet/parser/parser_factory.rb +30 -0
  695. data/vendored/puppet/lib/puppet/parser/relationship.rb +83 -0
  696. data/vendored/puppet/lib/puppet/parser/resource.rb +418 -0
  697. data/vendored/puppet/lib/puppet/parser/resource/param.rb +22 -0
  698. data/vendored/puppet/lib/puppet/parser/scope.rb +1112 -0
  699. data/vendored/puppet/lib/puppet/parser/script_compiler.rb +117 -0
  700. data/vendored/puppet/lib/puppet/parser/templatewrapper.rb +101 -0
  701. data/vendored/puppet/lib/puppet/parser/type_loader.rb +149 -0
  702. data/vendored/puppet/lib/puppet/plugins.rb +9 -0
  703. data/vendored/puppet/lib/puppet/plugins/configuration.rb +25 -0
  704. data/vendored/puppet/lib/puppet/plugins/syntax_checkers.rb +98 -0
  705. data/vendored/puppet/lib/puppet/pops.rb +120 -0
  706. data/vendored/puppet/lib/puppet/pops/adaptable.rb +206 -0
  707. data/vendored/puppet/lib/puppet/pops/adapters.rb +138 -0
  708. data/vendored/puppet/lib/puppet/pops/evaluator/access_operator.rb +706 -0
  709. data/vendored/puppet/lib/puppet/pops/evaluator/callable_signature.rb +107 -0
  710. data/vendored/puppet/lib/puppet/pops/evaluator/closure.rb +373 -0
  711. data/vendored/puppet/lib/puppet/pops/evaluator/collector_transformer.rb +233 -0
  712. data/vendored/puppet/lib/puppet/pops/evaluator/collectors/abstract_collector.rb +86 -0
  713. data/vendored/puppet/lib/puppet/pops/evaluator/collectors/catalog_collector.rb +29 -0
  714. data/vendored/puppet/lib/puppet/pops/evaluator/collectors/exported_collector.rb +69 -0
  715. data/vendored/puppet/lib/puppet/pops/evaluator/collectors/fixed_set_collector.rb +37 -0
  716. data/vendored/puppet/lib/puppet/pops/evaluator/compare_operator.rb +252 -0
  717. data/vendored/puppet/lib/puppet/pops/evaluator/epp_evaluator.rb +94 -0
  718. data/vendored/puppet/lib/puppet/pops/evaluator/evaluator_impl.rb +1258 -0
  719. data/vendored/puppet/lib/puppet/pops/evaluator/external_syntax_support.rb +45 -0
  720. data/vendored/puppet/lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb +82 -0
  721. data/vendored/puppet/lib/puppet/pops/evaluator/literal_evaluator.rb +87 -0
  722. data/vendored/puppet/lib/puppet/pops/evaluator/puppet_proc.rb +69 -0
  723. data/vendored/puppet/lib/puppet/pops/evaluator/relationship_operator.rb +185 -0
  724. data/vendored/puppet/lib/puppet/pops/evaluator/runtime3_converter.rb +200 -0
  725. data/vendored/puppet/lib/puppet/pops/evaluator/runtime3_resource_support.rb +117 -0
  726. data/vendored/puppet/lib/puppet/pops/evaluator/runtime3_support.rb +538 -0
  727. data/vendored/puppet/lib/puppet/pops/functions/dispatch.rb +100 -0
  728. data/vendored/puppet/lib/puppet/pops/functions/dispatcher.rb +71 -0
  729. data/vendored/puppet/lib/puppet/pops/functions/function.rb +135 -0
  730. data/vendored/puppet/lib/puppet/pops/issue_reporter.rb +115 -0
  731. data/vendored/puppet/lib/puppet/pops/issues.rb +888 -0
  732. data/vendored/puppet/lib/puppet/pops/label_provider.rb +90 -0
  733. data/vendored/puppet/lib/puppet/pops/loader/base_loader.rb +166 -0
  734. data/vendored/puppet/lib/puppet/pops/loader/dependency_loader.rb +92 -0
  735. data/vendored/puppet/lib/puppet/pops/loader/gem_support.rb +49 -0
  736. data/vendored/puppet/lib/puppet/pops/loader/loader.rb +204 -0
  737. data/vendored/puppet/lib/puppet/pops/loader/loader_paths.rb +296 -0
  738. data/vendored/puppet/lib/puppet/pops/loader/module_loaders.rb +452 -0
  739. data/vendored/puppet/lib/puppet/pops/loader/null_loader.rb +60 -0
  740. data/vendored/puppet/lib/puppet/pops/loader/predefined_loader.rb +24 -0
  741. data/vendored/puppet/lib/puppet/pops/loader/puppet_function_instantiator.rb +84 -0
  742. data/vendored/puppet/lib/puppet/pops/loader/puppet_plan_instantiator.rb +84 -0
  743. data/vendored/puppet/lib/puppet/pops/loader/puppet_resource_type_impl_instantiator.rb +79 -0
  744. data/vendored/puppet/lib/puppet/pops/loader/ruby_function_instantiator.rb +46 -0
  745. data/vendored/puppet/lib/puppet/pops/loader/runtime3_type_loader.rb +101 -0
  746. data/vendored/puppet/lib/puppet/pops/loader/simple_environment_loader.rb +20 -0
  747. data/vendored/puppet/lib/puppet/pops/loader/static_loader.rb +164 -0
  748. data/vendored/puppet/lib/puppet/pops/loader/task_instantiator.rb +117 -0
  749. data/vendored/puppet/lib/puppet/pops/loader/type_definition_instantiator.rb +97 -0
  750. data/vendored/puppet/lib/puppet/pops/loader/typed_name.rb +54 -0
  751. data/vendored/puppet/lib/puppet/pops/loader/uri_helper.rb +22 -0
  752. data/vendored/puppet/lib/puppet/pops/loaders.rb +517 -0
  753. data/vendored/puppet/lib/puppet/pops/lookup.rb +96 -0
  754. data/vendored/puppet/lib/puppet/pops/lookup/configured_data_provider.rb +93 -0
  755. data/vendored/puppet/lib/puppet/pops/lookup/context.rb +200 -0
  756. data/vendored/puppet/lib/puppet/pops/lookup/data_adapter.rb +27 -0
  757. data/vendored/puppet/lib/puppet/pops/lookup/data_dig_function_provider.rb +145 -0
  758. data/vendored/puppet/lib/puppet/pops/lookup/data_hash_function_provider.rb +126 -0
  759. data/vendored/puppet/lib/puppet/pops/lookup/data_provider.rb +92 -0
  760. data/vendored/puppet/lib/puppet/pops/lookup/environment_data_provider.rb +35 -0
  761. data/vendored/puppet/lib/puppet/pops/lookup/explainer.rb +594 -0
  762. data/vendored/puppet/lib/puppet/pops/lookup/function_provider.rb +110 -0
  763. data/vendored/puppet/lib/puppet/pops/lookup/global_data_provider.rb +75 -0
  764. data/vendored/puppet/lib/puppet/pops/lookup/hiera_config.rb +761 -0
  765. data/vendored/puppet/lib/puppet/pops/lookup/interpolation.rb +154 -0
  766. data/vendored/puppet/lib/puppet/pops/lookup/invocation.rb +261 -0
  767. data/vendored/puppet/lib/puppet/pops/lookup/location_resolver.rb +99 -0
  768. data/vendored/puppet/lib/puppet/pops/lookup/lookup_adapter.rb +472 -0
  769. data/vendored/puppet/lib/puppet/pops/lookup/lookup_key.rb +99 -0
  770. data/vendored/puppet/lib/puppet/pops/lookup/lookup_key_function_provider.rb +92 -0
  771. data/vendored/puppet/lib/puppet/pops/lookup/module_data_provider.rb +89 -0
  772. data/vendored/puppet/lib/puppet/pops/lookup/sub_lookup.rb +92 -0
  773. data/vendored/puppet/lib/puppet/pops/merge_strategy.rb +434 -0
  774. data/vendored/puppet/lib/puppet/pops/migration/migration_checker.rb +58 -0
  775. data/vendored/puppet/lib/puppet/pops/model/ast.pp +695 -0
  776. data/vendored/puppet/lib/puppet/pops/model/ast.rb +4870 -0
  777. data/vendored/puppet/lib/puppet/pops/model/ast_transformer.rb +131 -0
  778. data/vendored/puppet/lib/puppet/pops/model/factory.rb +1145 -0
  779. data/vendored/puppet/lib/puppet/pops/model/model_label_provider.rb +132 -0
  780. data/vendored/puppet/lib/puppet/pops/model/model_tree_dumper.rb +463 -0
  781. data/vendored/puppet/lib/puppet/pops/model/tree_dumper.rb +59 -0
  782. data/vendored/puppet/lib/puppet/pops/parser/code_merger.rb +29 -0
  783. data/vendored/puppet/lib/puppet/pops/parser/egrammar.ra +937 -0
  784. data/vendored/puppet/lib/puppet/pops/parser/eparser.rb +3347 -0
  785. data/vendored/puppet/lib/puppet/pops/parser/epp_parser.rb +51 -0
  786. data/vendored/puppet/lib/puppet/pops/parser/epp_support.rb +262 -0
  787. data/vendored/puppet/lib/puppet/pops/parser/evaluating_parser.rb +165 -0
  788. data/vendored/puppet/lib/puppet/pops/parser/heredoc_support.rb +143 -0
  789. data/vendored/puppet/lib/puppet/pops/parser/interpolation_support.rb +244 -0
  790. data/vendored/puppet/lib/puppet/pops/parser/lexer2.rb +796 -0
  791. data/vendored/puppet/lib/puppet/pops/parser/lexer_support.rb +220 -0
  792. data/vendored/puppet/lib/puppet/pops/parser/locatable.rb +23 -0
  793. data/vendored/puppet/lib/puppet/pops/parser/locator.rb +344 -0
  794. data/vendored/puppet/lib/puppet/pops/parser/parser_support.rb +247 -0
  795. data/vendored/puppet/lib/puppet/pops/parser/slurp_support.rb +120 -0
  796. data/vendored/puppet/lib/puppet/pops/patterns.rb +60 -0
  797. data/vendored/puppet/lib/puppet/pops/pcore.rb +107 -0
  798. data/vendored/puppet/lib/puppet/pops/puppet_stack.rb +43 -0
  799. data/vendored/puppet/lib/puppet/pops/resource/param.rb +55 -0
  800. data/vendored/puppet/lib/puppet/pops/resource/resource_type_impl.rb +314 -0
  801. data/vendored/puppet/lib/puppet/pops/resource/resource_type_set.pcore +22 -0
  802. data/vendored/puppet/lib/puppet/pops/semantic_error.rb +29 -0
  803. data/vendored/puppet/lib/puppet/pops/serialization.rb +41 -0
  804. data/vendored/puppet/lib/puppet/pops/serialization/abstract_reader.rb +176 -0
  805. data/vendored/puppet/lib/puppet/pops/serialization/abstract_writer.rb +215 -0
  806. data/vendored/puppet/lib/puppet/pops/serialization/deserializer.rb +80 -0
  807. data/vendored/puppet/lib/puppet/pops/serialization/extension.rb +157 -0
  808. data/vendored/puppet/lib/puppet/pops/serialization/from_data_converter.rb +169 -0
  809. data/vendored/puppet/lib/puppet/pops/serialization/instance_reader.rb +19 -0
  810. data/vendored/puppet/lib/puppet/pops/serialization/instance_writer.rb +14 -0
  811. data/vendored/puppet/lib/puppet/pops/serialization/json.rb +297 -0
  812. data/vendored/puppet/lib/puppet/pops/serialization/json_path.rb +126 -0
  813. data/vendored/puppet/lib/puppet/pops/serialization/object.rb +71 -0
  814. data/vendored/puppet/lib/puppet/pops/serialization/serializer.rb +139 -0
  815. data/vendored/puppet/lib/puppet/pops/serialization/time_factory.rb +67 -0
  816. data/vendored/puppet/lib/puppet/pops/serialization/to_data_converter.rb +301 -0
  817. data/vendored/puppet/lib/puppet/pops/time/timespan.rb +718 -0
  818. data/vendored/puppet/lib/puppet/pops/time/timestamp.rb +160 -0
  819. data/vendored/puppet/lib/puppet/pops/types/annotatable.rb +36 -0
  820. data/vendored/puppet/lib/puppet/pops/types/annotation.rb +71 -0
  821. data/vendored/puppet/lib/puppet/pops/types/class_loader.rb +129 -0
  822. data/vendored/puppet/lib/puppet/pops/types/enumeration.rb +16 -0
  823. data/vendored/puppet/lib/puppet/pops/types/execution_result.rb +126 -0
  824. data/vendored/puppet/lib/puppet/pops/types/implementation_registry.rb +141 -0
  825. data/vendored/puppet/lib/puppet/pops/types/iterable.rb +330 -0
  826. data/vendored/puppet/lib/puppet/pops/types/p_binary_type.rb +226 -0
  827. data/vendored/puppet/lib/puppet/pops/types/p_error_type.rb +146 -0
  828. data/vendored/puppet/lib/puppet/pops/types/p_init_type.rb +238 -0
  829. data/vendored/puppet/lib/puppet/pops/types/p_meta_type.rb +90 -0
  830. data/vendored/puppet/lib/puppet/pops/types/p_object_type.rb +976 -0
  831. data/vendored/puppet/lib/puppet/pops/types/p_runtime_type.rb +115 -0
  832. data/vendored/puppet/lib/puppet/pops/types/p_sem_ver_range_type.rb +191 -0
  833. data/vendored/puppet/lib/puppet/pops/types/p_sem_ver_type.rb +141 -0
  834. data/vendored/puppet/lib/puppet/pops/types/p_sensitive_type.rb +73 -0
  835. data/vendored/puppet/lib/puppet/pops/types/p_timespan_type.rb +192 -0
  836. data/vendored/puppet/lib/puppet/pops/types/p_timestamp_type.rb +73 -0
  837. data/vendored/puppet/lib/puppet/pops/types/p_type_set_type.rb +361 -0
  838. data/vendored/puppet/lib/puppet/pops/types/puppet_object.rb +30 -0
  839. data/vendored/puppet/lib/puppet/pops/types/recursion_guard.rb +136 -0
  840. data/vendored/puppet/lib/puppet/pops/types/ruby_generator.rb +432 -0
  841. data/vendored/puppet/lib/puppet/pops/types/ruby_method.rb +31 -0
  842. data/vendored/puppet/lib/puppet/pops/types/string_converter.rb +1102 -0
  843. data/vendored/puppet/lib/puppet/pops/types/task.rb +116 -0
  844. data/vendored/puppet/lib/puppet/pops/types/tree_iterators.rb +250 -0
  845. data/vendored/puppet/lib/puppet/pops/types/type_acceptor.rb +25 -0
  846. data/vendored/puppet/lib/puppet/pops/types/type_asserter.rb +47 -0
  847. data/vendored/puppet/lib/puppet/pops/types/type_assertion_error.rb +27 -0
  848. data/vendored/puppet/lib/puppet/pops/types/type_calculator.rb +799 -0
  849. data/vendored/puppet/lib/puppet/pops/types/type_conversion_error.rb +15 -0
  850. data/vendored/puppet/lib/puppet/pops/types/type_factory.rb +599 -0
  851. data/vendored/puppet/lib/puppet/pops/types/type_formatter.rb +769 -0
  852. data/vendored/puppet/lib/puppet/pops/types/type_mismatch_describer.rb +1062 -0
  853. data/vendored/puppet/lib/puppet/pops/types/type_parser.rb +602 -0
  854. data/vendored/puppet/lib/puppet/pops/types/type_set_reference.rb +59 -0
  855. data/vendored/puppet/lib/puppet/pops/types/types.rb +3519 -0
  856. data/vendored/puppet/lib/puppet/pops/utils.rb +119 -0
  857. data/vendored/puppet/lib/puppet/pops/validation.rb +464 -0
  858. data/vendored/puppet/lib/puppet/pops/validation/checker4_0.rb +996 -0
  859. data/vendored/puppet/lib/puppet/pops/validation/tasks_checker.rb +60 -0
  860. data/vendored/puppet/lib/puppet/pops/validation/validator_factory_4_0.rb +43 -0
  861. data/vendored/puppet/lib/puppet/pops/visitable.rb +6 -0
  862. data/vendored/puppet/lib/puppet/pops/visitor.rb +116 -0
  863. data/vendored/puppet/lib/puppet/property.rb +600 -0
  864. data/vendored/puppet/lib/puppet/property/boolean.rb +7 -0
  865. data/vendored/puppet/lib/puppet/property/ensure.rb +105 -0
  866. data/vendored/puppet/lib/puppet/property/keyvalue.rb +95 -0
  867. data/vendored/puppet/lib/puppet/property/list.rb +69 -0
  868. data/vendored/puppet/lib/puppet/property/ordered_list.rb +29 -0
  869. data/vendored/puppet/lib/puppet/provider.rb +603 -0
  870. data/vendored/puppet/lib/puppet/provider/aixobject.rb +392 -0
  871. data/vendored/puppet/lib/puppet/provider/augeas/augeas.rb +567 -0
  872. data/vendored/puppet/lib/puppet/provider/cisco.rb +9 -0
  873. data/vendored/puppet/lib/puppet/provider/command.rb +25 -0
  874. data/vendored/puppet/lib/puppet/provider/computer/computer.rb +20 -0
  875. data/vendored/puppet/lib/puppet/provider/confine.rb +6 -0
  876. data/vendored/puppet/lib/puppet/provider/cron/crontab.rb +297 -0
  877. data/vendored/puppet/lib/puppet/provider/exec.rb +98 -0
  878. data/vendored/puppet/lib/puppet/provider/exec/posix.rb +48 -0
  879. data/vendored/puppet/lib/puppet/provider/exec/shell.rb +25 -0
  880. data/vendored/puppet/lib/puppet/provider/exec/windows.rb +55 -0
  881. data/vendored/puppet/lib/puppet/provider/file/posix.rb +136 -0
  882. data/vendored/puppet/lib/puppet/provider/file/windows.rb +104 -0
  883. data/vendored/puppet/lib/puppet/provider/group/aix.rb +141 -0
  884. data/vendored/puppet/lib/puppet/provider/group/directoryservice.rb +22 -0
  885. data/vendored/puppet/lib/puppet/provider/group/groupadd.rb +85 -0
  886. data/vendored/puppet/lib/puppet/provider/group/ldap.rb +45 -0
  887. data/vendored/puppet/lib/puppet/provider/group/pw.rb +49 -0
  888. data/vendored/puppet/lib/puppet/provider/group/windows_adsi.rb +109 -0
  889. data/vendored/puppet/lib/puppet/provider/host/parsed.rb +46 -0
  890. data/vendored/puppet/lib/puppet/provider/interface/cisco.rb +27 -0
  891. data/vendored/puppet/lib/puppet/provider/ldap.rb +137 -0
  892. data/vendored/puppet/lib/puppet/provider/macauthorization/macauthorization.rb +298 -0
  893. data/vendored/puppet/lib/puppet/provider/mailalias/aliases.rb +50 -0
  894. data/vendored/puppet/lib/puppet/provider/maillist/mailman.rb +108 -0
  895. data/vendored/puppet/lib/puppet/provider/mcx/mcxcontent.rb +173 -0
  896. data/vendored/puppet/lib/puppet/provider/mount.rb +59 -0
  897. data/vendored/puppet/lib/puppet/provider/mount/parsed.rb +282 -0
  898. data/vendored/puppet/lib/puppet/provider/naginator.rb +63 -0
  899. data/vendored/puppet/lib/puppet/provider/nameservice.rb +317 -0
  900. data/vendored/puppet/lib/puppet/provider/nameservice/directoryservice.rb +507 -0
  901. data/vendored/puppet/lib/puppet/provider/nameservice/objectadd.rb +33 -0
  902. data/vendored/puppet/lib/puppet/provider/nameservice/pw.rb +21 -0
  903. data/vendored/puppet/lib/puppet/provider/network_device.rb +72 -0
  904. data/vendored/puppet/lib/puppet/provider/package.rb +56 -0
  905. data/vendored/puppet/lib/puppet/provider/package/aix.rb +152 -0
  906. data/vendored/puppet/lib/puppet/provider/package/appdmg.rb +110 -0
  907. data/vendored/puppet/lib/puppet/provider/package/apple.rb +47 -0
  908. data/vendored/puppet/lib/puppet/provider/package/apt.rb +116 -0
  909. data/vendored/puppet/lib/puppet/provider/package/aptitude.rb +29 -0
  910. data/vendored/puppet/lib/puppet/provider/package/aptrpm.rb +83 -0
  911. data/vendored/puppet/lib/puppet/provider/package/blastwave.rb +111 -0
  912. data/vendored/puppet/lib/puppet/provider/package/dnf.rb +46 -0
  913. data/vendored/puppet/lib/puppet/provider/package/dpkg.rb +165 -0
  914. data/vendored/puppet/lib/puppet/provider/package/fink.rb +79 -0
  915. data/vendored/puppet/lib/puppet/provider/package/freebsd.rb +47 -0
  916. data/vendored/puppet/lib/puppet/provider/package/gem.rb +175 -0
  917. data/vendored/puppet/lib/puppet/provider/package/hpux.rb +44 -0
  918. data/vendored/puppet/lib/puppet/provider/package/macports.rb +107 -0
  919. data/vendored/puppet/lib/puppet/provider/package/nim.rb +283 -0
  920. data/vendored/puppet/lib/puppet/provider/package/openbsd.rb +242 -0
  921. data/vendored/puppet/lib/puppet/provider/package/opkg.rb +81 -0
  922. data/vendored/puppet/lib/puppet/provider/package/pacman.rb +267 -0
  923. data/vendored/puppet/lib/puppet/provider/package/pip.rb +188 -0
  924. data/vendored/puppet/lib/puppet/provider/package/pip3.rb +20 -0
  925. data/vendored/puppet/lib/puppet/provider/package/pkg.rb +249 -0
  926. data/vendored/puppet/lib/puppet/provider/package/pkgdmg.rb +152 -0
  927. data/vendored/puppet/lib/puppet/provider/package/pkgin.rb +87 -0
  928. data/vendored/puppet/lib/puppet/provider/package/pkgng.rb +143 -0
  929. data/vendored/puppet/lib/puppet/provider/package/pkgutil.rb +186 -0
  930. data/vendored/puppet/lib/puppet/provider/package/portage.rb +301 -0
  931. data/vendored/puppet/lib/puppet/provider/package/ports.rb +91 -0
  932. data/vendored/puppet/lib/puppet/provider/package/portupgrade.rb +239 -0
  933. data/vendored/puppet/lib/puppet/provider/package/puppet_gem.rb +17 -0
  934. data/vendored/puppet/lib/puppet/provider/package/rpm.rb +405 -0
  935. data/vendored/puppet/lib/puppet/provider/package/rug.rb +51 -0
  936. data/vendored/puppet/lib/puppet/provider/package/sun.rb +133 -0
  937. data/vendored/puppet/lib/puppet/provider/package/sunfreeware.rb +9 -0
  938. data/vendored/puppet/lib/puppet/provider/package/tdnf.rb +28 -0
  939. data/vendored/puppet/lib/puppet/provider/package/up2date.rb +40 -0
  940. data/vendored/puppet/lib/puppet/provider/package/urpmi.rb +55 -0
  941. data/vendored/puppet/lib/puppet/provider/package/windows.rb +113 -0
  942. data/vendored/puppet/lib/puppet/provider/package/windows/exe_package.rb +71 -0
  943. data/vendored/puppet/lib/puppet/provider/package/windows/msi_package.rb +62 -0
  944. data/vendored/puppet/lib/puppet/provider/package/windows/package.rb +100 -0
  945. data/vendored/puppet/lib/puppet/provider/package/yum.rb +278 -0
  946. data/vendored/puppet/lib/puppet/provider/package/zypper.rb +145 -0
  947. data/vendored/puppet/lib/puppet/provider/parsedfile.rb +459 -0
  948. data/vendored/puppet/lib/puppet/provider/scheduled_task/win32_taskscheduler.rb +590 -0
  949. data/vendored/puppet/lib/puppet/provider/selboolean/getsetsebool.rb +47 -0
  950. data/vendored/puppet/lib/puppet/provider/selmodule/semodule.rb +138 -0
  951. data/vendored/puppet/lib/puppet/provider/service/base.rb +121 -0
  952. data/vendored/puppet/lib/puppet/provider/service/bsd.rb +51 -0
  953. data/vendored/puppet/lib/puppet/provider/service/daemontools.rb +194 -0
  954. data/vendored/puppet/lib/puppet/provider/service/debian.rb +74 -0
  955. data/vendored/puppet/lib/puppet/provider/service/freebsd.rb +143 -0
  956. data/vendored/puppet/lib/puppet/provider/service/gentoo.rb +45 -0
  957. data/vendored/puppet/lib/puppet/provider/service/init.rb +193 -0
  958. data/vendored/puppet/lib/puppet/provider/service/launchd.rb +346 -0
  959. data/vendored/puppet/lib/puppet/provider/service/openbsd.rb +100 -0
  960. data/vendored/puppet/lib/puppet/provider/service/openrc.rb +71 -0
  961. data/vendored/puppet/lib/puppet/provider/service/openwrt.rb +36 -0
  962. data/vendored/puppet/lib/puppet/provider/service/rcng.rb +51 -0
  963. data/vendored/puppet/lib/puppet/provider/service/redhat.rb +71 -0
  964. data/vendored/puppet/lib/puppet/provider/service/runit.rb +111 -0
  965. data/vendored/puppet/lib/puppet/provider/service/service.rb +42 -0
  966. data/vendored/puppet/lib/puppet/provider/service/smf.rb +167 -0
  967. data/vendored/puppet/lib/puppet/provider/service/src.rb +147 -0
  968. data/vendored/puppet/lib/puppet/provider/service/systemd.rb +186 -0
  969. data/vendored/puppet/lib/puppet/provider/service/upstart.rb +359 -0
  970. data/vendored/puppet/lib/puppet/provider/service/windows.rb +106 -0
  971. data/vendored/puppet/lib/puppet/provider/ssh_authorized_key/parsed.rb +105 -0
  972. data/vendored/puppet/lib/puppet/provider/sshkey/parsed.rb +50 -0
  973. data/vendored/puppet/lib/puppet/provider/user/aix.rb +375 -0
  974. data/vendored/puppet/lib/puppet/provider/user/directoryservice.rb +632 -0
  975. data/vendored/puppet/lib/puppet/provider/user/hpux.rb +95 -0
  976. data/vendored/puppet/lib/puppet/provider/user/ldap.rb +128 -0
  977. data/vendored/puppet/lib/puppet/provider/user/openbsd.rb +75 -0
  978. data/vendored/puppet/lib/puppet/provider/user/pw.rb +98 -0
  979. data/vendored/puppet/lib/puppet/provider/user/user_role_add.rb +227 -0
  980. data/vendored/puppet/lib/puppet/provider/user/useradd.rb +231 -0
  981. data/vendored/puppet/lib/puppet/provider/user/windows_adsi.rb +148 -0
  982. data/vendored/puppet/lib/puppet/provider/vlan/cisco.rb +28 -0
  983. data/vendored/puppet/lib/puppet/provider/yumrepo/inifile.rb +304 -0
  984. data/vendored/puppet/lib/puppet/provider/zfs/zfs.rb +84 -0
  985. data/vendored/puppet/lib/puppet/provider/zone/solaris.rb +364 -0
  986. data/vendored/puppet/lib/puppet/provider/zpool/zpool.rb +125 -0
  987. data/vendored/puppet/lib/puppet/reference/configuration.rb +82 -0
  988. data/vendored/puppet/lib/puppet/reference/function.rb +17 -0
  989. data/vendored/puppet/lib/puppet/reference/indirection.rb +71 -0
  990. data/vendored/puppet/lib/puppet/reference/metaparameter.rb +35 -0
  991. data/vendored/puppet/lib/puppet/reference/providers.rb +118 -0
  992. data/vendored/puppet/lib/puppet/reference/report.rb +20 -0
  993. data/vendored/puppet/lib/puppet/reference/type.rb +114 -0
  994. data/vendored/puppet/lib/puppet/relationship.rb +88 -0
  995. data/vendored/puppet/lib/puppet/reports.rb +93 -0
  996. data/vendored/puppet/lib/puppet/reports/http.rb +37 -0
  997. data/vendored/puppet/lib/puppet/reports/log.rb +14 -0
  998. data/vendored/puppet/lib/puppet/reports/store.rb +68 -0
  999. data/vendored/puppet/lib/puppet/resource.rb +669 -0
  1000. data/vendored/puppet/lib/puppet/resource/capability_finder.rb +147 -0
  1001. data/vendored/puppet/lib/puppet/resource/catalog.rb +667 -0
  1002. data/vendored/puppet/lib/puppet/resource/status.rb +221 -0
  1003. data/vendored/puppet/lib/puppet/resource/type.rb +524 -0
  1004. data/vendored/puppet/lib/puppet/resource/type_collection.rb +263 -0
  1005. data/vendored/puppet/lib/puppet/scheduler.rb +16 -0
  1006. data/vendored/puppet/lib/puppet/scheduler/job.rb +53 -0
  1007. data/vendored/puppet/lib/puppet/scheduler/scheduler.rb +44 -0
  1008. data/vendored/puppet/lib/puppet/scheduler/splay_job.rb +32 -0
  1009. data/vendored/puppet/lib/puppet/scheduler/timer.rb +13 -0
  1010. data/vendored/puppet/lib/puppet/settings.rb +1457 -0
  1011. data/vendored/puppet/lib/puppet/settings/array_setting.rb +17 -0
  1012. data/vendored/puppet/lib/puppet/settings/autosign_setting.rb +22 -0
  1013. data/vendored/puppet/lib/puppet/settings/base_setting.rb +177 -0
  1014. data/vendored/puppet/lib/puppet/settings/boolean_setting.rb +32 -0
  1015. data/vendored/puppet/lib/puppet/settings/certificate_revocation_setting.rb +21 -0
  1016. data/vendored/puppet/lib/puppet/settings/config_file.rb +143 -0
  1017. data/vendored/puppet/lib/puppet/settings/directory_setting.rb +18 -0
  1018. data/vendored/puppet/lib/puppet/settings/duration_setting.rb +32 -0
  1019. data/vendored/puppet/lib/puppet/settings/enum_setting.rb +16 -0
  1020. data/vendored/puppet/lib/puppet/settings/environment_conf.rb +204 -0
  1021. data/vendored/puppet/lib/puppet/settings/errors.rb +11 -0
  1022. data/vendored/puppet/lib/puppet/settings/file_or_directory_setting.rb +40 -0
  1023. data/vendored/puppet/lib/puppet/settings/file_setting.rb +245 -0
  1024. data/vendored/puppet/lib/puppet/settings/ini_file.rb +200 -0
  1025. data/vendored/puppet/lib/puppet/settings/path_setting.rb +8 -0
  1026. data/vendored/puppet/lib/puppet/settings/priority_setting.rb +42 -0
  1027. data/vendored/puppet/lib/puppet/settings/server_list_setting.rb +20 -0
  1028. data/vendored/puppet/lib/puppet/settings/string_setting.rb +9 -0
  1029. data/vendored/puppet/lib/puppet/settings/symbolic_enum_setting.rb +17 -0
  1030. data/vendored/puppet/lib/puppet/settings/terminus_setting.rb +14 -0
  1031. data/vendored/puppet/lib/puppet/settings/ttl_setting.rb +46 -0
  1032. data/vendored/puppet/lib/puppet/settings/value_translator.rb +15 -0
  1033. data/vendored/puppet/lib/puppet/ssl.rb +13 -0
  1034. data/vendored/puppet/lib/puppet/ssl/base.rb +153 -0
  1035. data/vendored/puppet/lib/puppet/ssl/certificate.rb +95 -0
  1036. data/vendored/puppet/lib/puppet/ssl/certificate_authority.rb +553 -0
  1037. data/vendored/puppet/lib/puppet/ssl/certificate_authority/autosign_command.rb +45 -0
  1038. data/vendored/puppet/lib/puppet/ssl/certificate_authority/interface.rb +324 -0
  1039. data/vendored/puppet/lib/puppet/ssl/certificate_factory.rb +219 -0
  1040. data/vendored/puppet/lib/puppet/ssl/certificate_request.rb +327 -0
  1041. data/vendored/puppet/lib/puppet/ssl/certificate_request_attributes.rb +37 -0
  1042. data/vendored/puppet/lib/puppet/ssl/certificate_revocation_list.rb +111 -0
  1043. data/vendored/puppet/lib/puppet/ssl/certificate_signer.rb +27 -0
  1044. data/vendored/puppet/lib/puppet/ssl/configuration.rb +61 -0
  1045. data/vendored/puppet/lib/puppet/ssl/digest.rb +20 -0
  1046. data/vendored/puppet/lib/puppet/ssl/host.rb +400 -0
  1047. data/vendored/puppet/lib/puppet/ssl/inventory.rb +55 -0
  1048. data/vendored/puppet/lib/puppet/ssl/key.rb +63 -0
  1049. data/vendored/puppet/lib/puppet/ssl/oids.rb +187 -0
  1050. data/vendored/puppet/lib/puppet/ssl/validator.rb +60 -0
  1051. data/vendored/puppet/lib/puppet/ssl/validator/default_validator.rb +173 -0
  1052. data/vendored/puppet/lib/puppet/ssl/validator/no_validator.rb +20 -0
  1053. data/vendored/puppet/lib/puppet/status.rb +40 -0
  1054. data/vendored/puppet/lib/puppet/syntax_checkers.rb +3 -0
  1055. data/vendored/puppet/lib/puppet/syntax_checkers/base64.rb +41 -0
  1056. data/vendored/puppet/lib/puppet/syntax_checkers/json.rb +35 -0
  1057. data/vendored/puppet/lib/puppet/test/test_helper.rb +252 -0
  1058. data/vendored/puppet/lib/puppet/transaction.rb +417 -0
  1059. data/vendored/puppet/lib/puppet/transaction/additional_resource_generator.rb +220 -0
  1060. data/vendored/puppet/lib/puppet/transaction/event.rb +144 -0
  1061. data/vendored/puppet/lib/puppet/transaction/event_manager.rb +167 -0
  1062. data/vendored/puppet/lib/puppet/transaction/persistence.rb +84 -0
  1063. data/vendored/puppet/lib/puppet/transaction/report.rb +460 -0
  1064. data/vendored/puppet/lib/puppet/transaction/resource_harness.rb +318 -0
  1065. data/vendored/puppet/lib/puppet/type.rb +2664 -0
  1066. data/vendored/puppet/lib/puppet/type/augeas.rb +211 -0
  1067. data/vendored/puppet/lib/puppet/type/component.rb +88 -0
  1068. data/vendored/puppet/lib/puppet/type/computer.rb +66 -0
  1069. data/vendored/puppet/lib/puppet/type/cron.rb +475 -0
  1070. data/vendored/puppet/lib/puppet/type/exec.rb +622 -0
  1071. data/vendored/puppet/lib/puppet/type/file.rb +1039 -0
  1072. data/vendored/puppet/lib/puppet/type/file/checksum.rb +44 -0
  1073. data/vendored/puppet/lib/puppet/type/file/checksum_value.rb +53 -0
  1074. data/vendored/puppet/lib/puppet/type/file/content.rb +160 -0
  1075. data/vendored/puppet/lib/puppet/type/file/ctime.rb +20 -0
  1076. data/vendored/puppet/lib/puppet/type/file/data_sync.rb +92 -0
  1077. data/vendored/puppet/lib/puppet/type/file/ensure.rb +192 -0
  1078. data/vendored/puppet/lib/puppet/type/file/group.rb +41 -0
  1079. data/vendored/puppet/lib/puppet/type/file/mode.rb +177 -0
  1080. data/vendored/puppet/lib/puppet/type/file/mtime.rb +18 -0
  1081. data/vendored/puppet/lib/puppet/type/file/owner.rb +44 -0
  1082. data/vendored/puppet/lib/puppet/type/file/selcontext.rb +141 -0
  1083. data/vendored/puppet/lib/puppet/type/file/source.rb +356 -0
  1084. data/vendored/puppet/lib/puppet/type/file/target.rb +87 -0
  1085. data/vendored/puppet/lib/puppet/type/file/type.rb +19 -0
  1086. data/vendored/puppet/lib/puppet/type/filebucket.rb +117 -0
  1087. data/vendored/puppet/lib/puppet/type/group.rb +206 -0
  1088. data/vendored/puppet/lib/puppet/type/host.rb +95 -0
  1089. data/vendored/puppet/lib/puppet/type/interface.rb +121 -0
  1090. data/vendored/puppet/lib/puppet/type/k5login.rb +88 -0
  1091. data/vendored/puppet/lib/puppet/type/macauthorization.rb +167 -0
  1092. data/vendored/puppet/lib/puppet/type/mailalias.rb +46 -0
  1093. data/vendored/puppet/lib/puppet/type/maillist.rb +62 -0
  1094. data/vendored/puppet/lib/puppet/type/mcx.rb +98 -0
  1095. data/vendored/puppet/lib/puppet/type/mount.rb +310 -0
  1096. data/vendored/puppet/lib/puppet/type/nagios_command.rb +3 -0
  1097. data/vendored/puppet/lib/puppet/type/nagios_contact.rb +3 -0
  1098. data/vendored/puppet/lib/puppet/type/nagios_contactgroup.rb +3 -0
  1099. data/vendored/puppet/lib/puppet/type/nagios_host.rb +3 -0
  1100. data/vendored/puppet/lib/puppet/type/nagios_hostdependency.rb +3 -0
  1101. data/vendored/puppet/lib/puppet/type/nagios_hostescalation.rb +3 -0
  1102. data/vendored/puppet/lib/puppet/type/nagios_hostextinfo.rb +3 -0
  1103. data/vendored/puppet/lib/puppet/type/nagios_hostgroup.rb +3 -0
  1104. data/vendored/puppet/lib/puppet/type/nagios_service.rb +3 -0
  1105. data/vendored/puppet/lib/puppet/type/nagios_servicedependency.rb +3 -0
  1106. data/vendored/puppet/lib/puppet/type/nagios_serviceescalation.rb +3 -0
  1107. data/vendored/puppet/lib/puppet/type/nagios_serviceextinfo.rb +3 -0
  1108. data/vendored/puppet/lib/puppet/type/nagios_servicegroup.rb +3 -0
  1109. data/vendored/puppet/lib/puppet/type/nagios_timeperiod.rb +3 -0
  1110. data/vendored/puppet/lib/puppet/type/notify.rb +46 -0
  1111. data/vendored/puppet/lib/puppet/type/package.rb +571 -0
  1112. data/vendored/puppet/lib/puppet/type/resources.rb +180 -0
  1113. data/vendored/puppet/lib/puppet/type/router.rb +17 -0
  1114. data/vendored/puppet/lib/puppet/type/schedule.rb +469 -0
  1115. data/vendored/puppet/lib/puppet/type/scheduled_task.rb +183 -0
  1116. data/vendored/puppet/lib/puppet/type/selboolean.rb +26 -0
  1117. data/vendored/puppet/lib/puppet/type/selmodule.rb +59 -0
  1118. data/vendored/puppet/lib/puppet/type/service.rb +258 -0
  1119. data/vendored/puppet/lib/puppet/type/ssh_authorized_key.rb +143 -0
  1120. data/vendored/puppet/lib/puppet/type/sshkey.rb +83 -0
  1121. data/vendored/puppet/lib/puppet/type/stage.rb +27 -0
  1122. data/vendored/puppet/lib/puppet/type/tidy.rb +336 -0
  1123. data/vendored/puppet/lib/puppet/type/user.rb +770 -0
  1124. data/vendored/puppet/lib/puppet/type/vlan.rb +26 -0
  1125. data/vendored/puppet/lib/puppet/type/whit.rb +34 -0
  1126. data/vendored/puppet/lib/puppet/type/yumrepo.rb +409 -0
  1127. data/vendored/puppet/lib/puppet/type/zfs.rb +150 -0
  1128. data/vendored/puppet/lib/puppet/type/zone.rb +382 -0
  1129. data/vendored/puppet/lib/puppet/type/zpool.rb +91 -0
  1130. data/vendored/puppet/lib/puppet/util.rb +705 -0
  1131. data/vendored/puppet/lib/puppet/util/at_fork.rb +35 -0
  1132. data/vendored/puppet/lib/puppet/util/at_fork/noop.rb +18 -0
  1133. data/vendored/puppet/lib/puppet/util/at_fork/solaris.rb +158 -0
  1134. data/vendored/puppet/lib/puppet/util/autoload.rb +226 -0
  1135. data/vendored/puppet/lib/puppet/util/backups.rb +86 -0
  1136. data/vendored/puppet/lib/puppet/util/character_encoding.rb +98 -0
  1137. data/vendored/puppet/lib/puppet/util/checksums.rb +282 -0
  1138. data/vendored/puppet/lib/puppet/util/classgen.rb +228 -0
  1139. data/vendored/puppet/lib/puppet/util/colors.rb +100 -0
  1140. data/vendored/puppet/lib/puppet/util/command_line.rb +185 -0
  1141. data/vendored/puppet/lib/puppet/util/command_line/puppet_option_parser.rb +87 -0
  1142. data/vendored/puppet/lib/puppet/util/command_line/trollop.rb +824 -0
  1143. data/vendored/puppet/lib/puppet/util/constant_inflector.rb +24 -0
  1144. data/vendored/puppet/lib/puppet/util/diff.rb +79 -0
  1145. data/vendored/puppet/lib/puppet/util/docs.rb +128 -0
  1146. data/vendored/puppet/lib/puppet/util/errors.rb +108 -0
  1147. data/vendored/puppet/lib/puppet/util/execution.rb +412 -0
  1148. data/vendored/puppet/lib/puppet/util/execution_stub.rb +26 -0
  1149. data/vendored/puppet/lib/puppet/util/feature.rb +95 -0
  1150. data/vendored/puppet/lib/puppet/util/file_watcher.rb +28 -0
  1151. data/vendored/puppet/lib/puppet/util/fileparsing.rb +377 -0
  1152. data/vendored/puppet/lib/puppet/util/filetype.rb +309 -0
  1153. data/vendored/puppet/lib/puppet/util/http_proxy.rb +197 -0
  1154. data/vendored/puppet/lib/puppet/util/inifile.rb +341 -0
  1155. data/vendored/puppet/lib/puppet/util/instance_loader.rb +81 -0
  1156. data/vendored/puppet/lib/puppet/util/json_lockfile.rb +44 -0
  1157. data/vendored/puppet/lib/puppet/util/ldap.rb +2 -0
  1158. data/vendored/puppet/lib/puppet/util/ldap/connection.rb +71 -0
  1159. data/vendored/puppet/lib/puppet/util/ldap/generator.rb +42 -0
  1160. data/vendored/puppet/lib/puppet/util/ldap/manager.rb +278 -0
  1161. data/vendored/puppet/lib/puppet/util/libuser.conf +15 -0
  1162. data/vendored/puppet/lib/puppet/util/libuser.rb +12 -0
  1163. data/vendored/puppet/lib/puppet/util/limits.rb +12 -0
  1164. data/vendored/puppet/lib/puppet/util/lockfile.rb +66 -0
  1165. data/vendored/puppet/lib/puppet/util/log.rb +423 -0
  1166. data/vendored/puppet/lib/puppet/util/log/destination.rb +49 -0
  1167. data/vendored/puppet/lib/puppet/util/log/destinations.rb +249 -0
  1168. data/vendored/puppet/lib/puppet/util/logging.rb +318 -0
  1169. data/vendored/puppet/lib/puppet/util/metaid.rb +21 -0
  1170. data/vendored/puppet/lib/puppet/util/methodhelper.rb +32 -0
  1171. data/vendored/puppet/lib/puppet/util/metric.rb +64 -0
  1172. data/vendored/puppet/lib/puppet/util/monkey_patches.rb +108 -0
  1173. data/vendored/puppet/lib/puppet/util/multi_match.rb +51 -0
  1174. data/vendored/puppet/lib/puppet/util/nagios_maker.rb +85 -0
  1175. data/vendored/puppet/lib/puppet/util/network_device.rb +17 -0
  1176. data/vendored/puppet/lib/puppet/util/network_device/base.rb +23 -0
  1177. data/vendored/puppet/lib/puppet/util/network_device/cisco.rb +4 -0
  1178. data/vendored/puppet/lib/puppet/util/network_device/cisco/device.rb +285 -0
  1179. data/vendored/puppet/lib/puppet/util/network_device/cisco/facts.rb +72 -0
  1180. data/vendored/puppet/lib/puppet/util/network_device/cisco/interface.rb +94 -0
  1181. data/vendored/puppet/lib/puppet/util/network_device/config.rb +98 -0
  1182. data/vendored/puppet/lib/puppet/util/network_device/ipcalc.rb +68 -0
  1183. data/vendored/puppet/lib/puppet/util/network_device/transport.rb +5 -0
  1184. data/vendored/puppet/lib/puppet/util/network_device/transport/base.rb +26 -0
  1185. data/vendored/puppet/lib/puppet/util/network_device/transport/ssh.rb +126 -0
  1186. data/vendored/puppet/lib/puppet/util/network_device/transport/telnet.rb +47 -0
  1187. data/vendored/puppet/lib/puppet/util/package.rb +31 -0
  1188. data/vendored/puppet/lib/puppet/util/pidlock.rb +62 -0
  1189. data/vendored/puppet/lib/puppet/util/platform.rb +22 -0
  1190. data/vendored/puppet/lib/puppet/util/plist.rb +153 -0
  1191. data/vendored/puppet/lib/puppet/util/posix.rb +137 -0
  1192. data/vendored/puppet/lib/puppet/util/profiler.rb +53 -0
  1193. data/vendored/puppet/lib/puppet/util/profiler/aggregate.rb +85 -0
  1194. data/vendored/puppet/lib/puppet/util/profiler/around_profiler.rb +67 -0
  1195. data/vendored/puppet/lib/puppet/util/profiler/logging.rb +48 -0
  1196. data/vendored/puppet/lib/puppet/util/profiler/object_counts.rb +17 -0
  1197. data/vendored/puppet/lib/puppet/util/profiler/wall_clock.rb +35 -0
  1198. data/vendored/puppet/lib/puppet/util/provider_features.rb +184 -0
  1199. data/vendored/puppet/lib/puppet/util/psych_support.rb +30 -0
  1200. data/vendored/puppet/lib/puppet/util/rdoc.rb +60 -0
  1201. data/vendored/puppet/lib/puppet/util/rdoc/code_objects.rb +294 -0
  1202. data/vendored/puppet/lib/puppet/util/rdoc/generators/puppet_generator.rb +910 -0
  1203. data/vendored/puppet/lib/puppet/util/rdoc/generators/template/puppet/puppet.rb +1085 -0
  1204. data/vendored/puppet/lib/puppet/util/rdoc/parser.rb +12 -0
  1205. data/vendored/puppet/lib/puppet/util/rdoc/parser/puppet_parser_core.rb +259 -0
  1206. data/vendored/puppet/lib/puppet/util/rdoc/parser/puppet_parser_rdoc2.rb +14 -0
  1207. data/vendored/puppet/lib/puppet/util/reference.rb +126 -0
  1208. data/vendored/puppet/lib/puppet/util/resource_template.rb +61 -0
  1209. data/vendored/puppet/lib/puppet/util/retry_action.rb +46 -0
  1210. data/vendored/puppet/lib/puppet/util/rubygems.rb +75 -0
  1211. data/vendored/puppet/lib/puppet/util/run_mode.rb +110 -0
  1212. data/vendored/puppet/lib/puppet/util/selinux.rb +264 -0
  1213. data/vendored/puppet/lib/puppet/util/skip_tags.rb +9 -0
  1214. data/vendored/puppet/lib/puppet/util/splayer.rb +18 -0
  1215. data/vendored/puppet/lib/puppet/util/ssl.rb +53 -0
  1216. data/vendored/puppet/lib/puppet/util/storage.rb +89 -0
  1217. data/vendored/puppet/lib/puppet/util/suidmanager.rb +165 -0
  1218. data/vendored/puppet/lib/puppet/util/symbolic_file_mode.rb +144 -0
  1219. data/vendored/puppet/lib/puppet/util/tag_set.rb +27 -0
  1220. data/vendored/puppet/lib/puppet/util/tagging.rb +118 -0
  1221. data/vendored/puppet/lib/puppet/util/terminal.rb +16 -0
  1222. data/vendored/puppet/lib/puppet/util/user_attr.rb +21 -0
  1223. data/vendored/puppet/lib/puppet/util/warnings.rb +33 -0
  1224. data/vendored/puppet/lib/puppet/util/watched_file.rb +37 -0
  1225. data/vendored/puppet/lib/puppet/util/watcher.rb +17 -0
  1226. data/vendored/puppet/lib/puppet/util/watcher/change_watcher.rb +33 -0
  1227. data/vendored/puppet/lib/puppet/util/watcher/periodic_watcher.rb +37 -0
  1228. data/vendored/puppet/lib/puppet/util/watcher/timer.rb +19 -0
  1229. data/vendored/puppet/lib/puppet/util/windows.rb +35 -0
  1230. data/vendored/puppet/lib/puppet/util/windows/access_control_entry.rb +84 -0
  1231. data/vendored/puppet/lib/puppet/util/windows/access_control_list.rb +113 -0
  1232. data/vendored/puppet/lib/puppet/util/windows/adsi.rb +548 -0
  1233. data/vendored/puppet/lib/puppet/util/windows/api_types.rb +282 -0
  1234. data/vendored/puppet/lib/puppet/util/windows/com.rb +224 -0
  1235. data/vendored/puppet/lib/puppet/util/windows/error.rb +83 -0
  1236. data/vendored/puppet/lib/puppet/util/windows/eventlog.rb +192 -0
  1237. data/vendored/puppet/lib/puppet/util/windows/file.rb +488 -0
  1238. data/vendored/puppet/lib/puppet/util/windows/principal.rb +191 -0
  1239. data/vendored/puppet/lib/puppet/util/windows/process.rb +497 -0
  1240. data/vendored/puppet/lib/puppet/util/windows/registry.rb +374 -0
  1241. data/vendored/puppet/lib/puppet/util/windows/root_certs.rb +108 -0
  1242. data/vendored/puppet/lib/puppet/util/windows/security.rb +857 -0
  1243. data/vendored/puppet/lib/puppet/util/windows/security_descriptor.rb +62 -0
  1244. data/vendored/puppet/lib/puppet/util/windows/sid.rb +231 -0
  1245. data/vendored/puppet/lib/puppet/util/windows/string.rb +16 -0
  1246. data/vendored/puppet/lib/puppet/util/windows/taskscheduler.rb +1276 -0
  1247. data/vendored/puppet/lib/puppet/util/windows/user.rb +309 -0
  1248. data/vendored/puppet/lib/puppet/util/yaml.rb +36 -0
  1249. data/vendored/puppet/lib/puppet/vendor.rb +57 -0
  1250. data/vendored/puppet/lib/puppet/vendor/deep_merge/CHANGELOG +45 -0
  1251. data/vendored/puppet/lib/puppet/vendor/deep_merge/Gemfile +3 -0
  1252. data/vendored/puppet/lib/puppet/vendor/deep_merge/LICENSE +21 -0
  1253. data/vendored/puppet/lib/puppet/vendor/deep_merge/PUPPET_README.md +6 -0
  1254. data/vendored/puppet/lib/puppet/vendor/deep_merge/README.md +113 -0
  1255. data/vendored/puppet/lib/puppet/vendor/deep_merge/Rakefile +19 -0
  1256. data/vendored/puppet/lib/puppet/vendor/deep_merge/deep_merge.gemspec +35 -0
  1257. data/vendored/puppet/lib/puppet/vendor/deep_merge/lib/deep_merge.rb +2 -0
  1258. data/vendored/puppet/lib/puppet/vendor/deep_merge/lib/deep_merge/core.rb +210 -0
  1259. data/vendored/puppet/lib/puppet/vendor/deep_merge/lib/deep_merge/deep_merge_hash.rb +28 -0
  1260. data/vendored/puppet/lib/puppet/vendor/deep_merge/lib/deep_merge/rails_compat.rb +27 -0
  1261. data/vendored/puppet/lib/puppet/vendor/deep_merge/test/test_deep_merge.rb +608 -0
  1262. data/vendored/puppet/lib/puppet/vendor/load_deep_merge.rb +1 -0
  1263. data/vendored/puppet/lib/puppet/vendor/load_pathspec.rb +1 -0
  1264. data/vendored/puppet/lib/puppet/vendor/load_semantic.rb +1 -0
  1265. data/vendored/puppet/lib/puppet/vendor/load_semantic_puppet.rb +1 -0
  1266. data/vendored/puppet/lib/puppet/vendor/pathspec/CHANGELOG.md +2 -0
  1267. data/vendored/puppet/lib/puppet/vendor/pathspec/LICENSE +201 -0
  1268. data/vendored/puppet/lib/puppet/vendor/pathspec/PUPPET_README.md +6 -0
  1269. data/vendored/puppet/lib/puppet/vendor/pathspec/README.md +53 -0
  1270. data/vendored/puppet/lib/puppet/vendor/pathspec/lib/pathspec.rb +122 -0
  1271. data/vendored/puppet/lib/puppet/vendor/pathspec/lib/pathspec/gitignorespec.rb +275 -0
  1272. data/vendored/puppet/lib/puppet/vendor/pathspec/lib/pathspec/regexspec.rb +17 -0
  1273. data/vendored/puppet/lib/puppet/vendor/pathspec/lib/pathspec/spec.rb +14 -0
  1274. data/vendored/puppet/lib/puppet/vendor/require_vendored.rb +6 -0
  1275. data/vendored/puppet/lib/puppet/vendor/semantic/lib/semantic.rb +5 -0
  1276. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet.rb +7 -0
  1277. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency.rb +181 -0
  1278. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/graph.rb +60 -0
  1279. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/graph_node.rb +117 -0
  1280. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/module_release.rb +58 -0
  1281. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/source.rb +25 -0
  1282. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/unsatisfiable_graph.rb +31 -0
  1283. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/gem_version.rb +3 -0
  1284. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/version.rb +203 -0
  1285. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/version_range.rb +758 -0
  1286. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/locales/config.yaml +21 -0
  1287. data/vendored/puppet/lib/puppet/version.rb +93 -0
  1288. data/vendored/puppet/lib/puppet_pal.rb +290 -0
  1289. data/vendored/puppet/lib/puppet_x.rb +14 -0
  1290. data/vendored/require_vendored.rb +11 -0
  1291. metadata +1501 -9
@@ -0,0 +1,59 @@
1
+ module Puppet::Pops
2
+ module Types
3
+ class TypeSetReference
4
+ include Annotatable
5
+
6
+ attr_reader :name_authority
7
+ attr_reader :name
8
+ attr_reader :version_range
9
+ attr_reader :type_set
10
+
11
+ def initialize(owner, init_hash)
12
+ @owner = owner
13
+ @name_authority = (init_hash[KEY_NAME_AUTHORITY] || owner.name_authority).freeze
14
+ @name = init_hash[KEY_NAME].freeze
15
+ @version_range = PSemVerRangeType.convert(init_hash[KEY_VERSION_RANGE])
16
+ init_annotatable(init_hash)
17
+ end
18
+
19
+ def accept(visitor, guard)
20
+ annotatable_accept(visitor, guard)
21
+ end
22
+
23
+ def eql?(o)
24
+ self.class == o.class && @name_authority.eql?(o.name_authority) && @name.eql?(o.name) && @version_range.eql?(o.version_range)
25
+ end
26
+
27
+ def hash
28
+ [@name_authority, @name, @version_range].hash
29
+ end
30
+
31
+ def _pcore_init_hash
32
+ result = super
33
+ result[KEY_NAME_AUTHORITY] = @name_authority unless @name_authority == @owner.name_authority
34
+ result[KEY_NAME] = @name
35
+ result[KEY_VERSION_RANGE] = @version_range.to_s
36
+ result
37
+ end
38
+
39
+ def resolve(loader)
40
+ typed_name = Loader::TypedName.new(:type, @name, @name_authority)
41
+ loaded_entry = loader.load_typed(typed_name)
42
+ type_set = loaded_entry.nil? ? nil : loaded_entry.value
43
+
44
+ raise ArgumentError, "#{self} cannot be resolved" if type_set.nil?
45
+ raise ArgumentError, "#{self} resolves to a #{type_set.name}" unless type_set.is_a?(PTypeSetType)
46
+
47
+ @type_set = type_set.resolve(loader)
48
+ unless @version_range.include?(@type_set.version)
49
+ raise ArgumentError, "#{self} resolves to an incompatible version. Expected #{@version_range}, got #{type_set.version}"
50
+ end
51
+ nil
52
+ end
53
+
54
+ def to_s
55
+ "#{@owner.label} reference to TypeSet named '#{@name}'"
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,3519 @@
1
+ require_relative 'iterable'
2
+ require_relative 'enumeration'
3
+ require_relative 'recursion_guard'
4
+ require_relative 'type_acceptor'
5
+ require_relative 'type_asserter'
6
+ require_relative 'type_assertion_error'
7
+ require_relative 'type_conversion_error'
8
+ require_relative 'type_formatter'
9
+ require_relative 'type_calculator'
10
+ require_relative 'type_factory'
11
+ require_relative 'type_parser'
12
+ require_relative 'class_loader'
13
+ require_relative 'type_mismatch_describer'
14
+ require_relative 'puppet_object'
15
+
16
+ module Puppet::Pops
17
+ module Types
18
+
19
+ # The EMPTY_xxx declarations is for backward compatibility. They should not be explicitly referenced
20
+
21
+ # @api private
22
+ # @deprecated
23
+ EMPTY_HASH = Puppet::Pops::EMPTY_HASH
24
+
25
+ # @api private
26
+ # @deprecated
27
+ EMPTY_ARRAY = Puppet::Pops::EMPTY_ARRAY
28
+
29
+ # @api private
30
+ # @deprecated
31
+ EMPTY_STRING = Puppet::Pops::EMPTY_STRING
32
+
33
+ # The Types model is a model of Puppet Language types.
34
+ #
35
+ # The {TypeCalculator} should be used to answer questions about types. The {TypeFactory} or {TypeParser} should be used
36
+ # to create an instance of a type whenever one is needed.
37
+ #
38
+ # The implementation of the Types model contains methods that are required for the type objects to behave as
39
+ # expected when comparing them and using them as keys in hashes. (No other logic is, or should be included directly in
40
+ # the model's classes).
41
+ #
42
+ # @api public
43
+ #
44
+ class TypedModelObject < Object
45
+ include PuppetObject
46
+ include Visitable
47
+ include Adaptable
48
+
49
+ def self._pcore_type
50
+ @type
51
+ end
52
+
53
+ def self.create_ptype(loader, ir, parent_name, attributes_hash = EMPTY_HASH)
54
+ @type = Pcore::create_object_type(loader, ir, self, "Pcore::#{simple_name}Type", "Pcore::#{parent_name}", attributes_hash)
55
+ end
56
+
57
+ def self.register_ptypes(loader, ir)
58
+ types = [
59
+ Annotation.register_ptype(loader, ir),
60
+ RubyMethod.register_ptype(loader, ir),
61
+ ]
62
+ if Puppet[:tasks]
63
+ types << Task.register_ptype(loader, ir)
64
+ types << GenericTask.register_ptype(loader, ir)
65
+ types << ExecutionResult.register_ptype(loader, ir)
66
+ end
67
+
68
+ Types.constants.each do |c|
69
+ next if c == :PType || c == :PHostClassType
70
+ cls = Types.const_get(c)
71
+ next unless cls.is_a?(Class) && cls < self
72
+ type = cls.register_ptype(loader, ir)
73
+ types << type unless type.nil?
74
+ end
75
+ types.each { |type| type.resolve(loader) }
76
+ end
77
+ end
78
+
79
+ # Base type for all types
80
+ # @api public
81
+ #
82
+ class PAnyType < TypedModelObject
83
+
84
+ def self.register_ptype(loader, ir)
85
+ @type = Pcore::create_object_type(loader, ir, self, 'Pcore::AnyType', 'Any', EMPTY_HASH)
86
+ end
87
+
88
+ def self.create(*args)
89
+ # NOTE! Important to use self::DEFAULT and not just DEFAULT since the latter yields PAnyType::DEFAULT
90
+ args.empty? ? self::DEFAULT : new(*args)
91
+ end
92
+
93
+ # Accept a visitor that will be sent the message `visit`, once with `self` as the
94
+ # argument. The visitor will then visit all types that this type contains.
95
+ #
96
+ def accept(visitor, guard)
97
+ visitor.visit(self, guard)
98
+ end
99
+
100
+ # Checks if _o_ is a type that is assignable to this type.
101
+ # If _o_ is a `Class` then it is first converted to a type.
102
+ # If _o_ is a Variant, then it is considered assignable when all its types are assignable
103
+ #
104
+ # The check for assignable must be guarded against self recursion since `self`, the given type _o_,
105
+ # or both, might be a `TypeAlias`. The initial caller of this method will typically never care
106
+ # about this and hence pass only the first argument, but as soon as a check of a contained type
107
+ # encounters a `TypeAlias`, then a `RecursionGuard` instance is created and passed on in all
108
+ # subsequent calls. The recursion is allowed to continue until self recursion has been detected in
109
+ # both `self` and in the given type. At that point the given type is considered to be assignable
110
+ # to `self` since all checks up to that point were positive.
111
+ #
112
+ # @param o [Class,PAnyType] the class or type to test
113
+ # @param guard [RecursionGuard] guard against recursion. Only used by internal calls
114
+ # @return [Boolean] `true` when _o_ is assignable to this type
115
+ # @api public
116
+ def assignable?(o, guard = nil)
117
+ case o
118
+ when Class
119
+ # Safe to call _assignable directly since a Class never is a Unit or Variant
120
+ _assignable?(TypeCalculator.singleton.type(o), guard)
121
+ when PUnitType
122
+ true
123
+ when PTypeAliasType
124
+ # An alias may contain self recursive constructs.
125
+ if o.self_recursion?
126
+ guard ||= RecursionGuard.new
127
+ if guard.add_that(o) == RecursionGuard::SELF_RECURSION_IN_BOTH
128
+ # Recursion detected both in self and other. This means that other is assignable
129
+ # to self. This point would not have been reached otherwise
130
+ true
131
+ else
132
+ assignable?(o.resolved_type, guard)
133
+ end
134
+ else
135
+ assignable?(o.resolved_type, guard)
136
+ end
137
+ when PVariantType
138
+ # Assignable if all contained types are assignable
139
+ o.types.all? { |vt| assignable?(vt, guard) }
140
+ when POptionalType
141
+ # Assignable if undef and contained type is assignable
142
+ assignable?(PUndefType::DEFAULT) && (o.type.nil? || assignable?(o.type))
143
+ when PNotUndefType
144
+ if !(o.type.nil? || o.type.assignable?(PUndefType::DEFAULT))
145
+ assignable?(o.type, guard)
146
+ else
147
+ _assignable?(o, guard)
148
+ end
149
+ else
150
+ _assignable?(o, guard)
151
+ end
152
+ end
153
+
154
+ # Returns `true` if this instance is a callable that accepts the given _args_type_ type
155
+ #
156
+ # @param args_type [PAnyType] the arguments to test
157
+ # @param guard [RecursionGuard] guard against recursion. Only used by internal calls
158
+ # @return [Boolean] `true` if this instance is a callable that accepts the given _args_
159
+ def callable?(args_type, guard = nil)
160
+ args_type.is_a?(PAnyType) && kind_of_callable? && args_type.callable_args?(self, guard)
161
+ end
162
+
163
+ # Returns `true` if this instance is a callable that accepts the given _args_
164
+ #
165
+ # @param args [Array] the arguments to test
166
+ # @param block [Proc] block, or nil if not called with a block
167
+ # @return [Boolean] `true` if this instance is a callable that accepts the given _args_
168
+ def callable_with?(args, block = nil)
169
+ false
170
+ end
171
+
172
+ # Returns `true` if this instance is considered valid as arguments to the given `callable`
173
+ # @param callable [PAnyType] the callable
174
+ # @param guard [RecursionGuard] guard against recursion. Only used by internal calls
175
+ # @return [Boolean] `true` if this instance is considered valid as arguments to the given `callable`
176
+ # @api private
177
+ def callable_args?(callable, guard)
178
+ false
179
+ end
180
+
181
+ # Called from the `PTypeAliasType` when it detects self recursion. The default is to do nothing
182
+ # but some self recursive constructs are illegal such as when a `PObjectType` somehow inherits itself
183
+ # @param originator [PTypeAliasType] the starting point for the check
184
+ # @raise Puppet::Error if an illegal self recursion is detected
185
+ # @api private
186
+ def check_self_recursion(originator)
187
+ end
188
+
189
+ # Generalizes value specific types. Types that are not value specific will return `self` otherwise
190
+ # the generalized type is returned.
191
+ #
192
+ # @return [PAnyType] The generalized type
193
+ # @api public
194
+ def generalize
195
+ # Applicable to all types that have no variables
196
+ self
197
+ end
198
+
199
+ # Returns the loader that loaded this type.
200
+ # @return [Loaders::Loader] the loader
201
+ def loader
202
+ Loaders.static_loader
203
+ end
204
+
205
+ # Normalizes the type. This does not change the characteristics of the type but it will remove duplicates
206
+ # and constructs like NotUndef[T] where T is not assignable from Undef and change Variant[*T] where all
207
+ # T are enums into an Enum.
208
+ #
209
+ # @param guard [RecursionGuard] guard against recursion. Only used by internal calls
210
+ # @return [PAnyType] The iterable type that this type is assignable to or `nil`
211
+ # @api public
212
+ def normalize(guard = nil)
213
+ self
214
+ end
215
+
216
+ # Called from the TypeParser once it has found a type using the Loader to enable that this type can
217
+ # resolve internal type expressions using a loader. Presently, this method is a no-op for all types
218
+ # except the {{PTypeAliasType}}.
219
+ #
220
+ # @param loader [Loader::Loader] loader to use
221
+ # @return [PTypeAliasType] the receiver of the call, i.e. `self`
222
+ # @api private
223
+ def resolve(loader)
224
+ self
225
+ end
226
+
227
+ # Responds `true` for all callables, variants of callables and unless _optional_ is
228
+ # false, all optional callables.
229
+ # @param optional [Boolean]
230
+ # @param guard [RecursionGuard] guard against recursion. Only used by internal calls
231
+ # @return [Boolean] `true`if this type is considered callable
232
+ # @api private
233
+ def kind_of_callable?(optional = true, guard = nil)
234
+ false
235
+ end
236
+
237
+ # Returns `true` if an instance of this type is iterable, `false` otherwise
238
+ # The method #iterable_type must produce a `PIterableType` instance when this
239
+ # method returns `true`
240
+ #
241
+ # @param guard [RecursionGuard] guard against recursion. Only used by internal calls
242
+ # @return [Boolean] flag to indicate if instances of this type is iterable.
243
+ def iterable?(guard = nil)
244
+ false
245
+ end
246
+
247
+ # Returns the `PIterableType` that this type should be assignable to, or `nil` if no such type exists.
248
+ # A type that returns a `PIterableType` must respond `true` to `#iterable?`.
249
+ #
250
+ # @example
251
+ # Any Collection[T] is assignable to an Iterable[T]
252
+ # A String is assignable to an Iterable[String] iterating over the strings characters
253
+ # An Integer is assignable to an Iterable[Integer] iterating over the 'times' enumerator
254
+ # A Type[T] is assignable to an Iterable[Type[T]] if T is an Integer or Enum
255
+ #
256
+ # @param guard [RecursionGuard] guard against recursion. Only used by internal calls
257
+ # @return [PIterableType,nil] The iterable type that this type is assignable to or `nil`
258
+ # @api private
259
+ def iterable_type(guard = nil)
260
+ nil
261
+ end
262
+
263
+ def hash
264
+ self.class.hash
265
+ end
266
+
267
+ # Returns true if the given argument _o_ is an instance of this type
268
+ # @param guard [RecursionGuard] guard against recursion. Only used by internal calls
269
+ # @return [Boolean]
270
+ # @api public
271
+ def instance?(o, guard = nil)
272
+ true
273
+ end
274
+
275
+ # An object is considered to really be an instance of a type when something other than a
276
+ # TypeAlias or a Variant responds true to a call to {#instance?}.
277
+ #
278
+ # @return [Integer] -1 = is not instance, 0 = recursion detected, 1 = is instance
279
+ # @api private
280
+ def really_instance?(o, guard = nil)
281
+ instance?(o, guard) ? 1 : -1
282
+ end
283
+
284
+ def eql?(o)
285
+ self.class == o.class
286
+ end
287
+
288
+ def ==(o)
289
+ eql?(o)
290
+ end
291
+
292
+ def simple_name
293
+ self.class.simple_name
294
+ end
295
+
296
+ # Strips the class name from all module prefixes, the leading 'P' and the ending 'Type'. I.e.
297
+ # an instance of PVariantType will return 'Variant'
298
+ # @return [String] the simple name of this type
299
+ def self.simple_name
300
+ @simple_name ||= (
301
+ n = name
302
+ n[n.rindex(DOUBLE_COLON)+3..n.size-5].freeze
303
+ )
304
+ end
305
+
306
+ def to_alias_expanded_s
307
+ TypeFormatter.new.alias_expanded_string(self)
308
+ end
309
+
310
+ def to_s
311
+ TypeFormatter.string(self)
312
+ end
313
+
314
+ # Returns the name of the type, without parameters
315
+ # @return [String] the name of the type
316
+ # @api public
317
+ def name
318
+ simple_name
319
+ end
320
+
321
+ def create(*args)
322
+ Loaders.find_loader(nil).load(:function, 'new').call({}, self, *args)
323
+ end
324
+
325
+ # Create an instance of this type.
326
+ # The default implementation will just dispatch the call to the class method with the
327
+ # same name and pass `self` as the first argument.
328
+ #
329
+ # @return [Function] the created function
330
+ # @raises ArgumentError
331
+ #
332
+ def new_function
333
+ self.class.new_function(self)
334
+ end
335
+
336
+ # This default implementation of of a new_function raises an Argument Error.
337
+ # Types for which creating a new instance is supported, should create and return
338
+ # a Puppet Function class by using Puppet:Loaders.create_loaded_function(:new, loader)
339
+ # and return that result.
340
+ #
341
+ # @param type [PAnyType] the type to create a new function for
342
+ # @return [Function] the created function
343
+ # @raises ArgumentError
344
+ #
345
+ def self.new_function(type)
346
+ raise ArgumentError.new("Creation of new instance of type '#{type.to_s}' is not supported")
347
+ end
348
+
349
+ # Answers the question if instances of this type can represent themselves as a string that
350
+ # can then be passed to the create method
351
+ #
352
+ # @return [Boolean] wether or not the instance has a canonical string representation
353
+ def roundtrip_with_string?
354
+ false
355
+ end
356
+
357
+ # The default instance of this type. Each type in the type system has this constant
358
+ # declared.
359
+ #
360
+ DEFAULT = PAnyType.new
361
+
362
+ protected
363
+
364
+ # @api private
365
+ def _assignable?(o, guard)
366
+ o.is_a?(PAnyType)
367
+ end
368
+
369
+ # Produces the tuple entry at the given index given a tuple type, its from/to constraints on the last
370
+ # type, and an index.
371
+ # Produces nil if the index is out of bounds
372
+ # from must be less than to, and from may not be less than 0
373
+ #
374
+ # @api private
375
+ #
376
+ def tuple_entry_at(tuple_t, to, index)
377
+ regular = (tuple_t.types.size - 1)
378
+ if index < regular
379
+ tuple_t.types[index]
380
+ elsif index < regular + to
381
+ # in the varargs part
382
+ tuple_t.types[-1]
383
+ else
384
+ nil
385
+ end
386
+ end
387
+
388
+ # Applies a transformation by sending the given _method_ and _method_args_ to each of the types of the given array
389
+ # and collecting the results in a new array. If all transformation calls returned the type instance itself (i.e. no
390
+ # transformation took place), then this method will return `self`. If a transformation did occur, then this method
391
+ # will either return the transformed array or in case a block was given, the result of calling a given block with
392
+ # the transformed array.
393
+ #
394
+ # @param types [Array<PAnyType>] the array of types to transform
395
+ # @param method [Symbol] The method to call on each type
396
+ # @param method_args [Object] The arguments to pass to the method, if any
397
+ # @return [Object] self, the transformed array, or the result of calling a given block with the transformed array
398
+ # @yieldparam altered_types [Array<PAnyType>] the altered type array
399
+ # @api private
400
+ def alter_type_array(types, method, *method_args)
401
+ modified = false
402
+ modified_types = types.map do |t|
403
+ t_mod = t.send(method, *method_args)
404
+ modified = !t.equal?(t_mod) unless modified
405
+ t_mod
406
+ end
407
+ if modified
408
+ block_given? ? yield(modified_types) : modified_types
409
+ else
410
+ self
411
+ end
412
+ end
413
+ end
414
+
415
+ # @abstract Encapsulates common behavior for a type that contains one type
416
+ # @api public
417
+ class PTypeWithContainedType < PAnyType
418
+ def self.register_ptype(loader, ir)
419
+ # Abstract type. It doesn't register anything
420
+ end
421
+
422
+ attr_reader :type
423
+
424
+ def initialize(type)
425
+ @type = type
426
+ end
427
+
428
+ def accept(visitor, guard)
429
+ super
430
+ @type.accept(visitor, guard) unless @type.nil?
431
+ end
432
+
433
+ def generalize
434
+ if @type.nil?
435
+ self.class::DEFAULT
436
+ else
437
+ ge_type = @type.generalize
438
+ @type.equal?(ge_type) ? self : self.class.new(ge_type)
439
+ end
440
+ end
441
+
442
+ def normalize(guard = nil)
443
+ if @type.nil?
444
+ self.class::DEFAULT
445
+ else
446
+ ne_type = @type.normalize(guard)
447
+ @type.equal?(ne_type) ? self : self.class.new(ne_type)
448
+ end
449
+ end
450
+
451
+ def hash
452
+ self.class.hash ^ @type.hash
453
+ end
454
+
455
+ def eql?(o)
456
+ self.class == o.class && @type == o.type
457
+ end
458
+
459
+ def resolve(loader)
460
+ rtype = @type
461
+ rtype = rtype.resolve(loader) unless rtype.nil?
462
+ rtype.equal?(@type) ? self : self.class.new(rtype)
463
+ end
464
+ end
465
+
466
+ # The type of types.
467
+ # @api public
468
+ #
469
+ class PTypeType < PTypeWithContainedType
470
+
471
+ def self.register_ptype(loader, ir)
472
+ create_ptype(loader, ir, 'AnyType',
473
+ 'type' => {
474
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
475
+ KEY_VALUE => nil
476
+ }
477
+ )
478
+ end
479
+
480
+ # Returns a new function that produces a Type instance
481
+ #
482
+ def self.new_function(type)
483
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_type, type.loader) do
484
+ dispatch :from_string do
485
+ param 'String', :type_string
486
+ end
487
+
488
+ def from_string(type_string)
489
+ TypeParser.singleton.parse(type_string, loader)
490
+ end
491
+ end
492
+ end
493
+
494
+ def instance?(o, guard = nil)
495
+ if o.is_a?(PAnyType)
496
+ type.nil? || type.assignable?(o, guard)
497
+ elsif o.is_a?(Module) || o.is_a?(Puppet::Resource) || o.is_a?(Puppet::Parser::Resource)
498
+ @type.nil? ? true : assignable?(TypeCalculator.infer(o))
499
+ else
500
+ false
501
+ end
502
+ end
503
+
504
+ def iterable?(guard = nil)
505
+ case @type
506
+ when PEnumType
507
+ true
508
+ when PIntegerType
509
+ @type.finite_range?
510
+ else
511
+ false
512
+ end
513
+ end
514
+
515
+ def iterable_type(guard = nil)
516
+ # The types PIntegerType and PEnumType are Iterable
517
+ case @type
518
+ when PEnumType
519
+ # @type describes the element type perfectly since the iteration is made over the
520
+ # contained choices.
521
+ PIterableType.new(@type)
522
+ when PIntegerType
523
+ # @type describes the element type perfectly since the iteration is made over the
524
+ # specified range.
525
+ @type.finite_range? ? PIterableType.new(@type) : nil
526
+ else
527
+ nil
528
+ end
529
+ end
530
+
531
+ def eql?(o)
532
+ self.class == o.class && @type == o.type
533
+ end
534
+
535
+ DEFAULT = PTypeType.new(nil)
536
+
537
+ protected
538
+
539
+ # @api private
540
+ def _assignable?(o, guard)
541
+ return false unless o.is_a?(PTypeType)
542
+ return true if @type.nil? # wide enough to handle all types
543
+ return false if o.type.nil? # wider than t
544
+ @type.assignable?(o.type, guard)
545
+ end
546
+ end
547
+
548
+ # For backward compatibility
549
+ PType = PTypeType
550
+
551
+ class PNotUndefType < PTypeWithContainedType
552
+ def self.register_ptype(loader, ir)
553
+ create_ptype(loader, ir, 'AnyType',
554
+ 'type' => {
555
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
556
+ KEY_VALUE => nil
557
+ }
558
+ )
559
+ end
560
+
561
+ def initialize(type = nil)
562
+ super(type.class == PAnyType ? nil : type)
563
+ end
564
+
565
+ def instance?(o, guard = nil)
566
+ !(o.nil? || o == :undef) && (@type.nil? || @type.instance?(o, guard))
567
+ end
568
+
569
+ def normalize(guard = nil)
570
+ n = super
571
+ if n.type.nil?
572
+ n
573
+ else
574
+ if n.type.is_a?(POptionalType)
575
+ # No point in having an optional in a NotUndef
576
+ PNotUndefType.new(n.type.type).normalize
577
+ elsif !n.type.assignable?(PUndefType::DEFAULT)
578
+ # THe type is NotUndef anyway, so it can be stripped of
579
+ n.type
580
+ else
581
+ n
582
+ end
583
+ end
584
+ end
585
+
586
+ def new_function
587
+ # If only NotUndef, then use Unit's null converter
588
+ if type.nil?
589
+ PUnitType.new_function(self)
590
+ else
591
+ type.new_function
592
+ end
593
+ end
594
+
595
+ DEFAULT = PNotUndefType.new
596
+
597
+ protected
598
+
599
+ # @api private
600
+ def _assignable?(o, guard)
601
+ o.is_a?(PAnyType) && !o.assignable?(PUndefType::DEFAULT, guard) && (@type.nil? || @type.assignable?(o, guard))
602
+ end
603
+ end
604
+
605
+ # @api public
606
+ #
607
+ class PUndefType < PAnyType
608
+ def self.register_ptype(loader, ir)
609
+ create_ptype(loader, ir, 'AnyType')
610
+ end
611
+
612
+ def instance?(o, guard = nil)
613
+ o.nil? || :undef == o
614
+ end
615
+
616
+ # @api private
617
+ def callable_args?(callable_t, guard)
618
+ # if callable_t is Optional (or indeed PUndefType), this means that 'missing callable' is accepted
619
+ callable_t.assignable?(DEFAULT, guard)
620
+ end
621
+
622
+ DEFAULT = PUndefType.new
623
+
624
+ protected
625
+ # @api private
626
+ def _assignable?(o, guard)
627
+ o.is_a?(PUndefType)
628
+ end
629
+ end
630
+
631
+ # A type private to the type system that describes "ignored type" - i.e. "I am what you are"
632
+ # @api private
633
+ #
634
+ class PUnitType < PAnyType
635
+ def self.register_ptype(loader, ir)
636
+ create_ptype(loader, ir, 'AnyType')
637
+ end
638
+
639
+ def instance?(o, guard = nil)
640
+ true
641
+ end
642
+
643
+ # A "null" implementation - that simply returns the given argument
644
+ def self.new_function(type)
645
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_unit, type.loader) do
646
+ dispatch :from_args do
647
+ param 'Any', :from
648
+ end
649
+
650
+ def from_args(from)
651
+ from
652
+ end
653
+ end
654
+ end
655
+
656
+ DEFAULT = PUnitType.new
657
+
658
+ protected
659
+ # @api private
660
+ def _assignable?(o, guard)
661
+ true
662
+ end
663
+ end
664
+
665
+ # @api public
666
+ #
667
+ class PDefaultType < PAnyType
668
+ def self.register_ptype(loader, ir)
669
+ create_ptype(loader, ir, 'AnyType')
670
+ end
671
+
672
+ def instance?(o, guard = nil)
673
+ # Ensure that Symbol.== is called here instead of something unknown
674
+ # that is implemented on o
675
+ :default == o
676
+ end
677
+
678
+ DEFAULT = PDefaultType.new
679
+
680
+ protected
681
+ # @api private
682
+ def _assignable?(o, guard)
683
+ o.is_a?(PDefaultType)
684
+ end
685
+ end
686
+
687
+ # Type that is a Scalar
688
+ # @api public
689
+ #
690
+ class PScalarType < PAnyType
691
+ def self.register_ptype(loader, ir)
692
+ create_ptype(loader, ir, 'AnyType')
693
+ end
694
+
695
+ def instance?(o, guard = nil)
696
+ if o.is_a?(String) || o.is_a?(Numeric) || o.is_a?(TrueClass) || o.is_a?(FalseClass) || o.is_a?(Regexp)
697
+ true
698
+ elsif o.instance_of?(Array) || o.instance_of?(Hash) || o.is_a?(PAnyType) || o.is_a?(NilClass)
699
+ false
700
+ else
701
+ assignable?(TypeCalculator.infer(o))
702
+ end
703
+ end
704
+
705
+ def roundtrip_with_string?
706
+ true
707
+ end
708
+
709
+ DEFAULT = PScalarType.new
710
+
711
+ protected
712
+
713
+ # @api private
714
+ def _assignable?(o, guard)
715
+ o.is_a?(PScalarType) ||
716
+ PStringType::DEFAULT.assignable?(o, guard) ||
717
+ PIntegerType::DEFAULT.assignable?(o, guard) ||
718
+ PFloatType::DEFAULT.assignable?(o, guard) ||
719
+ PBooleanType::DEFAULT.assignable?(o, guard) ||
720
+ PRegexpType::DEFAULT.assignable?(o, guard) ||
721
+ PSemVerType::DEFAULT.assignable?(o, guard) ||
722
+ PSemVerRangeType::DEFAULT.assignable?(o, guard) ||
723
+ PTimespanType::DEFAULT.assignable?(o, guard) ||
724
+ PTimestampType::DEFAULT.assignable?(o, guard)
725
+ end
726
+ end
727
+
728
+ # Like Scalar but limited to Json Data.
729
+ # @api public
730
+ #
731
+ class PScalarDataType < PScalarType
732
+ def self.register_ptype(loader, ir)
733
+ create_ptype(loader, ir, 'ScalarType')
734
+ end
735
+
736
+ def instance?(o, guard = nil)
737
+ return o.is_a?(String) || o.is_a?(Integer) || o.is_a?(Float) || o.is_a?(TrueClass) || o.is_a?(FalseClass)
738
+ end
739
+
740
+ DEFAULT = PScalarDataType.new
741
+
742
+ protected
743
+
744
+ # @api private
745
+ def _assignable?(o, guard)
746
+ o.is_a?(PScalarDataType) ||
747
+ PStringType::DEFAULT.assignable?(o, guard) ||
748
+ PIntegerType::DEFAULT.assignable?(o, guard) ||
749
+ PFloatType::DEFAULT.assignable?(o, guard) ||
750
+ PBooleanType::DEFAULT.assignable?(o, guard)
751
+ end
752
+ end
753
+
754
+ # A string type describing the set of strings having one of the given values
755
+ # @api public
756
+ #
757
+ class PEnumType < PScalarDataType
758
+ def self.register_ptype(loader, ir)
759
+ create_ptype(loader, ir, 'ScalarDataType', 'values' => PArrayType.new(PStringType::NON_EMPTY))
760
+ end
761
+
762
+ attr_reader :values
763
+
764
+ def initialize(values)
765
+ @values = values.uniq.sort.freeze
766
+ end
767
+
768
+ # Returns Enumerator if no block is given, otherwise, calls the given
769
+ # block with each of the strings for this enum
770
+ def each(&block)
771
+ r = Iterable.on(self)
772
+ block_given? ? r.each(&block) : r
773
+ end
774
+
775
+ def generalize
776
+ # General form of an Enum is a String
777
+ if @values.empty?
778
+ PStringType::DEFAULT
779
+ else
780
+ range = @values.map(&:size).minmax
781
+ PStringType.new(PIntegerType.new(range.min, range.max))
782
+ end
783
+ end
784
+
785
+ def iterable?(guard = nil)
786
+ true
787
+ end
788
+
789
+ def iterable_type(guard = nil)
790
+ # An instance of an Enum is a String
791
+ PStringType::ITERABLE_TYPE
792
+ end
793
+
794
+ def hash
795
+ @values.hash
796
+ end
797
+
798
+ def eql?(o)
799
+ self.class == o.class && @values == o.values
800
+ end
801
+
802
+ def instance?(o, guard = nil)
803
+ o.is_a?(String) && @values.any? { |p| p == o }
804
+ end
805
+
806
+ DEFAULT = PEnumType.new(EMPTY_ARRAY)
807
+
808
+ protected
809
+
810
+ # @api private
811
+ def _assignable?(o, guard)
812
+ return true if self == o
813
+ svalues = values
814
+ if svalues.empty?
815
+ return true if o.is_a?(PStringType) || o.is_a?(PEnumType) || o.is_a?(PPatternType)
816
+ end
817
+ case o
818
+ when PStringType
819
+ # if the contained string is found in the set of enums
820
+ instance?(o.value, guard)
821
+ when PEnumType
822
+ !o.values.empty? && o.values.all? { |s| instance?(s, guard) }
823
+ else
824
+ false
825
+ end
826
+ end
827
+ end
828
+
829
+ # @api public
830
+ #
831
+ class PNumericType < PScalarDataType
832
+ def self.register_ptype(loader, ir)
833
+ create_ptype(loader, ir, 'ScalarDataType',
834
+ 'from' => { KEY_TYPE => POptionalType.new(PNumericType::DEFAULT), KEY_VALUE => nil },
835
+ 'to' => { KEY_TYPE => POptionalType.new(PNumericType::DEFAULT), KEY_VALUE => nil }
836
+ )
837
+ end
838
+
839
+ def self.new_function(type)
840
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_numeric, type.loader) do
841
+ local_types do
842
+ type 'Convertible = Variant[Undef, Integer, Float, Boolean, String, Timespan, Timestamp]'
843
+ type 'NamedArgs = Struct[{from => Convertible, Optional[abs] => Boolean}]'
844
+ end
845
+
846
+ dispatch :from_args do
847
+ param 'Convertible', :from
848
+ optional_param 'Boolean', :abs
849
+ end
850
+
851
+ dispatch :from_hash do
852
+ param 'NamedArgs', :hash_args
853
+ end
854
+
855
+ def from_args(from, abs = false)
856
+ result = from_convertible(from)
857
+ abs ? result.abs : result
858
+ end
859
+
860
+ def from_hash(args_hash)
861
+ from_args(args_hash['from'], args_hash['abs'] || false)
862
+ end
863
+
864
+ def from_convertible(from)
865
+ case from
866
+ when NilClass
867
+ throw :undefined_value
868
+ when Float
869
+ from
870
+ when Integer
871
+ from
872
+ when Time::TimeData
873
+ from.to_f
874
+ when TrueClass
875
+ 1
876
+ when FalseClass
877
+ 0
878
+ when String
879
+ begin
880
+ if from[0] == '0' && (from[1].downcase == 'b' || from[1].downcase == 'x')
881
+ Integer(from)
882
+ else
883
+ Puppet::Pops::Utils.to_n(from)
884
+ end
885
+ rescue TypeError => e
886
+ raise TypeConversionError.new(e.message)
887
+ rescue ArgumentError => e
888
+ raise TypeConversionError.new(e.message)
889
+ end
890
+ else
891
+ t = Puppet::Pops::Types::TypeCalculator.singleton.infer(from).generalize
892
+ raise TypeConversionError.new("Value of type '#{t}' cannot be converted to Numeric")
893
+ end
894
+ end
895
+ end
896
+ end
897
+
898
+ def initialize(from, to = Float::INFINITY)
899
+ from = -Float::INFINITY if from.nil? || from == :default
900
+ to = Float::INFINITY if to.nil? || to == :default
901
+ raise ArgumentError, "'from' must be less or equal to 'to'. Got (#{from}, #{to}" if from > to
902
+ @from = from
903
+ @to = to
904
+ end
905
+
906
+ # Checks if this numeric range intersects with another
907
+ #
908
+ # @param o [PNumericType] the range to compare with
909
+ # @return [Boolean] `true` if this range intersects with the other range
910
+ # @api public
911
+ def intersect?(o)
912
+ self.class == o.class && !(@to < o.numeric_from || o.numeric_to < @from)
913
+ end
914
+
915
+ # Returns the lower bound of the numeric range or `nil` if no lower bound is set.
916
+ # @return [Float,Integer]
917
+ def from
918
+ @from == -Float::INFINITY ? nil : @from
919
+ end
920
+
921
+ # Returns the upper bound of the numeric range or `nil` if no upper bound is set.
922
+ # @return [Float,Integer]
923
+ def to
924
+ @to == Float::INFINITY ? nil : @to
925
+ end
926
+
927
+ # Same as #from but will return `-Float::Infinity` instead of `nil` if no lower bound is set.
928
+ # @return [Float,Integer]
929
+ def numeric_from
930
+ @from
931
+ end
932
+
933
+ # Same as #to but will return `Float::Infinity` instead of `nil` if no lower bound is set.
934
+ # @return [Float,Integer]
935
+ def numeric_to
936
+ @to
937
+ end
938
+
939
+ def hash
940
+ @from.hash ^ @to.hash
941
+ end
942
+
943
+ def eql?(o)
944
+ self.class == o.class && @from == o.numeric_from && @to == o.numeric_to
945
+ end
946
+
947
+ def instance?(o, guard = nil)
948
+ o.is_a?(Numeric) && o >= @from && o <= @to
949
+ end
950
+
951
+ def unbounded?
952
+ @from == -Float::INFINITY && @to == Float::INFINITY
953
+ end
954
+
955
+ protected
956
+
957
+ # @api_private
958
+ def _assignable?(o, guard)
959
+ return false unless o.is_a?(self.class)
960
+ # If o min and max are within the range of t
961
+ @from <= o.numeric_from && @to >= o.numeric_to
962
+ end
963
+
964
+ DEFAULT = PNumericType.new(-Float::INFINITY)
965
+ end
966
+
967
+ # @api public
968
+ #
969
+ class PIntegerType < PNumericType
970
+ def self.register_ptype(loader, ir)
971
+ create_ptype(loader, ir, 'NumericType')
972
+ end
973
+
974
+ # Will respond `true` for any range that is bounded at both ends.
975
+ #
976
+ # @return [Boolean] `true` if the type describes a finite range.
977
+ def finite_range?
978
+ @from != -Float::INFINITY && @to != Float::INFINITY
979
+ end
980
+
981
+ def generalize
982
+ DEFAULT
983
+ end
984
+
985
+ def instance?(o, guard = nil)
986
+ o.is_a?(Integer) && o >= numeric_from && o <= numeric_to
987
+ end
988
+
989
+ # Checks if this range is adjacent to the given range
990
+ #
991
+ # @param o [PIntegerType] the range to compare with
992
+ # @return [Boolean] `true` if this range is adjacent to the other range
993
+ # @api public
994
+ def adjacent?(o)
995
+ o.is_a?(PIntegerType) && (@to + 1 == o.from || o.to + 1 == @from)
996
+ end
997
+
998
+ # Concatenates this range with another range provided that the ranges intersect or
999
+ # are adjacent. When that's not the case, this method will return `nil`
1000
+ #
1001
+ # @param o [PIntegerType] the range to concatenate with this range
1002
+ # @return [PIntegerType,nil] the concatenated range or `nil` when the ranges were apart
1003
+ # @api public
1004
+ def merge(o)
1005
+ if intersect?(o) || adjacent?(o)
1006
+ min = @from <= o.numeric_from ? @from : o.numeric_from
1007
+ max = @to >= o.numeric_to ? @to : o.numeric_to
1008
+ PIntegerType.new(min, max)
1009
+ else
1010
+ nil
1011
+ end
1012
+ end
1013
+
1014
+ def iterable?(guard = nil)
1015
+ true
1016
+ end
1017
+
1018
+ def iterable_type(guard = nil)
1019
+ # It's unknown if the iterable will be a range (min, max) or a "times" (0, max)
1020
+ PIterableType.new(PIntegerType::DEFAULT)
1021
+ end
1022
+
1023
+ # Returns Float.Infinity if one end of the range is unbound
1024
+ def size
1025
+ return Float::INFINITY if @from == -Float::INFINITY || @to == Float::INFINITY
1026
+ 1+(to-from).abs
1027
+ end
1028
+
1029
+ # Returns the range as an array ordered so the smaller number is always first.
1030
+ # The number may be Infinity or -Infinity.
1031
+ def range
1032
+ [@from, @to]
1033
+ end
1034
+
1035
+ # Returns Enumerator if no block is given
1036
+ # Returns nil if size is infinity (does not yield)
1037
+ def each(&block)
1038
+ r = Iterable.on(self)
1039
+ block_given? ? r.each(&block) : r
1040
+ end
1041
+
1042
+ # Returns a range where both to and from are positive numbers. Negative
1043
+ # numbers are converted to zero
1044
+ # @return [PIntegerType] a positive range
1045
+ def to_size
1046
+ @from >= 0 ? self : PIntegerType.new(0, @to < 0 ? 0 : @to)
1047
+ end
1048
+
1049
+ def new_function
1050
+ @@new_function ||= Puppet::Functions.create_loaded_function(:new, loader) do
1051
+ local_types do
1052
+ type 'Radix = Variant[Default, Integer[2,2], Integer[8,8], Integer[10,10], Integer[16,16]]'
1053
+ type 'Convertible = Variant[Undef, Numeric, Boolean, String, Timespan, Timestamp]'
1054
+ type 'NamedArgs = Struct[{from => Convertible, Optional[radix] => Radix, Optional[abs] => Boolean}]'
1055
+ end
1056
+
1057
+ dispatch :from_args do
1058
+ param 'Convertible', :from
1059
+ optional_param 'Radix', :radix
1060
+ optional_param 'Boolean', :abs
1061
+ end
1062
+
1063
+ dispatch :from_hash do
1064
+ param 'NamedArgs', :hash_args
1065
+ end
1066
+
1067
+ def from_args(from, radix = :default, abs = false)
1068
+ result = from_convertible(from, radix)
1069
+ abs ? result.abs : result
1070
+ end
1071
+
1072
+ def from_hash(args_hash)
1073
+ from_args(args_hash['from'], args_hash['radix'] || :default, args_hash['abs'] || false)
1074
+ end
1075
+
1076
+ def from_convertible(from, radix)
1077
+ case from
1078
+ when NilClass
1079
+ throw :undefined_value
1080
+ when Float, Time::TimeData
1081
+ from.to_i
1082
+ when Integer
1083
+ from
1084
+ when TrueClass
1085
+ 1
1086
+ when FalseClass
1087
+ 0
1088
+ when String
1089
+ begin
1090
+ radix == :default ? Integer(from) : Integer(from, assert_radix(radix))
1091
+ rescue TypeError => e
1092
+ raise TypeConversionError.new(e.message)
1093
+ rescue ArgumentError => e
1094
+ # Test for special case where there is whitespace between sign and number
1095
+ match = Patterns::WS_BETWEEN_SIGN_AND_NUMBER.match(from)
1096
+ if match
1097
+ begin
1098
+ # Try again, this time with whitespace removed
1099
+ return from_args(match[1] + match[2], radix)
1100
+ rescue TypeConversionError
1101
+ # Ignored to retain original error
1102
+ end
1103
+ end
1104
+ raise TypeConversionError.new(e.message)
1105
+ end
1106
+ else
1107
+ t = Puppet::Pops::Types::TypeCalculator.singleton.infer(from).generalize
1108
+ raise TypeConversionError.new("Value of type '#{t}' cannot be converted to an Integer")
1109
+ end
1110
+ end
1111
+
1112
+ def assert_radix(radix)
1113
+ case radix
1114
+ when 2, 8, 10, 16, :default
1115
+ else
1116
+ raise ArgumentError.new("Illegal radix: '#{radix}', expected 2, 8, 10, 16, or default")
1117
+ end
1118
+ radix
1119
+ end
1120
+
1121
+ end
1122
+ end
1123
+
1124
+ DEFAULT = PIntegerType.new(-Float::INFINITY)
1125
+ end
1126
+
1127
+ # @api public
1128
+ #
1129
+ class PFloatType < PNumericType
1130
+ def self.register_ptype(loader, ir)
1131
+ create_ptype(loader, ir, 'NumericType')
1132
+ end
1133
+
1134
+ def generalize
1135
+ DEFAULT
1136
+ end
1137
+
1138
+ def instance?(o, guard = nil)
1139
+ o.is_a?(Float) && o >= numeric_from && o <= numeric_to
1140
+ end
1141
+
1142
+ # Concatenates this range with another range provided that the ranges intersect. When that's not the case, this
1143
+ # method will return `nil`
1144
+ #
1145
+ # @param o [PFloatType] the range to concatenate with this range
1146
+ # @return [PFloatType,nil] the concatenated range or `nil` when the ranges were apart
1147
+ # @api public
1148
+ def merge(o)
1149
+ if intersect?(o)
1150
+ min = @from <= o.from ? @from : o.from
1151
+ max = @to >= o.to ? @to : o.to
1152
+ PFloatType.new(min, max)
1153
+ else
1154
+ nil
1155
+ end
1156
+ end
1157
+
1158
+ # Returns a new function that produces a Float value
1159
+ #
1160
+ def self.new_function(type)
1161
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_float, type.loader) do
1162
+ local_types do
1163
+ type 'Convertible = Variant[Undef, Numeric, Boolean, String, Timespan, Timestamp]'
1164
+ type 'NamedArgs = Struct[{from => Convertible, Optional[abs] => Boolean}]'
1165
+ end
1166
+
1167
+ dispatch :from_args do
1168
+ param 'Convertible', :from
1169
+ optional_param 'Boolean', :abs
1170
+ end
1171
+
1172
+ dispatch :from_hash do
1173
+ param 'NamedArgs', :hash_args
1174
+ end
1175
+
1176
+ def from_args(from, abs = false)
1177
+ result = from_convertible(from)
1178
+ abs ? result.abs : result
1179
+ end
1180
+
1181
+ def from_hash(args_hash)
1182
+ from_args(args_hash['from'], args_hash['abs'] || false)
1183
+ end
1184
+
1185
+ def from_convertible(from)
1186
+ case from
1187
+ when NilClass
1188
+ throw :undefined_value
1189
+ when Float
1190
+ from
1191
+ when Integer
1192
+ Float(from)
1193
+ when Time::TimeData
1194
+ from.to_f
1195
+ when TrueClass
1196
+ 1.0
1197
+ when FalseClass
1198
+ 0.0
1199
+ when String
1200
+ begin
1201
+ # support a binary as float
1202
+ if from[0] == '0' && from[1].downcase == 'b'
1203
+ from = Integer(from)
1204
+ end
1205
+ Float(from)
1206
+ rescue TypeError => e
1207
+ raise TypeConversionError.new(e.message)
1208
+ rescue ArgumentError => e
1209
+ # Test for special case where there is whitespace between sign and number
1210
+ match = Patterns::WS_BETWEEN_SIGN_AND_NUMBER.match(from)
1211
+ if match
1212
+ begin
1213
+ # Try again, this time with whitespace removed
1214
+ return from_args(match[1] + match[2])
1215
+ rescue TypeConversionError
1216
+ # Ignored to retain original error
1217
+ end
1218
+ end
1219
+ raise TypeConversionError.new(e.message)
1220
+ end
1221
+ else
1222
+ t = Puppet::Pops::Types::TypeCalculator.singleton.infer(from).generalize
1223
+ raise TypeConversionError.new("Value of type '#{t}' cannot be converted to Float")
1224
+ end
1225
+ end
1226
+ end
1227
+ end
1228
+
1229
+ DEFAULT = PFloatType.new(-Float::INFINITY)
1230
+ end
1231
+
1232
+ # @api public
1233
+ #
1234
+ class PCollectionType < PAnyType
1235
+ def self.register_ptype(loader, ir)
1236
+ create_ptype(loader, ir, 'AnyType',
1237
+ 'size_type' => {
1238
+ KEY_TYPE => POptionalType.new(PTypeType.new(PIntegerType::DEFAULT)),
1239
+ KEY_VALUE => nil
1240
+ }
1241
+ )
1242
+ end
1243
+
1244
+ attr_reader :size_type
1245
+
1246
+ def initialize(size_type)
1247
+ @size_type = size_type
1248
+ end
1249
+
1250
+ def accept(visitor, guard)
1251
+ super
1252
+ @size_type.accept(visitor, guard) unless @size_type.nil?
1253
+ end
1254
+
1255
+ def generalize
1256
+ DEFAULT
1257
+ end
1258
+
1259
+ def normalize(guard = nil)
1260
+ DEFAULT
1261
+ end
1262
+
1263
+ def instance?(o, guard = nil)
1264
+ # The inferred type of a class derived from Array or Hash is either Runtime or Object. It's not assignable to the Collection type.
1265
+ if o.instance_of?(Array) || o.instance_of?(Hash)
1266
+ @size_type.nil? || @size_type.instance?(o.size)
1267
+ else
1268
+ false
1269
+ end
1270
+ end
1271
+
1272
+ # Returns an array with from (min) size to (max) size
1273
+ def size_range
1274
+ (@size_type || DEFAULT_SIZE).range
1275
+ end
1276
+
1277
+ def has_empty_range?
1278
+ from, to = size_range
1279
+ from == 0 && to == 0
1280
+ end
1281
+
1282
+ def hash
1283
+ @size_type.hash
1284
+ end
1285
+
1286
+ def iterable?(guard = nil)
1287
+ true
1288
+ end
1289
+
1290
+ def eql?(o)
1291
+ self.class == o.class && @size_type == o.size_type
1292
+ end
1293
+
1294
+
1295
+ DEFAULT_SIZE = PIntegerType.new(0)
1296
+ ZERO_SIZE = PIntegerType.new(0, 0)
1297
+ NOT_EMPTY_SIZE = PIntegerType.new(1)
1298
+ DEFAULT = PCollectionType.new(nil)
1299
+
1300
+ protected
1301
+
1302
+ # @api private
1303
+ #
1304
+ def _assignable?(o, guard)
1305
+ case o
1306
+ when PCollectionType
1307
+ (@size_type || DEFAULT_SIZE).assignable?(o.size_type || DEFAULT_SIZE, guard)
1308
+ when PTupleType
1309
+ # compute the tuple's min/max size, and check if that size matches
1310
+ size_s = size_type || DEFAULT_SIZE
1311
+ size_o = o.size_type
1312
+ if size_o.nil?
1313
+ type_count = o.types.size
1314
+ size_o = PIntegerType.new(type_count, type_count)
1315
+ end
1316
+ size_s.assignable?(size_o)
1317
+ when PStructType
1318
+ from = to = o.elements.size
1319
+ (@size_type || DEFAULT_SIZE).assignable?(PIntegerType.new(from, to), guard)
1320
+ else
1321
+ false
1322
+ end
1323
+ end
1324
+ end
1325
+
1326
+ class PIterableType < PTypeWithContainedType
1327
+ def self.register_ptype(loader, ir)
1328
+ create_ptype(loader, ir, 'AnyType',
1329
+ 'type' => {
1330
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
1331
+ KEY_VALUE => nil
1332
+ }
1333
+ )
1334
+ end
1335
+
1336
+ def element_type
1337
+ @type
1338
+ end
1339
+
1340
+ def instance?(o, guard = nil)
1341
+ if @type.nil? || @type.assignable?(PAnyType::DEFAULT, guard)
1342
+ # Any element_type will do
1343
+ case o
1344
+ when Iterable, String, Hash, Array, Range, PEnumType
1345
+ true
1346
+ when Integer
1347
+ o >= 0
1348
+ when PIntegerType
1349
+ o.finite_range?
1350
+ else
1351
+ false
1352
+ end
1353
+ else
1354
+ assignable?(TypeCalculator.infer(o), guard)
1355
+ end
1356
+ end
1357
+
1358
+ def iterable?(guard = nil)
1359
+ true
1360
+ end
1361
+
1362
+ def iterable_type(guard = nil)
1363
+ self
1364
+ end
1365
+
1366
+ DEFAULT = PIterableType.new(nil)
1367
+
1368
+ protected
1369
+
1370
+ # @api private
1371
+ def _assignable?(o, guard)
1372
+ if @type.nil? || @type.assignable?(PAnyType::DEFAULT, guard)
1373
+ # Don't request the iterable_type. Since this Iterable accepts Any element, it is enough that o is iterable.
1374
+ o.iterable?
1375
+ else
1376
+ o = o.iterable_type
1377
+ o.nil? || o.element_type.nil? ? false : @type.assignable?(o.element_type, guard)
1378
+ end
1379
+ end
1380
+ end
1381
+
1382
+ # @api public
1383
+ #
1384
+ class PIteratorType < PTypeWithContainedType
1385
+ def self.register_ptype(loader, ir)
1386
+ create_ptype(loader, ir, 'AnyType',
1387
+ 'type' => {
1388
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
1389
+ KEY_VALUE => nil
1390
+ }
1391
+ )
1392
+ end
1393
+
1394
+ def element_type
1395
+ @type
1396
+ end
1397
+
1398
+ def instance?(o, guard = nil)
1399
+ o.is_a?(Iterable) && (@type.nil? || @type.assignable?(o.element_type, guard))
1400
+ end
1401
+
1402
+ def iterable?(guard = nil)
1403
+ true
1404
+ end
1405
+
1406
+ def iterable_type(guard = nil)
1407
+ @type.nil? ? PIterableType::DEFAULT : PIterableType.new(@type)
1408
+ end
1409
+
1410
+ DEFAULT = PIteratorType.new(nil)
1411
+
1412
+ protected
1413
+
1414
+ # @api private
1415
+ def _assignable?(o, guard)
1416
+ o.is_a?(PIteratorType) && (@type.nil? || @type.assignable?(o.element_type, guard))
1417
+ end
1418
+ end
1419
+
1420
+ # @api public
1421
+ #
1422
+ class PStringType < PScalarDataType
1423
+ def self.register_ptype(loader, ir)
1424
+ create_ptype(loader, ir, 'ScalarDataType',
1425
+ 'size_type_or_value' => {
1426
+ KEY_TYPE => POptionalType.new(PVariantType.new([PStringType::DEFAULT, PTypeType.new(PIntegerType::DEFAULT)])),
1427
+ KEY_VALUE => nil
1428
+ })
1429
+ end
1430
+
1431
+ attr_reader :size_type_or_value
1432
+
1433
+ def initialize(size_type_or_value, deprecated_multi_args = EMPTY_ARRAY)
1434
+ unless deprecated_multi_args.empty?
1435
+ if Puppet[:strict] != :off
1436
+ Puppet.warn_once('deprecations', "PStringType#initialize_multi_args", "Passing more than one argument to PStringType#initialize is deprecated")
1437
+ end
1438
+ size_type_or_value = deprecated_multi_args[0]
1439
+ end
1440
+ @size_type_or_value = size_type_or_value
1441
+ end
1442
+
1443
+ def accept(visitor, guard)
1444
+ super
1445
+ @size_type_or_value.accept(visitor, guard) if @size_type_or_value.is_a?(PIntegerType)
1446
+ end
1447
+
1448
+ def generalize
1449
+ DEFAULT
1450
+ end
1451
+
1452
+ def hash
1453
+ @size_type_or_value.hash
1454
+ end
1455
+
1456
+ def iterable?(guard = nil)
1457
+ true
1458
+ end
1459
+
1460
+ def iterable_type(guard = nil)
1461
+ ITERABLE_TYPE
1462
+ end
1463
+
1464
+ def eql?(o)
1465
+ self.class == o.class && @size_type_or_value == o.size_type_or_value
1466
+ end
1467
+
1468
+ def instance?(o, guard = nil)
1469
+ # true if size compliant
1470
+ if o.is_a?(String)
1471
+ if @size_type_or_value.is_a?(PIntegerType)
1472
+ @size_type_or_value.instance?(o.size, guard)
1473
+ else
1474
+ @size_type_or_value.nil? ? true : o == value
1475
+ end
1476
+ else
1477
+ false
1478
+ end
1479
+ end
1480
+
1481
+ def value
1482
+ @size_type_or_value.is_a?(PIntegerType) ? nil : @size_type_or_value
1483
+ end
1484
+
1485
+ # @deprecated
1486
+ # @api private
1487
+ def values
1488
+ if Puppet[:strict] != :off
1489
+ Puppet.warn_once('deprecations', "PStringType#values", "Method PStringType#values is deprecated. Use #value instead")
1490
+ end
1491
+ @value.is_a?(String) ? [@value] : EMPTY_ARRAY
1492
+ end
1493
+
1494
+ def size_type
1495
+ @size_type_or_value.is_a?(PIntegerType) ? @size_type_or_value : nil
1496
+ end
1497
+
1498
+ def derived_size_type
1499
+ if @size_type_or_value.is_a?(PIntegerType)
1500
+ @size_type_or_value
1501
+ elsif @size_type_or_value.is_a?(String)
1502
+ sz = @size_type_or_value.size
1503
+ PIntegerType.new(sz, sz)
1504
+ else
1505
+ PCollectionType::DEFAULT_SIZE
1506
+ end
1507
+ end
1508
+
1509
+ def self.new_function(type)
1510
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_string, type.loader) do
1511
+ local_types do
1512
+ type "Format = Pattern[/#{StringConverter::Format::FMT_PATTERN_STR}/]"
1513
+ type 'ContainerFormat = Struct[{
1514
+ Optional[format] => Format,
1515
+ Optional[separator] => String,
1516
+ Optional[separator2] => String,
1517
+ Optional[string_formats] => Hash[Type, Format]
1518
+ }]'
1519
+ type 'TypeMap = Hash[Type, Variant[Format, ContainerFormat]]'
1520
+ type 'Convertible = Any'
1521
+ type 'Formats = Variant[Default, String[1], TypeMap]'
1522
+ end
1523
+
1524
+ dispatch :from_args do
1525
+ param 'Convertible', :from
1526
+ optional_param 'Formats', :string_formats
1527
+ end
1528
+
1529
+ def from_args(from, formats = :default)
1530
+ StringConverter.singleton.convert(from, formats)
1531
+ end
1532
+ end
1533
+ end
1534
+
1535
+ DEFAULT = PStringType.new(nil)
1536
+ NON_EMPTY = PStringType.new(PCollectionType::NOT_EMPTY_SIZE)
1537
+
1538
+ # Iterates over each character of the string
1539
+ ITERABLE_TYPE = PIterableType.new(PStringType.new(PIntegerType.new(1,1)))
1540
+
1541
+ protected
1542
+
1543
+ # @api private
1544
+ def _assignable?(o, guard)
1545
+ if @size_type_or_value.is_a?(PIntegerType)
1546
+ # A general string is assignable by any other string or pattern restricted string
1547
+ # if the string has a size constraint it does not match since there is no reasonable way
1548
+ # to compute the min/max length a pattern will match. For enum, it is possible to test that
1549
+ # each enumerator value is within range
1550
+ case o
1551
+ when PStringType
1552
+ @size_type_or_value.assignable?(o.derived_size_type, guard)
1553
+
1554
+ when PEnumType
1555
+ if o.values.empty?
1556
+ # enum represents all enums, and thus all strings, a sized constrained string can thus not
1557
+ # be assigned any enum (unless it is max size).
1558
+ @size_type_or_value.assignable?(PCollectionType::DEFAULT_SIZE, guard)
1559
+ else
1560
+ # true if all enum values are within range
1561
+ orange = o.values.map(&:size).minmax
1562
+ srange = @size_type_or_value.range
1563
+ # If o min and max are within the range of t
1564
+ srange[0] <= orange[0] && srange[1] >= orange[1]
1565
+ end
1566
+
1567
+ when PPatternType
1568
+ # true if size constraint is at least 0 to +Infinity (which is the same as the default)
1569
+ @size_type_or_value.assignable?(PCollectionType::DEFAULT_SIZE, guard)
1570
+ else
1571
+ # no other type matches string
1572
+ false
1573
+ end
1574
+ else
1575
+ case o
1576
+ when PStringType
1577
+ # Must match exactly when value is a string
1578
+ @size_type_or_value.nil? || @size_type_or_value == o.size_type_or_value
1579
+ when PEnumType
1580
+ @size_type_or_value.nil? ? true : o.values.size == 1 && @size_type_or_value == o.values[0]
1581
+ when PPatternType
1582
+ @size_type_or_value.nil?
1583
+ else
1584
+ # All others are false, since no other type describes the same set of specific strings
1585
+ false
1586
+ end
1587
+ end
1588
+ end
1589
+ end
1590
+
1591
+ # @api public
1592
+ #
1593
+ class PRegexpType < PScalarType
1594
+ def self.register_ptype(loader, ir)
1595
+ create_ptype(loader, ir, 'ScalarType',
1596
+ 'pattern' => {
1597
+ KEY_TYPE => PVariantType.new([PUndefType::DEFAULT, PStringType::DEFAULT, PRegexpType::DEFAULT]),
1598
+ KEY_VALUE => nil
1599
+ })
1600
+ end
1601
+
1602
+
1603
+ # Returns a new function that produces a Regexp instance
1604
+ #
1605
+ def self.new_function(type)
1606
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_float, type.loader) do
1607
+ dispatch :from_string do
1608
+ param 'String', :pattern
1609
+ end
1610
+
1611
+ def from_string(pattern)
1612
+ Regexp.new(pattern)
1613
+ end
1614
+ end
1615
+ end
1616
+
1617
+ attr_reader :pattern
1618
+
1619
+ # @param regexp [Regexp] the regular expression
1620
+ # @return [String] the Regexp as a slash delimited string with slashes escaped
1621
+ def self.regexp_to_s_with_delimiters(regexp)
1622
+ regexp.options == 0 ? regexp.inspect : "/#{regexp.to_s}/"
1623
+ end
1624
+
1625
+ # @param regexp [Regexp] the regular expression
1626
+ # @return [String] the Regexp as a string without escaped slash
1627
+ def self.regexp_to_s(regexp)
1628
+ # Rubies < 2.0.0 retains escaped delimiters in the source string.
1629
+ @source_retains_escaped_slash ||= Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0')
1630
+ source = regexp.source
1631
+ if @source_retains_escaped_slash && source.include?('\\')
1632
+ # Restore corrupt string in rubies <2.0.0, i.e. turn '\/' into '/' but
1633
+ # don't touch valid escapes such as '\s', '\{' etc.
1634
+ escaped = false
1635
+ bld = ''
1636
+ source.each_codepoint do |codepoint|
1637
+ if escaped
1638
+ bld << 0x5c unless codepoint == 0x2f # '/'
1639
+ bld << codepoint
1640
+ escaped = false
1641
+ elsif codepoint == 0x5c # '\'
1642
+ escaped = true
1643
+ elsif codepoint <= 0x7f
1644
+ bld << codepoint
1645
+ else
1646
+ bld << [codepoint].pack('U')
1647
+ end
1648
+ end
1649
+ source = bld
1650
+ end
1651
+ append_flags_group(source, regexp.options)
1652
+ end
1653
+
1654
+ def self.append_flags_group(rx_string, options)
1655
+ if options == 0
1656
+ rx_string
1657
+ else
1658
+ bld = '(?'
1659
+ bld << 'i' if (options & Regexp::IGNORECASE) != 0
1660
+ bld << 'm' if (options & Regexp::MULTILINE) != 0
1661
+ bld << 'x' if (options & Regexp::EXTENDED) != 0
1662
+ unless options == (Regexp::IGNORECASE | Regexp::MULTILINE | Regexp::EXTENDED)
1663
+ bld << '-'
1664
+ bld << 'i' if (options & Regexp::IGNORECASE) == 0
1665
+ bld << 'm' if (options & Regexp::MULTILINE) == 0
1666
+ bld << 'x' if (options & Regexp::EXTENDED) == 0
1667
+ end
1668
+ bld << ':' << rx_string << ')'
1669
+ bld.freeze
1670
+ end
1671
+ end
1672
+
1673
+ def initialize(pattern)
1674
+ if pattern.is_a?(Regexp)
1675
+ @regexp = pattern
1676
+ @pattern = PRegexpType.regexp_to_s(pattern)
1677
+ else
1678
+ @pattern = pattern
1679
+ end
1680
+ end
1681
+
1682
+ def regexp
1683
+ @regexp ||= Regexp.new(@pattern || '')
1684
+ end
1685
+
1686
+ def hash
1687
+ @pattern.hash
1688
+ end
1689
+
1690
+ def eql?(o)
1691
+ self.class == o.class && @pattern == o.pattern
1692
+ end
1693
+
1694
+ def instance?(o, guard=nil)
1695
+ o.is_a?(Regexp) && @pattern.nil? || regexp == o
1696
+ end
1697
+
1698
+ DEFAULT = PRegexpType.new(nil)
1699
+
1700
+ protected
1701
+
1702
+ # @api private
1703
+ #
1704
+ def _assignable?(o, guard)
1705
+ o.is_a?(PRegexpType) && (@pattern.nil? || @pattern == o.pattern)
1706
+ end
1707
+ end
1708
+
1709
+ # Represents a subtype of String that narrows the string to those matching the patterns
1710
+ # If specified without a pattern it is basically the same as the String type.
1711
+ #
1712
+ # @api public
1713
+ #
1714
+ class PPatternType < PScalarDataType
1715
+ def self.register_ptype(loader, ir)
1716
+ create_ptype(loader, ir, 'ScalarDataType', 'patterns' => PArrayType.new(PRegexpType::DEFAULT))
1717
+ end
1718
+
1719
+ attr_reader :patterns
1720
+
1721
+ def initialize(patterns)
1722
+ @patterns = patterns.freeze
1723
+ end
1724
+
1725
+ def accept(visitor, guard)
1726
+ super
1727
+ @patterns.each { |p| p.accept(visitor, guard) }
1728
+ end
1729
+
1730
+ def hash
1731
+ @patterns.hash
1732
+ end
1733
+
1734
+ def eql?(o)
1735
+ self.class == o.class && @patterns.size == o.patterns.size && (@patterns - o.patterns).empty?
1736
+ end
1737
+
1738
+ def instance?(o, guard = nil)
1739
+ o.is_a?(String) && (@patterns.empty? || @patterns.any? { |p| p.regexp.match(o) })
1740
+ end
1741
+
1742
+ DEFAULT = PPatternType.new(EMPTY_ARRAY)
1743
+
1744
+ protected
1745
+
1746
+ # @api private
1747
+ #
1748
+ def _assignable?(o, guard)
1749
+ return true if self == o
1750
+ case o
1751
+ when PStringType
1752
+ v = o.value
1753
+ if v.nil?
1754
+ # Strings cannot all match a pattern, but if there is no pattern it is ok
1755
+ # (There should really always be a pattern, but better safe than sorry).
1756
+ @patterns.empty?
1757
+ else
1758
+ # the string in String type must match one of the patterns in Pattern type,
1759
+ # or Pattern represents all Patterns == all Strings
1760
+ regexps = @patterns.map { |p| p.regexp }
1761
+ regexps.empty? || regexps.any? { |re| re.match(v) }
1762
+ end
1763
+ when PEnumType
1764
+ if o.values.empty?
1765
+ # Enums (unknown which ones) cannot all match a pattern, but if there is no pattern it is ok
1766
+ # (There should really always be a pattern, but better safe than sorry).
1767
+ @patterns.empty?
1768
+ else
1769
+ # all strings in String/Enum type must match one of the patterns in Pattern type,
1770
+ # or Pattern represents all Patterns == all Strings
1771
+ regexps = @patterns.map { |p| p.regexp }
1772
+ regexps.empty? || o.values.all? { |s| regexps.any? {|re| re.match(s) } }
1773
+ end
1774
+ when PPatternType
1775
+ @patterns.empty?
1776
+ else
1777
+ false
1778
+ end
1779
+ end
1780
+ end
1781
+
1782
+ # @api public
1783
+ #
1784
+ class PBooleanType < PScalarDataType
1785
+ def self.register_ptype(loader, ir)
1786
+ create_ptype(loader, ir, 'ScalarDataType')
1787
+ end
1788
+
1789
+ def instance?(o, guard = nil)
1790
+ o == true || o == false
1791
+ end
1792
+
1793
+ def self.new_function(type)
1794
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_boolean, type.loader) do
1795
+ dispatch :from_args do
1796
+ param 'Variant[Undef, Integer, Float, Boolean, String]', :from
1797
+ end
1798
+
1799
+ def from_args(from)
1800
+ from = from.downcase if from.is_a?(String)
1801
+ case from
1802
+ when NilClass
1803
+ throw :undefined_value
1804
+ when Float
1805
+ from != 0.0
1806
+ when Integer
1807
+ from != 0
1808
+ when true, false
1809
+ from
1810
+ when 'false', 'no', 'n'
1811
+ false
1812
+ when 'true', 'yes', 'y'
1813
+ true
1814
+ else
1815
+ raise TypeConversionError.new("Value '#{from}' of type '#{from.class}' cannot be converted to Boolean")
1816
+ end
1817
+ end
1818
+ end
1819
+ end
1820
+
1821
+ DEFAULT = PBooleanType.new
1822
+
1823
+ protected
1824
+
1825
+ # @api private
1826
+ #
1827
+ def _assignable?(o, guard)
1828
+ o.is_a?(PBooleanType)
1829
+ end
1830
+ end
1831
+
1832
+ # @api public
1833
+ #
1834
+ # @api public
1835
+ #
1836
+ class PStructElement < TypedModelObject
1837
+ def self.register_ptype(loader, ir)
1838
+ @type = Pcore::create_object_type(loader, ir, self, 'Pcore::StructElement'.freeze, nil,
1839
+ 'key_type' => PTypeType::DEFAULT,
1840
+ 'value_type' => PTypeType::DEFAULT)
1841
+ end
1842
+
1843
+ attr_accessor :key_type, :value_type
1844
+
1845
+ def accept(visitor, guard)
1846
+ @key_type.accept(visitor, guard)
1847
+ @value_type.accept(visitor, guard)
1848
+ end
1849
+
1850
+ def hash
1851
+ value_type.hash ^ key_type.hash
1852
+ end
1853
+
1854
+ def name
1855
+ k = key_type
1856
+ k = k.optional_type if k.is_a?(POptionalType)
1857
+ k.value
1858
+ end
1859
+
1860
+ def initialize(key_type, value_type)
1861
+ @key_type = key_type
1862
+ @value_type = value_type
1863
+ end
1864
+
1865
+ def generalize
1866
+ gv_type = @value_type.generalize
1867
+ @value_type.equal?(gv_type) ? self : PStructElement.new(@key_type, gv_type)
1868
+ end
1869
+
1870
+ def normalize(guard = nil)
1871
+ nv_type = @value_type.normalize(guard)
1872
+ @value_type.equal?(nv_type) ? self : PStructElement.new(@key_type, nv_type)
1873
+ end
1874
+
1875
+ def resolve(loader)
1876
+ rkey_type = @key_type.resolve(loader)
1877
+ rvalue_type = @value_type.resolve(loader)
1878
+ rkey_type.equal?(@key_type) && rvalue_type.equal?(@value_type) ? self : self.class.new(rkey_type, rvalue_type)
1879
+ end
1880
+
1881
+ def <=>(o)
1882
+ self.name <=> o.name
1883
+ end
1884
+
1885
+ def eql?(o)
1886
+ self == o
1887
+ end
1888
+
1889
+ def ==(o)
1890
+ self.class == o.class && value_type == o.value_type && key_type == o.key_type
1891
+ end
1892
+
1893
+ # Special boostrap method to overcome the hen and egg problem with the Object initializer that contains
1894
+ # types that are derived from Object (such as Annotation)
1895
+ #
1896
+ # @api private
1897
+ def replace_value_type(new_type)
1898
+ @value_type = new_type
1899
+ end
1900
+ end
1901
+
1902
+ # @api public
1903
+ #
1904
+ class PStructType < PAnyType
1905
+ include Enumerable
1906
+
1907
+ def self.register_ptype(loader, ir)
1908
+ create_ptype(loader, ir, 'AnyType', 'elements' => PArrayType.new(PTypeReferenceType.new('Pcore::StructElement')))
1909
+ end
1910
+
1911
+ def initialize(elements)
1912
+ @elements = elements.freeze
1913
+ end
1914
+
1915
+ def accept(visitor, guard)
1916
+ super
1917
+ @elements.each { |elem| elem.accept(visitor, guard) }
1918
+ end
1919
+
1920
+ def each
1921
+ if block_given?
1922
+ elements.each { |elem| yield elem }
1923
+ else
1924
+ elements.to_enum
1925
+ end
1926
+ end
1927
+
1928
+ def generalize
1929
+ if @elements.empty?
1930
+ DEFAULT
1931
+ else
1932
+ alter_type_array(@elements, :generalize) { |altered| PStructType.new(altered) }
1933
+ end
1934
+ end
1935
+
1936
+ def normalize(guard = nil)
1937
+ if @elements.empty?
1938
+ DEFAULT
1939
+ else
1940
+ alter_type_array(@elements, :normalize, guard) { |altered| PStructType.new(altered) }
1941
+ end
1942
+ end
1943
+
1944
+ def hashed_elements
1945
+ @hashed ||= @elements.reduce({}) {|memo, e| memo[e.name] = e; memo }
1946
+ end
1947
+
1948
+ def hash
1949
+ @elements.hash
1950
+ end
1951
+
1952
+ def iterable?(guard = nil)
1953
+ true
1954
+ end
1955
+
1956
+ def iterable_type(guard = nil)
1957
+ if self == DEFAULT
1958
+ PIterableType.new(PHashType::DEFAULT_KEY_PAIR_TUPLE)
1959
+ else
1960
+ tc = TypeCalculator.singleton
1961
+ PIterableType.new(
1962
+ PTupleType.new([
1963
+ PVariantType.maybe_create(@elements.map {|se| se.key_type }),
1964
+ PVariantType.maybe_create(@elements.map {|se| se.value_type })],
1965
+ PHashType::KEY_PAIR_TUPLE_SIZE))
1966
+ end
1967
+ end
1968
+
1969
+ def resolve(loader)
1970
+ changed = false
1971
+ relements = @elements.map do |elem|
1972
+ relem = elem.resolve(loader)
1973
+ changed ||= !relem.equal?(elem)
1974
+ relem
1975
+ end
1976
+ changed ? self.class.new(relements) : self
1977
+ end
1978
+
1979
+ def eql?(o)
1980
+ self.class == o.class && @elements == o.elements
1981
+ end
1982
+
1983
+ def elements
1984
+ @elements
1985
+ end
1986
+
1987
+ def instance?(o, guard = nil)
1988
+ # The inferred type of a class derived from Hash is either Runtime or Object. It's not assignable to the Struct type.
1989
+ return false unless o.instance_of?(Hash)
1990
+ matched = 0
1991
+ @elements.all? do |e|
1992
+ key = e.name
1993
+ v = o[key]
1994
+ if v.nil? && !o.include?(key)
1995
+ # Entry is missing. Only OK when key is optional
1996
+ e.key_type.assignable?(PUndefType::DEFAULT, guard)
1997
+ else
1998
+ matched += 1
1999
+ e.value_type.instance?(v, guard)
2000
+ end
2001
+ end && matched == o.size
2002
+ end
2003
+
2004
+ def new_function
2005
+ # Simply delegate to Hash type and let the higher level assertion deal with
2006
+ # compliance with the Struct type regarding the produced result.
2007
+ PHashType.new_function(self)
2008
+ end
2009
+
2010
+ DEFAULT = PStructType.new(EMPTY_ARRAY)
2011
+
2012
+ protected
2013
+
2014
+ # @api private
2015
+ def _assignable?(o, guard)
2016
+ if o.is_a?(Types::PStructType)
2017
+ h2 = o.hashed_elements
2018
+ matched = 0
2019
+ elements.all? do |e1|
2020
+ e2 = h2[e1.name]
2021
+ if e2.nil?
2022
+ e1.key_type.assignable?(PUndefType::DEFAULT, guard)
2023
+ else
2024
+ matched += 1
2025
+ e1.key_type.assignable?(e2.key_type, guard) && e1.value_type.assignable?(e2.value_type, guard)
2026
+ end
2027
+ end && matched == h2.size
2028
+ elsif o.is_a?(Types::PHashType)
2029
+ required = 0
2030
+ required_elements_assignable = elements.all? do |e|
2031
+ key_type = e.key_type
2032
+ if key_type.assignable?(PUndefType::DEFAULT)
2033
+ # Element is optional so Hash does not need to provide it
2034
+ true
2035
+ else
2036
+ required += 1
2037
+ if e.value_type.assignable?(o.value_type, guard)
2038
+ # Hash must have something that is assignable. We don't care about the name or size of the key though
2039
+ # because we have no instance of a hash to compare against.
2040
+ key_type.generalize.assignable?(o.key_type)
2041
+ else
2042
+ false
2043
+ end
2044
+ end
2045
+ end
2046
+ if required_elements_assignable
2047
+ size_o = o.size_type || PCollectionType::DEFAULT_SIZE
2048
+ PIntegerType.new(required, elements.size).assignable?(size_o, guard)
2049
+ else
2050
+ false
2051
+ end
2052
+ else
2053
+ false
2054
+ end
2055
+ end
2056
+ end
2057
+
2058
+ # @api public
2059
+ #
2060
+ class PTupleType < PAnyType
2061
+ include Enumerable
2062
+
2063
+ def self.register_ptype(loader, ir)
2064
+ create_ptype(loader, ir, 'AnyType',
2065
+ 'types' => PArrayType.new(PTypeType::DEFAULT),
2066
+ 'size_type' => {
2067
+ KEY_TYPE => POptionalType.new(PTypeType.new(PIntegerType::DEFAULT)),
2068
+ KEY_VALUE => nil
2069
+ }
2070
+ )
2071
+ end
2072
+
2073
+ # If set, describes min and max required of the given types - if max > size of
2074
+ # types, the last type entry repeats
2075
+ #
2076
+ attr_reader :size_type
2077
+
2078
+ attr_reader :types
2079
+
2080
+ def accept(visitor, guard)
2081
+ super
2082
+ @size_type.accept(visitor, guard) unless @size_type.nil?
2083
+ @types.each { |elem| elem.accept(visitor, guard) }
2084
+ end
2085
+
2086
+ # @api private
2087
+ def callable_args?(callable_t, guard)
2088
+ unless size_type.nil?
2089
+ raise ArgumentError, 'Callable tuple may not have a size constraint when used as args'
2090
+ end
2091
+
2092
+ params_tuple = callable_t.param_types
2093
+ param_block_t = callable_t.block_type
2094
+ arg_types = @types
2095
+ arg_block_t = arg_types.last
2096
+ if arg_block_t.kind_of_callable?(true, guard)
2097
+ # Can't pass a block to a callable that doesn't accept one
2098
+ return false if param_block_t.nil?
2099
+
2100
+ # Check that the block is of the right tyṕe
2101
+ return false unless param_block_t.assignable?(arg_block_t, guard)
2102
+
2103
+ # Check other arguments
2104
+ arg_count = arg_types.size - 1
2105
+ params_size_t = params_tuple.size_type || PIntegerType.new(*params_tuple.size_range)
2106
+ return false unless params_size_t.assignable?(PIntegerType.new(arg_count, arg_count), guard)
2107
+
2108
+ ctypes = params_tuple.types
2109
+ arg_count.times do |index|
2110
+ return false unless (ctypes[index] || ctypes[-1]).assignable?(arg_types[index], guard)
2111
+ end
2112
+ return true
2113
+ end
2114
+
2115
+ # Check that tuple is assignable and that the block (if declared) is optional
2116
+ params_tuple.assignable?(self, guard) && (param_block_t.nil? || param_block_t.assignable?(PUndefType::DEFAULT, guard))
2117
+ end
2118
+
2119
+ def initialize(types, size_type = nil)
2120
+ @types = types
2121
+ @size_type = size_type.nil? ? nil : size_type.to_size
2122
+ end
2123
+
2124
+ # Returns Enumerator for the types if no block is given, otherwise, calls the given
2125
+ # block with each of the types in this tuple
2126
+ def each
2127
+ if block_given?
2128
+ types.each { |x| yield x }
2129
+ else
2130
+ types.to_enum
2131
+ end
2132
+ end
2133
+
2134
+ def generalize
2135
+ if self == DEFAULT
2136
+ DEFAULT
2137
+ else
2138
+ alter_type_array(@types, :generalize) { |altered_types| PTupleType.new(altered_types, @size_type) }
2139
+ end
2140
+ end
2141
+
2142
+ def normalize(guard = nil)
2143
+ if self == DEFAULT
2144
+ DEFAULT
2145
+ else
2146
+ alter_type_array(@types, :normalize, guard) { |altered_types| PTupleType.new(altered_types, @size_type) }
2147
+ end
2148
+ end
2149
+
2150
+ def resolve(loader)
2151
+ changed = false
2152
+ rtypes = @types.map do |type|
2153
+ rtype = type.resolve(loader)
2154
+ changed ||= !rtype.equal?(type)
2155
+ rtype
2156
+ end
2157
+ changed ? self.class.new(rtypes, @size_type) : self
2158
+ end
2159
+
2160
+ def instance?(o, guard = nil)
2161
+ # The inferred type of a class derived from Array is either Runtime or Object. It's not assignable to the Tuple type.
2162
+ return false unless o.instance_of?(Array)
2163
+ if @size_type
2164
+ return false unless @size_type.instance?(o.size, guard)
2165
+ else
2166
+ return false unless @types.empty? || @types.size == o.size
2167
+ end
2168
+ index = -1
2169
+ @types.empty? || o.all? do |element|
2170
+ @types.fetch(index += 1) { @types.last }.instance?(element, guard)
2171
+ end
2172
+ end
2173
+
2174
+ def iterable?(guard = nil)
2175
+ true
2176
+ end
2177
+
2178
+ def iterable_type(guard = nil)
2179
+ PIterableType.new(PVariantType.maybe_create(types))
2180
+ end
2181
+
2182
+ # Returns the number of elements accepted [min, max] in the tuple
2183
+ def size_range
2184
+ if @size_type.nil?
2185
+ types_size = @types.size
2186
+ types_size == 0 ? [0, Float::INFINITY] : [types_size, types_size]
2187
+ else
2188
+ @size_type.range
2189
+ end
2190
+ end
2191
+
2192
+ # Returns the number of accepted occurrences [min, max] of the last type in the tuple
2193
+ # The defaults is [1,1]
2194
+ #
2195
+ def repeat_last_range
2196
+ if @size_type.nil?
2197
+ return [1, 1]
2198
+ end
2199
+ types_size = @types.size
2200
+ from, to = @size_type.range
2201
+ min = from - (types_size-1)
2202
+ min = min <= 0 ? 0 : min
2203
+ max = to - (types_size-1)
2204
+ [min, max]
2205
+ end
2206
+
2207
+ def hash
2208
+ @size_type.hash ^ @types.hash
2209
+ end
2210
+
2211
+ def eql?(o)
2212
+ self.class == o.class && @types == o.types && @size_type == o.size_type
2213
+ end
2214
+
2215
+ def new_function
2216
+ # Simply delegate to Array type and let the higher level assertion deal with
2217
+ # compliance with the Tuple type regarding the produced result.
2218
+ PArrayType.new_function(self)
2219
+ end
2220
+
2221
+ DEFAULT = PTupleType.new(EMPTY_ARRAY)
2222
+
2223
+ protected
2224
+
2225
+ # @api private
2226
+ def _assignable?(o, guard)
2227
+ return true if self == o
2228
+ return false unless o.is_a?(PTupleType) || o.is_a?(PArrayType)
2229
+ s_types = types
2230
+ size_s = size_type || PIntegerType.new(*size_range)
2231
+
2232
+ if o.is_a?(PTupleType)
2233
+ size_o = o.size_type || PIntegerType.new(*o.size_range)
2234
+ return false unless size_s.assignable?(size_o, guard)
2235
+ unless s_types.empty?
2236
+ o_types = o.types
2237
+ return size_s.numeric_from == 0 if o_types.empty?
2238
+ o_types.size.times do |index|
2239
+ return false unless (s_types[index] || s_types[-1]).assignable?(o_types[index], guard)
2240
+ end
2241
+ end
2242
+ else
2243
+ size_o = o.size_type || PCollectionType::DEFAULT_SIZE
2244
+ return false unless size_s.assignable?(size_o, guard)
2245
+ unless s_types.empty?
2246
+ o_entry = o.element_type
2247
+ # Array of anything can not be assigned (unless tuple is tuple of anything) - this case
2248
+ # was handled at the top of this method.
2249
+ #
2250
+ return false if o_entry.nil?
2251
+ [s_types.size, size_o.range[1]].min.times { |index| return false unless (s_types[index] || s_types[-1]).assignable?(o_entry, guard) }
2252
+ end
2253
+ end
2254
+ true
2255
+ end
2256
+ end
2257
+
2258
+ # @api public
2259
+ #
2260
+ class PCallableType < PAnyType
2261
+ def self.register_ptype(loader, ir)
2262
+ create_ptype(loader, ir, 'AnyType',
2263
+ 'param_types' => {
2264
+ KEY_TYPE => POptionalType.new(PTupleType::DEFAULT),
2265
+ KEY_VALUE => nil
2266
+ },
2267
+ 'block_type' => {
2268
+ KEY_TYPE => POptionalType.new(PCallableType::DEFAULT),
2269
+ KEY_VALUE => nil
2270
+ },
2271
+ 'return_type' => {
2272
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
2273
+ KEY_VALUE => PAnyType::DEFAULT
2274
+ }
2275
+ )
2276
+ end
2277
+
2278
+ # @return [PAnyType] The type for the values returned by this callable. Returns `nil` if return value is unconstrained
2279
+ attr_reader :return_type
2280
+
2281
+ # Types of parameters as a Tuple with required/optional count, or an Integer with min (required), max count
2282
+ # @return [PTupleType] the tuple representing the parameter types
2283
+ attr_reader :param_types
2284
+
2285
+ # Although being an abstract type reference, only Callable, or all Callables wrapped in
2286
+ # Optional or Variant are supported
2287
+ # If not set, the meaning is that block is not supported.
2288
+ # @return [PAnyType|nil] the block type
2289
+ attr_reader :block_type
2290
+
2291
+ # @param param_types [PTupleType]
2292
+ # @param block_type [PAnyType]
2293
+ # @param return_type [PAnyType]
2294
+ def initialize(param_types, block_type = nil, return_type = nil)
2295
+ @param_types = param_types
2296
+ @block_type = block_type
2297
+ @return_type = return_type == PAnyType::DEFAULT ? nil : return_type
2298
+ end
2299
+
2300
+ def accept(visitor, guard)
2301
+ super
2302
+ @param_types.accept(visitor, guard) unless @param_types.nil?
2303
+ @block_type.accept(visitor, guard) unless @block_type.nil?
2304
+ @return_type.accept(visitor, guard) unless @return_type.nil?
2305
+ end
2306
+
2307
+ def generalize
2308
+ if self == DEFAULT
2309
+ DEFAULT
2310
+ else
2311
+ params_t = @param_types.nil? ? nil : @param_types.generalize
2312
+ block_t = @block_type.nil? ? nil : @block_type.generalize
2313
+ return_t = @return_type.nil? ? nil : @return_type.generalize
2314
+ @param_types.equal?(params_t) && @block_type.equal?(block_t) && @return_type.equal?(return_t) ? self : PCallableType.new(params_t, block_t, return_t)
2315
+ end
2316
+ end
2317
+
2318
+ def normalize(guard = nil)
2319
+ if self == DEFAULT
2320
+ DEFAULT
2321
+ else
2322
+ params_t = @param_types.nil? ? nil : @param_types.normalize(guard)
2323
+ block_t = @block_type.nil? ? nil : @block_type.normalize(guard)
2324
+ return_t = @return_type.nil? ? nil : @return_type.normalize(guard)
2325
+ @param_types.equal?(params_t) && @block_type.equal?(block_t) && @return_type.equal?(return_t) ? self : PCallableType.new(params_t, block_t, return_t)
2326
+ end
2327
+ end
2328
+
2329
+ def instance?(o, guard = nil)
2330
+ (o.is_a?(Proc) || o.is_a?(Evaluator::Closure) || o.is_a?(Functions::Function)) && assignable?(TypeCalculator.infer(o), guard)
2331
+ end
2332
+
2333
+ # Returns `true` if this instance is a callable that accepts the given _args_
2334
+ #
2335
+ # @param args [Array] the arguments to test
2336
+ # @return [Boolean] `true` if this instance is a callable that accepts the given _args_
2337
+ def callable_with?(args, block = nil)
2338
+ # nil param_types and compatible return type means other Callable is assignable
2339
+ return true if @param_types.nil?
2340
+ return false unless @param_types.instance?(args)
2341
+ if @block_type.nil?
2342
+ block == nil
2343
+ else
2344
+ @block_type.instance?(block)
2345
+ end
2346
+ end
2347
+
2348
+ # @api private
2349
+ def callable_args?(required_callable_t, guard)
2350
+ # If the required callable is euqal or more specific than self, self is acceptable arguments
2351
+ required_callable_t.assignable?(self, guard)
2352
+ end
2353
+
2354
+ def kind_of_callable?(optional=true, guard = nil)
2355
+ true
2356
+ end
2357
+
2358
+ # Returns the number of accepted arguments [min, max]
2359
+ def size_range
2360
+ @param_types.nil? ? nil : @param_types.size_range
2361
+ end
2362
+
2363
+ # Returns the number of accepted arguments for the last parameter type [min, max]
2364
+ #
2365
+ def last_range
2366
+ @param_types.nil? ? nil : @param_types.repeat_last_range
2367
+ end
2368
+
2369
+ # Range [0,0], [0,1], or [1,1] for the block
2370
+ #
2371
+ def block_range
2372
+ case block_type
2373
+ when POptionalType
2374
+ [0,1]
2375
+ when PVariantType, PCallableType
2376
+ [1,1]
2377
+ else
2378
+ [0,0]
2379
+ end
2380
+ end
2381
+
2382
+ def hash
2383
+ [@param_types, @block_type, @return_type].hash
2384
+ end
2385
+
2386
+ def eql?(o)
2387
+ self.class == o.class && @param_types == o.param_types && @block_type == o.block_type && @return_type == o.return_type
2388
+ end
2389
+
2390
+ def resolve(loader)
2391
+ params_t = @param_types.nil? ? nil : @param_types.resolve(loader)
2392
+ block_t = @block_type.nil? ? nil : @block_type.resolve(loader)
2393
+ return_t = @return_type.nil? ? nil : @return_type.resolve(loader)
2394
+ @param_types.equal?(params_t) && @block_type.equal?(block_t) && @return_type.equal?(return_t) ? self : self.class.new(params_t, block_t, return_t)
2395
+ end
2396
+
2397
+ DEFAULT = PCallableType.new(nil, nil, nil)
2398
+
2399
+ protected
2400
+
2401
+ # @api private
2402
+ def _assignable?(o, guard)
2403
+ return false unless o.is_a?(PCallableType)
2404
+ return false unless @return_type.nil? || @return_type.assignable?(o.return_type || PAnyType::DEFAULT, guard)
2405
+
2406
+ # nil param_types and compatible return type means other Callable is assignable
2407
+ return true if @param_types.nil?
2408
+
2409
+ # NOTE: these tests are made in reverse as it is calling the callable that is constrained
2410
+ # (it's lower bound), not its upper bound
2411
+ other_param_types = o.param_types
2412
+
2413
+ return false if other_param_types.nil? || !other_param_types.assignable?(@param_types, guard)
2414
+ # names are ignored, they are just information
2415
+ # Blocks must be compatible
2416
+ this_block_t = @block_type || PUndefType::DEFAULT
2417
+ that_block_t = o.block_type || PUndefType::DEFAULT
2418
+ that_block_t.assignable?(this_block_t, guard)
2419
+ end
2420
+ end
2421
+
2422
+ # @api public
2423
+ #
2424
+ class PArrayType < PCollectionType
2425
+
2426
+ def self.register_ptype(loader, ir)
2427
+ create_ptype(loader, ir, 'CollectionType',
2428
+ 'element_type' => {
2429
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
2430
+ KEY_VALUE => PAnyType::DEFAULT
2431
+ }
2432
+ )
2433
+ end
2434
+
2435
+ attr_reader :element_type
2436
+
2437
+ def initialize(element_type, size_type = nil)
2438
+ super(size_type)
2439
+ if !size_type.nil? && size_type.from == 0 && size_type.to == 0
2440
+ @element_type = PUnitType::DEFAULT
2441
+ else
2442
+ @element_type = element_type.nil? ? PAnyType::DEFAULT : element_type
2443
+ end
2444
+ end
2445
+
2446
+ def accept(visitor, guard)
2447
+ super
2448
+ @element_type.accept(visitor, guard)
2449
+ end
2450
+
2451
+ # @api private
2452
+ def callable_args?(callable, guard = nil)
2453
+ param_t = callable.param_types
2454
+ block_t = callable.block_type
2455
+ # does not support calling with a block, but have to check that callable is ok with missing block
2456
+ (param_t.nil? || param_t.assignable?(self, guard)) && (block_t.nil? || block_t.assignable?(PUndefType::DEFAULT, guard))
2457
+ end
2458
+
2459
+ def generalize
2460
+ if PAnyType::DEFAULT.eql?(@element_type)
2461
+ DEFAULT
2462
+ else
2463
+ ge_type = @element_type.generalize
2464
+ @size_type.nil? && @element_type.equal?(ge_type) ? self : self.class.new(ge_type, nil)
2465
+ end
2466
+ end
2467
+
2468
+ def eql?(o)
2469
+ super && @element_type == o.element_type
2470
+ end
2471
+
2472
+ def hash
2473
+ super ^ @element_type.hash
2474
+ end
2475
+
2476
+ def normalize(guard = nil)
2477
+ if PAnyType::DEFAULT.eql?(@element_type)
2478
+ DEFAULT
2479
+ else
2480
+ ne_type = @element_type.normalize(guard)
2481
+ @element_type.equal?(ne_type) ? self : self.class.new(ne_type, @size_type)
2482
+ end
2483
+ end
2484
+
2485
+ def resolve(loader)
2486
+ relement_type = @element_type.resolve(loader)
2487
+ relement_type.equal?(@element_type) ? self : self.class.new(relement_type, @size_type)
2488
+ end
2489
+
2490
+ def instance?(o, guard = nil)
2491
+ # The inferred type of a class derived from Array is either Runtime or Object. It's not assignable to the Array type.
2492
+ return false unless o.instance_of?(Array)
2493
+ return false unless o.all? {|element| @element_type.instance?(element, guard) }
2494
+ size_t = size_type
2495
+ size_t.nil? || size_t.instance?(o.size, guard)
2496
+ end
2497
+
2498
+ def iterable_type(guard = nil)
2499
+ PAnyType::DEFAULT.eql?(@element_type) ? PIterableType::DEFAULT : PIterableType.new(@element_type)
2500
+ end
2501
+
2502
+ # Returns a new function that produces an Array
2503
+ #
2504
+ def self.new_function(type)
2505
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_array, type.loader) do
2506
+
2507
+ dispatch :from_args do
2508
+ param 'Any', :from
2509
+ optional_param 'Boolean', :wrap
2510
+ end
2511
+
2512
+ def from_args(from, wrap = false)
2513
+ case from
2514
+ when NilClass
2515
+ if wrap
2516
+ [nil]
2517
+ else
2518
+ throw :undefined_value
2519
+ end
2520
+ when Array
2521
+ from
2522
+ when Hash
2523
+ wrap ? [from] : from.to_a
2524
+
2525
+ when PBinaryType::Binary
2526
+ # For older rubies, the #bytes method returns an Enumerator that must be rolled out
2527
+ wrap ? [from] : from.binary_buffer.bytes.to_a
2528
+
2529
+ else
2530
+ if wrap
2531
+ [from]
2532
+ else
2533
+ if PIterableType::DEFAULT.instance?(from)
2534
+ Iterable.on(from).to_a
2535
+ else
2536
+ t = Puppet::Pops::Types::TypeCalculator.singleton.infer(from).generalize
2537
+ raise TypeConversionError.new("Value of type '#{t}' cannot be converted to Array")
2538
+ end
2539
+ end
2540
+ end
2541
+ end
2542
+ end
2543
+ end
2544
+
2545
+ DEFAULT = PArrayType.new(nil)
2546
+ EMPTY = PArrayType.new(PUnitType::DEFAULT, ZERO_SIZE)
2547
+
2548
+ protected
2549
+
2550
+ # Array is assignable if o is an Array and o's element type is assignable, or if o is a Tuple
2551
+ # @api private
2552
+ def _assignable?(o, guard)
2553
+ if o.is_a?(PTupleType)
2554
+ o_types = o.types
2555
+ size_s = size_type || DEFAULT_SIZE
2556
+ size_o = o.size_type
2557
+ if size_o.nil?
2558
+ type_count = o_types.size
2559
+ size_o = PIntegerType.new(type_count, type_count)
2560
+ end
2561
+ size_s.assignable?(size_o) && o_types.all? { |ot| @element_type.assignable?(ot, guard) }
2562
+ elsif o.is_a?(PArrayType)
2563
+ super && @element_type.assignable?(o.element_type, guard)
2564
+ else
2565
+ false
2566
+ end
2567
+ end
2568
+ end
2569
+
2570
+ # @api public
2571
+ #
2572
+ class PHashType < PCollectionType
2573
+
2574
+ def self.register_ptype(loader, ir)
2575
+ create_ptype(loader, ir, 'CollectionType',
2576
+ 'key_type' => {
2577
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
2578
+ KEY_VALUE => PAnyType::DEFAULT
2579
+ },
2580
+ 'value_type' => {
2581
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
2582
+ KEY_VALUE => PAnyType::DEFAULT
2583
+ }
2584
+ )
2585
+ end
2586
+
2587
+ attr_accessor :key_type, :value_type
2588
+
2589
+ def initialize(key_type, value_type, size_type = nil)
2590
+ super(size_type)
2591
+ if !size_type.nil? && size_type.from == 0 && size_type.to == 0
2592
+ @key_type = PUnitType::DEFAULT
2593
+ @value_type = PUnitType::DEFAULT
2594
+ else
2595
+ @key_type = key_type.nil? ? PAnyType::DEFAULT : key_type
2596
+ @value_type = value_type.nil? ? PAnyType::DEFAULT : value_type
2597
+ end
2598
+ end
2599
+
2600
+ def accept(visitor, guard)
2601
+ super
2602
+ @key_type.accept(visitor, guard)
2603
+ @value_type.accept(visitor, guard)
2604
+ end
2605
+
2606
+ def element_type
2607
+ if Puppet[:strict] != :off
2608
+ Puppet.warn_once('deprecations', 'Puppet::Pops::Types::PHashType#element_type',
2609
+ 'Puppet::Pops::Types::PHashType#element_type is deprecated, use #value_type instead')
2610
+ end
2611
+ @value_type
2612
+ end
2613
+
2614
+ def generalize
2615
+ if self == DEFAULT || self == EMPTY
2616
+ self
2617
+ else
2618
+ key_t = @key_type
2619
+ key_t = key_t.generalize
2620
+ value_t = @value_type
2621
+ value_t = value_t.generalize
2622
+ @size_type.nil? && @key_type.equal?(key_t) && @value_type.equal?(value_t) ? self : PHashType.new(key_t, value_t, nil)
2623
+ end
2624
+ end
2625
+
2626
+ def normalize(guard = nil)
2627
+ if self == DEFAULT || self == EMPTY
2628
+ self
2629
+ else
2630
+ key_t = @key_type.normalize(guard)
2631
+ value_t = @value_type.normalize(guard)
2632
+ @size_type.nil? && @key_type.equal?(key_t) && @value_type.equal?(value_t) ? self : PHashType.new(key_t, value_t, @size_type)
2633
+ end
2634
+ end
2635
+
2636
+ def hash
2637
+ super ^ @key_type.hash ^ @value_type.hash
2638
+ end
2639
+
2640
+ def instance?(o, guard = nil)
2641
+ # The inferred type of a class derived from Hash is either Runtime or Object. It's not assignable to the Hash type.
2642
+ return false unless o.instance_of?(Hash)
2643
+ if o.keys.all? {|key| @key_type.instance?(key, guard) } && o.values.all? {|value| @value_type.instance?(value, guard) }
2644
+ size_t = size_type
2645
+ size_t.nil? || size_t.instance?(o.size, guard)
2646
+ else
2647
+ false
2648
+ end
2649
+ end
2650
+
2651
+ def iterable?(guard = nil)
2652
+ true
2653
+ end
2654
+
2655
+ def iterable_type(guard = nil)
2656
+ if self == DEFAULT || self == EMPTY
2657
+ PIterableType.new(DEFAULT_KEY_PAIR_TUPLE)
2658
+ else
2659
+ PIterableType.new(PTupleType.new([@key_type, @value_type], KEY_PAIR_TUPLE_SIZE))
2660
+ end
2661
+ end
2662
+
2663
+ def eql?(o)
2664
+ super && @key_type == o.key_type && @value_type == o.value_type
2665
+ end
2666
+
2667
+ def is_the_empty_hash?
2668
+ self == EMPTY
2669
+ end
2670
+
2671
+ def resolve(loader)
2672
+ rkey_type = @key_type.resolve(loader)
2673
+ rvalue_type = @value_type.resolve(loader)
2674
+ rkey_type.equal?(@key_type) && rvalue_type.equal?(@value_type) ? self : self.class.new(rkey_type, rvalue_type, @size_type)
2675
+ end
2676
+
2677
+ def self.array_as_hash(value)
2678
+ return value unless value.is_a?(Array)
2679
+ result = {}
2680
+ value.each_with_index {|v, idx| result[idx] = array_as_hash(v) }
2681
+ result
2682
+ end
2683
+
2684
+ # Returns a new function that produces a Hash
2685
+ #
2686
+ def self.new_function(type)
2687
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_hash, type.loader) do
2688
+ local_types do
2689
+ type 'KeyValueArray = Array[Tuple[Any,Any],1]'
2690
+ type 'TreeArray = Array[Tuple[Array,Any],1]'
2691
+ type 'NewHashOption = Enum[tree, hash_tree]'
2692
+ end
2693
+
2694
+ dispatch :from_tree do
2695
+ param 'TreeArray', :from
2696
+ optional_param 'NewHashOption', :build_option
2697
+ end
2698
+
2699
+ dispatch :from_tuples do
2700
+ param 'KeyValueArray', :from
2701
+ end
2702
+
2703
+ dispatch :from_array do
2704
+ param 'Any', :from
2705
+ end
2706
+
2707
+ def from_tuples(tuple_array)
2708
+ Hash[tuple_array]
2709
+ end
2710
+
2711
+ def from_tree(tuple_array, build_option = nil)
2712
+ if build_option.nil?
2713
+ return from_tuples(tuple_array)
2714
+ end
2715
+ # only remaining possible options is 'tree' or 'hash_tree'
2716
+
2717
+ all_hashes = build_option == 'hash_tree'
2718
+ result = {}
2719
+ tuple_array.each do |entry|
2720
+ path = entry[0]
2721
+ value = entry[1]
2722
+ if path.empty?
2723
+ # root node (index [] was included - values merge into the result)
2724
+ # An array must be changed to a hash first as this is the root
2725
+ # (Cannot return an array from a Hash.new)
2726
+ if value.is_a?(Array)
2727
+ value.each_with_index {|v, idx| result[idx] = v }
2728
+ else
2729
+ result.merge!(value)
2730
+ end
2731
+ else
2732
+ r = path[0..-2].reduce(result) {|memo, idx| (memo.is_a?(Array) || memo.has_key?(idx)) ? memo[idx] : memo[idx] = {}}
2733
+ r[path[-1]]= (all_hashes ? PHashType.array_as_hash(value) : value)
2734
+ end
2735
+ end
2736
+ result
2737
+ end
2738
+
2739
+ def from_array(from)
2740
+ case from
2741
+ when NilClass
2742
+ throw :undefined_value
2743
+ when Array
2744
+ if from.size == 0
2745
+ {}
2746
+ else
2747
+ unless from.size % 2 == 0
2748
+ raise TypeConversionError.new("odd number of arguments for Hash")
2749
+ end
2750
+ Hash[*from]
2751
+ end
2752
+ when Hash
2753
+ from
2754
+ else
2755
+ if PIterableType::DEFAULT.instance?(from)
2756
+ Hash[*Iterable.on(from).to_a]
2757
+ else
2758
+ t = Puppet::Pops::Types::TypeCalculator.singleton.infer(from).generalize
2759
+ raise TypeConversionError.new("Value of type '#{t}' cannot be converted to Hash")
2760
+ end
2761
+ end
2762
+ end
2763
+ end
2764
+ end
2765
+
2766
+ DEFAULT = PHashType.new(nil, nil)
2767
+ KEY_PAIR_TUPLE_SIZE = PIntegerType.new(2,2)
2768
+ DEFAULT_KEY_PAIR_TUPLE = PTupleType.new([PUnitType::DEFAULT, PUnitType::DEFAULT], KEY_PAIR_TUPLE_SIZE)
2769
+ EMPTY = PHashType.new(PUnitType::DEFAULT, PUnitType::DEFAULT, PIntegerType.new(0, 0))
2770
+
2771
+ protected
2772
+
2773
+ # Hash is assignable if o is a Hash and o's key and element types are assignable
2774
+ # @api private
2775
+ def _assignable?(o, guard)
2776
+ case o
2777
+ when PHashType
2778
+ size_s = size_type
2779
+ return true if (size_s.nil? || size_s.from == 0) && o.is_the_empty_hash?
2780
+ return false unless @key_type.assignable?(o.key_type, guard) && @value_type.assignable?(o.value_type, guard)
2781
+ super
2782
+ when PStructType
2783
+ # hash must accept String as key type
2784
+ # hash must accept all value types
2785
+ # hash must accept the size of the struct
2786
+ o_elements = o.elements
2787
+ (size_type || DEFAULT_SIZE).instance?(o_elements.size, guard) &&
2788
+ o_elements.all? {|e| @key_type.instance?(e.name, guard) && @value_type.assignable?(e.value_type, guard) }
2789
+ else
2790
+ false
2791
+ end
2792
+ end
2793
+ end
2794
+
2795
+ # A flexible type describing an any? of other types
2796
+ # @api public
2797
+ #
2798
+ class PVariantType < PAnyType
2799
+ include Enumerable
2800
+
2801
+ def self.register_ptype(loader, ir)
2802
+ create_ptype(loader, ir, 'AnyType', 'types' => PArrayType.new(PTypeType::DEFAULT))
2803
+ end
2804
+
2805
+ attr_reader :types
2806
+
2807
+ # Checks if the number of unique types in the given array is greater than one, and if so
2808
+ # creates a Variant with those types and returns it. If only one unique type is found,
2809
+ # that type is instead returned.
2810
+ #
2811
+ # @param types [Array<PAnyType>] the variants
2812
+ # @return [PAnyType] the resulting type
2813
+ # @api public
2814
+ def self.maybe_create(types)
2815
+ types = flatten_variants(types).uniq
2816
+ types.size == 1 ? types[0] : new(types)
2817
+ end
2818
+
2819
+ # @param types [Array[PAnyType]] the variants
2820
+ def initialize(types)
2821
+ @types = types.freeze
2822
+ end
2823
+
2824
+ def accept(visitor, guard)
2825
+ super
2826
+ @types.each { |t| t.accept(visitor, guard) }
2827
+ end
2828
+
2829
+ def each
2830
+ if block_given?
2831
+ types.each { |t| yield t }
2832
+ else
2833
+ types.to_enum
2834
+ end
2835
+ end
2836
+
2837
+ def generalize
2838
+ if self == DEFAULT
2839
+ self
2840
+ else
2841
+ alter_type_array(@types, :generalize) { |altered| PVariantType.maybe_create(altered) }
2842
+ end
2843
+ end
2844
+
2845
+ def normalize(guard = nil)
2846
+ if self == DEFAULT || @types.empty?
2847
+ self
2848
+ else
2849
+ # Normalize all contained types
2850
+ modified = false
2851
+ types = alter_type_array(@types, :normalize, guard)
2852
+ if types == self
2853
+ types = @types
2854
+ else
2855
+ modified = true
2856
+ end
2857
+
2858
+ if types.size == 1
2859
+ types[0]
2860
+ elsif types.any? { |t| t.is_a?(PUndefType) || t.is_a?(POptionalType) }
2861
+ # Undef entry present. Use an OptionalType with a normalized Variant without Undefs and Optional wrappers
2862
+ POptionalType.new(PVariantType.maybe_create(types.reject { |t| t.is_a?(PUndefType) }.map { |t| t.is_a?(POptionalType) ? t.type : t })).normalize
2863
+ else
2864
+ # Merge all variants into this one
2865
+ types = PVariantType.flatten_variants(types)
2866
+ size_before_merge = types.size
2867
+
2868
+ types = swap_not_undefs(types)
2869
+ types = merge_enums(types)
2870
+ types = merge_patterns(types)
2871
+ types = merge_version_ranges(types)
2872
+ types = merge_numbers(PIntegerType, types)
2873
+ types = merge_numbers(PFloatType, types)
2874
+ types = merge_numbers(PTimespanType, types)
2875
+ types = merge_numbers(PTimestampType, types)
2876
+
2877
+ if types.size == 1
2878
+ types[0]
2879
+ else
2880
+ modified || types.size != size_before_merge ? PVariantType.maybe_create(types) : self
2881
+ end
2882
+ end
2883
+ end
2884
+ end
2885
+
2886
+ def self.flatten_variants(types)
2887
+ modified = false
2888
+ types = types.map do |t|
2889
+ if t.is_a?(PVariantType)
2890
+ modified = true
2891
+ t.types
2892
+ else
2893
+ t
2894
+ end
2895
+ end
2896
+ types.flatten! if modified
2897
+ types
2898
+ end
2899
+
2900
+ def hash
2901
+ @types.hash
2902
+ end
2903
+
2904
+ def instance?(o, guard = nil)
2905
+ # instance of variant if o is instance? of any of variant's types
2906
+ @types.any? { |type| type.instance?(o, guard) }
2907
+ end
2908
+
2909
+ def really_instance?(o, guard = nil)
2910
+ @types.reduce(-1) do |memo, type|
2911
+ ri = type.really_instance?(o, guard)
2912
+ break ri if ri > 0
2913
+ ri > memo ? ri : memo
2914
+ end
2915
+ end
2916
+
2917
+ def kind_of_callable?(optional = true, guard = nil)
2918
+ @types.all? { |type| type.kind_of_callable?(optional, guard) }
2919
+ end
2920
+
2921
+ def eql?(o)
2922
+ self.class == o.class && @types.size == o.types.size && (@types - o.types).empty?
2923
+ end
2924
+
2925
+ DEFAULT = PVariantType.new(EMPTY_ARRAY)
2926
+
2927
+ protected
2928
+
2929
+ # @api private
2930
+ def _assignable?(o, guard)
2931
+ # A variant is assignable if o is assignable to any of its types
2932
+ types.any? { |option_t| option_t.assignable?(o, guard) }
2933
+ end
2934
+
2935
+ # @api private
2936
+ def swap_not_undefs(array)
2937
+ if array.size > 1
2938
+ parts = array.partition {|t| t.is_a?(PNotUndefType) }
2939
+ not_undefs = parts[0]
2940
+ if not_undefs.size > 1
2941
+ others = parts[1]
2942
+ others << PNotUndefType.new(PVariantType.maybe_create(not_undefs.map { |not_undef| not_undef.type }).normalize)
2943
+ array = others
2944
+ end
2945
+ end
2946
+ array
2947
+ end
2948
+
2949
+ # @api private
2950
+ def merge_enums(array)
2951
+ if array.size > 1
2952
+ parts = array.partition {|t| t.is_a?(PEnumType) && !t.values.empty? || t.is_a?(PStringType) && !t.value.nil? }
2953
+ enums = parts[0]
2954
+ if enums.size > 1
2955
+ others = parts[1]
2956
+ others << PEnumType.new(enums.map { |enum| enum.is_a?(PStringType) ? enum.value : enum.values }.flatten.uniq)
2957
+ array = others
2958
+ end
2959
+ end
2960
+ array
2961
+ end
2962
+
2963
+ # @api private
2964
+ def merge_patterns(array)
2965
+ if array.size > 1
2966
+ parts = array.partition {|t| t.is_a?(PPatternType) }
2967
+ patterns = parts[0]
2968
+ if patterns.size > 1
2969
+ others = parts[1]
2970
+ others << PPatternType.new(patterns.map { |pattern| pattern.patterns }.flatten.uniq)
2971
+ array = others
2972
+ end
2973
+ end
2974
+ array
2975
+ end
2976
+
2977
+ # @api private
2978
+ def merge_numbers(clazz, array)
2979
+ if array.size > 1
2980
+ parts = array.partition {|t| t.is_a?(clazz) }
2981
+ ranges = parts[0]
2982
+ array = merge_ranges(ranges) + parts[1] if ranges.size > 1
2983
+ end
2984
+ array
2985
+ end
2986
+
2987
+ def merge_version_ranges(array)
2988
+ if array.size > 1
2989
+ parts = array.partition {|t| t.is_a?(PSemVerType) }
2990
+ ranges = parts[0]
2991
+ array = [PSemVerType.new(ranges.map(&:ranges).flatten)] + parts[1] if ranges.size > 1
2992
+ end
2993
+ array
2994
+ end
2995
+
2996
+ # @api private
2997
+ def merge_ranges(ranges)
2998
+ result = []
2999
+ until ranges.empty?
3000
+ unmerged = []
3001
+ x = ranges.pop
3002
+ result << ranges.inject(x) do |memo, y|
3003
+ merged = memo.merge(y)
3004
+ if merged.nil?
3005
+ unmerged << y
3006
+ else
3007
+ memo = merged
3008
+ end
3009
+ memo
3010
+ end
3011
+ ranges = unmerged
3012
+ end
3013
+ result
3014
+ end
3015
+ end
3016
+
3017
+ # Abstract representation of a type that can be placed in a Catalog.
3018
+ # @api public
3019
+ #
3020
+ class PCatalogEntryType < PAnyType
3021
+ def self.register_ptype(loader, ir)
3022
+ create_ptype(loader, ir, 'AnyType')
3023
+ end
3024
+
3025
+ DEFAULT = PCatalogEntryType.new
3026
+
3027
+ def instance?(o, guard = nil)
3028
+ assignable?(TypeCalculator.infer(o), guard)
3029
+ end
3030
+
3031
+ protected
3032
+ # @api private
3033
+ def _assignable?(o, guard)
3034
+ o.is_a?(PCatalogEntryType)
3035
+ end
3036
+ end
3037
+
3038
+ # Represents a (host-) class in the Puppet Language.
3039
+ # @api public
3040
+ #
3041
+ class PClassType < PCatalogEntryType
3042
+ attr_reader :class_name
3043
+
3044
+ def self.register_ptype(loader, ir)
3045
+ create_ptype(loader, ir, 'CatalogEntryType',
3046
+ 'class_name' => {
3047
+ KEY_TYPE => POptionalType.new(PStringType::NON_EMPTY),
3048
+ KEY_VALUE => nil
3049
+ }
3050
+ )
3051
+ end
3052
+
3053
+ def initialize(class_name)
3054
+ @class_name = class_name
3055
+ end
3056
+
3057
+ def hash
3058
+ 11 ^ @class_name.hash
3059
+ end
3060
+ def eql?(o)
3061
+ self.class == o.class && @class_name == o.class_name
3062
+ end
3063
+
3064
+ DEFAULT = PClassType.new(nil)
3065
+
3066
+ protected
3067
+
3068
+ # @api private
3069
+ def _assignable?(o, guard)
3070
+ return false unless o.is_a?(PClassType)
3071
+ # Class = Class[name}, Class[name] != Class
3072
+ return true if @class_name.nil?
3073
+ # Class[name] = Class[name]
3074
+ @class_name == o.class_name
3075
+ end
3076
+ end
3077
+
3078
+ # For backward compatibility
3079
+ PHostClassType = PClassType
3080
+
3081
+
3082
+ # Represents a Resource Type in the Puppet Language
3083
+ # @api public
3084
+ #
3085
+ class PResourceType < PCatalogEntryType
3086
+
3087
+ def self.register_ptype(loader, ir)
3088
+ create_ptype(loader, ir, 'CatalogEntryType',
3089
+ 'type_name' => {
3090
+ KEY_TYPE => POptionalType.new(PStringType::NON_EMPTY),
3091
+ KEY_VALUE => nil
3092
+ },
3093
+ 'title' => {
3094
+ KEY_TYPE => POptionalType.new(PStringType::NON_EMPTY),
3095
+ KEY_VALUE => nil
3096
+ }
3097
+ )
3098
+ end
3099
+
3100
+ attr_reader :type_name, :title, :downcased_name
3101
+
3102
+ def initialize(type_name, title = nil)
3103
+ @type_name = type_name.freeze
3104
+ @title = title.freeze
3105
+ @downcased_name = type_name.nil? ? nil : @type_name.downcase.freeze
3106
+ end
3107
+
3108
+ def eql?(o)
3109
+ self.class == o.class && @downcased_name == o.downcased_name && @title == o.title
3110
+ end
3111
+
3112
+ def hash
3113
+ @downcased_name.hash ^ @title.hash
3114
+ end
3115
+
3116
+ DEFAULT = PResourceType.new(nil)
3117
+
3118
+ protected
3119
+
3120
+ # @api private
3121
+ def _assignable?(o, guard)
3122
+ o.is_a?(PResourceType) && (@downcased_name.nil? || @downcased_name == o.downcased_name && (@title.nil? || @title == o.title))
3123
+ end
3124
+ end
3125
+
3126
+ # Represents a type that accept PUndefType instead of the type parameter
3127
+ # required_type - is a short hand for Variant[T, Undef]
3128
+ # @api public
3129
+ #
3130
+ class POptionalType < PTypeWithContainedType
3131
+
3132
+ def self.register_ptype(loader, ir)
3133
+ create_ptype(loader, ir, 'AnyType',
3134
+ 'type' => {
3135
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
3136
+ KEY_VALUE => nil
3137
+ }
3138
+ )
3139
+ end
3140
+
3141
+ def optional_type
3142
+ @type
3143
+ end
3144
+
3145
+ def kind_of_callable?(optional=true, guard = nil)
3146
+ optional && !@type.nil? && @type.kind_of_callable?(optional, guard)
3147
+ end
3148
+
3149
+ def instance?(o, guard = nil)
3150
+ PUndefType::DEFAULT.instance?(o, guard) || (!@type.nil? && @type.instance?(o, guard))
3151
+ end
3152
+
3153
+ def normalize(guard = nil)
3154
+ n = super
3155
+ if n.type.nil?
3156
+ n
3157
+ else
3158
+ if n.type.is_a?(PNotUndefType)
3159
+ # No point in having an NotUndef in an Optional
3160
+ POptionalType.new(n.type.type).normalize
3161
+ elsif n.type.assignable?(PUndefType::DEFAULT)
3162
+ # THe type is Optional anyway, so it can be stripped of
3163
+ n.type
3164
+ else
3165
+ n
3166
+ end
3167
+ end
3168
+ end
3169
+
3170
+ def new_function
3171
+ optional_type.new_function
3172
+ end
3173
+
3174
+ DEFAULT = POptionalType.new(nil)
3175
+
3176
+ protected
3177
+
3178
+ # @api private
3179
+ def _assignable?(o, guard)
3180
+ return true if o.is_a?(PUndefType)
3181
+ return true if @type.nil?
3182
+ if o.is_a?(POptionalType)
3183
+ @type.assignable?(o.optional_type, guard)
3184
+ else
3185
+ @type.assignable?(o, guard)
3186
+ end
3187
+ end
3188
+ end
3189
+
3190
+ class PTypeReferenceType < PAnyType
3191
+
3192
+ def self.register_ptype(loader, ir)
3193
+ create_ptype(loader, ir, 'AnyType', 'type_string' => PStringType::NON_EMPTY)
3194
+ end
3195
+
3196
+ attr_reader :type_string
3197
+
3198
+ def initialize(type_string)
3199
+ @type_string = type_string
3200
+ end
3201
+
3202
+ def callable?(args)
3203
+ false
3204
+ end
3205
+
3206
+ def instance?(o, guard = nil)
3207
+ false
3208
+ end
3209
+
3210
+ def hash
3211
+ @type_string.hash
3212
+ end
3213
+
3214
+ def eql?(o)
3215
+ super && o.type_string == @type_string
3216
+ end
3217
+
3218
+ def resolve(loader)
3219
+ TypeParser.singleton.parse(@type_string, loader)
3220
+ end
3221
+
3222
+ protected
3223
+
3224
+ def _assignable?(o, guard)
3225
+ # A type must be assignable to itself or a lot of unit tests will break
3226
+ o == self
3227
+ end
3228
+
3229
+ DEFAULT = PTypeReferenceType.new('UnresolvedReference')
3230
+ end
3231
+
3232
+ # Describes a named alias for another Type.
3233
+ # The alias is created with a name and an unresolved type expression. The type expression may
3234
+ # in turn contain other aliases (including the alias that contains it) which means that an alias
3235
+ # might contain self recursion. Whether or not that is the case is computed and remembered when the alias
3236
+ # is resolved since guarding against self recursive constructs is relatively expensive.
3237
+ #
3238
+ # @api public
3239
+ class PTypeAliasType < PAnyType
3240
+
3241
+ def self.register_ptype(loader, ir)
3242
+ create_ptype(loader, ir, 'AnyType',
3243
+ 'name' => PStringType::NON_EMPTY,
3244
+ 'type_expr' => PAnyType::DEFAULT,
3245
+ 'resolved_type' => {
3246
+ KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
3247
+ KEY_VALUE => nil
3248
+ }
3249
+ )
3250
+ end
3251
+
3252
+ attr_reader :loader, :name
3253
+
3254
+ # @param name [String] The name of the type
3255
+ # @param type_expr [Model::PopsObject] The expression that describes the aliased type
3256
+ # @param resolved_type [PAnyType] the resolve type (only used for the DEFAULT initialization)
3257
+ def initialize(name, type_expr, resolved_type = nil)
3258
+ @name = name
3259
+ @type_expr = type_expr
3260
+ @resolved_type = resolved_type
3261
+ @self_recursion = false
3262
+ end
3263
+
3264
+ def assignable?(o, guard = nil)
3265
+ if @self_recursion
3266
+ guard ||= RecursionGuard.new
3267
+ guard.with_this(self) { |state| state == RecursionGuard::SELF_RECURSION_IN_BOTH ? true : super(o, guard) }
3268
+ else
3269
+ super(o, guard)
3270
+ end
3271
+ end
3272
+
3273
+ # Returns the resolved type. The type must have been resolved by a call prior to calls to this
3274
+ # method or an error will be raised.
3275
+ #
3276
+ # @return [PAnyType] The resolved type of this alias.
3277
+ # @raise [Puppet::Error] unless the type has been resolved prior to calling this method
3278
+ def resolved_type
3279
+ raise Puppet::Error, "Reference to unresolved type #{@name}" unless @resolved_type
3280
+ @resolved_type
3281
+ end
3282
+
3283
+ def callable_args?(callable, guard)
3284
+ guarded_recursion(guard, false) { |g| resolved_type.callable_args?(callable, g) }
3285
+ end
3286
+
3287
+ def check_self_recursion(originator)
3288
+ resolved_type.check_self_recursion(originator) unless originator.equal?(self)
3289
+ end
3290
+
3291
+ def kind_of_callable?(optional=true, guard = nil)
3292
+ guarded_recursion(guard, false) { |g| resolved_type.kind_of_callable?(optional, g) }
3293
+ end
3294
+
3295
+ def instance?(o, guard = nil)
3296
+ really_instance?(o, guard) == 1
3297
+ end
3298
+
3299
+ def iterable?(guard = nil)
3300
+ guarded_recursion(guard, false) { |g| resolved_type.iterable?(g) }
3301
+ end
3302
+
3303
+ def iterable_type(guard = nil)
3304
+ guarded_recursion(guard, nil) { |g| resolved_type.iterable_type(g) }
3305
+ end
3306
+
3307
+ def hash
3308
+ @name.hash
3309
+ end
3310
+
3311
+ # Acceptor used when checking for self recursion and that a type contains
3312
+ # something other than aliases or type references
3313
+ #
3314
+ # @api private
3315
+ class AssertOtherTypeAcceptor
3316
+ def initialize
3317
+ @other_type_detected = false
3318
+ end
3319
+
3320
+ def visit(type, _)
3321
+ unless type.is_a?(PTypeAliasType) || type.is_a?(PVariantType)
3322
+ @other_type_detected = true
3323
+ end
3324
+ end
3325
+
3326
+ def other_type_detected?
3327
+ @other_type_detected
3328
+ end
3329
+ end
3330
+
3331
+ # Acceptor used when re-checking for self recursion after a self recursion has been detected
3332
+ #
3333
+ # @api private
3334
+ class AssertSelfRecursionStatusAcceptor
3335
+ def visit(type, _)
3336
+ type.set_self_recursion_status if type.is_a?(PTypeAliasType)
3337
+ end
3338
+ end
3339
+
3340
+ def set_self_recursion_status
3341
+ return if @self_recursion || @resolved_type.is_a?(PTypeReferenceType)
3342
+ @self_recursion = true
3343
+ guard = RecursionGuard.new
3344
+ accept(NoopTypeAcceptor::INSTANCE, guard)
3345
+ @self_recursion = guard.recursive_this?(self)
3346
+ when_self_recursion_detected if @self_recursion # no difference
3347
+ end
3348
+
3349
+ # Called from the TypeParser once it has found a type using the Loader. The TypeParser will
3350
+ # interpret the contained expression and the resolved type is remembered. This method also
3351
+ # checks and remembers if the resolve type contains self recursion.
3352
+ #
3353
+ # @param type_parser [TypeParser] type parser that will interpret the type expression
3354
+ # @param loader [Loader::Loader] loader to use when loading type aliases
3355
+ # @return [PTypeAliasType] the receiver of the call, i.e. `self`
3356
+ # @api private
3357
+ def resolve(loader)
3358
+ @loader = loader
3359
+ if @resolved_type.nil?
3360
+ # resolved to PTypeReferenceType::DEFAULT during resolve to avoid endless recursion
3361
+ @resolved_type = PTypeReferenceType::DEFAULT
3362
+ @self_recursion = true # assumed while it being found out below
3363
+ begin
3364
+ if @type_expr.is_a?(PTypeReferenceType)
3365
+ @resolved_type = @type_expr.resolve(loader)
3366
+ else
3367
+ @resolved_type = TypeParser.singleton.interpret(@type_expr, loader).normalize
3368
+ end
3369
+
3370
+ # Find out if this type is recursive. A recursive type has performance implications
3371
+ # on several methods and this knowledge is used to avoid that for non-recursive
3372
+ # types.
3373
+ guard = RecursionGuard.new
3374
+ real_type_asserter = AssertOtherTypeAcceptor.new
3375
+ accept(real_type_asserter, guard)
3376
+ unless real_type_asserter.other_type_detected?
3377
+ raise ArgumentError, "Type alias '#{name}' cannot be resolved to a real type"
3378
+ end
3379
+ @self_recursion = guard.recursive_this?(self)
3380
+ # All aliases involved must re-check status since this alias is now resolved
3381
+ if @self_recursion
3382
+ accept(AssertSelfRecursionStatusAcceptor.new, RecursionGuard.new)
3383
+ when_self_recursion_detected
3384
+ end
3385
+ rescue
3386
+ @resolved_type = nil
3387
+ raise
3388
+ end
3389
+ else
3390
+ # An alias may appoint an Object type that isn't resolved yet. The default type
3391
+ # reference is used to prevent endless recursion and should not be resolved here.
3392
+ @resolved_type.resolve(loader) unless @resolved_type.equal?(PTypeReferenceType::DEFAULT)
3393
+ end
3394
+ self
3395
+ end
3396
+
3397
+ def eql?(o)
3398
+ super && o.name == @name
3399
+ end
3400
+
3401
+ def accept(visitor, guard)
3402
+ guarded_recursion(guard, nil) do |g|
3403
+ super(visitor, g)
3404
+ @resolved_type.accept(visitor, g) unless @resolved_type.nil?
3405
+ end
3406
+ end
3407
+
3408
+ def self_recursion?
3409
+ @self_recursion
3410
+ end
3411
+
3412
+ # Returns the expanded string the form of the alias, e.g. <alias name> = <resolved type>
3413
+ #
3414
+ # @return [String] the expanded form of this alias
3415
+ # @api public
3416
+ def to_s
3417
+ TypeFormatter.singleton.alias_expanded_string(self)
3418
+ end
3419
+
3420
+ # Delegates to resolved type
3421
+ def respond_to_missing?(name, include_private)
3422
+ resolved_type.respond_to?(name, include_private)
3423
+ end
3424
+
3425
+ # Delegates to resolved type
3426
+ def method_missing(name, *arguments, &block)
3427
+ super if @resolved_type.equal?(PTypeReferenceType::DEFAULT)
3428
+ resolved_type.send(name, *arguments, &block)
3429
+ end
3430
+
3431
+ # @api private
3432
+ def really_instance?(o, guard = nil)
3433
+ if @self_recursion
3434
+ guard ||= RecursionGuard.new
3435
+ guard.with_that(o) do
3436
+ guard.with_this(self) { |state| state == RecursionGuard::SELF_RECURSION_IN_BOTH ? 0 : resolved_type.really_instance?(o, guard) }
3437
+ end
3438
+ else
3439
+ resolved_type.really_instance?(o, guard)
3440
+ end
3441
+ end
3442
+
3443
+ # @return `nil` to prevent serialization of the type_expr used when first initializing this instance
3444
+ # @api private
3445
+ def type_expr
3446
+ nil
3447
+ end
3448
+
3449
+ protected
3450
+
3451
+ def _assignable?(o, guard)
3452
+ resolved_type.assignable?(o, guard)
3453
+ end
3454
+
3455
+ def new_function
3456
+ resolved_type.new_function
3457
+ end
3458
+
3459
+ private
3460
+
3461
+ def guarded_recursion(guard, dflt)
3462
+ if @self_recursion
3463
+ guard ||= RecursionGuard.new
3464
+ guard.with_this(self) { |state| (state & RecursionGuard::SELF_RECURSION_IN_THIS) == 0 ? yield(guard) : dflt }
3465
+ else
3466
+ yield(guard)
3467
+ end
3468
+ end
3469
+
3470
+ def when_self_recursion_detected
3471
+ if @resolved_type.is_a?(PVariantType)
3472
+ # Drop variants that are not real types
3473
+ resolved_types = @resolved_type.types
3474
+ real_types = resolved_types.select do |type|
3475
+ next false if type == self
3476
+ real_type_asserter = AssertOtherTypeAcceptor.new
3477
+ type.accept(real_type_asserter, RecursionGuard.new)
3478
+ real_type_asserter.other_type_detected?
3479
+ end
3480
+ if real_types.size != resolved_types.size
3481
+ if real_types.size == 1
3482
+ @resolved_type = real_types[0]
3483
+ else
3484
+ @resolved_type = PVariantType.maybe_create(real_types)
3485
+ end
3486
+ # Drop self recursion status in case it's not self recursive anymore
3487
+ guard = RecursionGuard.new
3488
+ accept(NoopTypeAcceptor::INSTANCE, guard)
3489
+ @self_recursion = guard.recursive_this?(self)
3490
+ end
3491
+ end
3492
+ @resolved_type.check_self_recursion(self) if @self_recursion
3493
+ end
3494
+
3495
+ DEFAULT = PTypeAliasType.new('UnresolvedAlias', nil, PTypeReferenceType::DEFAULT)
3496
+ end
3497
+ end
3498
+ end
3499
+
3500
+ require 'puppet/pops/pcore'
3501
+
3502
+ require_relative 'annotatable'
3503
+ require_relative 'p_meta_type'
3504
+ require_relative 'p_object_type'
3505
+ require_relative 'annotation'
3506
+ require_relative 'ruby_method'
3507
+ require_relative 'p_runtime_type'
3508
+ require_relative 'p_sem_ver_type'
3509
+ require_relative 'p_sem_ver_range_type'
3510
+ require_relative 'p_sensitive_type'
3511
+ require_relative 'p_type_set_type'
3512
+ require_relative 'p_timespan_type'
3513
+ require_relative 'p_timestamp_type'
3514
+ require_relative 'p_binary_type'
3515
+ require_relative 'p_init_type'
3516
+ require_relative 'p_error_type'
3517
+ require_relative 'type_set_reference'
3518
+ require_relative 'implementation_registry'
3519
+ require_relative 'tree_iterators'