openvox 8.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1104) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +19 -0
  3. data/CODEOWNERS +11 -0
  4. data/CODE_OF_CONDUCT.md +70 -0
  5. data/Gemfile +87 -0
  6. data/Guardfile.example +76 -0
  7. data/LICENSE +202 -0
  8. data/README.md +63 -0
  9. data/Rakefile +170 -0
  10. data/bin/puppet +10 -0
  11. data/conf/environment.conf +18 -0
  12. data/conf/fileserver.conf +32 -0
  13. data/conf/hiera.yaml +11 -0
  14. data/conf/puppet.conf +6 -0
  15. data/examples/enc/regexp_nodes/classes/databases +2 -0
  16. data/examples/enc/regexp_nodes/classes/webservers +2 -0
  17. data/examples/enc/regexp_nodes/environment/development +2 -0
  18. data/examples/enc/regexp_nodes/parameters/service/prod +1 -0
  19. data/examples/enc/regexp_nodes/parameters/service/qa +3 -0
  20. data/examples/enc/regexp_nodes/parameters/service/sandbox +1 -0
  21. data/examples/enc/regexp_nodes/regexp_nodes.rb +270 -0
  22. data/examples/hiera/README.md +102 -0
  23. data/examples/hiera/data/common.yaml +12 -0
  24. data/examples/hiera/data/dc1.yaml +6 -0
  25. data/examples/hiera/hiera.yaml +15 -0
  26. data/examples/hiera/modules/ntp/data/common.yaml +4 -0
  27. data/examples/hiera/modules/ntp/hiera.yaml +9 -0
  28. data/examples/hiera/modules/ntp/manifests/config.pp +18 -0
  29. data/examples/hiera/modules/ntp/templates/ntp.conf.epp +3 -0
  30. data/examples/hiera/modules/users/manifests/common.pp +9 -0
  31. data/examples/hiera/modules/users/manifests/dc1.pp +9 -0
  32. data/examples/hiera/site.pp +3 -0
  33. data/examples/nagios/check_puppet.rb +123 -0
  34. data/ext/README.md +13 -0
  35. data/ext/build_defaults.yaml +18 -0
  36. data/ext/debian/puppet.default +4 -0
  37. data/ext/debian/puppet.init +113 -0
  38. data/ext/hiera/hiera.yaml +15 -0
  39. data/ext/osx/puppet.plist +32 -0
  40. data/ext/project_data.yaml +20 -0
  41. data/ext/redhat/client.init +169 -0
  42. data/ext/redhat/client.sysconfig +2 -0
  43. data/ext/solaris/smf/puppet +44 -0
  44. data/ext/solaris/smf/puppet.xml +46 -0
  45. data/ext/suse/client.init +141 -0
  46. data/ext/systemd/puppet.service +26 -0
  47. data/ext/windows/puppet_interactive.bat +6 -0
  48. data/ext/windows/puppet_shell.bat +9 -0
  49. data/ext/windows/run_puppet_interactive.bat +9 -0
  50. data/ext/windows/service/daemon.bat +6 -0
  51. data/ext/windows/service/daemon.rb +219 -0
  52. data/install.rb +428 -0
  53. data/lib/hiera/puppet_function.rb +86 -0
  54. data/lib/hiera/scope.rb +92 -0
  55. data/lib/hiera_puppet.rb +78 -0
  56. data/lib/puppet/agent/disabler.rb +55 -0
  57. data/lib/puppet/agent/locker.rb +46 -0
  58. data/lib/puppet/agent.rb +178 -0
  59. data/lib/puppet/application/agent.rb +527 -0
  60. data/lib/puppet/application/apply.rb +435 -0
  61. data/lib/puppet/application/catalog.rb +6 -0
  62. data/lib/puppet/application/config.rb +7 -0
  63. data/lib/puppet/application/describe.rb +255 -0
  64. data/lib/puppet/application/device.rb +440 -0
  65. data/lib/puppet/application/doc.rb +232 -0
  66. data/lib/puppet/application/epp.rb +7 -0
  67. data/lib/puppet/application/face_base.rb +277 -0
  68. data/lib/puppet/application/facts.rb +11 -0
  69. data/lib/puppet/application/filebucket.rb +324 -0
  70. data/lib/puppet/application/generate.rb +7 -0
  71. data/lib/puppet/application/help.rb +7 -0
  72. data/lib/puppet/application/indirection_base.rb +6 -0
  73. data/lib/puppet/application/lookup.rb +433 -0
  74. data/lib/puppet/application/module.rb +6 -0
  75. data/lib/puppet/application/node.rb +6 -0
  76. data/lib/puppet/application/parser.rb +7 -0
  77. data/lib/puppet/application/plugin.rb +6 -0
  78. data/lib/puppet/application/report.rb +6 -0
  79. data/lib/puppet/application/resource.rb +264 -0
  80. data/lib/puppet/application/script.rb +266 -0
  81. data/lib/puppet/application/ssl.rb +331 -0
  82. data/lib/puppet/application.rb +596 -0
  83. data/lib/puppet/application_support.rb +69 -0
  84. data/lib/puppet/coercion.rb +42 -0
  85. data/lib/puppet/compilable_resource_type.rb +17 -0
  86. data/lib/puppet/concurrent/lock.rb +15 -0
  87. data/lib/puppet/concurrent/synchronized.rb +15 -0
  88. data/lib/puppet/concurrent/thread_local_singleton.rb +18 -0
  89. data/lib/puppet/concurrent.rb +4 -0
  90. data/lib/puppet/configurer/downloader.rb +91 -0
  91. data/lib/puppet/configurer/fact_handler.rb +51 -0
  92. data/lib/puppet/configurer/plugin_handler.rb +61 -0
  93. data/lib/puppet/configurer.rb +759 -0
  94. data/lib/puppet/confine/any.rb +28 -0
  95. data/lib/puppet/confine/boolean.rb +47 -0
  96. data/lib/puppet/confine/exists.rb +21 -0
  97. data/lib/puppet/confine/false.rb +27 -0
  98. data/lib/puppet/confine/feature.rb +18 -0
  99. data/lib/puppet/confine/true.rb +28 -0
  100. data/lib/puppet/confine/variable.rb +61 -0
  101. data/lib/puppet/confine.rb +86 -0
  102. data/lib/puppet/confine_collection.rb +54 -0
  103. data/lib/puppet/confiner.rb +48 -0
  104. data/lib/puppet/context/trusted_information.rb +122 -0
  105. data/lib/puppet/context.rb +190 -0
  106. data/lib/puppet/daemon.rb +198 -0
  107. data/lib/puppet/data_binding.rb +16 -0
  108. data/lib/puppet/datatypes/error.rb +23 -0
  109. data/lib/puppet/datatypes/impl/error.rb +42 -0
  110. data/lib/puppet/datatypes.rb +218 -0
  111. data/lib/puppet/defaults.rb +2316 -0
  112. data/lib/puppet/environments.rb +599 -0
  113. data/lib/puppet/error.rb +142 -0
  114. data/lib/puppet/etc.rb +185 -0
  115. data/lib/puppet/external/dot.rb +315 -0
  116. data/lib/puppet/face/catalog/select.rb +51 -0
  117. data/lib/puppet/face/catalog.rb +167 -0
  118. data/lib/puppet/face/config.rb +266 -0
  119. data/lib/puppet/face/epp.rb +565 -0
  120. data/lib/puppet/face/facts.rb +176 -0
  121. data/lib/puppet/face/generate.rb +69 -0
  122. data/lib/puppet/face/help/action.erb +89 -0
  123. data/lib/puppet/face/help/face.erb +114 -0
  124. data/lib/puppet/face/help/global.erb +16 -0
  125. data/lib/puppet/face/help/man.erb +152 -0
  126. data/lib/puppet/face/help.rb +260 -0
  127. data/lib/puppet/face/module/changes.rb +44 -0
  128. data/lib/puppet/face/module/install.rb +149 -0
  129. data/lib/puppet/face/module/list.rb +271 -0
  130. data/lib/puppet/face/module/uninstall.rb +91 -0
  131. data/lib/puppet/face/module/upgrade.rb +89 -0
  132. data/lib/puppet/face/module.rb +21 -0
  133. data/lib/puppet/face/node/clean.rb +109 -0
  134. data/lib/puppet/face/node.rb +45 -0
  135. data/lib/puppet/face/parser.rb +226 -0
  136. data/lib/puppet/face/plugin.rb +62 -0
  137. data/lib/puppet/face/report.rb +54 -0
  138. data/lib/puppet/face/resource.rb +55 -0
  139. data/lib/puppet/face.rb +14 -0
  140. data/lib/puppet/facter_impl.rb +96 -0
  141. data/lib/puppet/feature/base.rb +76 -0
  142. data/lib/puppet/feature/bolt.rb +5 -0
  143. data/lib/puppet/feature/cfpropertylist.rb +5 -0
  144. data/lib/puppet/feature/eventlog.rb +7 -0
  145. data/lib/puppet/feature/hiera_eyaml.rb +5 -0
  146. data/lib/puppet/feature/hocon.rb +5 -0
  147. data/lib/puppet/feature/libuser.rb +10 -0
  148. data/lib/puppet/feature/msgpack.rb +5 -0
  149. data/lib/puppet/feature/pe_license.rb +6 -0
  150. data/lib/puppet/feature/pson.rb +6 -0
  151. data/lib/puppet/feature/selinux.rb +5 -0
  152. data/lib/puppet/feature/ssh.rb +5 -0
  153. data/lib/puppet/feature/telnet.rb +5 -0
  154. data/lib/puppet/feature/zlib.rb +7 -0
  155. data/lib/puppet/ffi/posix/constants.rb +16 -0
  156. data/lib/puppet/ffi/posix/functions.rb +25 -0
  157. data/lib/puppet/ffi/posix.rb +12 -0
  158. data/lib/puppet/ffi/windows/api_types.rb +313 -0
  159. data/lib/puppet/ffi/windows/constants.rb +406 -0
  160. data/lib/puppet/ffi/windows/functions.rb +629 -0
  161. data/lib/puppet/ffi/windows/structs.rb +339 -0
  162. data/lib/puppet/ffi/windows.rb +14 -0
  163. data/lib/puppet/file_bucket/dipper.rb +183 -0
  164. data/lib/puppet/file_bucket/file.rb +131 -0
  165. data/lib/puppet/file_bucket.rb +6 -0
  166. data/lib/puppet/file_serving/base.rb +94 -0
  167. data/lib/puppet/file_serving/configuration/parser.rb +116 -0
  168. data/lib/puppet/file_serving/configuration.rb +116 -0
  169. data/lib/puppet/file_serving/content.rb +45 -0
  170. data/lib/puppet/file_serving/fileset.rb +190 -0
  171. data/lib/puppet/file_serving/http_metadata.rb +61 -0
  172. data/lib/puppet/file_serving/metadata.rb +174 -0
  173. data/lib/puppet/file_serving/mount/file.rb +126 -0
  174. data/lib/puppet/file_serving/mount/locales.rb +35 -0
  175. data/lib/puppet/file_serving/mount/modules.rb +29 -0
  176. data/lib/puppet/file_serving/mount/pluginfacts.rb +35 -0
  177. data/lib/puppet/file_serving/mount/plugins.rb +35 -0
  178. data/lib/puppet/file_serving/mount/scripts.rb +27 -0
  179. data/lib/puppet/file_serving/mount/tasks.rb +26 -0
  180. data/lib/puppet/file_serving/mount.rb +41 -0
  181. data/lib/puppet/file_serving/terminus_helper.rb +33 -0
  182. data/lib/puppet/file_serving/terminus_selector.rb +33 -0
  183. data/lib/puppet/file_serving.rb +5 -0
  184. data/lib/puppet/file_system/file_impl.rb +189 -0
  185. data/lib/puppet/file_system/jruby.rb +25 -0
  186. data/lib/puppet/file_system/memory_file.rb +82 -0
  187. data/lib/puppet/file_system/memory_impl.rb +103 -0
  188. data/lib/puppet/file_system/path_pattern.rb +95 -0
  189. data/lib/puppet/file_system/posix.rb +52 -0
  190. data/lib/puppet/file_system/uniquefile.rb +190 -0
  191. data/lib/puppet/file_system/windows.rb +224 -0
  192. data/lib/puppet/file_system.rb +421 -0
  193. data/lib/puppet/forge/cache.rb +61 -0
  194. data/lib/puppet/forge/errors.rb +113 -0
  195. data/lib/puppet/forge/repository.rb +98 -0
  196. data/lib/puppet/forge.rb +257 -0
  197. data/lib/puppet/functions/abs.rb +64 -0
  198. data/lib/puppet/functions/alert.rb +16 -0
  199. data/lib/puppet/functions/all.rb +106 -0
  200. data/lib/puppet/functions/annotate.rb +110 -0
  201. data/lib/puppet/functions/any.rb +111 -0
  202. data/lib/puppet/functions/assert_type.rb +96 -0
  203. data/lib/puppet/functions/binary_file.rb +35 -0
  204. data/lib/puppet/functions/break.rb +49 -0
  205. data/lib/puppet/functions/call.rb +81 -0
  206. data/lib/puppet/functions/camelcase.rb +63 -0
  207. data/lib/puppet/functions/capitalize.rb +62 -0
  208. data/lib/puppet/functions/ceiling.rb +38 -0
  209. data/lib/puppet/functions/chomp.rb +58 -0
  210. data/lib/puppet/functions/chop.rb +68 -0
  211. data/lib/puppet/functions/compare.rb +127 -0
  212. data/lib/puppet/functions/contain.rb +58 -0
  213. data/lib/puppet/functions/convert_to.rb +36 -0
  214. data/lib/puppet/functions/crit.rb +16 -0
  215. data/lib/puppet/functions/debug.rb +16 -0
  216. data/lib/puppet/functions/defined.rb +163 -0
  217. data/lib/puppet/functions/dig.rb +70 -0
  218. data/lib/puppet/functions/downcase.rb +91 -0
  219. data/lib/puppet/functions/each.rb +169 -0
  220. data/lib/puppet/functions/emerg.rb +16 -0
  221. data/lib/puppet/functions/empty.rb +87 -0
  222. data/lib/puppet/functions/epp.rb +50 -0
  223. data/lib/puppet/functions/err.rb +16 -0
  224. data/lib/puppet/functions/eyaml_lookup_key.rb +103 -0
  225. data/lib/puppet/functions/filter.rb +138 -0
  226. data/lib/puppet/functions/find_file.rb +50 -0
  227. data/lib/puppet/functions/find_template.rb +65 -0
  228. data/lib/puppet/functions/flatten.rb +66 -0
  229. data/lib/puppet/functions/floor.rb +38 -0
  230. data/lib/puppet/functions/get.rb +152 -0
  231. data/lib/puppet/functions/getvar.rb +89 -0
  232. data/lib/puppet/functions/group_by.rb +62 -0
  233. data/lib/puppet/functions/hiera.rb +91 -0
  234. data/lib/puppet/functions/hiera_array.rb +83 -0
  235. data/lib/puppet/functions/hiera_hash.rb +94 -0
  236. data/lib/puppet/functions/hiera_include.rb +107 -0
  237. data/lib/puppet/functions/hocon_data.rb +41 -0
  238. data/lib/puppet/functions/import.rb +9 -0
  239. data/lib/puppet/functions/include.rb +56 -0
  240. data/lib/puppet/functions/index.rb +168 -0
  241. data/lib/puppet/functions/info.rb +16 -0
  242. data/lib/puppet/functions/inline_epp.rb +61 -0
  243. data/lib/puppet/functions/join.rb +58 -0
  244. data/lib/puppet/functions/json_data.rb +33 -0
  245. data/lib/puppet/functions/keys.rb +27 -0
  246. data/lib/puppet/functions/length.rb +45 -0
  247. data/lib/puppet/functions/lest.rb +57 -0
  248. data/lib/puppet/functions/lookup.rb +224 -0
  249. data/lib/puppet/functions/lstrip.rb +59 -0
  250. data/lib/puppet/functions/map.rb +137 -0
  251. data/lib/puppet/functions/match.rb +133 -0
  252. data/lib/puppet/functions/max.rb +250 -0
  253. data/lib/puppet/functions/min.rb +249 -0
  254. data/lib/puppet/functions/module_directory.rb +43 -0
  255. data/lib/puppet/functions/new.rb +1013 -0
  256. data/lib/puppet/functions/next.rb +35 -0
  257. data/lib/puppet/functions/notice.rb +16 -0
  258. data/lib/puppet/functions/partition.rb +62 -0
  259. data/lib/puppet/functions/reduce.rb +159 -0
  260. data/lib/puppet/functions/regsubst.rb +100 -0
  261. data/lib/puppet/functions/require.rb +81 -0
  262. data/lib/puppet/functions/return.rb +17 -0
  263. data/lib/puppet/functions/reverse_each.rb +96 -0
  264. data/lib/puppet/functions/round.rb +26 -0
  265. data/lib/puppet/functions/rstrip.rb +59 -0
  266. data/lib/puppet/functions/scanf.rb +46 -0
  267. data/lib/puppet/functions/size.rb +15 -0
  268. data/lib/puppet/functions/slice.rb +127 -0
  269. data/lib/puppet/functions/sort.rb +76 -0
  270. data/lib/puppet/functions/split.rb +78 -0
  271. data/lib/puppet/functions/step.rb +100 -0
  272. data/lib/puppet/functions/strftime.rb +214 -0
  273. data/lib/puppet/functions/strip.rb +59 -0
  274. data/lib/puppet/functions/then.rb +80 -0
  275. data/lib/puppet/functions/tree_each.rb +198 -0
  276. data/lib/puppet/functions/type.rb +74 -0
  277. data/lib/puppet/functions/unique.rb +135 -0
  278. data/lib/puppet/functions/unwrap.rb +61 -0
  279. data/lib/puppet/functions/upcase.rb +91 -0
  280. data/lib/puppet/functions/values.rb +27 -0
  281. data/lib/puppet/functions/versioncmp.rb +41 -0
  282. data/lib/puppet/functions/warning.rb +16 -0
  283. data/lib/puppet/functions/with.rb +34 -0
  284. data/lib/puppet/functions/yaml_data.rb +45 -0
  285. data/lib/puppet/functions.rb +858 -0
  286. data/lib/puppet/generate/models/type/property.rb +73 -0
  287. data/lib/puppet/generate/models/type/type.rb +68 -0
  288. data/lib/puppet/generate/templates/type/pcore.erb +42 -0
  289. data/lib/puppet/generate/type.rb +255 -0
  290. data/lib/puppet/gettext/config.rb +282 -0
  291. data/lib/puppet/gettext/module_translations.rb +43 -0
  292. data/lib/puppet/gettext/stubs.rb +13 -0
  293. data/lib/puppet/graph/key.rb +28 -0
  294. data/lib/puppet/graph/prioritizer.rb +31 -0
  295. data/lib/puppet/graph/rb_tree_map.rb +407 -0
  296. data/lib/puppet/graph/relationship_graph.rb +286 -0
  297. data/lib/puppet/graph/sequential_prioritizer.rb +33 -0
  298. data/lib/puppet/graph/simple_graph.rb +552 -0
  299. data/lib/puppet/graph.rb +11 -0
  300. data/lib/puppet/http/client.rb +529 -0
  301. data/lib/puppet/http/dns.rb +159 -0
  302. data/lib/puppet/http/errors.rb +50 -0
  303. data/lib/puppet/http/external_client.rb +89 -0
  304. data/lib/puppet/http/factory.rb +53 -0
  305. data/lib/puppet/http/pool.rb +174 -0
  306. data/lib/puppet/http/pool_entry.rb +19 -0
  307. data/lib/puppet/http/proxy.rb +139 -0
  308. data/lib/puppet/http/redirector.rb +87 -0
  309. data/lib/puppet/http/resolver/server_list.rb +88 -0
  310. data/lib/puppet/http/resolver/settings.rb +24 -0
  311. data/lib/puppet/http/resolver/srv.rb +42 -0
  312. data/lib/puppet/http/resolver.rb +50 -0
  313. data/lib/puppet/http/response.rb +104 -0
  314. data/lib/puppet/http/response_converter.rb +25 -0
  315. data/lib/puppet/http/response_net_http.rb +43 -0
  316. data/lib/puppet/http/retry_after_handler.rb +78 -0
  317. data/lib/puppet/http/service/ca.rb +133 -0
  318. data/lib/puppet/http/service/compiler.rb +356 -0
  319. data/lib/puppet/http/service/file_server.rb +200 -0
  320. data/lib/puppet/http/service/puppetserver.rb +54 -0
  321. data/lib/puppet/http/service/report.rb +62 -0
  322. data/lib/puppet/http/service.rb +177 -0
  323. data/lib/puppet/http/session.rb +124 -0
  324. data/lib/puppet/http/site.rb +44 -0
  325. data/lib/puppet/http.rb +48 -0
  326. data/lib/puppet/indirector/catalog/compiler.rb +432 -0
  327. data/lib/puppet/indirector/catalog/json.rb +42 -0
  328. data/lib/puppet/indirector/catalog/msgpack.rb +8 -0
  329. data/lib/puppet/indirector/catalog/rest.rb +51 -0
  330. data/lib/puppet/indirector/catalog/store_configs.rb +8 -0
  331. data/lib/puppet/indirector/catalog/yaml.rb +8 -0
  332. data/lib/puppet/indirector/code.rb +8 -0
  333. data/lib/puppet/indirector/data_binding/hiera.rb +8 -0
  334. data/lib/puppet/indirector/data_binding/none.rb +10 -0
  335. data/lib/puppet/indirector/direct_file_server.rb +20 -0
  336. data/lib/puppet/indirector/envelope.rb +13 -0
  337. data/lib/puppet/indirector/errors.rb +7 -0
  338. data/lib/puppet/indirector/exec.rb +40 -0
  339. data/lib/puppet/indirector/face.rb +142 -0
  340. data/lib/puppet/indirector/fact_search.rb +62 -0
  341. data/lib/puppet/indirector/facts/facter.rb +120 -0
  342. data/lib/puppet/indirector/facts/json.rb +29 -0
  343. data/lib/puppet/indirector/facts/memory.rb +11 -0
  344. data/lib/puppet/indirector/facts/network_device.rb +29 -0
  345. data/lib/puppet/indirector/facts/rest.rb +46 -0
  346. data/lib/puppet/indirector/facts/store_configs.rb +12 -0
  347. data/lib/puppet/indirector/facts/yaml.rb +31 -0
  348. data/lib/puppet/indirector/file_bucket_file/file.rb +268 -0
  349. data/lib/puppet/indirector/file_bucket_file/rest.rb +53 -0
  350. data/lib/puppet/indirector/file_bucket_file/selector.rb +54 -0
  351. data/lib/puppet/indirector/file_content/file.rb +9 -0
  352. data/lib/puppet/indirector/file_content/file_server.rb +9 -0
  353. data/lib/puppet/indirector/file_content/rest.rb +37 -0
  354. data/lib/puppet/indirector/file_content/selector.rb +32 -0
  355. data/lib/puppet/indirector/file_content.rb +7 -0
  356. data/lib/puppet/indirector/file_metadata/file.rb +9 -0
  357. data/lib/puppet/indirector/file_metadata/file_server.rb +9 -0
  358. data/lib/puppet/indirector/file_metadata/http.rb +49 -0
  359. data/lib/puppet/indirector/file_metadata/rest.rb +58 -0
  360. data/lib/puppet/indirector/file_metadata/selector.rb +32 -0
  361. data/lib/puppet/indirector/file_metadata.rb +7 -0
  362. data/lib/puppet/indirector/file_server.rb +57 -0
  363. data/lib/puppet/indirector/generic_http.rb +7 -0
  364. data/lib/puppet/indirector/hiera.rb +101 -0
  365. data/lib/puppet/indirector/indirection.rb +381 -0
  366. data/lib/puppet/indirector/json.rb +82 -0
  367. data/lib/puppet/indirector/memory.rb +37 -0
  368. data/lib/puppet/indirector/msgpack.rb +87 -0
  369. data/lib/puppet/indirector/node/exec.rb +70 -0
  370. data/lib/puppet/indirector/node/json.rb +9 -0
  371. data/lib/puppet/indirector/node/memory.rb +12 -0
  372. data/lib/puppet/indirector/node/msgpack.rb +9 -0
  373. data/lib/puppet/indirector/node/plain.rb +23 -0
  374. data/lib/puppet/indirector/node/rest.rb +31 -0
  375. data/lib/puppet/indirector/node/store_configs.rb +8 -0
  376. data/lib/puppet/indirector/node/yaml.rb +9 -0
  377. data/lib/puppet/indirector/none.rb +10 -0
  378. data/lib/puppet/indirector/plain.rb +11 -0
  379. data/lib/puppet/indirector/report/json.rb +36 -0
  380. data/lib/puppet/indirector/report/msgpack.rb +13 -0
  381. data/lib/puppet/indirector/report/processor.rb +63 -0
  382. data/lib/puppet/indirector/report/rest.rb +31 -0
  383. data/lib/puppet/indirector/report/yaml.rb +36 -0
  384. data/lib/puppet/indirector/request.rb +197 -0
  385. data/lib/puppet/indirector/resource/ral.rb +66 -0
  386. data/lib/puppet/indirector/resource/store_configs.rb +14 -0
  387. data/lib/puppet/indirector/resource/validator.rb +10 -0
  388. data/lib/puppet/indirector/rest.rb +66 -0
  389. data/lib/puppet/indirector/store_configs.rb +32 -0
  390. data/lib/puppet/indirector/terminus.rb +180 -0
  391. data/lib/puppet/indirector/yaml.rb +65 -0
  392. data/lib/puppet/indirector.rb +64 -0
  393. data/lib/puppet/info_service/class_information_service.rb +108 -0
  394. data/lib/puppet/info_service/plan_information_service.rb +38 -0
  395. data/lib/puppet/info_service/task_information_service.rb +45 -0
  396. data/lib/puppet/info_service.rb +27 -0
  397. data/lib/puppet/interface/action.rb +410 -0
  398. data/lib/puppet/interface/action_builder.rb +167 -0
  399. data/lib/puppet/interface/action_manager.rb +101 -0
  400. data/lib/puppet/interface/documentation.rb +363 -0
  401. data/lib/puppet/interface/face_collection.rb +141 -0
  402. data/lib/puppet/interface/option.rb +184 -0
  403. data/lib/puppet/interface/option_builder.rb +110 -0
  404. data/lib/puppet/interface/option_manager.rb +108 -0
  405. data/lib/puppet/interface.rb +240 -0
  406. data/lib/puppet/loaders.rb +31 -0
  407. data/lib/puppet/metatype/manager.rb +198 -0
  408. data/lib/puppet/module/plan.rb +166 -0
  409. data/lib/puppet/module/task.rb +288 -0
  410. data/lib/puppet/module.rb +487 -0
  411. data/lib/puppet/module_tool/applications/application.rb +96 -0
  412. data/lib/puppet/module_tool/applications/checksummer.rb +62 -0
  413. data/lib/puppet/module_tool/applications/installer.rb +402 -0
  414. data/lib/puppet/module_tool/applications/uninstaller.rb +121 -0
  415. data/lib/puppet/module_tool/applications/unpacker.rb +102 -0
  416. data/lib/puppet/module_tool/applications/upgrader.rb +288 -0
  417. data/lib/puppet/module_tool/applications.rb +14 -0
  418. data/lib/puppet/module_tool/checksums.rb +50 -0
  419. data/lib/puppet/module_tool/dependency.rb +42 -0
  420. data/lib/puppet/module_tool/errors/base.rb +17 -0
  421. data/lib/puppet/module_tool/errors/installer.rb +94 -0
  422. data/lib/puppet/module_tool/errors/shared.rb +228 -0
  423. data/lib/puppet/module_tool/errors/uninstaller.rb +51 -0
  424. data/lib/puppet/module_tool/errors/upgrader.rb +64 -0
  425. data/lib/puppet/module_tool/errors.rb +13 -0
  426. data/lib/puppet/module_tool/install_directory.rb +48 -0
  427. data/lib/puppet/module_tool/installed_modules.rb +99 -0
  428. data/lib/puppet/module_tool/local_tarball.rb +92 -0
  429. data/lib/puppet/module_tool/metadata.rb +227 -0
  430. data/lib/puppet/module_tool/shared_behaviors.rb +199 -0
  431. data/lib/puppet/module_tool/tar/gnu.rb +23 -0
  432. data/lib/puppet/module_tool/tar/mini.rb +118 -0
  433. data/lib/puppet/module_tool/tar.rb +20 -0
  434. data/lib/puppet/module_tool.rb +194 -0
  435. data/lib/puppet/network/authconfig.rb +9 -0
  436. data/lib/puppet/network/authorization.rb +21 -0
  437. data/lib/puppet/network/client_request.rb +32 -0
  438. data/lib/puppet/network/format.rb +116 -0
  439. data/lib/puppet/network/format_handler.rb +110 -0
  440. data/lib/puppet/network/format_support.rb +140 -0
  441. data/lib/puppet/network/formats.rb +338 -0
  442. data/lib/puppet/network/http/api/indirected_routes.rb +270 -0
  443. data/lib/puppet/network/http/api/indirection_type.rb +33 -0
  444. data/lib/puppet/network/http/api/master/v3/environments.rb +4 -0
  445. data/lib/puppet/network/http/api/master/v3.rb +4 -0
  446. data/lib/puppet/network/http/api/master.rb +5 -0
  447. data/lib/puppet/network/http/api/server/v3/environments.rb +54 -0
  448. data/lib/puppet/network/http/api/server/v3.rb +40 -0
  449. data/lib/puppet/network/http/api/server.rb +12 -0
  450. data/lib/puppet/network/http/api.rb +41 -0
  451. data/lib/puppet/network/http/connection.rb +288 -0
  452. data/lib/puppet/network/http/error.rb +75 -0
  453. data/lib/puppet/network/http/handler.rb +213 -0
  454. data/lib/puppet/network/http/issues.rb +14 -0
  455. data/lib/puppet/network/http/memory_response.rb +15 -0
  456. data/lib/puppet/network/http/request.rb +83 -0
  457. data/lib/puppet/network/http/response.rb +25 -0
  458. data/lib/puppet/network/http/route.rb +104 -0
  459. data/lib/puppet/network/http.rb +30 -0
  460. data/lib/puppet/network/http_pool.rb +78 -0
  461. data/lib/puppet/network/uri.rb +20 -0
  462. data/lib/puppet/network.rb +5 -0
  463. data/lib/puppet/node/environment.rb +638 -0
  464. data/lib/puppet/node/facts.rb +165 -0
  465. data/lib/puppet/node/server_facts.rb +46 -0
  466. data/lib/puppet/node.rb +256 -0
  467. data/lib/puppet/pal/catalog_compiler.rb +107 -0
  468. data/lib/puppet/pal/compiler.rb +227 -0
  469. data/lib/puppet/pal/function_signature.rb +54 -0
  470. data/lib/puppet/pal/json_catalog_encoder.rb +76 -0
  471. data/lib/puppet/pal/pal_api.rb +17 -0
  472. data/lib/puppet/pal/pal_impl.rb +585 -0
  473. data/lib/puppet/pal/plan_signature.rb +73 -0
  474. data/lib/puppet/pal/script_compiler.rb +75 -0
  475. data/lib/puppet/pal/task_signature.rb +64 -0
  476. data/lib/puppet/parameter/boolean.rb +17 -0
  477. data/lib/puppet/parameter/package_options.rb +33 -0
  478. data/lib/puppet/parameter/path.rb +61 -0
  479. data/lib/puppet/parameter/value.rb +93 -0
  480. data/lib/puppet/parameter/value_collection.rb +213 -0
  481. data/lib/puppet/parameter.rb +590 -0
  482. data/lib/puppet/parser/abstract_compiler.rb +35 -0
  483. data/lib/puppet/parser/ast/block_expression.rb +17 -0
  484. data/lib/puppet/parser/ast/branch.rb +21 -0
  485. data/lib/puppet/parser/ast/hostclass.rb +29 -0
  486. data/lib/puppet/parser/ast/leaf.rb +84 -0
  487. data/lib/puppet/parser/ast/node.rb +19 -0
  488. data/lib/puppet/parser/ast/pops_bridge.rb +245 -0
  489. data/lib/puppet/parser/ast/resource.rb +66 -0
  490. data/lib/puppet/parser/ast/resource_instance.rb +13 -0
  491. data/lib/puppet/parser/ast/resourceparam.rb +33 -0
  492. data/lib/puppet/parser/ast/top_level_construct.rb +6 -0
  493. data/lib/puppet/parser/ast.rb +62 -0
  494. data/lib/puppet/parser/catalog_compiler.rb +56 -0
  495. data/lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb +41 -0
  496. data/lib/puppet/parser/compiler/catalog_validator.rb +35 -0
  497. data/lib/puppet/parser/compiler.rb +616 -0
  498. data/lib/puppet/parser/e4_parser_adapter.rb +61 -0
  499. data/lib/puppet/parser/files.rb +95 -0
  500. data/lib/puppet/parser/functions/assert_type.rb +62 -0
  501. data/lib/puppet/parser/functions/binary_file.rb +26 -0
  502. data/lib/puppet/parser/functions/break.rb +41 -0
  503. data/lib/puppet/parser/functions/contain.rb +32 -0
  504. data/lib/puppet/parser/functions/create_resources.rb +114 -0
  505. data/lib/puppet/parser/functions/defined.rb +109 -0
  506. data/lib/puppet/parser/functions/dig.rb +40 -0
  507. data/lib/puppet/parser/functions/digest.rb +7 -0
  508. data/lib/puppet/parser/functions/each.rb +106 -0
  509. data/lib/puppet/parser/functions/epp.rb +40 -0
  510. data/lib/puppet/parser/functions/fail.rb +13 -0
  511. data/lib/puppet/parser/functions/file.rb +35 -0
  512. data/lib/puppet/parser/functions/filter.rb +81 -0
  513. data/lib/puppet/parser/functions/find_file.rb +29 -0
  514. data/lib/puppet/parser/functions/fqdn_rand.rb +46 -0
  515. data/lib/puppet/parser/functions/generate.rb +39 -0
  516. data/lib/puppet/parser/functions/hiera.rb +105 -0
  517. data/lib/puppet/parser/functions/hiera_array.rb +93 -0
  518. data/lib/puppet/parser/functions/hiera_hash.rb +103 -0
  519. data/lib/puppet/parser/functions/hiera_include.rb +102 -0
  520. data/lib/puppet/parser/functions/include.rb +36 -0
  521. data/lib/puppet/parser/functions/inline_epp.rb +52 -0
  522. data/lib/puppet/parser/functions/inline_template.rb +28 -0
  523. data/lib/puppet/parser/functions/lest.rb +51 -0
  524. data/lib/puppet/parser/functions/lookup.rb +134 -0
  525. data/lib/puppet/parser/functions/map.rb +78 -0
  526. data/lib/puppet/parser/functions/match.rb +45 -0
  527. data/lib/puppet/parser/functions/md5.rb +7 -0
  528. data/lib/puppet/parser/functions/new.rb +992 -0
  529. data/lib/puppet/parser/functions/next.rb +40 -0
  530. data/lib/puppet/parser/functions/realize.rb +22 -0
  531. data/lib/puppet/parser/functions/reduce.rb +139 -0
  532. data/lib/puppet/parser/functions/regsubst.rb +65 -0
  533. data/lib/puppet/parser/functions/require.rb +43 -0
  534. data/lib/puppet/parser/functions/return.rb +94 -0
  535. data/lib/puppet/parser/functions/reverse_each.rb +85 -0
  536. data/lib/puppet/parser/functions/scanf.rb +40 -0
  537. data/lib/puppet/parser/functions/sha1.rb +7 -0
  538. data/lib/puppet/parser/functions/sha256.rb +7 -0
  539. data/lib/puppet/parser/functions/shellquote.rb +63 -0
  540. data/lib/puppet/parser/functions/slice.rb +41 -0
  541. data/lib/puppet/parser/functions/split.rb +29 -0
  542. data/lib/puppet/parser/functions/sprintf.rb +62 -0
  543. data/lib/puppet/parser/functions/step.rb +86 -0
  544. data/lib/puppet/parser/functions/strftime.rb +187 -0
  545. data/lib/puppet/parser/functions/tag.rb +15 -0
  546. data/lib/puppet/parser/functions/tagged.rb +24 -0
  547. data/lib/puppet/parser/functions/template.rb +42 -0
  548. data/lib/puppet/parser/functions/then.rb +75 -0
  549. data/lib/puppet/parser/functions/type.rb +55 -0
  550. data/lib/puppet/parser/functions/versioncmp.rb +31 -0
  551. data/lib/puppet/parser/functions/with.rb +30 -0
  552. data/lib/puppet/parser/functions.rb +324 -0
  553. data/lib/puppet/parser/parser_factory.rb +32 -0
  554. data/lib/puppet/parser/relationship.rb +90 -0
  555. data/lib/puppet/parser/resource/param.rb +37 -0
  556. data/lib/puppet/parser/resource.rb +353 -0
  557. data/lib/puppet/parser/scope.rb +1141 -0
  558. data/lib/puppet/parser/script_compiler.rb +123 -0
  559. data/lib/puppet/parser/templatewrapper.rb +105 -0
  560. data/lib/puppet/parser/type_loader.rb +151 -0
  561. data/lib/puppet/parser.rb +22 -0
  562. data/lib/puppet/plugins/configuration.rb +31 -0
  563. data/lib/puppet/plugins/syntax_checkers.rb +99 -0
  564. data/lib/puppet/plugins.rb +11 -0
  565. data/lib/puppet/pops/adaptable.rb +199 -0
  566. data/lib/puppet/pops/adapters.rb +159 -0
  567. data/lib/puppet/pops/evaluator/access_operator.rb +732 -0
  568. data/lib/puppet/pops/evaluator/callable_signature.rb +108 -0
  569. data/lib/puppet/pops/evaluator/closure.rb +370 -0
  570. data/lib/puppet/pops/evaluator/collector_transformer.rb +237 -0
  571. data/lib/puppet/pops/evaluator/collectors/abstract_collector.rb +88 -0
  572. data/lib/puppet/pops/evaluator/collectors/catalog_collector.rb +30 -0
  573. data/lib/puppet/pops/evaluator/collectors/exported_collector.rb +71 -0
  574. data/lib/puppet/pops/evaluator/collectors/fixed_set_collector.rb +38 -0
  575. data/lib/puppet/pops/evaluator/compare_operator.rb +269 -0
  576. data/lib/puppet/pops/evaluator/deferred_resolver.rb +227 -0
  577. data/lib/puppet/pops/evaluator/epp_evaluator.rb +121 -0
  578. data/lib/puppet/pops/evaluator/evaluator_impl.rb +1317 -0
  579. data/lib/puppet/pops/evaluator/external_syntax_support.rb +47 -0
  580. data/lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb +83 -0
  581. data/lib/puppet/pops/evaluator/literal_evaluator.rb +100 -0
  582. data/lib/puppet/pops/evaluator/puppet_proc.rb +72 -0
  583. data/lib/puppet/pops/evaluator/relationship_operator.rb +188 -0
  584. data/lib/puppet/pops/evaluator/runtime3_converter.rb +225 -0
  585. data/lib/puppet/pops/evaluator/runtime3_resource_support.rb +119 -0
  586. data/lib/puppet/pops/evaluator/runtime3_support.rb +528 -0
  587. data/lib/puppet/pops/functions/dispatch.rb +107 -0
  588. data/lib/puppet/pops/functions/dispatcher.rb +76 -0
  589. data/lib/puppet/pops/functions/function.rb +137 -0
  590. data/lib/puppet/pops/issue_reporter.rb +140 -0
  591. data/lib/puppet/pops/issues.rb +933 -0
  592. data/lib/puppet/pops/label_provider.rb +92 -0
  593. data/lib/puppet/pops/loader/base_loader.rb +178 -0
  594. data/lib/puppet/pops/loader/dependency_loader.rb +95 -0
  595. data/lib/puppet/pops/loader/gem_support.rb +54 -0
  596. data/lib/puppet/pops/loader/generic_plan_instantiator.rb +30 -0
  597. data/lib/puppet/pops/loader/loader.rb +221 -0
  598. data/lib/puppet/pops/loader/loader_paths.rb +413 -0
  599. data/lib/puppet/pops/loader/module_loaders.rb +552 -0
  600. data/lib/puppet/pops/loader/predefined_loader.rb +28 -0
  601. data/lib/puppet/pops/loader/puppet_function_instantiator.rb +88 -0
  602. data/lib/puppet/pops/loader/puppet_plan_instantiator.rb +97 -0
  603. data/lib/puppet/pops/loader/puppet_resource_type_impl_instantiator.rb +80 -0
  604. data/lib/puppet/pops/loader/ruby_data_type_instantiator.rb +43 -0
  605. data/lib/puppet/pops/loader/ruby_function_instantiator.rb +49 -0
  606. data/lib/puppet/pops/loader/ruby_legacy_function_instantiator.rb +130 -0
  607. data/lib/puppet/pops/loader/runtime3_type_loader.rb +104 -0
  608. data/lib/puppet/pops/loader/simple_environment_loader.rb +20 -0
  609. data/lib/puppet/pops/loader/static_loader.rb +133 -0
  610. data/lib/puppet/pops/loader/task_instantiator.rb +46 -0
  611. data/lib/puppet/pops/loader/type_definition_instantiator.rb +104 -0
  612. data/lib/puppet/pops/loader/typed_name.rb +56 -0
  613. data/lib/puppet/pops/loader/uri_helper.rb +24 -0
  614. data/lib/puppet/pops/loaders.rb +550 -0
  615. data/lib/puppet/pops/lookup/configured_data_provider.rb +95 -0
  616. data/lib/puppet/pops/lookup/context.rb +208 -0
  617. data/lib/puppet/pops/lookup/data_adapter.rb +29 -0
  618. data/lib/puppet/pops/lookup/data_dig_function_provider.rb +146 -0
  619. data/lib/puppet/pops/lookup/data_hash_function_provider.rb +128 -0
  620. data/lib/puppet/pops/lookup/data_provider.rb +94 -0
  621. data/lib/puppet/pops/lookup/environment_data_provider.rb +37 -0
  622. data/lib/puppet/pops/lookup/explainer.rb +597 -0
  623. data/lib/puppet/pops/lookup/function_provider.rb +112 -0
  624. data/lib/puppet/pops/lookup/global_data_provider.rb +76 -0
  625. data/lib/puppet/pops/lookup/hiera_config.rb +823 -0
  626. data/lib/puppet/pops/lookup/interpolation.rb +166 -0
  627. data/lib/puppet/pops/lookup/invocation.rb +272 -0
  628. data/lib/puppet/pops/lookup/key_recorder.rb +21 -0
  629. data/lib/puppet/pops/lookup/location_resolver.rb +101 -0
  630. data/lib/puppet/pops/lookup/lookup_adapter.rb +533 -0
  631. data/lib/puppet/pops/lookup/lookup_key.rb +101 -0
  632. data/lib/puppet/pops/lookup/lookup_key_function_provider.rb +94 -0
  633. data/lib/puppet/pops/lookup/module_data_provider.rb +92 -0
  634. data/lib/puppet/pops/lookup/sub_lookup.rb +96 -0
  635. data/lib/puppet/pops/lookup.rb +102 -0
  636. data/lib/puppet/pops/merge_strategy.rb +447 -0
  637. data/lib/puppet/pops/migration/migration_checker.rb +61 -0
  638. data/lib/puppet/pops/model/ast.pp +669 -0
  639. data/lib/puppet/pops/model/ast.rb +4776 -0
  640. data/lib/puppet/pops/model/ast_transformer.rb +131 -0
  641. data/lib/puppet/pops/model/factory.rb +1157 -0
  642. data/lib/puppet/pops/model/model_label_provider.rb +137 -0
  643. data/lib/puppet/pops/model/model_tree_dumper.rb +447 -0
  644. data/lib/puppet/pops/model/pn_transformer.rb +384 -0
  645. data/lib/puppet/pops/model/tree_dumper.rb +62 -0
  646. data/lib/puppet/pops/parser/code_merger.rb +29 -0
  647. data/lib/puppet/pops/parser/egrammar.ra +889 -0
  648. data/lib/puppet/pops/parser/eparser.rb +3184 -0
  649. data/lib/puppet/pops/parser/epp_parser.rb +52 -0
  650. data/lib/puppet/pops/parser/epp_support.rb +266 -0
  651. data/lib/puppet/pops/parser/evaluating_parser.rb +166 -0
  652. data/lib/puppet/pops/parser/heredoc_support.rb +153 -0
  653. data/lib/puppet/pops/parser/interpolation_support.rb +249 -0
  654. data/lib/puppet/pops/parser/lexer2.rb +789 -0
  655. data/lib/puppet/pops/parser/lexer_support.rb +221 -0
  656. data/lib/puppet/pops/parser/locatable.rb +23 -0
  657. data/lib/puppet/pops/parser/locator.rb +361 -0
  658. data/lib/puppet/pops/parser/parser_support.rb +252 -0
  659. data/lib/puppet/pops/parser/pn_parser.rb +318 -0
  660. data/lib/puppet/pops/parser/slurp_support.rb +119 -0
  661. data/lib/puppet/pops/patterns.rb +60 -0
  662. data/lib/puppet/pops/pcore.rb +136 -0
  663. data/lib/puppet/pops/pn.rb +239 -0
  664. data/lib/puppet/pops/puppet_stack.rb +63 -0
  665. data/lib/puppet/pops/resource/param.rb +56 -0
  666. data/lib/puppet/pops/resource/resource_type_impl.rb +296 -0
  667. data/lib/puppet/pops/resource/resource_type_set.pcore +22 -0
  668. data/lib/puppet/pops/semantic_error.rb +31 -0
  669. data/lib/puppet/pops/serialization/abstract_reader.rb +182 -0
  670. data/lib/puppet/pops/serialization/abstract_writer.rb +224 -0
  671. data/lib/puppet/pops/serialization/deserializer.rb +83 -0
  672. data/lib/puppet/pops/serialization/extension.rb +166 -0
  673. data/lib/puppet/pops/serialization/from_data_converter.rb +231 -0
  674. data/lib/puppet/pops/serialization/instance_reader.rb +21 -0
  675. data/lib/puppet/pops/serialization/instance_writer.rb +16 -0
  676. data/lib/puppet/pops/serialization/json.rb +301 -0
  677. data/lib/puppet/pops/serialization/json_path.rb +129 -0
  678. data/lib/puppet/pops/serialization/object.rb +73 -0
  679. data/lib/puppet/pops/serialization/serializer.rb +144 -0
  680. data/lib/puppet/pops/serialization/time_factory.rb +68 -0
  681. data/lib/puppet/pops/serialization/to_data_converter.rb +316 -0
  682. data/lib/puppet/pops/serialization/to_stringified_converter.rb +227 -0
  683. data/lib/puppet/pops/serialization.rb +45 -0
  684. data/lib/puppet/pops/time/timespan.rb +728 -0
  685. data/lib/puppet/pops/time/timestamp.rb +167 -0
  686. data/lib/puppet/pops/types/annotatable.rb +37 -0
  687. data/lib/puppet/pops/types/annotation.rb +73 -0
  688. data/lib/puppet/pops/types/class_loader.rb +134 -0
  689. data/lib/puppet/pops/types/implementation_registry.rb +137 -0
  690. data/lib/puppet/pops/types/iterable.rb +375 -0
  691. data/lib/puppet/pops/types/p_binary_type.rb +232 -0
  692. data/lib/puppet/pops/types/p_init_type.rb +241 -0
  693. data/lib/puppet/pops/types/p_meta_type.rb +95 -0
  694. data/lib/puppet/pops/types/p_object_type.rb +1142 -0
  695. data/lib/puppet/pops/types/p_object_type_extension.rb +229 -0
  696. data/lib/puppet/pops/types/p_runtime_type.rb +117 -0
  697. data/lib/puppet/pops/types/p_sem_ver_range_type.rb +191 -0
  698. data/lib/puppet/pops/types/p_sem_ver_type.rb +155 -0
  699. data/lib/puppet/pops/types/p_sensitive_type.rb +81 -0
  700. data/lib/puppet/pops/types/p_timespan_type.rb +194 -0
  701. data/lib/puppet/pops/types/p_timestamp_type.rb +74 -0
  702. data/lib/puppet/pops/types/p_type_set_type.rb +394 -0
  703. data/lib/puppet/pops/types/p_uri_type.rb +198 -0
  704. data/lib/puppet/pops/types/puppet_object.rb +41 -0
  705. data/lib/puppet/pops/types/recursion_guard.rb +142 -0
  706. data/lib/puppet/pops/types/ruby_generator.rb +477 -0
  707. data/lib/puppet/pops/types/ruby_method.rb +32 -0
  708. data/lib/puppet/pops/types/string_converter.rb +1144 -0
  709. data/lib/puppet/pops/types/tree_iterators.rb +250 -0
  710. data/lib/puppet/pops/types/type_acceptor.rb +27 -0
  711. data/lib/puppet/pops/types/type_asserter.rb +49 -0
  712. data/lib/puppet/pops/types/type_assertion_error.rb +27 -0
  713. data/lib/puppet/pops/types/type_calculator.rb +829 -0
  714. data/lib/puppet/pops/types/type_conversion_error.rb +7 -0
  715. data/lib/puppet/pops/types/type_factory.rb +640 -0
  716. data/lib/puppet/pops/types/type_formatter.rb +796 -0
  717. data/lib/puppet/pops/types/type_mismatch_describer.rb +1105 -0
  718. data/lib/puppet/pops/types/type_parser.rb +690 -0
  719. data/lib/puppet/pops/types/type_set_reference.rb +62 -0
  720. data/lib/puppet/pops/types/type_with_members.rb +43 -0
  721. data/lib/puppet/pops/types/types.rb +3651 -0
  722. data/lib/puppet/pops/utils.rb +117 -0
  723. data/lib/puppet/pops/validation/checker4_0.rb +1155 -0
  724. data/lib/puppet/pops/validation/tasks_checker.rb +95 -0
  725. data/lib/puppet/pops/validation/validator_factory_4_0.rb +45 -0
  726. data/lib/puppet/pops/validation.rb +462 -0
  727. data/lib/puppet/pops/visitable.rb +8 -0
  728. data/lib/puppet/pops/visitor.rb +136 -0
  729. data/lib/puppet/pops.rb +124 -0
  730. data/lib/puppet/property/boolean.rb +9 -0
  731. data/lib/puppet/property/ensure.rb +107 -0
  732. data/lib/puppet/property/keyvalue.rb +159 -0
  733. data/lib/puppet/property/list.rb +71 -0
  734. data/lib/puppet/property/ordered_list.rb +30 -0
  735. data/lib/puppet/property.rb +610 -0
  736. data/lib/puppet/provider/aix_object.rb +491 -0
  737. data/lib/puppet/provider/command.rb +27 -0
  738. data/lib/puppet/provider/confine.rb +8 -0
  739. data/lib/puppet/provider/exec/posix.rb +63 -0
  740. data/lib/puppet/provider/exec/shell.rb +27 -0
  741. data/lib/puppet/provider/exec/windows.rb +57 -0
  742. data/lib/puppet/provider/exec.rb +107 -0
  743. data/lib/puppet/provider/file/posix.rb +162 -0
  744. data/lib/puppet/provider/file/windows.rb +151 -0
  745. data/lib/puppet/provider/group/aix.rb +101 -0
  746. data/lib/puppet/provider/group/directoryservice.rb +24 -0
  747. data/lib/puppet/provider/group/groupadd.rb +180 -0
  748. data/lib/puppet/provider/group/ldap.rb +51 -0
  749. data/lib/puppet/provider/group/pw.rb +52 -0
  750. data/lib/puppet/provider/group/windows_adsi.rb +116 -0
  751. data/lib/puppet/provider/ldap.rb +143 -0
  752. data/lib/puppet/provider/nameservice/directoryservice.rb +522 -0
  753. data/lib/puppet/provider/nameservice/objectadd.rb +22 -0
  754. data/lib/puppet/provider/nameservice/pw.rb +21 -0
  755. data/lib/puppet/provider/nameservice.rb +297 -0
  756. data/lib/puppet/provider/network_device.rb +74 -0
  757. data/lib/puppet/provider/package/aix.rb +171 -0
  758. data/lib/puppet/provider/package/appdmg.rb +113 -0
  759. data/lib/puppet/provider/package/apple.rb +49 -0
  760. data/lib/puppet/provider/package/apt.rb +265 -0
  761. data/lib/puppet/provider/package/aptitude.rb +35 -0
  762. data/lib/puppet/provider/package/aptrpm.rb +87 -0
  763. data/lib/puppet/provider/package/blastwave.rb +109 -0
  764. data/lib/puppet/provider/package/dnf.rb +57 -0
  765. data/lib/puppet/provider/package/dnfmodule.rb +143 -0
  766. data/lib/puppet/provider/package/dpkg.rb +191 -0
  767. data/lib/puppet/provider/package/fink.rb +99 -0
  768. data/lib/puppet/provider/package/freebsd.rb +49 -0
  769. data/lib/puppet/provider/package/gem.rb +296 -0
  770. data/lib/puppet/provider/package/hpux.rb +46 -0
  771. data/lib/puppet/provider/package/macports.rb +112 -0
  772. data/lib/puppet/provider/package/nim.rb +290 -0
  773. data/lib/puppet/provider/package/openbsd.rb +263 -0
  774. data/lib/puppet/provider/package/opkg.rb +85 -0
  775. data/lib/puppet/provider/package/pacman.rb +270 -0
  776. data/lib/puppet/provider/package/pip.rb +347 -0
  777. data/lib/puppet/provider/package/pip2.rb +18 -0
  778. data/lib/puppet/provider/package/pip3.rb +18 -0
  779. data/lib/puppet/provider/package/pkg.rb +300 -0
  780. data/lib/puppet/provider/package/pkgdmg.rb +159 -0
  781. data/lib/puppet/provider/package/pkgin.rb +88 -0
  782. data/lib/puppet/provider/package/pkgng.rb +178 -0
  783. data/lib/puppet/provider/package/pkgutil.rb +186 -0
  784. data/lib/puppet/provider/package/portage.rb +314 -0
  785. data/lib/puppet/provider/package/ports.rb +94 -0
  786. data/lib/puppet/provider/package/portupgrade.rb +233 -0
  787. data/lib/puppet/provider/package/puppet_gem.rb +25 -0
  788. data/lib/puppet/provider/package/puppetserver_gem.rb +174 -0
  789. data/lib/puppet/provider/package/rpm.rb +255 -0
  790. data/lib/puppet/provider/package/rug.rb +51 -0
  791. data/lib/puppet/provider/package/sun.rb +137 -0
  792. data/lib/puppet/provider/package/sunfreeware.rb +11 -0
  793. data/lib/puppet/provider/package/tdnf.rb +35 -0
  794. data/lib/puppet/provider/package/up2date.rb +40 -0
  795. data/lib/puppet/provider/package/urpmi.rb +57 -0
  796. data/lib/puppet/provider/package/windows/exe_package.rb +108 -0
  797. data/lib/puppet/provider/package/windows/msi_package.rb +72 -0
  798. data/lib/puppet/provider/package/windows/package.rb +113 -0
  799. data/lib/puppet/provider/package/windows.rb +131 -0
  800. data/lib/puppet/provider/package/xbps.rb +127 -0
  801. data/lib/puppet/provider/package/yum.rb +390 -0
  802. data/lib/puppet/provider/package/zypper.rb +206 -0
  803. data/lib/puppet/provider/package.rb +61 -0
  804. data/lib/puppet/provider/package_targetable.rb +71 -0
  805. data/lib/puppet/provider/parsedfile.rb +494 -0
  806. data/lib/puppet/provider/service/base.rb +135 -0
  807. data/lib/puppet/provider/service/bsd.rb +53 -0
  808. data/lib/puppet/provider/service/daemontools.rb +196 -0
  809. data/lib/puppet/provider/service/debian.rb +77 -0
  810. data/lib/puppet/provider/service/freebsd.rb +141 -0
  811. data/lib/puppet/provider/service/gentoo.rb +47 -0
  812. data/lib/puppet/provider/service/init.rb +194 -0
  813. data/lib/puppet/provider/service/launchd.rb +391 -0
  814. data/lib/puppet/provider/service/openbsd.rb +101 -0
  815. data/lib/puppet/provider/service/openrc.rb +72 -0
  816. data/lib/puppet/provider/service/openwrt.rb +37 -0
  817. data/lib/puppet/provider/service/rcng.rb +53 -0
  818. data/lib/puppet/provider/service/redhat.rb +75 -0
  819. data/lib/puppet/provider/service/runit.rb +107 -0
  820. data/lib/puppet/provider/service/service.rb +67 -0
  821. data/lib/puppet/provider/service/smf.rb +322 -0
  822. data/lib/puppet/provider/service/src.rb +147 -0
  823. data/lib/puppet/provider/service/systemd.rb +232 -0
  824. data/lib/puppet/provider/service/upstart.rb +385 -0
  825. data/lib/puppet/provider/service/windows.rb +179 -0
  826. data/lib/puppet/provider/user/aix.rb +365 -0
  827. data/lib/puppet/provider/user/directoryservice.rb +687 -0
  828. data/lib/puppet/provider/user/hpux.rb +93 -0
  829. data/lib/puppet/provider/user/ldap.rb +135 -0
  830. data/lib/puppet/provider/user/openbsd.rb +79 -0
  831. data/lib/puppet/provider/user/pw.rb +109 -0
  832. data/lib/puppet/provider/user/user_role_add.rb +243 -0
  833. data/lib/puppet/provider/user/useradd.rb +417 -0
  834. data/lib/puppet/provider/user/windows_adsi.rb +176 -0
  835. data/lib/puppet/provider.rb +613 -0
  836. data/lib/puppet/reference/configuration.rb +105 -0
  837. data/lib/puppet/reference/function.rb +19 -0
  838. data/lib/puppet/reference/indirection.rb +76 -0
  839. data/lib/puppet/reference/metaparameter.rb +35 -0
  840. data/lib/puppet/reference/providers.rb +119 -0
  841. data/lib/puppet/reference/report.rb +22 -0
  842. data/lib/puppet/reference/type.rb +111 -0
  843. data/lib/puppet/relationship.rb +85 -0
  844. data/lib/puppet/reports/http.rb +45 -0
  845. data/lib/puppet/reports/log.rb +15 -0
  846. data/lib/puppet/reports/store.rb +71 -0
  847. data/lib/puppet/reports.rb +95 -0
  848. data/lib/puppet/resource/catalog.rb +655 -0
  849. data/lib/puppet/resource/status.rb +231 -0
  850. data/lib/puppet/resource/type.rb +449 -0
  851. data/lib/puppet/resource/type_collection.rb +235 -0
  852. data/lib/puppet/resource.rb +673 -0
  853. data/lib/puppet/runtime.rb +67 -0
  854. data/lib/puppet/scheduler/job.rb +55 -0
  855. data/lib/puppet/scheduler/scheduler.rb +46 -0
  856. data/lib/puppet/scheduler/splay_job.rb +45 -0
  857. data/lib/puppet/scheduler/timer.rb +15 -0
  858. data/lib/puppet/scheduler.rb +18 -0
  859. data/lib/puppet/settings/alias_setting.rb +37 -0
  860. data/lib/puppet/settings/array_setting.rb +18 -0
  861. data/lib/puppet/settings/autosign_setting.rb +23 -0
  862. data/lib/puppet/settings/base_setting.rb +228 -0
  863. data/lib/puppet/settings/boolean_setting.rb +34 -0
  864. data/lib/puppet/settings/certificate_revocation_setting.rb +22 -0
  865. data/lib/puppet/settings/config_file.rb +148 -0
  866. data/lib/puppet/settings/directory_setting.rb +20 -0
  867. data/lib/puppet/settings/duration_setting.rb +33 -0
  868. data/lib/puppet/settings/enum_setting.rb +18 -0
  869. data/lib/puppet/settings/environment_conf.rb +228 -0
  870. data/lib/puppet/settings/errors.rb +14 -0
  871. data/lib/puppet/settings/file_or_directory_setting.rb +37 -0
  872. data/lib/puppet/settings/file_setting.rb +232 -0
  873. data/lib/puppet/settings/http_extra_headers_setting.rb +26 -0
  874. data/lib/puppet/settings/ini_file.rb +228 -0
  875. data/lib/puppet/settings/integer_setting.rb +19 -0
  876. data/lib/puppet/settings/path_setting.rb +10 -0
  877. data/lib/puppet/settings/port_setting.rb +17 -0
  878. data/lib/puppet/settings/priority_setting.rb +44 -0
  879. data/lib/puppet/settings/server_list_setting.rb +30 -0
  880. data/lib/puppet/settings/string_setting.rb +11 -0
  881. data/lib/puppet/settings/symbolic_enum_setting.rb +19 -0
  882. data/lib/puppet/settings/terminus_setting.rb +16 -0
  883. data/lib/puppet/settings/ttl_setting.rb +53 -0
  884. data/lib/puppet/settings/value_translator.rb +16 -0
  885. data/lib/puppet/settings.rb +1650 -0
  886. data/lib/puppet/ssl/base.rb +152 -0
  887. data/lib/puppet/ssl/certificate.rb +98 -0
  888. data/lib/puppet/ssl/certificate_request.rb +320 -0
  889. data/lib/puppet/ssl/certificate_request_attributes.rb +40 -0
  890. data/lib/puppet/ssl/certificate_signer.rb +39 -0
  891. data/lib/puppet/ssl/digest.rb +22 -0
  892. data/lib/puppet/ssl/error.rb +29 -0
  893. data/lib/puppet/ssl/oids.rb +199 -0
  894. data/lib/puppet/ssl/openssl_loader.rb +26 -0
  895. data/lib/puppet/ssl/ssl_context.rb +27 -0
  896. data/lib/puppet/ssl/ssl_provider.rb +354 -0
  897. data/lib/puppet/ssl/state_machine.rb +605 -0
  898. data/lib/puppet/ssl/verifier.rb +143 -0
  899. data/lib/puppet/ssl.rb +25 -0
  900. data/lib/puppet/syntax_checkers/base64.rb +42 -0
  901. data/lib/puppet/syntax_checkers/epp.rb +35 -0
  902. data/lib/puppet/syntax_checkers/json.rb +35 -0
  903. data/lib/puppet/syntax_checkers/pp.rb +35 -0
  904. data/lib/puppet/syntax_checkers.rb +5 -0
  905. data/lib/puppet/test/test_helper.rb +251 -0
  906. data/lib/puppet/thread_local.rb +6 -0
  907. data/lib/puppet/transaction/additional_resource_generator.rb +225 -0
  908. data/lib/puppet/transaction/event.rb +171 -0
  909. data/lib/puppet/transaction/event_manager.rb +180 -0
  910. data/lib/puppet/transaction/persistence.rb +119 -0
  911. data/lib/puppet/transaction/report.rb +511 -0
  912. data/lib/puppet/transaction/resource_harness.rb +331 -0
  913. data/lib/puppet/transaction.rb +493 -0
  914. data/lib/puppet/trusted_external.rb +46 -0
  915. data/lib/puppet/type/component.rb +96 -0
  916. data/lib/puppet/type/exec.rb +730 -0
  917. data/lib/puppet/type/file/checksum.rb +54 -0
  918. data/lib/puppet/type/file/checksum_value.rb +56 -0
  919. data/lib/puppet/type/file/content.rb +180 -0
  920. data/lib/puppet/type/file/ctime.rb +22 -0
  921. data/lib/puppet/type/file/data_sync.rb +101 -0
  922. data/lib/puppet/type/file/ensure.rb +194 -0
  923. data/lib/puppet/type/file/group.rb +50 -0
  924. data/lib/puppet/type/file/mode.rb +192 -0
  925. data/lib/puppet/type/file/mtime.rb +21 -0
  926. data/lib/puppet/type/file/owner.rb +52 -0
  927. data/lib/puppet/type/file/selcontext.rb +143 -0
  928. data/lib/puppet/type/file/source.rb +380 -0
  929. data/lib/puppet/type/file/target.rb +86 -0
  930. data/lib/puppet/type/file/type.rb +21 -0
  931. data/lib/puppet/type/file.rb +1139 -0
  932. data/lib/puppet/type/filebucket.rb +123 -0
  933. data/lib/puppet/type/group.rb +238 -0
  934. data/lib/puppet/type/notify.rb +48 -0
  935. data/lib/puppet/type/package.rb +715 -0
  936. data/lib/puppet/type/resources.rb +192 -0
  937. data/lib/puppet/type/schedule.rb +441 -0
  938. data/lib/puppet/type/service.rb +310 -0
  939. data/lib/puppet/type/stage.rb +29 -0
  940. data/lib/puppet/type/tidy.rb +382 -0
  941. data/lib/puppet/type/user.rb +865 -0
  942. data/lib/puppet/type/whit.rb +35 -0
  943. data/lib/puppet/type.rb +2629 -0
  944. data/lib/puppet/util/at_fork/noop.rb +20 -0
  945. data/lib/puppet/util/at_fork/solaris.rb +158 -0
  946. data/lib/puppet/util/at_fork.rb +37 -0
  947. data/lib/puppet/util/autoload.rb +221 -0
  948. data/lib/puppet/util/backups.rb +88 -0
  949. data/lib/puppet/util/character_encoding.rb +83 -0
  950. data/lib/puppet/util/checksums.rb +380 -0
  951. data/lib/puppet/util/classgen.rb +223 -0
  952. data/lib/puppet/util/colors.rb +102 -0
  953. data/lib/puppet/util/command_line/puppet_option_parser.rb +89 -0
  954. data/lib/puppet/util/command_line/trollop.rb +847 -0
  955. data/lib/puppet/util/command_line.rb +198 -0
  956. data/lib/puppet/util/constant_inflector.rb +25 -0
  957. data/lib/puppet/util/diff.rb +80 -0
  958. data/lib/puppet/util/docs.rb +132 -0
  959. data/lib/puppet/util/errors.rb +161 -0
  960. data/lib/puppet/util/execution.rb +446 -0
  961. data/lib/puppet/util/execution_stub.rb +28 -0
  962. data/lib/puppet/util/feature.rb +129 -0
  963. data/lib/puppet/util/file_watcher.rb +31 -0
  964. data/lib/puppet/util/fileparsing.rb +404 -0
  965. data/lib/puppet/util/filetype.rb +358 -0
  966. data/lib/puppet/util/http_proxy.rb +6 -0
  967. data/lib/puppet/util/inifile.rb +335 -0
  968. data/lib/puppet/util/instance_loader.rb +69 -0
  969. data/lib/puppet/util/json.rb +94 -0
  970. data/lib/puppet/util/json_lockfile.rb +47 -0
  971. data/lib/puppet/util/ldap/connection.rb +75 -0
  972. data/lib/puppet/util/ldap/generator.rb +44 -0
  973. data/lib/puppet/util/ldap/manager.rb +283 -0
  974. data/lib/puppet/util/ldap.rb +4 -0
  975. data/lib/puppet/util/libuser.conf +15 -0
  976. data/lib/puppet/util/libuser.rb +13 -0
  977. data/lib/puppet/util/limits.rb +14 -0
  978. data/lib/puppet/util/lockfile.rb +66 -0
  979. data/lib/puppet/util/log/destination.rb +50 -0
  980. data/lib/puppet/util/log/destinations.rb +253 -0
  981. data/lib/puppet/util/log.rb +436 -0
  982. data/lib/puppet/util/logging.rb +304 -0
  983. data/lib/puppet/util/metaid.rb +22 -0
  984. data/lib/puppet/util/metric.rb +68 -0
  985. data/lib/puppet/util/monkey_patches.rb +114 -0
  986. data/lib/puppet/util/multi_match.rb +55 -0
  987. data/lib/puppet/util/network_device/base.rb +24 -0
  988. data/lib/puppet/util/network_device/config.rb +105 -0
  989. data/lib/puppet/util/network_device/transport/base.rb +26 -0
  990. data/lib/puppet/util/network_device/transport.rb +7 -0
  991. data/lib/puppet/util/network_device.rb +19 -0
  992. data/lib/puppet/util/package/version/debian.rb +177 -0
  993. data/lib/puppet/util/package/version/gem.rb +18 -0
  994. data/lib/puppet/util/package/version/pip.rb +173 -0
  995. data/lib/puppet/util/package/version/range/eq.rb +17 -0
  996. data/lib/puppet/util/package/version/range/gt.rb +17 -0
  997. data/lib/puppet/util/package/version/range/gt_eq.rb +17 -0
  998. data/lib/puppet/util/package/version/range/lt.rb +17 -0
  999. data/lib/puppet/util/package/version/range/lt_eq.rb +17 -0
  1000. data/lib/puppet/util/package/version/range/min_max.rb +26 -0
  1001. data/lib/puppet/util/package/version/range/simple.rb +13 -0
  1002. data/lib/puppet/util/package/version/range.rb +57 -0
  1003. data/lib/puppet/util/package/version/rpm.rb +75 -0
  1004. data/lib/puppet/util/package.rb +43 -0
  1005. data/lib/puppet/util/pidlock.rb +103 -0
  1006. data/lib/puppet/util/platform.rb +72 -0
  1007. data/lib/puppet/util/plist.rb +161 -0
  1008. data/lib/puppet/util/posix.rb +206 -0
  1009. data/lib/puppet/util/profiler/aggregate.rb +82 -0
  1010. data/lib/puppet/util/profiler/around_profiler.rb +68 -0
  1011. data/lib/puppet/util/profiler/logging.rb +50 -0
  1012. data/lib/puppet/util/profiler/object_counts.rb +19 -0
  1013. data/lib/puppet/util/profiler/wall_clock.rb +36 -0
  1014. data/lib/puppet/util/profiler.rb +55 -0
  1015. data/lib/puppet/util/provider_features.rb +183 -0
  1016. data/lib/puppet/util/psych_support.rb +32 -0
  1017. data/lib/puppet/util/rdoc/code_objects.rb +293 -0
  1018. data/lib/puppet/util/rdoc/generators/puppet_generator.rb +902 -0
  1019. data/lib/puppet/util/rdoc/generators/template/puppet/puppet.rb +1068 -0
  1020. data/lib/puppet/util/rdoc/parser/puppet_parser_core.rb +262 -0
  1021. data/lib/puppet/util/rdoc/parser/puppet_parser_rdoc2.rb +16 -0
  1022. data/lib/puppet/util/rdoc/parser.rb +14 -0
  1023. data/lib/puppet/util/rdoc.rb +54 -0
  1024. data/lib/puppet/util/reference.rb +94 -0
  1025. data/lib/puppet/util/resource_template.rb +63 -0
  1026. data/lib/puppet/util/retry_action.rb +47 -0
  1027. data/lib/puppet/util/rpm_compare.rb +196 -0
  1028. data/lib/puppet/util/rubygems.rb +67 -0
  1029. data/lib/puppet/util/run_mode.rb +164 -0
  1030. data/lib/puppet/util/selinux.rb +331 -0
  1031. data/lib/puppet/util/skip_tags.rb +15 -0
  1032. data/lib/puppet/util/splayer.rb +20 -0
  1033. data/lib/puppet/util/storage.rb +100 -0
  1034. data/lib/puppet/util/suidmanager.rb +167 -0
  1035. data/lib/puppet/util/symbolic_file_mode.rb +156 -0
  1036. data/lib/puppet/util/tag_set.rb +29 -0
  1037. data/lib/puppet/util/tagging.rb +131 -0
  1038. data/lib/puppet/util/terminal.rb +18 -0
  1039. data/lib/puppet/util/user_attr.rb +23 -0
  1040. data/lib/puppet/util/warnings.rb +35 -0
  1041. data/lib/puppet/util/watched_file.rb +40 -0
  1042. data/lib/puppet/util/watcher/change_watcher.rb +35 -0
  1043. data/lib/puppet/util/watcher/periodic_watcher.rb +38 -0
  1044. data/lib/puppet/util/watcher/timer.rb +21 -0
  1045. data/lib/puppet/util/watcher.rb +17 -0
  1046. data/lib/puppet/util/windows/access_control_entry.rb +86 -0
  1047. data/lib/puppet/util/windows/access_control_list.rb +116 -0
  1048. data/lib/puppet/util/windows/adsi.rb +662 -0
  1049. data/lib/puppet/util/windows/com.rb +228 -0
  1050. data/lib/puppet/util/windows/daemon.rb +340 -0
  1051. data/lib/puppet/util/windows/error.rb +86 -0
  1052. data/lib/puppet/util/windows/eventlog.rb +191 -0
  1053. data/lib/puppet/util/windows/file.rb +359 -0
  1054. data/lib/puppet/util/windows/monkey_patches/process.rb +413 -0
  1055. data/lib/puppet/util/windows/principal.rb +204 -0
  1056. data/lib/puppet/util/windows/process.rb +360 -0
  1057. data/lib/puppet/util/windows/registry.rb +443 -0
  1058. data/lib/puppet/util/windows/root_certs.rb +110 -0
  1059. data/lib/puppet/util/windows/security.rb +909 -0
  1060. data/lib/puppet/util/windows/security_descriptor.rb +64 -0
  1061. data/lib/puppet/util/windows/service.rb +708 -0
  1062. data/lib/puppet/util/windows/sid.rb +291 -0
  1063. data/lib/puppet/util/windows/string.rb +17 -0
  1064. data/lib/puppet/util/windows/user.rb +551 -0
  1065. data/lib/puppet/util/windows.rb +58 -0
  1066. data/lib/puppet/util/yaml.rb +67 -0
  1067. data/lib/puppet/util.rb +759 -0
  1068. data/lib/puppet/vendor/require_vendored.rb +4 -0
  1069. data/lib/puppet/vendor.rb +59 -0
  1070. data/lib/puppet/version.rb +98 -0
  1071. data/lib/puppet/x509/cert_provider.rb +405 -0
  1072. data/lib/puppet/x509/pem_store.rb +57 -0
  1073. data/lib/puppet/x509.rb +13 -0
  1074. data/lib/puppet.rb +348 -0
  1075. data/lib/puppet_pal.rb +10 -0
  1076. data/lib/puppet_x.rb +16 -0
  1077. data/locales/config.yaml +29 -0
  1078. data/locales/en/puppet.po +19 -0
  1079. data/locales/puppet.pot +9738 -0
  1080. data/man/man5/puppet.conf.5 +1407 -0
  1081. data/man/man8/puppet-agent.8 +135 -0
  1082. data/man/man8/puppet-apply.8 +67 -0
  1083. data/man/man8/puppet-catalog.8 +194 -0
  1084. data/man/man8/puppet-config.8 +103 -0
  1085. data/man/man8/puppet-describe.8 +35 -0
  1086. data/man/man8/puppet-device.8 +83 -0
  1087. data/man/man8/puppet-doc.8 +30 -0
  1088. data/man/man8/puppet-epp.8 +232 -0
  1089. data/man/man8/puppet-facts.8 +156 -0
  1090. data/man/man8/puppet-filebucket.8 +134 -0
  1091. data/man/man8/puppet-generate.8 +54 -0
  1092. data/man/man8/puppet-help.8 +46 -0
  1093. data/man/man8/puppet-lookup.8 +71 -0
  1094. data/man/man8/puppet-module.8 +220 -0
  1095. data/man/man8/puppet-node.8 +142 -0
  1096. data/man/man8/puppet-parser.8 +87 -0
  1097. data/man/man8/puppet-plugin.8 +50 -0
  1098. data/man/man8/puppet-report.8 +84 -0
  1099. data/man/man8/puppet-resource.8 +63 -0
  1100. data/man/man8/puppet-script.8 +48 -0
  1101. data/man/man8/puppet-ssl.8 +45 -0
  1102. data/man/man8/puppet.8 +98 -0
  1103. data/tasks/tag.rake +34 -0
  1104. metadata +1336 -0
