openvox 7.37.1

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