@@ -0,0 +1,2629 @@
1
+ # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../puppet'
5
+ require_relative '../puppet/util/log'
6
+ require_relative '../puppet/util/metric'
7
+ require_relative '../puppet/property'
8
+ require_relative '../puppet/parameter'
9
+ require_relative '../puppet/util'
10
+ require_relative '../puppet/util/autoload'
11
+ require_relative '../puppet/metatype/manager'
12
+ require_relative '../puppet/util/errors'
13
+ require_relative '../puppet/util/logging'
14
+ require_relative '../puppet/util/tagging'
15
+ require_relative '../puppet/concurrent/lock'
16
+
17
+ # see the bottom of the file for the rest of the inclusions
18
+
19
+ module Puppet
20
+ # The base class for all Puppet types.
21
+ #
22
+ # A type describes:
23
+ #--
24
+ # * **Attributes** - properties, parameters, and meta-parameters are different types of attributes of a type.
25
+ # * **Properties** - these are the properties of the managed resource (attributes of the entity being managed; like
26
+ # a file's owner, group and mode). A property describes two states; the 'is' (current state) and the 'should' (wanted
27
+ # state).
28
+ # * **Ensurable** - a set of traits that control the lifecycle (create, remove, etc.) of a managed entity.
29
+ # There is a default set of operations associated with being _ensurable_, but this can be changed.
30
+ # * **Name/Identity** - one property is the name/identity of a resource, the _namevar_ that uniquely identifies
31
+ # one instance of a type from all others.
32
+ # * **Parameters** - additional attributes of the type (that does not directly related to an instance of the managed
33
+ # resource; if an operation is recursive or not, where to look for things, etc.). A Parameter (in contrast to Property)
34
+ # has one current value where a Property has two (current-state and wanted-state).
35
+ # * **Meta-Parameters** - parameters that are available across all types. A meta-parameter typically has
36
+ # additional semantics; like the `require` meta-parameter. A new type typically does not add new meta-parameters,
37
+ # but you need to be aware of their existence so you do not inadvertently shadow an existing meta-parameters.
38
+ # * **Parent** - a type can have a super type (that it inherits from).
39
+ # * **Validation** - If not just a basic data type, or an enumeration of symbolic values, it is possible to provide
40
+ # validation logic for a type, properties and parameters.
41
+ # * **Munging** - munging/unmunging is the process of turning a value in external representation (as used
42
+ # by a provider) into an internal representation and vice versa. A Type supports adding custom logic for these.
43
+ # * **Auto Requirements** - a type can specify automatic relationships to resources to ensure that if they are being
44
+ # managed, they will be processed before this type.
45
+ # * **Providers** - a provider is an implementation of a type's behavior - the management of a resource in the
46
+ # system being managed. A provider is often platform specific and is selected at runtime based on
47
+ # criteria/predicates specified in the configured providers. See {Puppet::Provider} for details.
48
+ # * **Device Support** - A type has some support for being applied to a device; i.e. something that is managed
49
+ # by running logic external to the device itself. There are several methods that deals with type
50
+ # applicability for these special cases such as {apply_to_device}.
51
+ #
52
+ # Additional Concepts:
53
+ # --
54
+ # * **Resource-type** - A _resource type_ is a term used to denote the type of a resource; internally a resource
55
+ # is really an instance of a Ruby class i.e. {Puppet::Resource} which defines its behavior as "resource data".
56
+ # Conceptually however, a resource is an instance of a subclass of Type (e.g. File), where such a class describes
57
+ # its interface (what can be said/what is known about a resource of this type),
58
+ # * **Managed Entity** - This is not a term in general use, but is used here when there is a need to make
59
+ # a distinction between a resource (a description of what/how something should be managed), and what it is
60
+ # managing (a file in the file system). The term _managed entity_ is a reference to the "file in the file system"
61
+ # * **Isomorphism** - the quality of being _isomorphic_ means that two resource instances with the same name
62
+ # refers to the same managed entity. Or put differently; _an isomorphic name is the identity of a resource_.
63
+ # As an example, `exec` resources (that executes some command) have the command (i.e. the command line string) as
64
+ # their name, and these resources are said to be non-isomorphic.
65
+ #
66
+ # @note The Type class deals with multiple concerns; some methods provide an internal DSL for convenient definition
67
+ # of types, other methods deal with various aspects while running; wiring up a resource (expressed in Puppet DSL)
68
+ # with its _resource type_ (i.e. an instance of Type) to enable validation, transformation of values
69
+ # (munge/unmunge), etc. Lastly, Type is also responsible for dealing with Providers; the concrete implementations
70
+ # of the behavior that constitutes how a particular Type behaves on a particular type of system (e.g. how
71
+ # commands are executed on a flavor of Linux, on Windows, etc.). This means that as you are reading through the
72
+ # documentation of this class, you will be switching between these concepts, as well as switching between
73
+ # the conceptual level "a resource is an instance of a resource-type" and the actual implementation classes
74
+ # (Type, Resource, Provider, and various utility and helper classes).
75
+ #
76
+ # @api public
77
+ #
78
+ #
79
+ class Type
80
+ extend Puppet::CompilableResourceType
81
+ include Puppet::Util
82
+ include Puppet::Util::Errors
83
+ include Puppet::Util::Logging
84
+ include Puppet::Util::Tagging
85
+
86
+ # Comparing type instances.
87
+ include Comparable
88
+
89
+ # These variables are used in Metatype::Manager for managing types
90
+ @types = {}
91
+ @manager_lock = Puppet::Concurrent::Lock.new
92
+ extend Puppet::MetaType::Manager
93
+
94
+ # Compares this type against the given _other_ (type) and returns -1, 0, or +1 depending on the order.
95
+ # @param other [Object] the object to compare against (produces nil, if not kind of Type}
96
+ # @return [-1, 0, +1, nil] produces -1 if this type is before the given _other_ type, 0 if equals, and 1 if after.
97
+ # Returns nil, if the given _other_ is not a kind of Type.
98
+ # @see Comparable
99
+ #
100
+ def <=>(other)
101
+ # Order is only maintained against other types, not arbitrary objects.
102
+ # The natural order is based on the reference name used when comparing
103
+ return nil unless other.is_a?(Puppet::CompilableResourceType) || other.class.is_a?(Puppet::CompilableResourceType)
104
+
105
+ # against other type instances.
106
+ ref <=> other.ref
107
+ end
108
+
109
+ # Code related to resource type attributes.
110
+ class << self
111
+ include Puppet::Util::ClassGen
112
+ include Puppet::Util::Warnings
113
+
114
+ # @return [Array<Puppet::Property>] The list of declared properties for the resource type.
115
+ # The returned lists contains instances if Puppet::Property or its subclasses.
116
+ attr_reader :properties
117
+ end
118
+
119
+ # Returns all the attribute names of the type in the appropriate order.
120
+ # The {key_attributes} come first, then the {provider}, then the {properties}, and finally
121
+ # the {parameters} and {metaparams},
122
+ # all in the order they were specified in the respective files.
123
+ # @return [Array<String>] all type attribute names in a defined order.
124
+ #
125
+ def self.allattrs
126
+ key_attributes | (parameters & [:provider]) | properties.collect(&:name) | parameters | metaparams
127
+ end
128
+
129
+ # Returns the class associated with the given attribute name.
130
+ # @param name [String] the name of the attribute to obtain the class for
131
+ # @return [Class, nil] the class for the given attribute, or nil if the name does not refer to an existing attribute
132
+ #
133
+ def self.attrclass(name)
134
+ @attrclasses ||= {}
135
+
136
+ # We cache the value, since this method gets called such a huge number
137
+ # of times (as in, hundreds of thousands in a given run).
138
+ unless @attrclasses.include?(name)
139
+ @attrclasses[name] = case attrtype(name)
140
+ when :property; @validproperties[name]
141
+ when :meta; @@metaparamhash[name]
142
+ when :param; @paramhash[name]
143
+ end
144
+ end
145
+ @attrclasses[name]
146
+ end
147
+
148
+ # Returns the attribute type (`:property`, `;param`, `:meta`).
149
+ # @comment What type of parameter are we dealing with? Cache the results, because
150
+ # this method gets called so many times.
151
+ # @return [Symbol] a symbol describing the type of attribute (`:property`, `;param`, `:meta`)
152
+ #
153
+ def self.attrtype(attr)
154
+ @attrtypes ||= {}
155
+ unless @attrtypes.include?(attr)
156
+ @attrtypes[attr] = case
157
+ when @validproperties.include?(attr); :property
158
+ when @paramhash.include?(attr); :param
159
+ when @@metaparamhash.include?(attr); :meta
160
+ end
161
+ end
162
+
163
+ @attrtypes[attr]
164
+ end
165
+
166
+ # Provides iteration over meta-parameters.
167
+ # @yieldparam p [Puppet::Parameter] each meta parameter
168
+ # @return [void]
169
+ #
170
+ def self.eachmetaparam
171
+ @@metaparams.each { |p| yield p.name }
172
+ end
173
+
174
+ # Creates a new `ensure` property with configured default values or with configuration by an optional block.
175
+ # This method is a convenience method for creating a property `ensure` with default accepted values.
176
+ # If no block is specified, the new `ensure` property will accept the default symbolic
177
+ # values `:present`, and `:absent` - see {Puppet::Property::Ensure}.
178
+ # If something else is wanted, pass a block and make calls to {Puppet::Property.newvalue} from this block
179
+ # to define each possible value. If a block is passed, the defaults are not automatically added to the set of
180
+ # valid values.
181
+ #
182
+ # @note This method will be automatically called without a block if the type implements the methods
183
+ # specified by {ensurable?}. It is recommended to always call this method and not rely on this automatic
184
+ # specification to clearly state that the type is ensurable.
185
+ #
186
+ # @overload ensurable()
187
+ # @overload ensurable({ ... })
188
+ # @yield [ ] A block evaluated in scope of the new Parameter
189
+ # @yieldreturn [void]
190
+ # @return [void]
191
+ # @dsl type
192
+ # @api public
193
+ #
194
+ def self.ensurable(&block)
195
+ if block_given?
196
+ newproperty(:ensure, :parent => Puppet::Property::Ensure, &block)
197
+ else
198
+ newproperty(:ensure, :parent => Puppet::Property::Ensure) do
199
+ defaultvalues
200
+ end
201
+ end
202
+ end
203
+
204
+ # Returns true if the type implements the default behavior expected by being _ensurable_ "by default".
205
+ # A type is _ensurable_ by default if it responds to `:exists`, `:create`, and `:destroy`.
206
+ # If a type implements these methods and have not already specified that it is _ensurable_, it will be
207
+ # made so with the defaults specified in {ensurable}.
208
+ # @return [Boolean] whether the type is _ensurable_ or not.
209
+ #
210
+ def self.ensurable?
211
+ # If the class has all three of these methods defined, then it's
212
+ # ensurable.
213
+ [:exists?, :create, :destroy].all? { |method|
214
+ public_method_defined?(method)
215
+ }
216
+ end
217
+
218
+ # @comment These `apply_to` methods are horrible. They should really be implemented
219
+ # as part of the usual system of constraints that apply to a type and
220
+ # provider pair, but were implemented as a separate shadow system.
221
+ #
222
+ # @comment We should rip them out in favour of a real constraint pattern around the
223
+ # target device - whatever that looks like - and not have this additional
224
+ # magic here. --daniel 2012-03-08
225
+ #
226
+ # Makes this type applicable to `:device`.
227
+ # @return [Symbol] Returns `:device`
228
+ # @api private
229
+ #
230
+ def self.apply_to_device
231
+ @apply_to = :device
232
+ end
233
+
234
+ # Makes this type applicable to `:host`.
235
+ # @return [Symbol] Returns `:host`
236
+ # @api private
237
+ #
238
+ def self.apply_to_host
239
+ @apply_to = :host
240
+ end
241
+
242
+ # Makes this type applicable to `:both` (i.e. `:host` and `:device`).
243
+ # @return [Symbol] Returns `:both`
244
+ # @api private
245
+ #
246
+ def self.apply_to_all
247
+ @apply_to = :both
248
+ end
249
+
250
+ # Makes this type apply to `:host` if not already applied to something else.
251
+ # @return [Symbol] a `:device`, `:host`, or `:both` enumeration
252
+ # @api private
253
+ def self.apply_to
254
+ @apply_to ||= :host
255
+ end
256
+
257
+ # Returns true if this type is applicable to the given target.
258
+ # @param target [Symbol] should be :device, :host or :target, if anything else, :host is enforced
259
+ # @return [Boolean] true
260
+ # @api private
261
+ #
262
+ def self.can_apply_to(target)
263
+ [target == :device ? :device : :host, :both].include?(apply_to)
264
+ end
265
+
266
+ # Processes the options for a named parameter.
267
+ # @param name [String] the name of a parameter
268
+ # @param options [Hash] a hash of options
269
+ # @option options [Boolean] :boolean if option set to true, an access method on the form _name_? is added for the param
270
+ # @return [void]
271
+ #
272
+ def self.handle_param_options(name, options)
273
+ # If it's a boolean parameter, create a method to test the value easily
274
+ if options[:boolean]
275
+ define_method(name.to_s + "?") do
276
+ val = self[name]
277
+ if val == :true or val == true
278
+ true
279
+ end
280
+ end
281
+ end
282
+ end
283
+
284
+ # Is the given parameter a meta-parameter?
285
+ # @return [Boolean] true if the given parameter is a meta-parameter.
286
+ #
287
+ def self.metaparam?(param)
288
+ @@metaparamhash.include?(param.intern)
289
+ end
290
+
291
+ # Returns the meta-parameter class associated with the given meta-parameter name.
292
+ # Accepts a `nil` name, and return nil.
293
+ # @param name [String, nil] the name of a meta-parameter
294
+ # @return [Class,nil] the class for the given meta-parameter, or `nil` if no such meta-parameter exists, (or if
295
+ # the given meta-parameter name is `nil`.
296
+ #
297
+ def self.metaparamclass(name)
298
+ return nil if name.nil?
299
+
300
+ @@metaparamhash[name.intern]
301
+ end
302
+
303
+ # Returns all meta-parameter names.
304
+ # @return [Array<String>] all meta-parameter names
305
+ #
306
+ def self.metaparams
307
+ @@metaparams.collect(&:name)
308
+ end
309
+
310
+ # Returns the documentation for a given meta-parameter of this type.
311
+ # @param metaparam [Puppet::Parameter] the meta-parameter to get documentation for.
312
+ # @return [String] the documentation associated with the given meta-parameter, or nil of no such documentation
313
+ # exists.
314
+ # @raise if the given metaparam is not a meta-parameter in this type
315
+ #
316
+ def self.metaparamdoc(metaparam)
317
+ @@metaparamhash[metaparam].doc
318
+ end
319
+
320
+ # Creates a new meta-parameter.
321
+ # This creates a new meta-parameter that is added to this and all inheriting types.
322
+ # @param name [Symbol] the name of the parameter
323
+ # @param options [Hash] a hash with options.
324
+ # @option options [Class<inherits Puppet::Parameter>] :parent (Puppet::Parameter) the super class of this parameter
325
+ # @option options [Hash{String => Object}] :attributes a hash that is applied to the generated class
326
+ # by calling setter methods corresponding to this hash's keys/value pairs. This is done before the given
327
+ # block is evaluated.
328
+ # @option options [Boolean] :boolean (false) specifies if this is a boolean parameter
329
+ # @option options [Boolean] :namevar (false) specifies if this parameter is the namevar
330
+ # @option options [Symbol, Array<Symbol>] :required_features specifies required provider features by name
331
+ # @return [Class<inherits Puppet::Parameter>] the created parameter
332
+ # @yield [ ] a required block that is evaluated in the scope of the new meta-parameter
333
+ # @api public
334
+ # @dsl type
335
+ # @todo Verify that this description is ok
336
+ #
337
+ def self.newmetaparam(name, options = {}, &block)
338
+ @@metaparams ||= []
339
+ @@metaparamhash ||= {}
340
+ name = name.intern
341
+
342
+ param = genclass(
343
+ name,
344
+ :parent => options[:parent] || Puppet::Parameter,
345
+ :prefix => "MetaParam",
346
+ :hash => @@metaparamhash,
347
+ :array => @@metaparams,
348
+ :attributes => options[:attributes],
349
+ &block
350
+ )
351
+
352
+ # Grr.
353
+ param.required_features = options[:required_features] if options[:required_features]
354
+
355
+ handle_param_options(name, options)
356
+
357
+ param.metaparam = true
358
+
359
+ param
360
+ end
361
+
362
+ # Copies all of a resource's metaparameters (except `alias`) to a generated child resource
363
+ # @param parameters [Hash] of a resource's parameters
364
+ # @return [Void]
365
+ def copy_metaparams(parameters)
366
+ parameters.each do |name, param|
367
+ self[name] = param.value if param.metaparam? && name != :alias
368
+ end
369
+ nil
370
+ end
371
+
372
+ # Returns the list of parameters that comprise the composite key / "uniqueness key".
373
+ # All parameters that return true from #isnamevar? or is named `:name` are included in the returned result.
374
+ # @see uniqueness_key
375
+ # @return [Array<Puppet::Parameter>] WARNING: this return type is uncertain
376
+ def self.key_attribute_parameters
377
+ @key_attribute_parameters ||= (
378
+ @parameters.find_all { |param|
379
+ param.isnamevar? or param.name == :name
380
+ }
381
+ )
382
+ end
383
+
384
+ # Returns cached {key_attribute_parameters} names.
385
+ # Key attributes are properties and parameters that comprise a composite key
386
+ # or "uniqueness key".
387
+ # @return [Array<String>] cached key_attribute names
388
+ #
389
+ def self.key_attributes
390
+ # This is a cache miss around 0.05 percent of the time. --daniel 2012-07-17
391
+ # rubocop:disable Naming/MemoizedInstanceVariableName
392
+ @key_attributes_cache ||= key_attribute_parameters.collect(&:name)
393
+ # rubocop:enable Naming/MemoizedInstanceVariableName
394
+ end
395
+
396
+ # Returns any parameters that should be included by default in puppet resource's output
397
+ # @return [Array<Symbol>] the parameters to include
398
+ def self.parameters_to_include
399
+ []
400
+ end
401
+
402
+ # Returns a mapping from the title string to setting of attribute values.
403
+ # This default implementation provides a mapping of title to the one and only _namevar_ present
404
+ # in the type's definition.
405
+ # @note Advanced: some logic requires this mapping to be done differently, using a different
406
+ # validation/pattern, breaking up the title
407
+ # into several parts assigning each to an individual attribute, or even use a composite identity where
408
+ # all namevars are seen as part of the unique identity (such computation is done by the {#uniqueness} method.
409
+ # These advanced options are rarely used (only one of the built in puppet types use this, and then only
410
+ # a small part of the available functionality), and the support for these advanced mappings is not
411
+ # implemented in a straight forward way. For these reasons, this method has been marked as private).
412
+ #
413
+ # @raise [Puppet::DevError] if there is no title pattern and there are two or more key attributes
414
+ # @return [Array<Array<Regexp, Array<Array <Symbol, Proc>>>>, nil] a structure with a regexp and the first key_attribute ???
415
+ # @comment This wonderful piece of logic creates a structure used by Resource.parse_title which
416
+ # has the capability to assign parts of the title to one or more attributes; It looks like an implementation
417
+ # of a composite identity key (all parts of the key_attributes array are in the key). This can also
418
+ # be seen in the method uniqueness_key.
419
+ # The implementation in this method simply assigns the title to the one and only namevar (which is name
420
+ # or a variable marked as namevar).
421
+ # If there are multiple namevars (any in addition to :name?) then this method MUST be implemented
422
+ # as it raises an exception if there is more than 1. Note that in puppet, it is only File that uses this
423
+ # to create a different pattern for assigning to the :path attribute
424
+ # This requires further digging.
425
+ # The entire construct is somewhat strange, since resource checks if the method "title_patterns" is
426
+ # implemented (it seems it always is) - why take this more expensive regexp mathching route for all
427
+ # other types?
428
+ # @api private
429
+ #
430
+ def self.title_patterns
431
+ case key_attributes.length
432
+ when 0; []
433
+ when 1;
434
+ [[/(.*)/m, [[key_attributes.first]]]]
435
+ else
436
+ raise Puppet::DevError, _("you must specify title patterns when there are two or more key attributes")
437
+ end
438
+ end
439
+
440
+ # Produces a resource's _uniqueness_key_ (or composite key).
441
+ # This key is an array of all key attributes' values. Each distinct tuple must be unique for each resource type.
442
+ # @see key_attributes
443
+ # @return [Object] an object that is a _uniqueness_key_ for this object
444
+ #
445
+ def uniqueness_key
446
+ self.class.key_attributes.sort_by(&:to_s).map { |attribute_name| self[attribute_name] }
447
+ end
448
+
449
+ # Creates a new parameter.
450
+ # @param name [Symbol] the name of the parameter
451
+ # @param options [Hash] a hash with options.
452
+ # @option options [Class<inherits Puppet::Parameter>] :parent (Puppet::Parameter) the super class of this parameter
453
+ # @option options [Hash{String => Object}] :attributes a hash that is applied to the generated class
454
+ # by calling setter methods corresponding to this hash's keys/value pairs. This is done before the given
455
+ # block is evaluated.
456
+ # @option options [Boolean] :boolean (false) specifies if this is a boolean parameter
457
+ # @option options [Boolean] :namevar (false) specifies if this parameter is the namevar
458
+ # @option options [Symbol, Array<Symbol>] :required_features specifies required provider features by name
459
+ # @return [Class<inherits Puppet::Parameter>] the created parameter
460
+ # @yield [ ] a required block that is evaluated in the scope of the new parameter
461
+ # @api public
462
+ # @dsl type
463
+ #
464
+ def self.newparam(name, options = {}, &block)
465
+ options[:attributes] ||= {}
466
+
467
+ param = genclass(
468
+ name,
469
+ :parent => options[:parent] || Puppet::Parameter,
470
+ :attributes => options[:attributes],
471
+ :block => block,
472
+ :prefix => "Parameter",
473
+ :array => @parameters,
474
+ :hash => @paramhash
475
+ )
476
+
477
+ handle_param_options(name, options)
478
+
479
+ # Grr.
480
+ param.required_features = options[:required_features] if options[:required_features]
481
+
482
+ param.isnamevar if options[:namevar]
483
+
484
+ param
485
+ end
486
+
487
+ # Creates a new property.
488
+ # @param name [Symbol] the name of the property
489
+ # @param options [Hash] a hash with options.
490
+ # @option options [Symbol] :array_matching (:first) specifies how the current state is matched against
491
+ # the wanted state. Use `:first` if the property is single valued, and (`:all`) otherwise.
492
+ # @option options [Class<inherits Puppet::Property>] :parent (Puppet::Property) the super class of this property
493
+ # @option options [Hash{String => Object}] :attributes a hash that is applied to the generated class
494
+ # by calling setter methods corresponding to this hash's keys/value pairs. This is done before the given
495
+ # block is evaluated.
496
+ # @option options [Boolean] :boolean (false) specifies if this is a boolean parameter
497
+ # @option options [Symbol] :retrieve the method to call on the provider (or `parent` if `provider` is not set)
498
+ # to retrieve the current value of this property.
499
+ # @option options [Symbol, Array<Symbol>] :required_features specifies required provider features by name
500
+ # @return [Class<inherits Puppet::Property>] the created property
501
+ # @yield [ ] a required block that is evaluated in the scope of the new property
502
+ # @api public
503
+ # @dsl type
504
+ #
505
+ def self.newproperty(name, options = {}, &block)
506
+ name = name.intern
507
+
508
+ # This is here for types that might still have the old method of defining
509
+ # a parent class.
510
+ unless options.is_a? Hash
511
+ raise Puppet::DevError, _("Options must be a hash, not %{type}") % { type: options.inspect }
512
+ end
513
+
514
+ raise Puppet::DevError, _("Class %{class_name} already has a property named %{property}") % { class_name: self.name, property: name } if @validproperties.include?(name)
515
+
516
+ parent = options[:parent]
517
+ if parent
518
+ options.delete(:parent)
519
+ else
520
+ parent = Puppet::Property
521
+ end
522
+
523
+ # We have to create our own, new block here because we want to define
524
+ # an initial :retrieve method, if told to, and then eval the passed
525
+ # block if available.
526
+ prop = genclass(name, :parent => parent, :hash => @validproperties, :attributes => options) do
527
+ # If they've passed a retrieve method, then override the retrieve
528
+ # method on the class.
529
+ if options[:retrieve]
530
+ define_method(:retrieve) do
531
+ provider.send(options[:retrieve])
532
+ end
533
+ end
534
+
535
+ class_eval(&block) if block
536
+ end
537
+
538
+ # If it's the 'ensure' property, always put it first.
539
+ if name == :ensure
540
+ @properties.unshift prop
541
+ else
542
+ @properties << prop
543
+ end
544
+
545
+ prop
546
+ end
547
+
548
+ def self.paramdoc(param)
549
+ @paramhash[param].doc
550
+ end
551
+
552
+ # @return [Array<String>] Returns the parameter names
553
+ def self.parameters
554
+ return [] unless defined?(@parameters)
555
+
556
+ @parameters.collect(&:name)
557
+ end
558
+
559
+ # @return [Puppet::Parameter] Returns the parameter class associated with the given parameter name.
560
+ def self.paramclass(name)
561
+ @paramhash[name]
562
+ end
563
+
564
+ # @return [Puppet::Property] Returns the property class ??? associated with the given property name
565
+ def self.propertybyname(name)
566
+ @validproperties[name]
567
+ end
568
+
569
+ # Returns whether or not the given name is the name of a property, parameter or meta-parameter
570
+ # @return [Boolean] true if the given attribute name is the name of an existing property, parameter or meta-parameter
571
+ #
572
+ def self.validattr?(name)
573
+ name = name.intern
574
+ return true if name == :name
575
+
576
+ @validattrs ||= {}
577
+
578
+ unless @validattrs.include?(name)
579
+ @validattrs[name] = !!(validproperty?(name) or validparameter?(name) or metaparam?(name))
580
+ end
581
+
582
+ @validattrs[name]
583
+ end
584
+
585
+ # @return [Boolean] Returns true if the given name is the name of an existing property
586
+ def self.validproperty?(name)
587
+ name = name.intern
588
+ @validproperties.include?(name) && @validproperties[name]
589
+ end
590
+
591
+ # @return [Array<Symbol>, {}] Returns a list of valid property names, or an empty hash if there are none.
592
+ # @todo An empty hash is returned if there are no defined parameters (not an empty array). This looks like
593
+ # a bug.
594
+ #
595
+ def self.validproperties
596
+ return {} unless defined?(@parameters)
597
+
598
+ @validproperties.keys
599
+ end
600
+
601
+ # @return [Boolean] Returns true if the given name is the name of an existing parameter
602
+ def self.validparameter?(name)
603
+ raise Puppet::DevError, _("Class %{class_name} has not defined parameters") % { class_name: self } unless defined?(@parameters)
604
+
605
+ !!(@paramhash.include?(name) or @@metaparamhash.include?(name))
606
+ end
607
+
608
+ # (see validattr?)
609
+ # @note see comment in code - how should this be documented? Are some of the other query methods deprecated?
610
+ # (or should be).
611
+ # @comment This is a forward-compatibility method - it's the validity interface we'll use in Puppet::Resource.
612
+ def self.valid_parameter?(name)
613
+ validattr?(name)
614
+ end
615
+
616
+ # @return [Boolean] Returns true if the wanted state of the resource is that it should be absent (i.e. to be deleted).
617
+ def deleting?
618
+ obj = @parameters[:ensure] and obj.should == :absent
619
+ end
620
+
621
+ # Creates a new property value holder for the resource if it is valid and does not already exist
622
+ # @return [Boolean] true if a new parameter was added, false otherwise
623
+ def add_property_parameter(prop_name)
624
+ if self.class.validproperty?(prop_name) && !@parameters[prop_name]
625
+ newattr(prop_name)
626
+ return true
627
+ end
628
+ false
629
+ end
630
+
631
+ # @return [Symbol, Boolean] Returns the name of the namevar if there is only one or false otherwise.
632
+ # @comment This is really convoluted and part of the support for multiple namevars (?).
633
+ # If there is only one namevar, the produced value is naturally this namevar, but if there are several?
634
+ # The logic caches the name of the namevar if it is a single name, but otherwise always
635
+ # calls key_attributes, and then caches the first if there was only one, otherwise it returns
636
+ # false and caches this (which is then subsequently returned as a cache hit).
637
+ #
638
+ def name_var
639
+ return @name_var_cache unless @name_var_cache.nil?
640
+
641
+ key_attributes = self.class.key_attributes
642
+ @name_var_cache = (key_attributes.length == 1) && key_attributes.first
643
+ end
644
+
645
+ # Gets the 'should' (wanted state) value of a parameter or property by name.
646
+ # To explicitly get the 'is' (current state) value use `o.is(:name)`, and to explicitly get the 'should' value
647
+ # use `o.should(:name)`
648
+ # @param name [String] the name of the attribute to obtain the 'should' value for.
649
+ # @return [Object] 'should'/wanted value of the given attribute
650
+ def [](name)
651
+ name = name.intern
652
+ fail("Invalid parameter #{name}(#{name.inspect})") unless self.class.validattr?(name)
653
+
654
+ if name == :name
655
+ nv = name_var
656
+ name = nv if nv
657
+ end
658
+
659
+ obj = @parameters[name]
660
+ if obj
661
+ # Note that if this is a property, then the value is the "should" value,
662
+ # not the current value.
663
+ obj.value
664
+ else
665
+ nil
666
+ end
667
+ end
668
+
669
+ # Sets the 'should' (wanted state) value of a property, or the value of a parameter.
670
+ #
671
+ # @raise [Puppet::Error] if the setting of the value fails, or if the given name is nil.
672
+ # @raise [Puppet::ResourceError] when the parameter validation raises Puppet::Error or
673
+ # ArgumentError
674
+ def []=(name, value)
675
+ name = name.intern
676
+
677
+ fail("no parameter named '#{name}'") unless self.class.validattr?(name)
678
+
679
+ if name == :name
680
+ nv = name_var
681
+ name = nv if nv
682
+ end
683
+ raise Puppet::Error, "Got nil value for #{name}" if value.nil?
684
+
685
+ property = newattr(name)
686
+
687
+ if property
688
+ begin
689
+ # make sure the parameter doesn't have any errors
690
+ property.value = value
691
+ rescue Puppet::Error, ArgumentError => detail
692
+ error = Puppet::ResourceError.new(_("Parameter %{name} failed on %{ref}: %{detail}") %
693
+ { name: name, ref: ref, detail: detail })
694
+ adderrorcontext(error, detail)
695
+ raise error
696
+ end
697
+ end
698
+ end
699
+
700
+ # Removes an attribute from the object; useful in testing or in cleanup
701
+ # when an error has been encountered
702
+ # @todo Don't know what the attr is (name or Property/Parameter?). Guessing it is a String name...
703
+ # @todo Is it possible to delete a meta-parameter?
704
+ # @todo What does delete mean? Is it deleted from the type or is its value state 'is'/'should' deleted?
705
+ # @param attr [String] the attribute to delete from this object. WHAT IS THE TYPE?
706
+ # @raise [Puppet::DecError] when an attempt is made to delete an attribute that does not exists.
707
+ #
708
+ def delete(attr)
709
+ attr = attr.intern
710
+ if @parameters.has_key?(attr)
711
+ @parameters.delete(attr)
712
+ else
713
+ raise Puppet::DevError, _("Undefined attribute '%{attribute}' in %{name}") % { attribute: attr, name: self }
714
+ end
715
+ end
716
+
717
+ # Iterates over the properties that were set on this resource.
718
+ # @yieldparam property [Puppet::Property] each property
719
+ # @return [void]
720
+ def eachproperty
721
+ # properties is a private method
722
+ properties.each { |property|
723
+ yield property
724
+ }
725
+ end
726
+
727
+ # Return the parameters, metaparams, and properties that have a value or were set by a default. Properties are
728
+ # included since they are a subclass of parameter.
729
+ # @return [Array<Puppet::Parameter>] Array of parameter objects ( or subclass thereof )
730
+ def parameters_with_value
731
+ self.class.allattrs.filter_map { |attr| parameter(attr) }
732
+ end
733
+
734
+ # Iterates over all parameters with value currently set.
735
+ # @yieldparam parameter [Puppet::Parameter] or a subclass thereof
736
+ # @return [void]
737
+ def eachparameter
738
+ parameters_with_value.each { |parameter| yield parameter }
739
+ end
740
+
741
+ # Creates a transaction event.
742
+ # Called by Transaction or by a property.
743
+ # Merges the given options with the options `:resource`, `:file`, `:line`, and `:tags`, initialized from
744
+ # values in this object. For possible options to pass (if any ????) see {Puppet::Transaction::Event}.
745
+ # @todo Needs a better explanation "Why should I care who is calling this method?", What do I need to know
746
+ # about events and how they work? Where can I read about them?
747
+ # @param options [Hash] options merged with a fixed set of options defined by this method, passed on to {Puppet::Transaction::Event}.
748
+ # @return [Puppet::Transaction::Event] the created event
749
+ def event(options = {})
750
+ Puppet::Transaction::Event.new(**{ :resource => self, :file => file, :line => line, :tags => tags }.merge(options))
751
+ end
752
+
753
+ # @return [Object, nil] Returns the 'should' (wanted state) value for a specified property, or nil if the
754
+ # given attribute name is not a property (i.e. if it is a parameter, meta-parameter, or does not exist).
755
+ def should(name)
756
+ prop = @parameters[name.intern]
757
+ if prop && prop.is_a?(Puppet::Property)
758
+ prop.should
759
+ else
760
+ nil
761
+ end
762
+ end
763
+
764
+ # Registers an attribute to this resource type instance.
765
+ # Requires either the attribute name or class as its argument.
766
+ # This is a noop if the named property/parameter is not supported
767
+ # by this resource. Otherwise, an attribute instance is created
768
+ # and kept in this resource's parameters hash.
769
+ # @overload newattr(name)
770
+ # @param name [Symbol] symbolic name of the attribute
771
+ # @overload newattr(klass)
772
+ # @param klass [Class] a class supported as an attribute class, i.e. a subclass of
773
+ # Parameter or Property
774
+ # @return [Object] An instance of the named Parameter or Property class associated
775
+ # to this resource type instance, or nil if the attribute is not supported
776
+ #
777
+ def newattr(name)
778
+ if name.is_a?(Class)
779
+ klass = name
780
+ name = klass.name
781
+ end
782
+
783
+ klass = self.class.attrclass(name)
784
+ unless klass
785
+ raise Puppet::Error, "Resource type #{self.class.name} does not support parameter #{name}"
786
+ end
787
+
788
+ if provider and !provider.class.supports_parameter?(klass)
789
+ missing = klass.required_features.find_all { |f| !provider.class.feature?(f) }
790
+ debug "Provider %s does not support features %s; not managing attribute %s" % [provider.class.name, missing.join(", "), name]
791
+ return nil
792
+ end
793
+
794
+ return @parameters[name] if @parameters.include?(name)
795
+
796
+ @parameters[name] = klass.new(:resource => self)
797
+ end
798
+
799
+ # Returns a string representation of the resource's containment path in
800
+ # the catalog.
801
+ # @return [String]
802
+ def path
803
+ @path ||= '/' + pathbuilder.join('/')
804
+ end
805
+
806
+ # Returns the value of this object's parameter given by name
807
+ # @param name [String] the name of the parameter
808
+ # @return [Object] the value
809
+ def parameter(name)
810
+ @parameters[name.to_sym]
811
+ end
812
+
813
+ # Returns a shallow copy of this object's hash of attributes by name.
814
+ # Note that his not only comprises parameters, but also properties and metaparameters.
815
+ # Changes to the contained parameters will have an effect on the parameters of this type, but changes to
816
+ # the returned hash does not.
817
+ # @return [Hash{String => Object}] a new hash being a shallow copy of the parameters map name to parameter
818
+ def parameters
819
+ @parameters.dup
820
+ end
821
+
822
+ # @return [Boolean] Returns whether the attribute given by name has been added
823
+ # to this resource or not.
824
+ def propertydefined?(name)
825
+ name = name.intern unless name.is_a? Symbol
826
+ @parameters.include?(name)
827
+ end
828
+
829
+ # Returns a {Puppet::Property} instance by name.
830
+ # To return the value, use 'resource[param]'
831
+ # @todo LAK:NOTE(20081028) Since the 'parameter' method is now a superset of this method,
832
+ # this one should probably go away at some point. - Does this mean it should be deprecated ?
833
+ # @return [Puppet::Property] the property with the given name, or nil if not a property or does not exist.
834
+ def property(name)
835
+ obj = @parameters[name.intern]
836
+ if obj && obj.is_a?(Puppet::Property)
837
+ obj
838
+ else
839
+ nil
840
+ end
841
+ end
842
+
843
+ # @todo comment says "For any parameters or properties that have defaults and have not yet been
844
+ # set, set them now. This method can be handed a list of attributes,
845
+ # and if so it will only set defaults for those attributes."
846
+ # @todo Needs a better explanation, and investigation about the claim an array can be passed (it is passed
847
+ # to self.class.attrclass to produce a class on which a check is made if it has a method class :default (does
848
+ # not seem to support an array...
849
+ # @return [void]
850
+ #
851
+ def set_default(attr)
852
+ klass = self.class.attrclass(attr)
853
+ return unless klass
854
+ # TODO this is not a necessary check, as we define a class level attr_reader
855
+ return unless klass.method_defined?(:default)
856
+ return if @parameters.include?(klass.name)
857
+
858
+ parameter = newattr(klass.name)
859
+ return unless parameter
860
+
861
+ value = parameter.default
862
+ if value and !value.nil?
863
+ parameter.value = value
864
+ else
865
+ @parameters.delete(parameter.name)
866
+ end
867
+ end
868
+
869
+ # @todo the comment says: "Convert our object to a hash. This just includes properties."
870
+ # @todo this is confused, again it is the @parameters instance variable that is consulted, and
871
+ # each value is copied - does it contain "properties" and "parameters" or both? Does it contain
872
+ # meta-parameters?
873
+ #
874
+ # @return [Hash{ ??? => ??? }] a hash of WHAT?. The hash is a shallow copy, any changes to the
875
+ # objects returned in this hash will be reflected in the original resource having these attributes.
876
+ #
877
+ def to_hash
878
+ rethash = {}
879
+
880
+ @parameters.each do |name, obj|
881
+ rethash[name] = obj.value
882
+ end
883
+
884
+ rethash
885
+ end
886
+
887
+ # @return [String] the name of this object's class
888
+ # @todo Would that be "file" for the "File" resource type? of "File" or something else?
889
+ #
890
+ def type
891
+ self.class.name
892
+ end
893
+
894
+ # @todo Comment says "Return a specific value for an attribute.", as opposed to what "An unspecific value"???
895
+ # @todo is this the 'is' or the 'should' value?
896
+ # @todo why is the return restricted to things that respond to :value? (Only non structural basic data types
897
+ # supported?
898
+ #
899
+ # @return [Object, nil] the value of the attribute having the given name, or nil if the given name is not
900
+ # an attribute, or the referenced attribute does not respond to `:value`.
901
+ def value(name)
902
+ name = name.intern
903
+
904
+ obj = @parameters[name]
905
+ if obj && obj.respond_to?(:value)
906
+ obj.value
907
+ else
908
+ nil
909
+ end
910
+ end
911
+
912
+ # @todo What is this used for? Needs a better explanation.
913
+ # @return [???] the version of the catalog or 0 if there is no catalog.
914
+ def version
915
+ return 0 unless catalog
916
+
917
+ catalog.version
918
+ end
919
+
920
+ # @return [Array<Puppet::Property>] Returns all of the property objects, in the order specified in the
921
+ # class.
922
+ # @todo "what does the 'order specified in the class' mean? The order the properties where added in the
923
+ # ruby file adding a new type with new properties?
924
+ #
925
+ def properties
926
+ self.class.properties.filter_map { |prop| @parameters[prop.name] }
927
+ end
928
+
929
+ # Returns true if the type's notion of name is the identity of a resource.
930
+ # See the overview of this class for a longer explanation of the concept _isomorphism_.
931
+ # Defaults to true.
932
+ #
933
+ # @return [Boolean] true, if this type's name is isomorphic with the object
934
+ def self.isomorphic?
935
+ if defined?(@isomorphic)
936
+ @isomorphic
937
+ else
938
+ true
939
+ end
940
+ end
941
+
942
+ # @todo check that this gets documentation (it is at the class level as well as instance).
943
+ # (see isomorphic?)
944
+ def isomorphic?
945
+ self.class.isomorphic?
946
+ end
947
+
948
+ # Returns true if the instance is a managed instance.
949
+ # A 'yes' here means that the instance was created from the language, vs. being created
950
+ # in order resolve other questions, such as finding a package in a list.
951
+ # @note An object that is managed always stays managed, but an object that is not managed
952
+ # may become managed later in its lifecycle.
953
+ # @return [Boolean] true if the object is managed
954
+ def managed?
955
+ # Once an object is managed, it always stays managed; but an object
956
+ # that is listed as unmanaged might become managed later in the process,
957
+ # so we have to check that every time
958
+ unless @managed
959
+ @managed = false
960
+ properties.each { |property|
961
+ s = property.should
962
+ if s and !property.class.unmanaged
963
+ @managed = true
964
+ break
965
+ end
966
+ }
967
+ end
968
+ @managed
969
+ end
970
+
971
+ ###############################
972
+ # Code related to the container behaviour.
973
+
974
+ # Returns true if the search should be done in depth-first order.
975
+ # This implementation always returns false.
976
+ # @todo What is this used for?
977
+ #
978
+ # @return [Boolean] true if the search should be done in depth first order.
979
+ #
980
+ def depthfirst?
981
+ false
982
+ end
983
+
984
+ # Removes this object (FROM WHERE?)
985
+ # @todo removes if from where?
986
+ # @return [void]
987
+ def remove
988
+ # This is hackish (mmm, cut and paste), but it works for now, and it's
989
+ # better than warnings.
990
+ @parameters.each do |_name, obj|
991
+ obj.remove
992
+ end
993
+ @parameters.clear
994
+
995
+ @parent = nil
996
+
997
+ # Remove the reference to the provider.
998
+ if provider
999
+ @provider.clear
1000
+ @provider = nil
1001
+ end
1002
+ end
1003
+
1004
+ ###############################
1005
+ # Code related to evaluating the resources.
1006
+
1007
+ # Returns the ancestors - WHAT?
1008
+ # This implementation always returns an empty list.
1009
+ # @todo WHAT IS THIS ?
1010
+ # @return [Array<???>] returns a list of ancestors.
1011
+ def ancestors
1012
+ []
1013
+ end
1014
+
1015
+ # Lifecycle method for a resource. This is called during graph creation.
1016
+ # It should perform any consistency checking of the catalog and raise a
1017
+ # Puppet::Error if the transaction should be aborted.
1018
+ #
1019
+ # It differs from the validate method, since it is called later during
1020
+ # initialization and can rely on self.catalog to have references to all
1021
+ # resources that comprise the catalog.
1022
+ #
1023
+ # @see Puppet::Transaction#add_vertex
1024
+ # @raise [Puppet::Error] If the pre-run check failed.
1025
+ # @return [void]
1026
+ # @abstract a resource type may implement this method to perform
1027
+ # validation checks that can query the complete catalog
1028
+ def pre_run_check
1029
+ end
1030
+
1031
+ # Flushes the provider if supported by the provider, else no action.
1032
+ # This is called by the transaction.
1033
+ # @todo What does Flushing the provider mean? Why is it interesting to know that this is
1034
+ # called by the transaction? (It is not explained anywhere what a transaction is).
1035
+ #
1036
+ # @return [???, nil] WHAT DOES IT RETURN? GUESS IS VOID
1037
+ def flush
1038
+ provider.flush if provider and provider.respond_to?(:flush)
1039
+ end
1040
+
1041
+ # Says if the ensure property should be retrieved if the resource is ensurable
1042
+ # Defaults to true. Some resource type classes can override it
1043
+ def self.needs_ensure_retrieved
1044
+ true
1045
+ end
1046
+
1047
+ # Retrieves the current value of all contained properties.
1048
+ # Parameters and meta-parameters are not included in the result.
1049
+ # @todo As opposed to all non contained properties? How is this different than any of the other
1050
+ # methods that also "gets" properties/parameters/etc. ?
1051
+ # @return [Puppet::Resource] array of all property values (mix of types)
1052
+ # @raise [fail???] if there is a provider and it is not suitable for the host this is evaluated for.
1053
+ def retrieve
1054
+ fail "Provider #{provider.class.name} is not functional on this host" if provider.is_a?(Puppet::Provider) and !provider.class.suitable?
1055
+
1056
+ result = Puppet::Resource.new(self.class, title)
1057
+
1058
+ # Provide the name, so we know we'll always refer to a real thing
1059
+ result[:name] = self[:name] unless self[:name] == title
1060
+
1061
+ ensure_prop = property(:ensure)
1062
+ if !ensure_prop && self.class.needs_ensure_retrieved && self.class.validattr?(:ensure)
1063
+ ensure_prop = newattr(:ensure)
1064
+ end
1065
+
1066
+ if ensure_prop
1067
+ result[:ensure] = ensure_state = ensure_prop.retrieve
1068
+ else
1069
+ ensure_state = nil
1070
+ end
1071
+
1072
+ properties.each do |property|
1073
+ next if property.name == :ensure
1074
+
1075
+ if ensure_state == :absent
1076
+ result[property] = :absent
1077
+ else
1078
+ result[property] = property.retrieve
1079
+ end
1080
+ end
1081
+
1082
+ result
1083
+ end
1084
+
1085
+ # Retrieve the current state of the system as a Puppet::Resource. For
1086
+ # the base Puppet::Type this does the same thing as #retrieve, but
1087
+ # specific types are free to implement #retrieve as returning a hash,
1088
+ # and this will call #retrieve and convert the hash to a resource.
1089
+ # This is used when determining when syncing a resource.
1090
+ #
1091
+ # @return [Puppet::Resource] A resource representing the current state
1092
+ # of the system.
1093
+ #
1094
+ # @api private
1095
+ def retrieve_resource
1096
+ resource = retrieve
1097
+ resource = Resource.new(self.class, title, :parameters => resource) if resource.is_a? Hash
1098
+ resource
1099
+ end
1100
+
1101
+ # Given the hash of current properties, should this resource be treated as if it
1102
+ # currently exists on the system. May need to be overridden by types that offer up
1103
+ # more than just :absent and :present.
1104
+ def present?(current_values)
1105
+ current_values[:ensure] != :absent
1106
+ end
1107
+
1108
+ # Returns a hash of the current properties and their values.
1109
+ # If a resource is absent, its value is the symbol `:absent`
1110
+ # @return [Hash{Puppet::Property => Object}] mapping of property instance to its value
1111
+ #
1112
+ def currentpropvalues
1113
+ # It's important to use the 'properties' method here, as it follows the order
1114
+ # in which they're defined in the class. It also guarantees that 'ensure'
1115
+ # is the first property, which is important for skipping 'retrieve' on
1116
+ # all the properties if the resource is absent.
1117
+ ensure_state = false
1118
+ properties.each_with_object({}) do |property, prophash|
1119
+ if property.name == :ensure
1120
+ ensure_state = property.retrieve
1121
+ prophash[property] = ensure_state
1122
+ elsif ensure_state == :absent
1123
+ prophash[property] = :absent
1124
+ else
1125
+ prophash[property] = property.retrieve
1126
+ end
1127
+ end
1128
+ end
1129
+
1130
+ # Returns the `noop` run mode status of this.
1131
+ # @return [Boolean] true if running in noop mode.
1132
+ def noop?
1133
+ # If we're not a host_config, we're almost certainly part of
1134
+ # Settings, and we want to ignore 'noop'
1135
+ return false if catalog and !catalog.host_config?
1136
+
1137
+ if defined?(@noop)
1138
+ @noop
1139
+ else
1140
+ Puppet[:noop]
1141
+ end
1142
+ end
1143
+
1144
+ # (see #noop?)
1145
+ def noop
1146
+ noop?
1147
+ end
1148
+
1149
+ # Retrieves all known instances.
1150
+ # @todo Retrieves them from where? Known to whom?
1151
+ # Either requires providers or must be overridden.
1152
+ # @raise [Puppet::DevError] when there are no providers and the implementation has not overridden this method.
1153
+ def self.instances
1154
+ raise Puppet::DevError, _("%{name} has no providers and has not overridden 'instances'") % { name: name } if provider_hash.empty?
1155
+
1156
+ # Put the default provider first, then the rest of the suitable providers.
1157
+ provider_instances = {}
1158
+ providers_by_source.collect do |provider|
1159
+ provider.instances.collect do |instance|
1160
+ # We always want to use the "first" provider instance we find, unless the resource
1161
+ # is already managed and has a different provider set
1162
+ title = instance.respond_to?(:title) ? instance.title : instance.name
1163
+ other = provider_instances[title]
1164
+ if other
1165
+ Puppet.debug {
1166
+ "%s %s found in both %s and %s; skipping the %s version" % [name.to_s.capitalize, title, other.class.name, instance.class.name, instance.class.name]
1167
+ }
1168
+ next
1169
+ end
1170
+ provider_instances[title] = instance
1171
+
1172
+ result = new(:name => instance.name, :provider => instance, :title => title)
1173
+ properties.each { |name| result.newattr(name) }
1174
+ result
1175
+ end
1176
+ end.flatten.compact
1177
+ end
1178
+
1179
+ # Returns a list of one suitable provider per source, with the default provider first.
1180
+ # @todo Needs better explanation; what does "source" mean in this context?
1181
+ # @return [Array<Puppet::Provider>] list of providers
1182
+ #
1183
+ def self.providers_by_source
1184
+ # Put the default provider first (can be nil), then the rest of the suitable providers.
1185
+ sources = []
1186
+ [defaultprovider, suitableprovider].flatten.uniq.filter_map do |provider|
1187
+ next if provider.nil?
1188
+ next if sources.include?(provider.source)
1189
+
1190
+ sources << provider.source
1191
+ provider
1192
+ end
1193
+ end
1194
+
1195
+ # Converts a simple hash into a Resource instance.
1196
+ # @todo as opposed to a complex hash? Other raised exceptions?
1197
+ # @param [Hash{Symbol, String => Object}] hash resource attribute to value map to initialize the created resource from
1198
+ # @return [Puppet::Resource] the resource created from the hash
1199
+ # @raise [Puppet::Error] if a title is missing in the given hash
1200
+ def self.hash2resource(hash)
1201
+ hash = hash.each_with_object({}) { |ary, result| result[ary[0].to_sym] = ary[1]; }
1202
+
1203
+ title = hash.delete(:title)
1204
+ title ||= hash[:name]
1205
+ title ||= hash[key_attributes.first] if key_attributes.length == 1
1206
+
1207
+ raise Puppet::Error, "Title or name must be provided" unless title
1208
+
1209
+ # Now create our resource.
1210
+ resource = Puppet::Resource.new(self, title)
1211
+ resource.catalog = hash.delete(:catalog)
1212
+
1213
+ sensitive = hash.delete(:sensitive_parameters)
1214
+ if sensitive
1215
+ resource.sensitive_parameters = sensitive
1216
+ end
1217
+
1218
+ hash.each do |param, value|
1219
+ resource[param] = value
1220
+ end
1221
+ resource
1222
+ end
1223
+
1224
+ # Returns an array of strings representing the containment hierarchy
1225
+ # (types/classes) that make up the path to the resource from the root
1226
+ # of the catalog. This is mostly used for logging purposes.
1227
+ #
1228
+ # @api private
1229
+ def pathbuilder
1230
+ p = parent
1231
+ if p
1232
+ [p.pathbuilder, ref].flatten
1233
+ else
1234
+ [ref]
1235
+ end
1236
+ end
1237
+
1238
+ ###############################
1239
+ # Add all of the meta-parameters.
1240
+ newmetaparam(:noop) do
1241
+ desc "Whether to apply this resource in noop mode.
1242
+
1243
+ When applying a resource in noop mode, Puppet will check whether it is in sync,
1244
+ like it does when running normally. However, if a resource attribute is not in
1245
+ the desired state (as declared in the catalog), Puppet will take no
1246
+ action, and will instead report the changes it _would_ have made. These
1247
+ simulated changes will appear in the report sent to the primary Puppet server, or
1248
+ be shown on the console if running puppet agent or puppet apply in the
1249
+ foreground. The simulated changes will not send refresh events to any
1250
+ subscribing or notified resources, although Puppet will log that a refresh
1251
+ event _would_ have been sent.
1252
+
1253
+ **Important note:**
1254
+ [The `noop` setting](https://puppet.com/docs/puppet/latest/configuration.html#noop)
1255
+ allows you to globally enable or disable noop mode, but it will _not_ override
1256
+ the `noop` metaparameter on individual resources. That is, the value of the
1257
+ global `noop` setting will _only_ affect resources that do not have an explicit
1258
+ value set for their `noop` attribute."
1259
+
1260
+ newvalues(:true, :false)
1261
+ munge do |value|
1262
+ case value
1263
+ when true, :true, "true"; @resource.noop = true
1264
+ when false, :false, "false"; @resource.noop = false
1265
+ end
1266
+ end
1267
+ end
1268
+
1269
+ newmetaparam(:schedule) do
1270
+ desc "A schedule to govern when Puppet is allowed to manage this resource.
1271
+ The value of this metaparameter must be the `name` of a `schedule`
1272
+ resource. This means you must declare a schedule resource, then
1273
+ refer to it by name; see
1274
+ [the docs for the `schedule` type](https://puppet.com/docs/puppet/latest/type.html#schedule)
1275
+ for more info.
1276
+
1277
+ schedule { 'everyday':
1278
+ period => daily,
1279
+ range => \"2-4\"
1280
+ }
1281
+
1282
+ exec { \"/usr/bin/apt-get update\":
1283
+ schedule => 'everyday'
1284
+ }
1285
+
1286
+ Note that you can declare the schedule resource anywhere in your
1287
+ manifests, as long as it ends up in the final compiled catalog."
1288
+ end
1289
+
1290
+ newmetaparam(:audit) do
1291
+ desc "Marks a subset of this resource's unmanaged attributes for auditing. Accepts an
1292
+ attribute name, an array of attribute names, or `all`.
1293
+
1294
+ Auditing a resource attribute has two effects: First, whenever a catalog
1295
+ is applied with puppet apply or puppet agent, Puppet will check whether
1296
+ that attribute of the resource has been modified, comparing its current
1297
+ value to the previous run; any change will be logged alongside any actions
1298
+ performed by Puppet while applying the catalog.
1299
+
1300
+ Secondly, marking a resource attribute for auditing will include that
1301
+ attribute in inspection reports generated by puppet inspect; see the
1302
+ puppet inspect documentation for more details.
1303
+
1304
+ Managed attributes for a resource can also be audited, but note that
1305
+ changes made by Puppet will be logged as additional modifications. (I.e.
1306
+ if a user manually edits a file whose contents are audited and managed,
1307
+ puppet agent's next two runs will both log an audit notice: the first run
1308
+ will log the user's edit and then revert the file to the desired state,
1309
+ and the second run will log the edit made by Puppet.)"
1310
+
1311
+ validate do |list|
1312
+ list = Array(list).collect(&:to_sym)
1313
+ unless list == [:all]
1314
+ list.each do |param|
1315
+ next if @resource.class.validattr?(param)
1316
+
1317
+ fail "Cannot audit #{param}: not a valid attribute for #{resource}"
1318
+ end
1319
+ end
1320
+ end
1321
+
1322
+ munge do |args|
1323
+ properties_to_audit(args).each do |param|
1324
+ next unless resource.class.validproperty?(param)
1325
+
1326
+ resource.newattr(param)
1327
+ end
1328
+ end
1329
+
1330
+ def all_properties
1331
+ resource.class.properties.find_all do |property|
1332
+ resource.provider.nil? or resource.provider.class.supports_parameter?(property)
1333
+ end.collect(&:name)
1334
+ end
1335
+
1336
+ def properties_to_audit(list)
1337
+ if !list.is_a?(Array) && list.to_sym == :all
1338
+ all_properties
1339
+ else
1340
+ Array(list).collect(&:to_sym)
1341
+ end
1342
+ end
1343
+ end
1344
+
1345
+ newmetaparam(:loglevel) do
1346
+ desc "Sets the level that information will be logged.
1347
+ The log levels have the biggest impact when logs are sent to
1348
+ syslog (which is currently the default).
1349
+
1350
+ The order of the log levels, in decreasing priority, is:
1351
+
1352
+ * `emerg`
1353
+ * `alert`
1354
+ * `crit`
1355
+ * `err`
1356
+ * `warning`
1357
+ * `notice`
1358
+ * `info` / `verbose`
1359
+ * `debug`
1360
+ "
1361
+ defaultto :notice
1362
+
1363
+ newvalues(*Puppet::Util::Log.levels)
1364
+ newvalues(:verbose)
1365
+
1366
+ munge do |loglevel|
1367
+ val = super(loglevel)
1368
+ if val == :verbose
1369
+ val = :info
1370
+ end
1371
+ val
1372
+ end
1373
+ end
1374
+
1375
+ newmetaparam(:alias) do
1376
+ desc "Creates an alias for the resource. Puppet uses this internally when you
1377
+ provide a symbolic title and an explicit namevar value:
1378
+
1379
+ file { 'sshdconfig':
1380
+ path => $os['name'] ? {
1381
+ solaris => '/usr/local/etc/ssh/sshd_config',
1382
+ default => '/etc/ssh/sshd_config',
1383
+ },
1384
+ source => '...'
1385
+ }
1386
+
1387
+ service { 'sshd':
1388
+ subscribe => File['sshdconfig'],
1389
+ }
1390
+
1391
+ When you use this feature, the parser sets `sshdconfig` as the title,
1392
+ and the library sets that as an alias for the file so the dependency
1393
+ lookup in `Service['sshd']` works. You can use this metaparameter yourself,
1394
+ but note that aliases generally only work for creating relationships; anything
1395
+ else that refers to an existing resource (such as amending or overriding
1396
+ resource attributes in an inherited class) must use the resource's exact
1397
+ title. For example, the following code will not work:
1398
+
1399
+ file { '/etc/ssh/sshd_config':
1400
+ owner => root,
1401
+ group => root,
1402
+ alias => 'sshdconfig',
1403
+ }
1404
+
1405
+ File['sshdconfig'] {
1406
+ mode => '0644',
1407
+ }
1408
+
1409
+ There's no way here for the Puppet parser to know that these two stanzas
1410
+ should be affecting the same file.
1411
+
1412
+ "
1413
+
1414
+ munge do |aliases|
1415
+ aliases = [aliases] unless aliases.is_a?(Array)
1416
+
1417
+ raise(ArgumentError, _("Cannot add aliases without a catalog")) unless @resource.catalog
1418
+
1419
+ aliases.each do |other|
1420
+ obj = @resource.catalog.resource(@resource.class.name, other)
1421
+ if obj
1422
+ unless obj.equal?(@resource) # same object?
1423
+ self.fail("#{@resource.title} can not create alias #{other}: object already exists")
1424
+ end
1425
+ next
1426
+ end
1427
+
1428
+ # Newschool, add it to the catalog.
1429
+ @resource.catalog.alias(@resource, other)
1430
+ end
1431
+ end
1432
+ end
1433
+
1434
+ newmetaparam(:tag) do
1435
+ desc "Add the specified tags to the associated resource. While all resources
1436
+ are automatically tagged with as much information as possible
1437
+ (e.g., each class and definition containing the resource), it can
1438
+ be useful to add your own tags to a given resource.
1439
+
1440
+ Multiple tags can be specified as an array:
1441
+
1442
+ file {'/etc/hosts':
1443
+ ensure => file,
1444
+ source => 'puppet:///modules/site/hosts',
1445
+ mode => '0644',
1446
+ tag => ['bootstrap', 'minimumrun', 'mediumrun'],
1447
+ }
1448
+
1449
+ Tags are useful for things like applying a subset of a host's configuration
1450
+ with [the `tags` setting](https://puppet.com/docs/puppet/latest/configuration.html#tags)
1451
+ (e.g. `puppet agent --test --tags bootstrap`)."
1452
+
1453
+ munge do |tags|
1454
+ tags = [tags] unless tags.is_a? Array
1455
+
1456
+ tags.each do |tag|
1457
+ @resource.tag(tag)
1458
+ end
1459
+ end
1460
+ end
1461
+
1462
+ # RelationshipMetaparam is an implementation supporting the meta-parameters `:require`, `:subscribe`,
1463
+ # `:notify`, and `:before`.
1464
+ #
1465
+ #
1466
+ class RelationshipMetaparam < Puppet::Parameter
1467
+ class << self
1468
+ attr_accessor :direction, :events, :callback, :subclasses
1469
+ end
1470
+
1471
+ @subclasses = []
1472
+
1473
+ def self.inherited(sub)
1474
+ @subclasses << sub
1475
+ end
1476
+
1477
+ # @return [Array<Puppet::Resource>] turns attribute values into list of resources
1478
+ def munge(references)
1479
+ references = [references] unless references.is_a?(Array)
1480
+ references.collect do |ref|
1481
+ if ref.is_a?(Puppet::Resource)
1482
+ ref
1483
+ else
1484
+ Puppet::Resource.new(ref)
1485
+ end
1486
+ end
1487
+ end
1488
+
1489
+ # Checks each reference to assert that what it references exists in the catalog.
1490
+ #
1491
+ # @raise [???fail] if the referenced resource can not be found
1492
+ # @return [void]
1493
+ def validate_relationship
1494
+ @value.each do |ref|
1495
+ next if @resource.catalog.resource(ref.to_s)
1496
+
1497
+ description = self.class.direction == :in ? "dependency" : "dependent"
1498
+ fail ResourceError, _("Could not find %{description} %{ref} for %{resource}") %
1499
+ { description: description, ref: ref, resource: resource.ref }
1500
+ end
1501
+ end
1502
+
1503
+ # Creates edges for all relationships.
1504
+ # The `:in` relationships are specified by the event-receivers, and `:out`
1505
+ # relationships are specified by the event generator.
1506
+ # @todo references to "event-receivers" and "event generator" means in this context - are those just
1507
+ # the resources at the two ends of the relationship?
1508
+ # This way 'source' and 'target' are consistent terms in both edges
1509
+ # and events, i.e. an event targets edges whose source matches
1510
+ # the event's source. The direction of the relationship determines
1511
+ # which resource is applied first and which resource is considered
1512
+ # to be the event generator.
1513
+ # @return [Array<Puppet::Relationship>]
1514
+ # @raise [???fail] when a reference can not be resolved
1515
+ #
1516
+ def to_edges
1517
+ @value.collect do |reference|
1518
+ reference.catalog = resource.catalog
1519
+
1520
+ # Either of the two retrieval attempts could have returned
1521
+ # nil.
1522
+ related_resource = reference.resolve
1523
+ unless related_resource
1524
+ self.fail "Could not retrieve dependency '#{reference}' of #{@resource.ref}"
1525
+ end
1526
+
1527
+ # Are we requiring them, or vice versa? See the method docs
1528
+ # for further info on this.
1529
+ if self.class.direction == :in
1530
+ source = related_resource
1531
+ target = @resource
1532
+ else
1533
+ source = @resource
1534
+ target = related_resource
1535
+ end
1536
+
1537
+ method = self.class.callback
1538
+ if method
1539
+ subargs = {
1540
+ :event => self.class.events,
1541
+ :callback => method
1542
+ }
1543
+ else
1544
+ # If there's no callback, there's no point in even adding
1545
+ # a label.
1546
+ subargs = nil
1547
+ end
1548
+
1549
+ ## Corrected syntax of debug statement to reflect the way this was called.
1550
+ # i.e. before, after, subscribe, notify
1551
+ debug do
1552
+ relation = case self.class.name
1553
+ when "subscribe"
1554
+ "subscribes"
1555
+ when "notify"
1556
+ "notifies"
1557
+ else
1558
+ self.class.name
1559
+ end
1560
+
1561
+ "#{relation} to #{related_resource.ref}"
1562
+ end
1563
+
1564
+ Puppet::Relationship.new(source, target, subargs)
1565
+ end
1566
+ end
1567
+ end
1568
+
1569
+ # @todo document this, have no clue what this does... it returns "RelationshipMetaparam.subclasses"
1570
+ #
1571
+ def self.relationship_params
1572
+ RelationshipMetaparam.subclasses
1573
+ end
1574
+
1575
+ # Note that the order in which the relationships params is defined
1576
+ # matters. The labeled params (notify and subscribe) must be later,
1577
+ # so that if both params are used, those ones win. It's a hackish
1578
+ # solution, but it works.
1579
+
1580
+ newmetaparam(:require, :parent => RelationshipMetaparam, :attributes => { :direction => :in, :events => :NONE }) do
1581
+ desc "One or more resources that this resource depends on, expressed as
1582
+ [resource references](https://puppet.com/docs/puppet/latest/lang_data_resource_reference.html).
1583
+ Multiple resources can be specified as an array of references. When this
1584
+ attribute is present:
1585
+
1586
+ * The required resources will be applied **before** this resource.
1587
+
1588
+ This is one of the four relationship metaparameters, along with
1589
+ `before`, `notify`, and `subscribe`. For more context, including the
1590
+ alternate chaining arrow (`->` and `~>`) syntax, see
1591
+ [the language page on relationships](https://puppet.com/docs/puppet/latest/lang_relationships.html)."
1592
+ end
1593
+
1594
+ newmetaparam(:subscribe, :parent => RelationshipMetaparam, :attributes => { :direction => :in, :events => :ALL_EVENTS, :callback => :refresh }) do
1595
+ desc "One or more resources that this resource depends on, expressed as
1596
+ [resource references](https://puppet.com/docs/puppet/latest/lang_data_resource_reference.html).
1597
+ Multiple resources can be specified as an array of references. When this
1598
+ attribute is present:
1599
+
1600
+ * The subscribed resources will be applied _before_ this resource.
1601
+ * If Puppet makes changes to any of the subscribed resources, it will cause
1602
+ this resource to _refresh._ (Refresh behavior varies by resource
1603
+ type: services will restart, mounts will unmount and re-mount, etc. Not
1604
+ all types can refresh.)
1605
+
1606
+ This is one of the four relationship metaparameters, along with
1607
+ `before`, `require`, and `notify`. For more context, including the
1608
+ alternate chaining arrow (`->` and `~>`) syntax, see
1609
+ [the language page on relationships](https://puppet.com/docs/puppet/latest/lang_relationships.html)."
1610
+ end
1611
+
1612
+ newmetaparam(:before, :parent => RelationshipMetaparam, :attributes => { :direction => :out, :events => :NONE }) do
1613
+ desc "One or more resources that depend on this resource, expressed as
1614
+ [resource references](https://puppet.com/docs/puppet/latest/lang_data_resource_reference.html).
1615
+ Multiple resources can be specified as an array of references. When this
1616
+ attribute is present:
1617
+
1618
+ * This resource will be applied _before_ the dependent resources.
1619
+
1620
+ This is one of the four relationship metaparameters, along with
1621
+ `require`, `notify`, and `subscribe`. For more context, including the
1622
+ alternate chaining arrow (`->` and `~>`) syntax, see
1623
+ [the language page on relationships](https://puppet.com/docs/puppet/latest/lang_relationships.html)."
1624
+ end
1625
+
1626
+ newmetaparam(:notify, :parent => RelationshipMetaparam, :attributes => { :direction => :out, :events => :ALL_EVENTS, :callback => :refresh }) do
1627
+ desc "One or more resources that depend on this resource, expressed as
1628
+ [resource references](https://puppet.com/docs/puppet/latest/lang_data_resource_reference.html).
1629
+ Multiple resources can be specified as an array of references. When this
1630
+ attribute is present:
1631
+
1632
+ * This resource will be applied _before_ the notified resources.
1633
+ * If Puppet makes changes to this resource, it will cause all of the
1634
+ notified resources to _refresh._ (Refresh behavior varies by resource
1635
+ type: services will restart, mounts will unmount and re-mount, etc. Not
1636
+ all types can refresh.)
1637
+
1638
+ This is one of the four relationship metaparameters, along with
1639
+ `before`, `require`, and `subscribe`. For more context, including the
1640
+ alternate chaining arrow (`->` and `~>`) syntax, see
1641
+ [the language page on relationships](https://puppet.com/docs/puppet/latest/lang_relationships.html)."
1642
+ end
1643
+
1644
+ newmetaparam(:stage) do
1645
+ desc %{Which run stage this class should reside in.
1646
+
1647
+ **Note: This metaparameter can only be used on classes,** and only when
1648
+ declaring them with the resource-like syntax. It cannot be used on normal
1649
+ resources or on classes declared with `include`.
1650
+
1651
+ By default, all classes are declared in the `main` stage. To assign a class
1652
+ to a different stage, you must:
1653
+
1654
+ * Declare the new stage as a [`stage` resource](https://puppet.com/docs/puppet/latest/type.html#stage).
1655
+ * Declare an order relationship between the new stage and the `main` stage.
1656
+ * Use the resource-like syntax to declare the class, and set the `stage`
1657
+ metaparameter to the name of the desired stage.
1658
+
1659
+ For example:
1660
+
1661
+ stage { 'pre':
1662
+ before => Stage['main'],
1663
+ }
1664
+
1665
+ class { 'apt-updates':
1666
+ stage => 'pre',
1667
+ }
1668
+ }
1669
+ end
1670
+
1671
+ ###############################
1672
+ # All of the provider plumbing for the resource types.
1673
+ require_relative '../puppet/provider'
1674
+ require_relative '../puppet/util/provider_features'
1675
+
1676
+ # Add the feature handling module.
1677
+ extend Puppet::Util::ProviderFeatures
1678
+
1679
+ # The provider that has been selected for the instance of the resource type.
1680
+ # @return [Puppet::Provider,nil] the selected provider or nil, if none has been selected
1681
+ #
1682
+ attr_reader :provider
1683
+
1684
+ # the Type class attribute accessors
1685
+ class << self
1686
+ # The loader of providers to use when loading providers from disk.
1687
+ # Although it looks like this attribute provides a way to operate with different loaders of
1688
+ # providers that is not the case; the attribute is written when a new type is created,
1689
+ # and should not be changed thereafter.
1690
+ # @api private
1691
+ #
1692
+ attr_accessor :providerloader
1693
+
1694
+ # @todo Don't know if this is a name, or a reference to a Provider instance (now marked up as an instance
1695
+ # of Provider.
1696
+ # @return [Puppet::Provider, nil] The default provider for this type, or nil if non is defines
1697
+ #
1698
+ attr_writer :defaultprovider
1699
+ end
1700
+
1701
+ # The default provider, or the most suitable provider if no default provider was set.
1702
+ # @note a warning will be issued if no default provider has been configured and a search for the most
1703
+ # suitable provider returns more than one equally suitable provider.
1704
+ # @return [Puppet::Provider, nil] the default or most suitable provider, or nil if no provider was found
1705
+ #
1706
+ def self.defaultprovider
1707
+ return @defaultprovider if @defaultprovider
1708
+
1709
+ suitable = suitableprovider
1710
+
1711
+ # Find which providers are a default for this system.
1712
+ defaults = suitable.find_all(&:default?)
1713
+
1714
+ # If we don't have any default we use suitable providers
1715
+ defaults = suitable if defaults.empty?
1716
+ max = defaults.collect(&:specificity).max
1717
+ defaults = defaults.find_all { |provider| provider.specificity == max }
1718
+
1719
+ if defaults.length > 1
1720
+ Puppet.warning(_("Found multiple default providers for %{name}: %{provider_list}; using %{selected_provider}") %
1721
+ { name: name, provider_list: defaults.collect { |i| i.name.to_s }.join(", "), selected_provider: defaults[0].name })
1722
+ end
1723
+
1724
+ @defaultprovider = defaults.shift unless defaults.empty?
1725
+ end
1726
+
1727
+ # @return [Hash{??? => Puppet::Provider}] Returns a hash of WHAT EXACTLY for the given type
1728
+ # @todo what goes into this hash?
1729
+ def self.provider_hash_by_type(type)
1730
+ @provider_hashes ||= {}
1731
+ @provider_hashes[type] ||= {}
1732
+ end
1733
+
1734
+ # @return [Hash{ ??? => Puppet::Provider}] Returns a hash of WHAT EXACTLY for this type.
1735
+ # @see provider_hash_by_type method to get the same for some other type
1736
+ def self.provider_hash
1737
+ Puppet::Type.provider_hash_by_type(name)
1738
+ end
1739
+
1740
+ # Returns the provider having the given name.
1741
+ # This will load a provider if it is not already loaded. The returned provider is the first found provider
1742
+ # having the given name, where "first found" semantics is defined by the {providerloader} in use.
1743
+ #
1744
+ # @param name [String] the name of the provider to get
1745
+ # @return [Puppet::Provider, nil] the found provider, or nil if no provider of the given name was found
1746
+ #
1747
+ def self.provider(name)
1748
+ name = name.intern
1749
+
1750
+ # If we don't have it yet, try loading it.
1751
+ @providerloader.load(name, Puppet.lookup(:current_environment)) unless provider_hash.has_key?(name)
1752
+ provider_hash[name]
1753
+ end
1754
+
1755
+ # Returns a list of loaded providers by name.
1756
+ # This method will not load/search for available providers.
1757
+ # @return [Array<String>] list of loaded provider names
1758
+ #
1759
+ def self.providers
1760
+ provider_hash.keys
1761
+ end
1762
+
1763
+ # Returns true if the given name is a reference to a provider and if this is a suitable provider for
1764
+ # this type.
1765
+ # @todo How does the provider know if it is suitable for the type? Is it just suitable for the platform/
1766
+ # environment where this method is executing?
1767
+ # @param name [String] the name of the provider for which validity is checked
1768
+ # @return [Boolean] true if the given name references a provider that is suitable
1769
+ #
1770
+ def self.validprovider?(name)
1771
+ name = name.intern
1772
+
1773
+ provider_hash.has_key?(name) && provider_hash[name].suitable?
1774
+ end
1775
+
1776
+ # Creates a new provider of a type.
1777
+ # This method must be called directly on the type that it's implementing.
1778
+ # @todo Fix Confusing Explanations!
1779
+ # Is this a new provider of a Type (metatype), or a provider of an instance of Type (a resource), or
1780
+ # a Provider (the implementation of a Type's behavior). CONFUSED. It calls magically named methods like
1781
+ # "providify" ...
1782
+ # @param name [String, Symbol] the name of the WHAT? provider? type?
1783
+ # @param options [Hash{Symbol => Object}] a hash of options, used by this method, and passed on to {#genclass}, (see
1784
+ # it for additional options to pass).
1785
+ # @option options [Puppet::Provider] :parent the parent provider (what is this?)
1786
+ # @option options [Puppet::Type] :resource_type the resource type, defaults to this type if unspecified
1787
+ # @return [Puppet::Provider] a provider ???
1788
+ # @raise [Puppet::DevError] when the parent provider could not be found.
1789
+ #
1790
+ def self.provide(name, options = {}, &block)
1791
+ name = name.intern
1792
+
1793
+ if unprovide(name)
1794
+ Puppet.debug { "Reloading #{name} #{self.name} provider" }
1795
+ end
1796
+
1797
+ pname = options[:parent]
1798
+ parent = if pname
1799
+ options.delete(:parent)
1800
+ if pname.is_a? Class
1801
+ pname
1802
+ else
1803
+ provider = self.provider(pname)
1804
+ provider || raise(Puppet::DevError, _("Could not find parent provider %{parent} of %{name}") % { parent: pname, name: name })
1805
+ end
1806
+ else
1807
+ Puppet::Provider
1808
+ end
1809
+
1810
+ options[:resource_type] ||= self
1811
+
1812
+ providify
1813
+
1814
+ genclass(
1815
+ name,
1816
+ :parent => parent,
1817
+ :hash => provider_hash,
1818
+ :prefix => "Provider",
1819
+ :block => block,
1820
+ :include => feature_module,
1821
+ :extend => feature_module,
1822
+ :attributes => options
1823
+ )
1824
+ end
1825
+
1826
+ # Ensures there is a `:provider` parameter defined.
1827
+ # Should only be called if there are providers.
1828
+ # @return [void]
1829
+ def self.providify
1830
+ return if @paramhash.has_key? :provider
1831
+
1832
+ param = newparam(:provider) do
1833
+ # We're using a hacky way to get the name of our type, since there doesn't
1834
+ # seem to be a correct way to introspect this at the time this code is run.
1835
+ # We expect that the class in which this code is executed will be something
1836
+ # like Puppet::Type::Ssh_authorized_key::ParameterProvider.
1837
+ desc <<-EOT
1838
+ The specific backend to use for this `#{to_s.split('::')[2].downcase}`
1839
+ resource. You will seldom need to specify this --- Puppet will usually
1840
+ discover the appropriate provider for your platform.
1841
+ EOT
1842
+
1843
+ # This is so we can refer back to the type to get a list of
1844
+ # providers for documentation.
1845
+ class << self
1846
+ # The reference to a parent type for the parameter `:provider` used to get a list of
1847
+ # providers for documentation purposes.
1848
+ #
1849
+ attr_accessor :parenttype
1850
+ end
1851
+
1852
+ # Provides the ability to add documentation to a provider.
1853
+ #
1854
+ def self.doc
1855
+ # Since we're mixing @doc with text from other sources, we must normalize
1856
+ # its indentation with scrub. But we don't need to manually scrub the
1857
+ # provider's doc string, since markdown_definitionlist sanitizes its inputs.
1858
+ scrub(@doc) + "Available providers are:\n\n" + parenttype.providers.sort_by(&:to_s).collect { |i|
1859
+ markdown_definitionlist(i, scrub(parenttype().provider(i).doc))
1860
+ }.join
1861
+ end
1862
+
1863
+ # For each resource, the provider param defaults to
1864
+ # the type's default provider
1865
+ defaultto {
1866
+ prov = @resource.class.defaultprovider
1867
+ prov.name if prov
1868
+ }
1869
+
1870
+ validate do |provider_class|
1871
+ provider_class = provider_class[0] if provider_class.is_a? Array
1872
+ provider_class = provider_class.class.name if provider_class.is_a?(Puppet::Provider)
1873
+
1874
+ unless @resource.class.provider(provider_class)
1875
+ raise ArgumentError, _("Invalid %{resource} provider '%{provider_class}'") % { resource: @resource.class.name, provider_class: provider_class }
1876
+ end
1877
+ end
1878
+
1879
+ munge do |provider|
1880
+ provider = provider[0] if provider.is_a? Array
1881
+ provider = provider.intern if provider.is_a? String
1882
+ @resource.provider = provider
1883
+
1884
+ if provider.is_a?(Puppet::Provider)
1885
+ provider.class.name
1886
+ else
1887
+ provider
1888
+ end
1889
+ end
1890
+ end
1891
+ param.parenttype = self
1892
+ end
1893
+
1894
+ # @todo this needs a better explanation
1895
+ # Removes the implementation class of a given provider.
1896
+ # @return [Object] returns what {Puppet::Util::ClassGen#rmclass} returns
1897
+ def self.unprovide(name)
1898
+ if @defaultprovider and @defaultprovider.name == name
1899
+ @defaultprovider = nil
1900
+ end
1901
+
1902
+ rmclass(name, :hash => provider_hash, :prefix => "Provider")
1903
+ end
1904
+
1905
+ # Returns a list of suitable providers for the given type.
1906
+ # A call to this method will load all providers if not already loaded and ask each if it is
1907
+ # suitable - those that are included in the result.
1908
+ # @note This method also does some special processing which rejects a provider named `:fake` (for testing purposes).
1909
+ # @return [Array<Puppet::Provider>] Returns an array of all suitable providers.
1910
+ #
1911
+ def self.suitableprovider
1912
+ providerloader.loadall(Puppet.lookup(:current_environment)) if provider_hash.empty?
1913
+ provider_hash.find_all { |_name, provider|
1914
+ provider.suitable?
1915
+ }.collect { |_name, provider|
1916
+ provider
1917
+ }.reject { |p| p.name == :fake } # For testing
1918
+ end
1919
+
1920
+ # @return [Boolean] Returns true if this is something else than a `:provider`, or if it
1921
+ # is a provider and it is suitable, or if there is a default provider. Otherwise, false is returned.
1922
+ #
1923
+ def suitable?
1924
+ # If we don't use providers, then we consider it suitable.
1925
+ return true unless self.class.paramclass(:provider)
1926
+
1927
+ # We have a provider and it is suitable.
1928
+ return true if provider && provider.class.suitable?
1929
+
1930
+ # We're using the default provider and there is one.
1931
+ if !provider and self.class.defaultprovider
1932
+ self.provider = self.class.defaultprovider.name
1933
+ return true
1934
+ end
1935
+
1936
+ # We specified an unsuitable provider, or there isn't any suitable
1937
+ # provider.
1938
+ false
1939
+ end
1940
+
1941
+ # Sets the provider to the given provider/name.
1942
+ # @overload provider=(name)
1943
+ # Sets the provider to the result of resolving the name to an instance of Provider.
1944
+ # @param name [String] the name of the provider
1945
+ # @overload provider=(provider)
1946
+ # Sets the provider to the given instances of Provider.
1947
+ # @param provider [Puppet::Provider] the provider to set
1948
+ # @return [Puppet::Provider] the provider set
1949
+ # @raise [ArgumentError] if the provider could not be found/resolved.
1950
+ #
1951
+ def provider=(name)
1952
+ if name.is_a?(Puppet::Provider)
1953
+ @provider = name
1954
+ @provider.resource = self
1955
+ else
1956
+ klass = self.class.provider(name)
1957
+ if klass
1958
+ @provider = klass.new(self)
1959
+ else
1960
+ raise ArgumentError, _("Could not find %{name} provider of %{provider}") % { name: name, provider: self.class.name }
1961
+ end
1962
+ end
1963
+ end
1964
+
1965
+ ###############################
1966
+ # All of the relationship code.
1967
+
1968
+ # Adds a block producing a single name (or list of names) of the given
1969
+ # resource type name to autorelate.
1970
+ #
1971
+ # The four relationship types require, before, notify, and subscribe are all
1972
+ # supported.
1973
+ #
1974
+ # Be *careful* with notify and subscribe as they may have unintended
1975
+ # consequences.
1976
+ #
1977
+ # Resources in the catalog that have the named type and a title that is
1978
+ # included in the result will be linked to the calling resource as a
1979
+ # requirement.
1980
+ #
1981
+ # @example Autorequire the files File['foo', 'bar']
1982
+ # autorequire( 'file', { ['foo', 'bar'] })
1983
+ #
1984
+ # @example Autobefore the files File['foo', 'bar']
1985
+ # autobefore( 'file', { ['foo', 'bar'] })
1986
+ #
1987
+ # @example Autosubscribe the files File['foo', 'bar']
1988
+ # autosubscribe( 'file', { ['foo', 'bar'] })
1989
+ #
1990
+ # @example Autonotify the files File['foo', 'bar']
1991
+ # autonotify( 'file', { ['foo', 'bar'] })
1992
+ #
1993
+ # @param name [String] the name of a type of which one or several resources should be autorelated e.g. "file"
1994
+ # @yield [ ] a block returning list of names of given type to auto require
1995
+ # @yieldreturn [String, Array<String>] one or several resource names for the named type
1996
+ # @return [void]
1997
+ # @dsl type
1998
+ # @api public
1999
+ #
2000
+ def self.autorequire(name, &block)
2001
+ @autorequires ||= {}
2002
+ @autorequires[name] = block
2003
+ end
2004
+
2005
+ def self.autobefore(name, &block)
2006
+ @autobefores ||= {}
2007
+ @autobefores[name] = block
2008
+ end
2009
+
2010
+ def self.autosubscribe(name, &block)
2011
+ @autosubscribes ||= {}
2012
+ @autosubscribes[name] = block
2013
+ end
2014
+
2015
+ def self.autonotify(name, &block)
2016
+ @autonotifies ||= {}
2017
+ @autonotifies[name] = block
2018
+ end
2019
+
2020
+ # Provides iteration over added auto-requirements (see {autorequire}).
2021
+ # @yieldparam type [String] the name of the type to autorequire an instance of
2022
+ # @yieldparam block [Proc] a block producing one or several dependencies to auto require (see {autorequire}).
2023
+ # @yieldreturn [void]
2024
+ # @return [void]
2025
+ def self.eachautorequire
2026
+ @autorequires ||= {}
2027
+ @autorequires.each { |type, block|
2028
+ yield(type, block)
2029
+ }
2030
+ end
2031
+
2032
+ # Provides iteration over added auto-requirements (see {autobefore}).
2033
+ # @yieldparam type [String] the name of the type to autorequire an instance of
2034
+ # @yieldparam block [Proc] a block producing one or several dependencies to auto require (see {autobefore}).
2035
+ # @yieldreturn [void]
2036
+ # @return [void]
2037
+ def self.eachautobefore
2038
+ @autobefores ||= {}
2039
+ @autobefores.each { |type, block|
2040
+ yield(type, block)
2041
+ }
2042
+ end
2043
+
2044
+ # Provides iteration over added auto-requirements (see {autosubscribe}).
2045
+ # @yieldparam type [String] the name of the type to autorequire an instance of
2046
+ # @yieldparam block [Proc] a block producing one or several dependencies to auto require (see {autosubscribe}).
2047
+ # @yieldreturn [void]
2048
+ # @return [void]
2049
+ def self.eachautosubscribe
2050
+ @autosubscribes ||= {}
2051
+ @autosubscribes.each { |type, block|
2052
+ yield(type, block)
2053
+ }
2054
+ end
2055
+
2056
+ # Provides iteration over added auto-requirements (see {autonotify}).
2057
+ # @yieldparam type [String] the name of the type to autorequire an instance of
2058
+ # @yieldparam block [Proc] a block producing one or several dependencies to auto require (see {autonotify}).
2059
+ # @yieldreturn [void]
2060
+ # @return [void]
2061
+ def self.eachautonotify
2062
+ @autonotifies ||= {}
2063
+ @autonotifies.each { |type, block|
2064
+ yield(type, block)
2065
+ }
2066
+ end
2067
+
2068
+ # Adds dependencies to the catalog from added autorelations.
2069
+ # See {autorequire} for how to add an auto-requirement.
2070
+ # @todo needs details - see the param rel_catalog, and type of this param
2071
+ # @param rel_catalog [Puppet::Resource::Catalog, nil] the catalog to
2072
+ # add dependencies to. Defaults to the current catalog (set when the
2073
+ # type instance was added to a catalog)
2074
+ # @raise [Puppet::DevError] if there is no catalog
2075
+ #
2076
+ def autorelation(rel_type, rel_catalog = nil)
2077
+ rel_catalog ||= catalog
2078
+ raise Puppet::DevError, _("You cannot add relationships without a catalog") unless rel_catalog
2079
+
2080
+ reqs = []
2081
+
2082
+ auto_rel = "eachauto#{rel_type}".to_sym
2083
+
2084
+ self.class.send(auto_rel) { |type, block|
2085
+ # Ignore any types we can't find, although that would be a bit odd.
2086
+ next unless Puppet::Type.type(type)
2087
+
2088
+ # Retrieve the list of names from the block.
2089
+ list = instance_eval(&block)
2090
+ next unless list
2091
+
2092
+ list = [list] unless list.is_a?(Array)
2093
+
2094
+ # Collect the current prereqs
2095
+ list.each { |dep|
2096
+ next if dep.nil?
2097
+
2098
+ # Support them passing objects directly, to save some effort.
2099
+ unless dep.is_a?(Puppet::Type)
2100
+ # Skip autorelation that we aren't managing
2101
+ dep = rel_catalog.resource(type, dep)
2102
+ next unless dep
2103
+ end
2104
+
2105
+ if [:require, :subscribe].include?(rel_type)
2106
+ reqs << Puppet::Relationship.new(dep, self)
2107
+ else
2108
+ reqs << Puppet::Relationship.new(self, dep)
2109
+ end
2110
+ }
2111
+ }
2112
+ reqs
2113
+ end
2114
+
2115
+ def autorequire(rel_catalog = nil)
2116
+ autorelation(:require, rel_catalog)
2117
+ end
2118
+
2119
+ def autobefore(rel_catalog = nil)
2120
+ autorelation(:before, rel_catalog)
2121
+ end
2122
+
2123
+ def autosubscribe(rel_catalog = nil)
2124
+ autorelation(:subscribe, rel_catalog)
2125
+ end
2126
+
2127
+ def autonotify(rel_catalog = nil)
2128
+ autorelation(:notify, rel_catalog)
2129
+ end
2130
+
2131
+ # Builds the dependencies associated with this resource.
2132
+ #
2133
+ # @return [Array<Puppet::Relationship>] list of relationships to other resources
2134
+ def builddepends
2135
+ # Handle the requires
2136
+ self.class.relationship_params.collect do |klass|
2137
+ param = @parameters[klass.name]
2138
+ param.to_edges if param
2139
+ end.flatten.compact
2140
+ end
2141
+
2142
+ # Sets the initial list of tags to associate to this resource.
2143
+ #
2144
+ # @return [void] ???
2145
+ def tags=(list)
2146
+ tag(self.class.name)
2147
+ tag(*list)
2148
+ end
2149
+
2150
+ # @comment - these two comments were floating around here, and turned up as documentation
2151
+ # for the attribute "title", much to my surprise and amusement. Clearly these comments
2152
+ # are orphaned ... I think they can just be removed as what they say should be covered
2153
+ # by the now added yardoc. <irony>(Yo! to quote some of the other actual awesome specific comments applicable
2154
+ # to objects called from elsewhere, or not. ;-)</irony>
2155
+ #
2156
+ # @comment Types (which map to resources in the languages) are entirely composed of
2157
+ # attribute value pairs. Generally, Puppet calls any of these things an
2158
+ # 'attribute', but these attributes always take one of three specific
2159
+ # forms: parameters, metaparams, or properties.
2160
+
2161
+ # @comment In naming methods, I have tried to consistently name the method so
2162
+ # that it is clear whether it operates on all attributes (thus has 'attr' in
2163
+ # the method name, or whether it operates on a specific type of attributes.
2164
+
2165
+ # The title attribute of WHAT ???
2166
+ # @todo Figure out what this is the title attribute of (it appears on line 1926 currently).
2167
+ # @return [String] the title
2168
+ attr_writer :title
2169
+
2170
+ # The noop attribute of WHAT ??? does WHAT???
2171
+ # @todo Figure out what this is the noop attribute of (it appears on line 1931 currently).
2172
+ # @return [???] the noop WHAT ??? (mode? if so of what, or noop for an instance of the type, or for all
2173
+ # instances of a type, or for what???
2174
+ #
2175
+ attr_writer :noop
2176
+
2177
+ include Enumerable
2178
+
2179
+ # class methods dealing with Type management
2180
+
2181
+ # The Type class attribute accessors
2182
+ class << self
2183
+ # @return [String] the name of the resource type; e.g., "File"
2184
+ #
2185
+ attr_reader :name
2186
+
2187
+ # @return [Boolean] true if the type should send itself a refresh event on change.
2188
+ #
2189
+ attr_accessor :self_refresh
2190
+
2191
+ include Enumerable, Puppet::Util::ClassGen
2192
+
2193
+ include Puppet::Util
2194
+ include Puppet::Util::Logging
2195
+ end
2196
+
2197
+ # Initializes all of the variables that must be initialized for each subclass.
2198
+ # @todo Does the explanation make sense?
2199
+ # @return [void]
2200
+ def self.initvars
2201
+ # all of the instances of this class
2202
+ @objects = Hash.new
2203
+ @aliases = Hash.new
2204
+
2205
+ @defaults = {}
2206
+
2207
+ @parameters ||= []
2208
+
2209
+ @validproperties = {}
2210
+ @properties = []
2211
+ @parameters = []
2212
+ @paramhash = {}
2213
+
2214
+ @paramdoc = Hash.new { |hash, key|
2215
+ key = key.intern if key.is_a?(String)
2216
+ if hash.include?(key)
2217
+ hash[key]
2218
+ else
2219
+ "Param Documentation for #{key} not found"
2220
+ end
2221
+ }
2222
+ # rubocop:disable Naming/MemoizedInstanceVariableName
2223
+ @doc ||= ""
2224
+ # rubocop:enable Naming/MemoizedInstanceVariableName
2225
+ end
2226
+
2227
+ # Returns the name of this type (if specified) or the parent type #to_s.
2228
+ # The returned name is on the form "Puppet::Type::<name>", where the first letter of name is
2229
+ # capitalized.
2230
+ # @return [String] the fully qualified name Puppet::Type::<name> where the first letter of name is capitalized
2231
+ #
2232
+ def self.to_s
2233
+ if defined?(@name)
2234
+ "Puppet::Type::#{@name.to_s.capitalize}"
2235
+ else
2236
+ super
2237
+ end
2238
+ end
2239
+
2240
+ # Creates a `validate` method that is used to validate a resource before it is operated on.
2241
+ # The validation should raise exceptions if the validation finds errors. (It is not recommended to
2242
+ # issue warnings as this typically just ends up in a logfile - you should fail if a validation fails).
2243
+ # The easiest way to raise an appropriate exception is to call the method {Puppet::Util::Errors.fail} with
2244
+ # the message as an argument.
2245
+ #
2246
+ # @yield [ ] a required block called with self set to the instance of a Type class representing a resource.
2247
+ # @return [void]
2248
+ # @dsl type
2249
+ # @api public
2250
+ #
2251
+ def self.validate(&block)
2252
+ define_method(:unsafe_validate, &block)
2253
+
2254
+ define_method(:validate) do
2255
+ return if enum_for(:eachparameter).any? { |p| p.value.instance_of?(Puppet::Pops::Evaluator::DeferredValue) }
2256
+
2257
+ unsafe_validate
2258
+ end
2259
+ end
2260
+
2261
+ # @return [String] The file from which this type originates from
2262
+ attr_accessor :file
2263
+
2264
+ # @return [Integer] The line in {#file} from which this type originates from
2265
+ attr_accessor :line
2266
+
2267
+ # @todo what does this mean "this resource" (sounds like this if for an instance of the type, not the meta Type),
2268
+ # but not sure if this is about the catalog where the meta Type is included)
2269
+ # @return [??? TODO] The catalog that this resource is stored in.
2270
+ attr_accessor :catalog
2271
+
2272
+ # @return [Boolean] Flag indicating if this type is exported
2273
+ attr_accessor :exported
2274
+
2275
+ # @return [Boolean] Flag indicating if the type is virtual (it should not be).
2276
+ attr_accessor :virtual
2277
+
2278
+ # Creates a log entry with the given message at the log level specified by the parameter `loglevel`
2279
+ # @return [void]
2280
+ #
2281
+ def log(msg)
2282
+ Puppet::Util::Log.create(
2283
+ :level => @parameters[:loglevel].value,
2284
+ :message => msg,
2285
+
2286
+ :source => self
2287
+ )
2288
+ end
2289
+
2290
+ # instance methods related to instance intrinsics
2291
+ # e.g., initialize and name
2292
+
2293
+ # @return [Hash] hash of parameters originally defined
2294
+ # @api private
2295
+ attr_reader :original_parameters
2296
+
2297
+ # Creates an instance of Type from a hash or a {Puppet::Resource}.
2298
+ # @todo Unclear if this is a new Type or a new instance of a given type (the initialization ends
2299
+ # with calling validate - which seems like validation of an instance of a given type, not a new
2300
+ # meta type.
2301
+ #
2302
+ # @todo Explain what the Hash and Resource are. There seems to be two different types of
2303
+ # resources; one that causes the title to be set to resource.title, and one that
2304
+ # causes the title to be resource.ref ("for components") - what is a component?
2305
+ #
2306
+ # @overload initialize(hash)
2307
+ # @param [Hash] hash
2308
+ # @raise [Puppet::ResourceError] when the type validation raises
2309
+ # Puppet::Error or ArgumentError
2310
+ # @overload initialize(resource)
2311
+ # @param resource [Puppet:Resource]
2312
+ # @raise [Puppet::ResourceError] when the type validation raises
2313
+ # Puppet::Error or ArgumentError
2314
+ #
2315
+ def initialize(resource)
2316
+ resource = self.class.hash2resource(resource) unless resource.is_a?(Puppet::Resource)
2317
+
2318
+ # The list of parameter/property instances.
2319
+ @parameters = {}
2320
+
2321
+ # Set the title first, so any failures print correctly.
2322
+ if resource.type.to_s.downcase.to_sym == self.class.name
2323
+ self.title = resource.title
2324
+ else
2325
+ # This should only ever happen for components
2326
+ self.title = resource.ref
2327
+ end
2328
+
2329
+ [:file, :line, :catalog, :exported, :virtual].each do |getter|
2330
+ setter = getter.to_s + "="
2331
+ val = resource.send(getter)
2332
+ send(setter, val) if val
2333
+ end
2334
+
2335
+ merge_tags_from(resource)
2336
+
2337
+ @original_parameters = resource.to_hash
2338
+
2339
+ set_name(@original_parameters)
2340
+
2341
+ set_default(:provider)
2342
+
2343
+ set_parameters(@original_parameters)
2344
+
2345
+ validate_resource
2346
+
2347
+ set_sensitive_parameters(resource.sensitive_parameters)
2348
+ end
2349
+
2350
+ # Optionally validate the resource. This method is a noop if the type has not defined
2351
+ # a `validate` method using the puppet DSL. If validation fails, then an exception will
2352
+ # be raised with this resources as the context.
2353
+ #
2354
+ # @api public
2355
+ #
2356
+ # @return [void]
2357
+ def validate_resource
2358
+ validate if respond_to?(:validate)
2359
+ rescue Puppet::Error, ArgumentError => detail
2360
+ error = Puppet::ResourceError.new("Validation of #{ref} failed: #{detail}")
2361
+ adderrorcontext(error, detail)
2362
+ raise error
2363
+ end
2364
+
2365
+ protected
2366
+
2367
+ # Mark parameters associated with this type as sensitive, based on the associated resource.
2368
+ #
2369
+ # Currently, only instances of `Puppet::Property` can be easily marked for sensitive data handling
2370
+ # and information redaction is limited to redacting events generated while synchronizing
2371
+ # properties. While support for redaction will be broadened in the future we can't automatically
2372
+ # deduce how to redact arbitrary parameters, so if a parameter is marked for redaction the best
2373
+ # we can do is warn that we can't handle treating that parameter as sensitive and move on.
2374
+ #
2375
+ # In some unusual cases a given parameter will be marked as sensitive but that sensitive context
2376
+ # needs to be transferred to another parameter. In this case resource types may need to override
2377
+ # this method in order to copy the sensitive context from one parameter to another (and in the
2378
+ # process force the early generation of a parameter that might otherwise be lazily generated.)
2379
+ # See `Puppet::Type.type(:file)#set_sensitive_parameters` for an example of this.
2380
+ #
2381
+ # @note This method visibility is protected since it should only be called by #initialize, but is
2382
+ # marked as public as subclasses may need to override this method.
2383
+ #
2384
+ # @api public
2385
+ #
2386
+ # @param sensitive_parameters [Array<Symbol>] A list of parameters to mark as sensitive.
2387
+ #
2388
+ # @return [void]
2389
+ def set_sensitive_parameters(sensitive_parameters)
2390
+ sensitive_parameters.each do |name|
2391
+ p = parameter(name)
2392
+ if p.is_a?(Puppet::Property)
2393
+ p.sensitive = true
2394
+ elsif p.is_a?(Puppet::Parameter)
2395
+ warning(_("Unable to mark '%{name}' as sensitive: %{name} is a parameter and not a property, and cannot be automatically redacted.") %
2396
+ { name: name })
2397
+ elsif self.class.attrclass(name)
2398
+ warning(_("Unable to mark '%{name}' as sensitive: the property itself was not assigned a value.") % { name: name })
2399
+ else
2400
+ err(_("Unable to mark '%{name}' as sensitive: the property itself is not defined on %{type}.") % { name: name, type: type })
2401
+ end
2402
+ end
2403
+
2404
+ parameters.each do |_name, param|
2405
+ next if param.sensitive
2406
+
2407
+ if param.is_a?(Puppet::Parameter)
2408
+ param.sensitive = param.is_sensitive if param.respond_to?(:is_sensitive)
2409
+ end
2410
+ end
2411
+ end
2412
+
2413
+ private
2414
+
2415
+ # Sets the name of the resource from a hash containing a mapping of `name_var` to value.
2416
+ # Sets the value of the property/parameter appointed by the `name_var` (if it is defined). The value set is
2417
+ # given by the corresponding entry in the given hash - e.g. if name_var appoints the name `:path` the value
2418
+ # of `:path` is set to the value at the key `:path` in the given hash. As a side effect this key/value is then
2419
+ # removed from the given hash.
2420
+ #
2421
+ # @note This method mutates the given hash by removing the entry with a key equal to the value
2422
+ # returned from name_var!
2423
+ # @param hash [Hash] a hash of what
2424
+ # @return [void]
2425
+ def set_name(hash)
2426
+ self[name_var] = hash.delete(name_var) if name_var
2427
+ end
2428
+
2429
+ # Sets parameters from the given hash.
2430
+ # Values are set in _attribute order_ i.e. higher priority attributes before others, otherwise in
2431
+ # the order they were specified (as opposed to just setting them in the order they happen to appear in
2432
+ # when iterating over the given hash).
2433
+ #
2434
+ # Attributes that are not included in the given hash are set to their default value.
2435
+ #
2436
+ # @todo Is this description accurate? Is "ensure" an example of such a higher priority attribute?
2437
+ # @return [void]
2438
+ # @raise [Puppet::DevError] when impossible to set the value due to some problem
2439
+ # @raise [ArgumentError, TypeError, Puppet::Error] when faulty arguments have been passed
2440
+ #
2441
+ def set_parameters(hash)
2442
+ # Use the order provided by allattrs, but add in any
2443
+ # extra attributes from the resource so we get failures
2444
+ # on invalid attributes.
2445
+ no_values = []
2446
+ (self.class.allattrs + hash.keys).uniq.each do |attr|
2447
+ # Set any defaults immediately. This is mostly done so
2448
+ # that the default provider is available for any other
2449
+ # property validation.
2450
+ if hash.has_key?(attr)
2451
+ self[attr] = hash[attr]
2452
+ else
2453
+ no_values << attr
2454
+ end
2455
+ rescue ArgumentError, Puppet::Error, TypeError
2456
+ raise
2457
+ rescue => detail
2458
+ error = Puppet::DevError.new(_("Could not set %{attribute} on %{class_name}: %{detail}") % { attribute: attr, class_name: self.class.name, detail: detail })
2459
+ error.set_backtrace(detail.backtrace)
2460
+ raise error
2461
+ end
2462
+ no_values.each do |attr|
2463
+ set_default(attr)
2464
+ end
2465
+ end
2466
+
2467
+ public
2468
+
2469
+ # Finishes any outstanding processing.
2470
+ # This method should be called as a final step in setup,
2471
+ # to allow the parameters that have associated auto-require needs to be processed.
2472
+ #
2473
+ # @todo what is the expected sequence here - who is responsible for calling this? When?
2474
+ # Is the returned type correct?
2475
+ # @return [Array<Puppet::Parameter>] the validated list/set of attributes
2476
+ #
2477
+ def finish
2478
+ # Call post_compile hook on every parameter that implements it. This includes all subclasses
2479
+ # of parameter including, but not limited to, regular parameters, metaparameters, relationship
2480
+ # parameters, and properties.
2481
+ eachparameter do |parameter|
2482
+ parameter.post_compile if parameter.respond_to? :post_compile
2483
+ end
2484
+
2485
+ # Make sure all of our relationships are valid. Again, must be done
2486
+ # when the entire catalog is instantiated.
2487
+ self.class.relationship_params.collect do |klass|
2488
+ param = @parameters[klass.name]
2489
+ param.validate_relationship if param
2490
+ end.flatten.compact
2491
+ end
2492
+
2493
+ # @comment For now, leave the 'name' method functioning like it used to. Once 'title'
2494
+ # works everywhere, I'll switch it.
2495
+ # Returns the resource's name
2496
+ # @todo There is a comment in source that this is not quite the same as ':title' and that a switch should
2497
+ # be made...
2498
+ # @return [String] the name of a resource
2499
+ def name
2500
+ self[:name]
2501
+ end
2502
+
2503
+ # Returns the parent of this in the catalog. In case of an erroneous catalog
2504
+ # where multiple parents have been produced, the first found (non
2505
+ # deterministic) parent is returned.
2506
+ # @return [Puppet::Type, nil] the
2507
+ # containing resource or nil if there is no catalog or no containing
2508
+ # resource.
2509
+ def parent
2510
+ return nil unless catalog
2511
+ return @parent if @parent
2512
+
2513
+ parents = catalog.adjacent(self, :direction => :in)
2514
+ @parent = if parents
2515
+ parents.shift
2516
+ else
2517
+ nil
2518
+ end
2519
+ end
2520
+
2521
+ # Returns a reference to this as a string in "Type[name]" format.
2522
+ # @return [String] a reference to this object on the form 'Type[name]'
2523
+ #
2524
+ def ref
2525
+ # memoizing this is worthwhile ~ 3 percent of calls are the "first time
2526
+ # around" in an average run of Puppet. --daniel 2012-07-17
2527
+ @ref ||= "#{self.class.name.to_s.capitalize}[#{title}]"
2528
+ end
2529
+
2530
+ # (see self_refresh)
2531
+ # @todo check that meaningful yardoc is produced - this method delegates to "self.class.self_refresh"
2532
+ # @return [Boolean] - ??? returns true when ... what?
2533
+ #
2534
+ def self_refresh?
2535
+ self.class.self_refresh
2536
+ end
2537
+
2538
+ # Marks the object as "being purged".
2539
+ # This method is used by transactions to forbid deletion when there are dependencies.
2540
+ # @todo what does this mean; "mark that we are purging" (purging what from where). How to use/when?
2541
+ # Is this internal API in transactions?
2542
+ # @see purging?
2543
+ def purging
2544
+ @purging = true
2545
+ end
2546
+
2547
+ # Returns whether this resource is being purged or not.
2548
+ # This method is used by transactions to forbid deletion when there are dependencies.
2549
+ # @return [Boolean] the current "purging" state
2550
+ #
2551
+ def purging?
2552
+ if defined?(@purging)
2553
+ @purging
2554
+ else
2555
+ false
2556
+ end
2557
+ end
2558
+
2559
+ # Returns the title of this object, or its name if title was not explicitly set.
2560
+ # If the title is not already set, it will be computed by looking up the {#name_var} and using
2561
+ # that value as the title.
2562
+ # @todo it is somewhat confusing that if the name_var is a valid parameter, it is assumed to
2563
+ # be the name_var called :name, but if it is a property, it uses the name_var.
2564
+ # It is further confusing as Type in some respects supports multiple namevars.
2565
+ #
2566
+ # @return [String] Returns the title of this object, or its name if title was not explicitly set.
2567
+ # @raise [??? devfail] if title is not set, and name_var can not be found.
2568
+ def title
2569
+ unless @title
2570
+ if self.class.validparameter?(name_var)
2571
+ @title = self[:name]
2572
+ elsif self.class.validproperty?(name_var)
2573
+ @title = should(name_var)
2574
+ else
2575
+ devfail "Could not find namevar #{name_var} for #{self.class.name}"
2576
+ end
2577
+ end
2578
+
2579
+ @title
2580
+ end
2581
+
2582
+ # Produces a reference to this in reference format.
2583
+ # @see #ref
2584
+ #
2585
+ def to_s
2586
+ ref
2587
+ end
2588
+
2589
+ # Convert this resource type instance to a Puppet::Resource.
2590
+ # @return [Puppet::Resource] Returns a serializable representation of this resource
2591
+ #
2592
+ def to_resource
2593
+ resource = retrieve_resource
2594
+ resource.merge_tags_from(self)
2595
+
2596
+ @parameters.each do |name, param|
2597
+ # Avoid adding each instance name twice
2598
+ next if param.class.isnamevar? and param.value == title
2599
+
2600
+ # We've already got property values
2601
+ next if param.is_a?(Puppet::Property)
2602
+
2603
+ resource[name] = param.value
2604
+ end
2605
+
2606
+ resource
2607
+ end
2608
+
2609
+ # @return [Boolean] Returns whether the resource is virtual or not
2610
+ def virtual?; !!@virtual; end
2611
+ # @return [Boolean] Returns whether the resource is exported or not
2612
+ def exported?; !!@exported; end
2613
+
2614
+ # @return [Boolean] Returns whether the resource is applicable to `:device`
2615
+ # Returns true if a resource of this type can be evaluated on a 'network device' kind
2616
+ # of hosts.
2617
+ # @api private
2618
+ def appliable_to_device?
2619
+ self.class.can_apply_to(:device)
2620
+ end
2621
+
2622
+ # @return [Boolean] Returns whether the resource is applicable to `:host`
2623
+ # Returns true if a resource of this type can be evaluated on a regular generalized computer (ie not an appliance like a network device)
2624
+ # @api private
2625
+ def appliable_to_host?
2626
+ self.class.can_apply_to(:host)
2627
+ end
2628
+ end
2629
+ end