puppet 4.2.0 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (422) hide show
  1. data/CONTRIBUTING.md +1 -1
  2. data/Gemfile +5 -7
  3. data/README.md +1 -1
  4. data/Rakefile +20 -0
  5. data/ext/debian/puppet.init +0 -1
  6. data/ext/debian/puppet.logrotate +14 -5
  7. data/ext/osx/puppet.plist +2 -4
  8. data/ext/project_data.yaml +1 -1
  9. data/ext/redhat/client.init +65 -12
  10. data/ext/redhat/logrotate +15 -3
  11. data/ext/redhat/puppet.spec.erb +5 -1
  12. data/ext/redhat/server.init +1 -1
  13. data/ext/solaris/smf/puppet +44 -0
  14. data/ext/solaris/smf/puppet.xml +44 -0
  15. data/ext/suse/client.init +27 -27
  16. data/ext/suse/server.init +2 -2
  17. data/ext/systemd/puppet.service +1 -0
  18. data/install.rb +21 -39
  19. data/lib/hiera/puppet_function.rb +5 -5
  20. data/lib/puppet/agent/locker.rb +11 -2
  21. data/lib/puppet/agent.rb +4 -4
  22. data/lib/puppet/application/agent.rb +28 -14
  23. data/lib/puppet/application/apply.rb +17 -4
  24. data/lib/puppet/application/cert.rb +16 -0
  25. data/lib/puppet/application/filebucket.rb +78 -4
  26. data/lib/puppet/application/lookup.rb +356 -0
  27. data/lib/puppet/application/master.rb +5 -1
  28. data/lib/puppet/configurer.rb +9 -5
  29. data/lib/puppet/context/trusted_information.rb +21 -1
  30. data/lib/puppet/context.rb +16 -1
  31. data/lib/puppet/daemon.rb +17 -13
  32. data/lib/puppet/data_binding.rb +4 -2
  33. data/lib/puppet/data_providers/data_adapter.rb +7 -68
  34. data/lib/puppet/data_providers/data_function_support.rb +5 -26
  35. data/lib/puppet/data_providers/function_env_data_provider.rb +0 -10
  36. data/lib/puppet/data_providers/function_module_data_provider.rb +0 -22
  37. data/lib/puppet/data_providers/hiera_config.rb +106 -0
  38. data/lib/puppet/data_providers/hiera_env_data_provider.rb +18 -0
  39. data/lib/puppet/data_providers/hiera_interpolate.rb +97 -0
  40. data/lib/puppet/data_providers/hiera_module_data_provider.rb +23 -0
  41. data/lib/puppet/data_providers/hiera_support.rb +37 -0
  42. data/lib/puppet/data_providers/json_data_provider_factory.rb +31 -0
  43. data/lib/puppet/data_providers/lookup_adapter.rb +200 -0
  44. data/lib/puppet/data_providers/yaml_data_provider_factory.rb +32 -0
  45. data/lib/puppet/data_providers.rb +12 -13
  46. data/lib/puppet/defaults.rb +14 -3
  47. data/lib/puppet/environments.rb +94 -6
  48. data/lib/puppet/error.rb +4 -0
  49. data/lib/puppet/face/module/changes.rb +2 -1
  50. data/lib/puppet/feature/cfacter.rb +1 -0
  51. data/lib/puppet/file_bucket/dipper.rb +58 -2
  52. data/lib/puppet/file_system/windows.rb +3 -1
  53. data/lib/puppet/functions/assert_type.rb +48 -12
  54. data/lib/puppet/functions/defined.rb +79 -48
  55. data/lib/puppet/functions/each.rb +85 -27
  56. data/lib/puppet/functions/epp.rb +29 -37
  57. data/lib/puppet/functions/filter.rb +60 -25
  58. data/lib/puppet/functions/hiera.rb +76 -3
  59. data/lib/puppet/functions/hiera_array.rb +65 -3
  60. data/lib/puppet/functions/hiera_hash.rb +74 -2
  61. data/lib/puppet/functions/hiera_include.rb +77 -4
  62. data/lib/puppet/functions/inline_epp.rb +44 -71
  63. data/lib/puppet/functions/lookup.rb +19 -17
  64. data/lib/puppet/functions/map.rb +56 -21
  65. data/lib/puppet/functions/match.rb +29 -12
  66. data/lib/puppet/functions/reduce.rb +95 -58
  67. data/lib/puppet/functions/versioncmp.rb +36 -0
  68. data/lib/puppet/functions/with.rb +15 -7
  69. data/lib/puppet/functions.rb +2 -4
  70. data/lib/puppet/indirector/catalog/compiler.rb +3 -3
  71. data/lib/puppet/indirector/catalog/static_compiler.rb +46 -30
  72. data/lib/puppet/indirector/data_binding/none.rb +4 -1
  73. data/lib/puppet/indirector/file_bucket_file/file.rb +58 -1
  74. data/lib/puppet/indirector/hiera.rb +4 -0
  75. data/lib/puppet/indirector/indirection.rb +6 -1
  76. data/lib/puppet/indirector/json.rb +1 -1
  77. data/lib/puppet/indirector/msgpack.rb +1 -1
  78. data/lib/puppet/indirector/request.rb +7 -8
  79. data/lib/puppet/indirector/resource_type/parser.rb +5 -3
  80. data/lib/puppet/info_service/class_information_service.rb +111 -0
  81. data/lib/puppet/info_service.rb +7 -0
  82. data/lib/puppet/module_tool/applications/unpacker.rb +1 -1
  83. data/lib/puppet/module_tool/metadata.rb +32 -9
  84. data/lib/puppet/module_tool/skeleton/templates/generator/README.md.erb +42 -38
  85. data/lib/puppet/module_tool/skeleton/templates/generator/manifests/init.pp.erb +25 -18
  86. data/lib/puppet/network/authconfig.rb +21 -1
  87. data/lib/puppet/network/authorization.rb +8 -1
  88. data/lib/puppet/network/http/api/master/v3/environment.rb +59 -0
  89. data/lib/puppet/network/http/api/master/v3.rb +7 -1
  90. data/lib/puppet/node/environment.rb +9 -2
  91. data/lib/puppet/node.rb +11 -5
  92. data/lib/puppet/parser/ast/pops_bridge.rb +39 -1
  93. data/lib/puppet/parser/compiler/catalog_validator/env_relationship_validator.rb +64 -0
  94. data/lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb +38 -0
  95. data/lib/puppet/parser/compiler/catalog_validator/site_validator.rb +20 -0
  96. data/lib/puppet/parser/compiler/catalog_validator.rb +33 -0
  97. data/lib/puppet/parser/compiler.rb +300 -12
  98. data/lib/puppet/parser/environment_compiler.rb +165 -0
  99. data/lib/puppet/parser/functions/assert_type.rb +46 -16
  100. data/lib/puppet/parser/functions/defined.rb +105 -68
  101. data/lib/puppet/parser/functions/each.rb +85 -27
  102. data/lib/puppet/parser/functions/epp.rb +29 -37
  103. data/lib/puppet/parser/functions/filter.rb +59 -23
  104. data/lib/puppet/parser/functions/hiera.rb +83 -27
  105. data/lib/puppet/parser/functions/hiera_array.rb +71 -28
  106. data/lib/puppet/parser/functions/hiera_hash.rb +81 -30
  107. data/lib/puppet/parser/functions/hiera_include.rb +81 -40
  108. data/lib/puppet/parser/functions/inline_epp.rb +35 -60
  109. data/lib/puppet/parser/functions/inline_template.rb +2 -2
  110. data/lib/puppet/parser/functions/map.rb +55 -20
  111. data/lib/puppet/parser/functions/match.rb +27 -12
  112. data/lib/puppet/parser/functions/reduce.rb +97 -60
  113. data/lib/puppet/parser/functions/with.rb +16 -8
  114. data/lib/puppet/parser/resource.rb +103 -21
  115. data/lib/puppet/parser.rb +3 -0
  116. data/lib/puppet/plugins/configuration.rb +3 -2
  117. data/lib/puppet/plugins/data_providers/data_provider.rb +283 -0
  118. data/lib/puppet/plugins/data_providers/registry.rb +84 -0
  119. data/lib/puppet/plugins/data_providers.rb +12 -60
  120. data/lib/puppet/pops/adapters.rb +12 -0
  121. data/lib/puppet/pops/binder/binder.rb +2 -2
  122. data/lib/puppet/pops/binder/bindings_checker.rb +1 -1
  123. data/lib/puppet/pops/binder/bindings_label_provider.rb +3 -1
  124. data/lib/puppet/pops/binder/bindings_loader.rb +6 -2
  125. data/lib/puppet/pops/binder/bindings_model_meta.rb +2 -2
  126. data/lib/puppet/pops/binder/config/binder_config.rb +1 -1
  127. data/lib/puppet/pops/binder/injector.rb +4 -4
  128. data/lib/puppet/pops/binder/key_factory.rb +3 -9
  129. data/lib/puppet/pops/binder/scheme_handler/module_scheme.rb +68 -9
  130. data/lib/puppet/pops/evaluator/access_operator.rb +27 -60
  131. data/lib/puppet/pops/evaluator/closure.rb +8 -8
  132. data/lib/puppet/pops/evaluator/collectors/abstract_collector.rb +1 -1
  133. data/lib/puppet/pops/evaluator/evaluator_impl.rb +10 -6
  134. data/lib/puppet/pops/evaluator/literal_evaluator.rb +87 -0
  135. data/lib/puppet/pops/evaluator/relationship_operator.rb +7 -1
  136. data/lib/puppet/pops/functions/dispatcher.rb +3 -3
  137. data/lib/puppet/pops/issues.rb +11 -3
  138. data/lib/puppet/pops/label_provider.rb +1 -1
  139. data/lib/puppet/pops/lookup/explainer.rb +402 -0
  140. data/lib/puppet/pops/lookup/invocation.rb +117 -0
  141. data/lib/puppet/pops/lookup.rb +25 -47
  142. data/lib/puppet/pops/merge_strategy.rb +73 -5
  143. data/lib/puppet/pops/model/factory.rb +38 -3
  144. data/lib/puppet/pops/model/model_label_provider.rb +10 -1
  145. data/lib/puppet/pops/model/model_meta.rb +19 -1
  146. data/lib/puppet/pops/model/model_tree_dumper.rb +18 -0
  147. data/lib/puppet/pops/parser/code_merger.rb +13 -1
  148. data/lib/puppet/pops/parser/egrammar.ra +65 -2
  149. data/lib/puppet/pops/parser/eparser.rb +1569 -1241
  150. data/lib/puppet/pops/parser/lexer2.rb +32 -1
  151. data/lib/puppet/pops/parser/locator.rb +1 -1
  152. data/lib/puppet/pops/parser/parser_support.rb +25 -13
  153. data/lib/puppet/pops/patterns.rb +3 -0
  154. data/lib/puppet/pops/types/enumeration.rb +1 -2
  155. data/lib/puppet/pops/types/type_asserter.rb +16 -15
  156. data/lib/puppet/pops/types/type_assertion_error.rb +1 -0
  157. data/lib/puppet/pops/types/type_calculator.rb +171 -1020
  158. data/lib/puppet/pops/types/type_factory.rb +87 -148
  159. data/lib/puppet/pops/types/type_mismatch_describer.rb +743 -0
  160. data/lib/puppet/pops/types/type_parser.rb +118 -129
  161. data/lib/puppet/pops/types/types.rb +1394 -255
  162. data/lib/puppet/pops/types/types_meta.rb +0 -234
  163. data/lib/puppet/pops/validation/checker4_0.rb +49 -1
  164. data/lib/puppet/pops/validation/validator_factory_4_0.rb +3 -1
  165. data/lib/puppet/pops/validation.rb +7 -2
  166. data/lib/puppet/pops.rb +19 -17
  167. data/lib/puppet/provider/augeas/augeas.rb +50 -0
  168. data/lib/puppet/provider/exec.rb +6 -1
  169. data/lib/puppet/provider/group/directoryservice.rb +10 -0
  170. data/lib/puppet/provider/package/dnf.rb +41 -0
  171. data/lib/puppet/provider/package/gem.rb +7 -2
  172. data/lib/puppet/provider/package/nim.rb +1 -1
  173. data/lib/puppet/provider/package/rpm.rb +1 -0
  174. data/lib/puppet/provider/package/windows/exe_package.rb +10 -8
  175. data/lib/puppet/provider/package/windows/msi_package.rb +4 -3
  176. data/lib/puppet/provider/package/windows/package.rb +9 -1
  177. data/lib/puppet/provider/package/yum.rb +20 -9
  178. data/lib/puppet/provider/service/bsd.rb +1 -1
  179. data/lib/puppet/provider/service/debian.rb +21 -0
  180. data/lib/puppet/provider/service/init.rb +6 -0
  181. data/lib/puppet/provider/service/launchd.rb +36 -7
  182. data/lib/puppet/provider/service/rcng.rb +51 -0
  183. data/lib/puppet/provider/service/redhat.rb +2 -1
  184. data/lib/puppet/provider/service/smf.rb +43 -2
  185. data/lib/puppet/provider/service/src.rb +27 -0
  186. data/lib/puppet/provider/service/systemd.rb +25 -5
  187. data/lib/puppet/provider/sshkey/parsed.rb +19 -9
  188. data/lib/puppet/provider/zone/solaris.rb +2 -2
  189. data/lib/puppet/reference/configuration.rb +10 -4
  190. data/lib/puppet/reference/report.rb +9 -12
  191. data/lib/puppet/reports.rb +5 -1
  192. data/lib/puppet/resource/capability_finder.rb +95 -0
  193. data/lib/puppet/resource/catalog.rb +47 -7
  194. data/lib/puppet/resource/status.rb +0 -2
  195. data/lib/puppet/resource/type.rb +238 -44
  196. data/lib/puppet/resource/type_collection.rb +60 -2
  197. data/lib/puppet/resource.rb +50 -73
  198. data/lib/puppet/settings/file_setting.rb +10 -9
  199. data/lib/puppet/settings.rb +2 -2
  200. data/lib/puppet/ssl/certificate_authority/interface.rb +2 -2
  201. data/lib/puppet/ssl/oids.rb +9 -1
  202. data/lib/puppet/transaction/additional_resource_generator.rb +71 -8
  203. data/lib/puppet/transaction/resource_harness.rb +9 -4
  204. data/lib/puppet/transaction.rb +8 -1
  205. data/lib/puppet/type/augeas.rb +8 -0
  206. data/lib/puppet/type/file/source.rb +14 -12
  207. data/lib/puppet/type/package.rb +9 -6
  208. data/lib/puppet/type/user.rb +4 -2
  209. data/lib/puppet/type.rb +78 -7
  210. data/lib/puppet/util/command_line.rb +4 -0
  211. data/lib/puppet/util/execution.rb +18 -2
  212. data/lib/puppet/util/tagging.rb +7 -1
  213. data/lib/puppet/util/windows/adsi.rb +5 -2
  214. data/lib/puppet/util/windows/security.rb +4 -1
  215. data/lib/puppet/util/windows/taskscheduler.rb +1 -1
  216. data/lib/puppet/util.rb +9 -1
  217. data/lib/puppet/version.rb +1 -1
  218. data/lib/puppet.rb +12 -0
  219. data/spec/fixtures/unit/application/environments/production/data/common.yaml +3 -0
  220. data/spec/fixtures/unit/application/environments/production/environment.conf +1 -0
  221. data/spec/fixtures/unit/data_providers/environments/hiera_bad_syntax_json/data/bad.json +3 -0
  222. data/spec/fixtures/unit/data_providers/environments/hiera_bad_syntax_json/environment.conf +2 -0
  223. data/spec/fixtures/unit/data_providers/environments/hiera_bad_syntax_json/hiera.yaml +5 -0
  224. data/spec/fixtures/unit/data_providers/environments/hiera_bad_syntax_json/manifests/site.pp +5 -0
  225. data/spec/fixtures/unit/data_providers/environments/hiera_bad_syntax_yaml/data/bad.yaml +3 -0
  226. data/spec/fixtures/unit/data_providers/environments/hiera_bad_syntax_yaml/environment.conf +2 -0
  227. data/spec/fixtures/unit/data_providers/environments/hiera_bad_syntax_yaml/hiera.yaml +5 -0
  228. data/spec/fixtures/unit/data_providers/environments/hiera_bad_syntax_yaml/manifests/site.pp +5 -0
  229. data/spec/fixtures/unit/data_providers/environments/hiera_defaults/data/common.yaml +2 -0
  230. data/spec/fixtures/unit/data_providers/environments/hiera_defaults/environment.conf +2 -0
  231. data/spec/fixtures/unit/data_providers/environments/hiera_defaults/manifests/site.pp +1 -0
  232. data/spec/fixtures/unit/data_providers/environments/hiera_defaults/modules/one/data/common.yaml +2 -0
  233. data/spec/fixtures/unit/data_providers/environments/hiera_defaults/modules/one/manifests/init.pp +5 -0
  234. data/spec/fixtures/unit/data_providers/environments/hiera_defaults/modules/one/metadata.json +9 -0
  235. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/data1/first.json +3 -0
  236. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/data1/name.yaml +2 -0
  237. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/data1/second.json +3 -0
  238. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/data1/single.yaml +2 -0
  239. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/data2/single.yaml +2 -0
  240. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/environment.conf +2 -0
  241. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/hiera.yaml +18 -0
  242. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/manifests/site.pp +5 -0
  243. data/spec/fixtures/unit/data_providers/environments/hiera_misc/data/common.yaml +46 -0
  244. data/spec/fixtures/unit/data_providers/environments/hiera_misc/environment.conf +2 -0
  245. data/spec/fixtures/unit/data_providers/environments/hiera_misc/manifests/site.pp +1 -0
  246. data/spec/fixtures/unit/data_providers/environments/hiera_misc/modules/one/data/common.yaml +30 -0
  247. data/spec/fixtures/unit/data_providers/environments/hiera_misc/modules/one/manifests/init.pp +13 -0
  248. data/spec/fixtures/unit/data_providers/environments/hiera_misc/modules/one/metadata.json +9 -0
  249. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/environment.conf +2 -0
  250. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/manifests/site.pp +1 -0
  251. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/modules/one/data1/first.json +3 -0
  252. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/modules/one/data1/name.yaml +1 -0
  253. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/modules/one/data1/second.json +3 -0
  254. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/modules/one/data1/single.yaml +2 -0
  255. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/modules/one/data2/single.yaml +2 -0
  256. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/modules/one/hiera.yaml +18 -0
  257. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/modules/one/manifests/init.pp +5 -0
  258. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/modules/one/metadata.json +9 -0
  259. data/spec/fixtures/unit/data_providers/environments/sample/modules/dataprovider/lib/puppet_x/helindbe/sample_env_data.rb +1 -0
  260. data/spec/fixtures/unit/data_providers/environments/sample/modules/dataprovider/lib/puppet_x/helindbe/sample_module_data.rb +1 -0
  261. data/spec/fixtures/unit/functions/lookup/environments/production/modules/hieraprovider/data/first.json +3 -0
  262. data/spec/fixtures/unit/functions/lookup/environments/production/modules/hieraprovider/hiera.yaml +8 -0
  263. data/spec/fixtures/unit/functions/lookup/environments/production/modules/hieraprovider/manifests/init.pp +5 -0
  264. data/spec/fixtures/unit/functions/lookup/environments/production/modules/hieraprovider/metadata.json +9 -0
  265. data/spec/fixtures/unit/functions/lookup/environments/production/modules/meta/lib/puppet/functions/meta/data.rb +9 -0
  266. data/spec/fixtures/unit/functions/lookup/environments/production/modules/meta/manifests/init.pp +3 -0
  267. data/spec/fixtures/unit/functions/lookup/environments/production/modules/meta/metadata.json +9 -0
  268. data/spec/fixtures/unit/functions/lookup/environments/production/modules/metawcp/lib/puppet/bindings/metawcp/default.rb +10 -0
  269. data/spec/fixtures/unit/functions/lookup/environments/production/modules/metawcp/lib/puppet_x/thallgren/sample_module_data.rb +23 -0
  270. data/spec/fixtures/unit/functions/lookup/environments/production/modules/metawcp/manifests/init.pp +3 -0
  271. data/spec/fixtures/unit/functions/lookup/environments/production/modules/metawcp/metadata.json +9 -0
  272. data/spec/fixtures/unit/provider/package/yum/yum-check-update-security.txt +184 -0
  273. data/spec/fixtures/vcr/cassettes/Puppet_Network_HTTP_Connection/when_handling_requests/_request_get/should_yield_to_the_block.yml +24 -0
  274. data/spec/fixtures/vcr/cassettes/Puppet_Network_HTTP_Connection/when_handling_requests/_request_head/should_yield_to_the_block.yml +24 -0
  275. data/spec/fixtures/vcr/cassettes/Puppet_Network_HTTP_Connection/when_handling_requests/_request_post/should_yield_to_the_block.yml +24 -0
  276. data/spec/integration/data_binding_spec.rb +229 -0
  277. data/spec/integration/file_bucket/file_spec.rb +2 -2
  278. data/spec/integration/parser/compiler_spec.rb +30 -24
  279. data/spec/integration/parser/resource_expressions_spec.rb +4 -4
  280. data/spec/integration/parser/undef_param_spec.rb +1 -1
  281. data/spec/integration/provider/package_spec.rb +3 -1
  282. data/spec/integration/resource/catalog_spec.rb +1 -1
  283. data/spec/integration/ssl/certificate_authority_spec.rb +0 -1
  284. data/spec/integration/ssl/certificate_request_spec.rb +0 -1
  285. data/spec/integration/ssl/certificate_revocation_list_spec.rb +0 -1
  286. data/spec/integration/ssl/host_spec.rb +0 -1
  287. data/spec/integration/type/package_spec.rb +2 -0
  288. data/spec/integration/util/rdoc/parser_spec.rb +1 -1
  289. data/spec/integration/util/windows/security_spec.rb +18 -0
  290. data/spec/lib/matchers/include_in_order.rb +2 -2
  291. data/spec/shared_behaviours/iterative_functions.rb +8 -8
  292. data/spec/spec_helper.rb +7 -0
  293. data/spec/unit/agent/locker_spec.rb +4 -4
  294. data/spec/unit/agent_spec.rb +0 -8
  295. data/spec/unit/application/agent_spec.rb +5 -0
  296. data/spec/unit/application/apply_spec.rb +9 -1
  297. data/spec/unit/application/filebucket_spec.rb +88 -2
  298. data/spec/unit/application/lookup_spec.rb +195 -0
  299. data/spec/unit/application/master_spec.rb +2 -2
  300. data/spec/unit/application_spec.rb +3 -3
  301. data/spec/unit/appmgmt_spec.rb +657 -0
  302. data/spec/unit/capability_spec.rb +414 -0
  303. data/spec/unit/configurer_spec.rb +7 -1
  304. data/spec/unit/context/trusted_information_spec.rb +24 -1
  305. data/spec/unit/daemon_spec.rb +18 -8
  306. data/spec/unit/data_providers/hiera_data_provider_spec.rb +201 -0
  307. data/spec/unit/environments_spec.rb +2 -0
  308. data/spec/unit/face/node_spec.rb +1 -1
  309. data/spec/unit/file_bucket/dipper_spec.rb +210 -1
  310. data/spec/unit/file_serving/configuration_spec.rb +1 -1
  311. data/spec/unit/file_system_spec.rb +20 -0
  312. data/spec/unit/functions/assert_type_spec.rb +5 -7
  313. data/spec/unit/functions/defined_spec.rb +2 -2
  314. data/spec/unit/functions/epp_spec.rb +2 -2
  315. data/spec/unit/functions/filter_spec.rb +18 -0
  316. data/spec/unit/functions/hiera_spec.rb +2 -2
  317. data/spec/unit/functions/lookup_spec.rb +200 -9
  318. data/spec/unit/functions/regsubst_spec.rb +17 -8
  319. data/spec/unit/functions/scanf_spec.rb +1 -1
  320. data/spec/unit/functions/split_spec.rb +2 -2
  321. data/spec/unit/functions/versioncmp_spec.rb +36 -0
  322. data/spec/unit/functions4_spec.rb +58 -72
  323. data/spec/unit/graph/sequential_prioritizer_spec.rb +1 -1
  324. data/spec/unit/indirector/catalog/compiler_spec.rb +28 -8
  325. data/spec/unit/indirector/catalog/static_compiler_spec.rb +38 -20
  326. data/spec/unit/indirector/data_binding/none_spec.rb +2 -2
  327. data/spec/unit/indirector/file_bucket_file/file_spec.rb +52 -1
  328. data/spec/unit/indirector/indirection_spec.rb +13 -2
  329. data/spec/unit/indirector/request_spec.rb +8 -8
  330. data/spec/unit/indirector/ssl_file_spec.rb +1 -1
  331. data/spec/unit/indirector/yaml_spec.rb +1 -1
  332. data/spec/unit/info_service_spec.rb +236 -0
  333. data/spec/unit/module_tool/application_spec.rb +1 -1
  334. data/spec/unit/module_tool/applications/builder_spec.rb +1 -1
  335. data/spec/unit/module_tool/metadata_spec.rb +31 -2
  336. data/spec/unit/network/authconfig_spec.rb +62 -32
  337. data/spec/unit/network/authorization_spec.rb +30 -2
  338. data/spec/unit/network/authstore_spec.rb +1 -1
  339. data/spec/unit/network/http/compression_spec.rb +1 -1
  340. data/spec/unit/network/http/connection_spec.rb +14 -19
  341. data/spec/unit/network/http/handler_spec.rb +0 -5
  342. data/spec/unit/network/rights_spec.rb +3 -3
  343. data/spec/unit/node_spec.rb +27 -0
  344. data/spec/unit/parser/ast/leaf_spec.rb +1 -1
  345. data/spec/unit/parser/compiler_spec.rb +86 -2
  346. data/spec/unit/parser/functions/create_resources_spec.rb +1 -1
  347. data/spec/unit/parser/resource_spec.rb +2 -20
  348. data/spec/unit/pops/binder/config/binder_config_spec.rb +1 -1
  349. data/spec/unit/pops/binder/injector_spec.rb +3 -3
  350. data/spec/unit/pops/evaluator/access_ops_spec.rb +13 -11
  351. data/spec/unit/pops/evaluator/basic_expressions_spec.rb +1 -2
  352. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +20 -11
  353. data/spec/unit/pops/evaluator/literal_evaluator_spec.rb +43 -0
  354. data/spec/unit/pops/label_provider_spec.rb +5 -1
  355. data/spec/unit/pops/parser/lexer2_spec.rb +39 -0
  356. data/spec/unit/pops/parser/parse_application_spec.rb +40 -0
  357. data/spec/unit/pops/parser/parse_basic_expressions_spec.rb +4 -0
  358. data/spec/unit/pops/parser/parse_capabilities_spec.rb +47 -0
  359. data/spec/unit/pops/parser/parse_site_spec.rb +38 -0
  360. data/spec/unit/pops/parser/parser_rspec_helper.rb +5 -0
  361. data/spec/unit/pops/parser/parser_spec.rb +18 -0
  362. data/spec/unit/pops/types/type_calculator_spec.rb +427 -444
  363. data/spec/unit/pops/types/type_factory_spec.rb +12 -12
  364. data/spec/unit/pops/types/type_parser_spec.rb +15 -12
  365. data/spec/unit/pops/validator/validator_spec.rb +68 -0
  366. data/spec/unit/property_spec.rb +1 -1
  367. data/spec/unit/provider/augeas/augeas_spec.rb +50 -0
  368. data/spec/unit/provider/group/directoryservice_spec.rb +33 -0
  369. data/spec/unit/provider/group/windows_adsi_spec.rb +3 -0
  370. data/spec/unit/provider/package/dnf_spec.rb +92 -0
  371. data/spec/unit/provider/package/gem_spec.rb +7 -0
  372. data/spec/unit/provider/package/nim_spec.rb +6 -6
  373. data/spec/unit/provider/package/rpm_spec.rb +25 -2
  374. data/spec/unit/provider/package/windows/package_spec.rb +41 -0
  375. data/spec/unit/provider/package/yum_spec.rb +35 -12
  376. data/spec/unit/provider/scheduled_task/win32_taskscheduler_spec.rb +10 -0
  377. data/spec/unit/provider/service/debian_spec.rb +28 -0
  378. data/spec/unit/provider/service/gentoo_spec.rb +1 -0
  379. data/spec/unit/provider/service/init_spec.rb +6 -0
  380. data/spec/unit/provider/service/launchd_spec.rb +85 -10
  381. data/spec/unit/provider/service/openrc_spec.rb +1 -0
  382. data/spec/unit/provider/service/rcng_spec.rb +41 -0
  383. data/spec/unit/provider/service/redhat_spec.rb +8 -1
  384. data/spec/unit/provider/service/smf_spec.rb +30 -5
  385. data/spec/unit/provider/service/src_spec.rb +20 -4
  386. data/spec/unit/provider/service/systemd_spec.rb +79 -29
  387. data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +1 -1
  388. data/spec/unit/provider/sshkey/parsed_spec.rb +23 -0
  389. data/spec/unit/provider/user/windows_adsi_spec.rb +2 -1
  390. data/spec/unit/provider/zone/solaris_spec.rb +19 -0
  391. data/spec/unit/reports_spec.rb +10 -0
  392. data/spec/unit/resource/capability_finder_spec.rb +56 -0
  393. data/spec/unit/resource/catalog_spec.rb +31 -8
  394. data/spec/unit/resource/type_collection_spec.rb +23 -2
  395. data/spec/unit/resource/type_spec.rb +1 -1
  396. data/spec/unit/resource_spec.rb +23 -5
  397. data/spec/unit/settings/file_setting_spec.rb +31 -0
  398. data/spec/unit/settings_spec.rb +91 -2
  399. data/spec/unit/ssl/certificate_authority/interface_spec.rb +4 -3
  400. data/spec/unit/ssl/certificate_authority_spec.rb +5 -3
  401. data/spec/unit/ssl/host_spec.rb +2 -2
  402. data/spec/unit/ssl/oids_spec.rb +8 -0
  403. data/spec/unit/transaction/additional_resource_generator_spec.rb +78 -5
  404. data/spec/unit/transaction/report_spec.rb +24 -1
  405. data/spec/unit/transaction_spec.rb +7 -0
  406. data/spec/unit/type/exec_spec.rb +16 -8
  407. data/spec/unit/type/host_spec.rb +4 -4
  408. data/spec/unit/type/package_spec.rb +1 -0
  409. data/spec/unit/type/tidy_spec.rb +4 -4
  410. data/spec/unit/type/user_spec.rb +14 -7
  411. data/spec/unit/type/vlan_spec.rb +1 -1
  412. data/spec/unit/type_spec.rb +1 -1
  413. data/spec/unit/util/ldap/generator_spec.rb +1 -1
  414. data/spec/unit/util/network_device/cisco/device_spec.rb +1 -1
  415. data/spec/unit/util/network_device/transport/ssh_spec.rb +1 -1
  416. data/spec/unit/util/network_device_spec.rb +1 -1
  417. data/spec/unit/util/storage_spec.rb +5 -1
  418. data/spec/unit/util/windows/adsi_spec.rb +13 -0
  419. data/spec/unit/util_spec.rb +21 -2
  420. metadata +173 -7
  421. data/lib/puppet/pops/evaluator/callable_mismatch_describer.rb +0 -175
  422. data/spec/integration/data_binding.rb +0 -104
@@ -2,78 +2,82 @@
2
2
 
3
3
  #### Table of Contents
4
4
 
5
- 1. [Overview](#overview)
6
- 2. [Module Description - What the module does and why it is useful](#module-description)
7
- 3. [Setup - The basics of getting started with <%= metadata.name %>](#setup)
5
+ 1. [Description](#description)
6
+ 1. [Setup - The basics of getting started with <%= metadata.name %>](#setup)
8
7
  * [What <%= metadata.name %> affects](#what-<%= metadata.name %>-affects)
9
8
  * [Setup requirements](#setup-requirements)
10
9
  * [Beginning with <%= metadata.name %>](#beginning-with-<%= metadata.name %>)
11
- 4. [Usage - Configuration options and additional functionality](#usage)
12
- 5. [Reference - An under-the-hood peek at what the module is doing and how](#reference)
13
- 5. [Limitations - OS compatibility, etc.](#limitations)
14
- 6. [Development - Guide for contributing to the module](#development)
10
+ 1. [Usage - Configuration options and additional functionality](#usage)
11
+ 1. [Reference - An under-the-hood peek at what the module is doing and how](#reference)
12
+ 1. [Limitations - OS compatibility, etc.](#limitations)
13
+ 1. [Development - Guide for contributing to the module](#development)
15
14
 
16
- ## Overview
15
+ ## Description
17
16
 
18
- A one-maybe-two sentence summary of what the module does/what problem it solves.
19
- This is your 30 second elevator pitch for your module. Consider including
20
- OS/Puppet version it works with.
17
+ Start with a one- or two-sentence summary of what the module does and/or what
18
+ problem it solves. This is your 30-second elevator pitch for your module.
19
+ Consider including OS/Puppet version it works with.
21
20
 
22
- ## Module Description
23
-
24
- If applicable, this section should have a brief description of the technology
25
- the module integrates with and what that integration enables. This section
21
+ You can give more descriptive information in a second paragraph. This paragraph
26
22
  should answer the questions: "What does this module *do*?" and "Why would I use
27
- it?"
28
-
29
- If your module has a range of functionality (installation, configuration,
30
- management, etc.) this is the time to mention it.
23
+ it?" If your module has a range of functionality (installation, configuration,
24
+ management, etc.), this is the time to mention it.
31
25
 
32
26
  ## Setup
33
27
 
34
- ### What <%= metadata.name %> affects
28
+ ### What <%= metadata.name %> affects **OPTIONAL**
29
+
30
+ If it's obvious what your module touches, you can skip this section. For
31
+ example, folks can probably figure out that your mysql_instance module affects
32
+ their MySQL instances.
33
+
34
+ If there's more that they should know about, though, this is the place to mention:
35
35
 
36
36
  * A list of files, packages, services, or operations that the module will alter,
37
- impact, or execute on the system it's installed on.
38
- * This is a great place to stick any warnings.
39
- * Can be in list or paragraph form.
37
+ impact, or execute.
38
+ * Dependencies that your module automatically installs.
39
+ * Warnings or other important notices.
40
40
 
41
41
  ### Setup Requirements **OPTIONAL**
42
42
 
43
43
  If your module requires anything extra before setting up (pluginsync enabled,
44
44
  etc.), mention it here.
45
45
 
46
- ### Beginning with <%= metadata.name %>
46
+ If your most recent release breaks compatibility or requires particular steps
47
+ for upgrading, you might want to include an additional "Upgrading" section
48
+ here.
47
49
 
48
- The very basic steps needed for a user to get the module up and running.
50
+ ### Beginning with <%= metadata.name %>
49
51
 
50
- If your most recent release breaks compatibility or requires particular steps
51
- for upgrading, you may wish to include an additional section here: Upgrading
52
- (For an example, see http://forge.puppetlabs.com/puppetlabs/firewall).
52
+ The very basic steps needed for a user to get the module up and running. This
53
+ can include setup steps, if necessary, or it can be an example of the most
54
+ basic use of the module.
53
55
 
54
56
  ## Usage
55
57
 
56
- Put the classes, types, and resources for customizing, configuring, and doing
57
- the fancy stuff with your module here.
58
+ This section is where you describe how to customize, configure, and do the
59
+ fancy stuff with your module here. It's especially helpful if you include usage
60
+ examples and code samples for doing things with your module.
58
61
 
59
62
  ## Reference
60
63
 
61
- Here, list the classes, types, providers, facts, etc contained in your module.
62
- This section should include all of the under-the-hood workings of your module so
63
- people know what the module is touching on their system but don't need to mess
64
- with things. (We are working on automating this section!)
64
+ Here, include a complete list of your module's classes, types, providers,
65
+ facts, along with the parameters for each. Users refer to this section (thus
66
+ the name "Reference") to find specific details; most users don't read it per
67
+ se.
65
68
 
66
69
  ## Limitations
67
70
 
68
- This is where you list OS compatibility, version compatibility, etc.
71
+ This is where you list OS compatibility, version compatibility, etc. If there
72
+ are Known Issues, you might want to include them under their own heading here.
69
73
 
70
74
  ## Development
71
75
 
72
76
  Since your module is awesome, other users will want to play with it. Let them
73
77
  know what the ground rules for contributing are.
74
78
 
75
- ## Release Notes/Contributors/Etc **Optional**
79
+ ## Release Notes/Contributors/Etc. **Optional**
76
80
 
77
81
  If you aren't using changelog, put your release notes here (though you should
78
- consider using changelog). You may also add any additional sections you feel are
79
- necessary or important to include here. Please use the `## ` header.
82
+ consider using changelog). You can also add any additional sections you feel
83
+ are necessary or important to include here. Please use the `## ` header.
@@ -1,37 +1,44 @@
1
- # == Class: <%= metadata.name %>
1
+ # Class: <%= metadata.name %>
2
+ # ===========================
2
3
  #
3
4
  # Full description of class <%= metadata.name %> here.
4
5
  #
5
- # === Parameters
6
+ # Parameters
7
+ # ----------
6
8
  #
7
9
  # Document parameters here.
8
10
  #
9
- # [*sample_parameter*]
10
- # Explanation of what this parameter affects and what it defaults to.
11
- # e.g. "Specify one or more upstream ntp servers as an array."
11
+ # * `sample parameter`
12
+ # Explanation of what this parameter affects and what it defaults to.
13
+ # e.g. "Specify one or more upstream ntp servers as an array."
12
14
  #
13
- # === Variables
15
+ # Variables
16
+ # ----------
14
17
  #
15
18
  # Here you should define a list of variables that this module would require.
16
19
  #
17
- # [*sample_variable*]
18
- # Explanation of how this variable affects the function of this class and if
19
- # it has a default. e.g. "The parameter enc_ntp_servers must be set by the
20
- # External Node Classifier as a comma separated list of hostnames." (Note,
21
- # global variables should be avoided in favor of class parameters as
22
- # of Puppet 2.6.)
20
+ # * `sample variable`
21
+ # Explanation of how this variable affects the function of this class and if
22
+ # it has a default. e.g. "The parameter enc_ntp_servers must be set by the
23
+ # External Node Classifier as a comma separated list of hostnames." (Note,
24
+ # global variables should be avoided in favor of class parameters as
25
+ # of Puppet 2.6.)
23
26
  #
24
- # === Examples
27
+ # Examples
28
+ # --------
25
29
  #
26
- # class { '<%= metadata.name %>':
27
- # servers => [ 'pool.ntp.org', 'ntp.local.company.com' ],
28
- # }
30
+ # @example
31
+ # class { '<%= metadata.name %>':
32
+ # servers => [ 'pool.ntp.org', 'ntp.local.company.com' ],
33
+ # }
29
34
  #
30
- # === Authors
35
+ # Authors
36
+ # -------
31
37
  #
32
38
  # Author Name <author@domain.com>
33
39
  #
34
- # === Copyright
40
+ # Copyright
41
+ # ---------
35
42
  #
36
43
  # Copyright <%= Time.now.year %> Your name here, unless otherwise noted.
37
44
  #
@@ -3,7 +3,7 @@ require 'puppet/network/http'
3
3
 
4
4
  module Puppet
5
5
  class ConfigurationError < Puppet::Error; end
6
- class Network::AuthConfig
6
+ class Network::DefaultAuthProvider
7
7
  attr_accessor :rights
8
8
 
9
9
  def self.master_url_prefix
@@ -89,4 +89,24 @@ module Puppet
89
89
  insert_default_acl
90
90
  end
91
91
  end
92
+
93
+ class Network::AuthConfig
94
+ @@authprovider_class = nil
95
+
96
+ def self.authprovider_class=(klass)
97
+ @@authprovider_class = klass
98
+ end
99
+
100
+ def self.authprovider_class
101
+ @@authprovider_class || Puppet::Network::DefaultAuthProvider
102
+ end
103
+
104
+ def initialize(rights=nil)
105
+ @authprovider = self.class.authprovider_class.new(rights)
106
+ end
107
+
108
+ def check_authorization(method, path, params)
109
+ @authprovider.check_authorization(method, path, params)
110
+ end
111
+ end
92
112
  end
@@ -21,8 +21,15 @@ module Puppet::Network
21
21
  end
22
22
 
23
23
  module Authorization
24
+ @@authconfigloader_class = nil
25
+
26
+ def self.authconfigloader_class=(klass)
27
+ @@authconfigloader_class = klass
28
+ end
29
+
24
30
  def authconfig
25
- AuthConfigLoader.authconfig
31
+ authconfigloader = @@authconfigloader_class || AuthConfigLoader
32
+ authconfigloader.authconfig
26
33
  end
27
34
 
28
35
  # Verify that our client has access.
@@ -0,0 +1,59 @@
1
+ require 'json'
2
+ require 'puppet/parser/environment_compiler'
3
+
4
+ class Puppet::Network::HTTP::API::Master::V3::Environment
5
+ def call(request, response)
6
+ env_name = request.routing_path.split('/').last
7
+ env = Puppet.lookup(:environments).get(env_name)
8
+
9
+ if env.nil?
10
+ raise Puppet::Network::HTTP::Error::HTTPNotFoundError.new("#{env_name} is not a known environment", Puppet::Network::HTTP::Issues::RESOURCE_NOT_FOUND)
11
+ end
12
+
13
+ catalog = Puppet::Parser::EnvironmentCompiler.compile(env).to_resource
14
+
15
+ env_graph = {:environment => env.name, :applications => {}}
16
+ applications = catalog.resources.select do |res|
17
+ type = res.resource_type
18
+ type.is_a?(Puppet::Resource::Type) && type.application?
19
+ end
20
+ applications.each do |app|
21
+ app_components = {}
22
+ # Turn the 'nodes' hash into a map component ref => node name
23
+ node_mapping = {}
24
+ app['nodes'].each do |node, comps|
25
+ comps = [comps] unless comps.is_a?(Array)
26
+ comps.each do |comp|
27
+ raise Puppet::ParseError, "Application #{app} maps component #{comp} to multiple nodes" if node_mapping.include?(comp.ref)
28
+ node_mapping[comp.ref] = node.title
29
+ end
30
+ end
31
+
32
+ catalog.direct_dependents_of(app).each do |comp|
33
+ mapped_node = node_mapping[comp.ref]
34
+ if mapped_node.nil?
35
+ raise Puppet::ParseError, "Component #{comp} is not mapped to any node"
36
+ end
37
+ app_components[comp.ref] = {
38
+ :produces => comp.export.map(&:ref),
39
+ :consumes => prerequisites(comp).map(&:ref),
40
+ :node => mapped_node
41
+ }
42
+ end
43
+ env_graph[:applications][app.ref] = app_components
44
+ end
45
+ response.respond_with(200, "application/json", JSON.dump(env_graph))
46
+ end
47
+
48
+ private
49
+
50
+ # Finds all the prerequisites of component +comp+. They are all the
51
+ # capability resources that +comp+ depends on; this includes resources
52
+ # that +comp+ consumes but also resources it merely requires
53
+ def prerequisites(comp)
54
+ params = Puppet::Type.relationship_params.select { |p| p.direction == :in }.map(&:name)
55
+ params.map { |rel| comp[rel] }.flatten.compact.select do |rel|
56
+ rel.resource_type && rel.resource_type.is_capability?
57
+ end
58
+ end
59
+ end
@@ -1,6 +1,7 @@
1
1
  class Puppet::Network::HTTP::API::Master::V3
2
2
  require 'puppet/network/http/api/master/v3/authorization'
3
3
  require 'puppet/network/http/api/master/v3/environments'
4
+ require 'puppet/network/http/api/master/v3/environment'
4
5
  require 'puppet/network/http/api/indirected_routes'
5
6
 
6
7
  AUTHZ = Authorization.new
@@ -14,9 +15,14 @@ class Puppet::Network::HTTP::API::Master::V3
14
15
  Environments.new(Puppet.lookup(:environments))
15
16
  end)
16
17
 
18
+ ENVIRONMENT = Puppet::Network::HTTP::Route.
19
+ path(%r{/environment/[^/]+$}).get(AUTHZ.wrap do
20
+ Environment.new
21
+ end)
22
+
17
23
  def self.routes
18
24
  Puppet::Network::HTTP::Route.path(%r{v3}).
19
25
  any.
20
- chain(ENVIRONMENTS, INDIRECTED)
26
+ chain(ENVIRONMENTS, ENVIRONMENT, INDIRECTED)
21
27
  end
22
28
  end
@@ -182,11 +182,18 @@ class Puppet::Node::Environment
182
182
  # @api private
183
183
  def conflicting_manifest_settings?
184
184
  return false if !Puppet[:disable_per_environment_manifest]
185
- environment_conf = Puppet.lookup(:environments).get_conf(name)
186
- original_manifest = environment_conf.raw_setting(:manifest)
185
+ original_manifest = configuration.raw_setting(:manifest)
187
186
  !original_manifest.nil? && !original_manifest.empty? && original_manifest != Puppet[:default_manifest]
188
187
  end
189
188
 
189
+ # Return the environment configuration
190
+ # @return [Puppet::Settings::EnvironmentConf] The configuration
191
+ #
192
+ # @api private
193
+ def configuration
194
+ Puppet.lookup(:environments).get_conf(name)
195
+ end
196
+
190
197
  # Checks the environment and settings for any conflicts
191
198
  # @return [Array<String>] an array of validation errors
192
199
  # @api public
data/lib/puppet/node.rb CHANGED
@@ -9,6 +9,9 @@ class Puppet::Node
9
9
  # the node sources.
10
10
  extend Puppet::Indirector
11
11
 
12
+ # Asymmetric serialization/deserialization required in this class via to/from datahash
13
+ include Puppet::Util::PsychSupport
14
+
12
15
  # Use the node source as the indirection terminus.
13
16
  indirects :node, :terminus_setting => :node_terminus, :doc => "Where to find node information.
14
17
  A node is composed of its name, its facts, and its environment."
@@ -18,13 +21,16 @@ class Puppet::Node
18
21
 
19
22
  attr_reader :server_facts
20
23
 
21
- def self.from_data_hash(data)
22
- raise ArgumentError, "No name provided in serialized data" unless name = data['name']
24
+ def initialize_from_hash(data)
25
+ @name = data['name'] || (raise ArgumentError, "No name provided in serialized data")
26
+ @classes = data['classes'] || []
27
+ @parameters = data['parameters'] || {}
28
+ @environment_name = data['environment']
29
+ end
23
30
 
31
+ def self.from_data_hash(data)
24
32
  node = new(name)
25
- node.classes = data['classes']
26
- node.parameters = data['parameters']
27
- node.environment_name = data['environment']
33
+ node.initialize_from_hash(data)
28
34
  node
29
35
  end
30
36
 
@@ -88,12 +88,18 @@ class Puppet::Parser::AST::PopsBridge
88
88
  instantiate_HostClassDefinition(d, modname)
89
89
  when Puppet::Pops::Model::ResourceTypeDefinition
90
90
  instantiate_ResourceTypeDefinition(d, modname)
91
+ when Puppet::Pops::Model::CapabilityMapping
92
+ instantiate_CapabilityMapping(d, modname)
91
93
  when Puppet::Pops::Model::NodeDefinition
92
94
  instantiate_NodeDefinition(d, modname)
95
+ when Puppet::Pops::Model::SiteDefinition
96
+ instantiate_SiteDefinition(d, modname)
93
97
  when Puppet::Pops::Model::FunctionDefinition
94
98
  instantiate_FunctionDefinition(d, modname)
95
99
  # The 3x logic calling this will not know what to do with the result, it is compacted away at the end
96
100
  next
101
+ when Puppet::Pops::Model::Application
102
+ instantiate_ApplicationDefinition(d, modname)
97
103
  else
98
104
  raise Puppet::ParseError, "Internal Error: Unknown type of definition - got '#{d.class}'"
99
105
  end
@@ -182,6 +188,27 @@ class Puppet::Parser::AST::PopsBridge
182
188
  Puppet::Resource::Type.new(:definition, o.name, @context.merge(args_from_definition(o, modname)))
183
189
  end
184
190
 
191
+ def instantiate_CapabilityMapping(o, modname)
192
+ # Use an intermediate 'capability_mapping' type to pass this info to the compiler where the
193
+ # actual mapping takes place
194
+ Puppet::Resource::Type.new(:capability_mapping, "#{o.component} #{o.kind} #{o.capability}", { :arguments => {
195
+ 'component' => o.component,
196
+ 'kind' => o.kind,
197
+ 'blueprint' => {
198
+ :capability => o.capability,
199
+ :mappings => o.mappings.reduce({}) do |memo, mapping|
200
+ memo[mapping.attribute_name] =
201
+ Expression.new(:value => mapping.value_expr)
202
+ memo
203
+ end
204
+ }}})
205
+ end
206
+
207
+ def instantiate_ApplicationDefinition(o, modname)
208
+ args = args_from_definition(o, modname)
209
+ Puppet::Resource::Type.new(:application, o.name, @context.merge(args))
210
+ end
211
+
185
212
  def instantiate_NodeDefinition(o, modname)
186
213
  args = { :module_name => modname }
187
214
 
@@ -192,14 +219,25 @@ class Puppet::Parser::AST::PopsBridge
192
219
  unless is_nop?(o.parent)
193
220
  args[:parent] = @ast_transformer.hostname(o.parent)
194
221
  end
222
+ args = @ast_transformer.merge_location(args, o)
195
223
 
196
224
  host_matches = @ast_transformer.hostname(o.host_matches)
197
- @ast_transformer.merge_location(args, o)
198
225
  host_matches.collect do |name|
199
226
  Puppet::Resource::Type.new(:node, name, @context.merge(args))
200
227
  end
201
228
  end
202
229
 
230
+ def instantiate_SiteDefinition(o, modname)
231
+ args = { :module_name => modname }
232
+
233
+ unless is_nop?(o.body)
234
+ args[:code] = Expression.new(:value => o.body)
235
+ end
236
+
237
+ args = @ast_transformer.merge_location(args, o)
238
+ Puppet::Resource::Type.new(:site, 'site', @context.merge(args))
239
+ end
240
+
203
241
  # Propagates a found Function to the appropriate loader.
204
242
  # This is for 4x evaluator/loader
205
243
  #
@@ -0,0 +1,64 @@
1
+ class Puppet::Parser::Compiler
2
+ # Validator that asserts that all capability resources that are referenced by 'consume' or 'require' has
3
+ # been exported by some other resource in the environment
4
+ class CatalogValidator::EnvironmentRelationshipValidator < CatalogValidator
5
+
6
+ def validate
7
+ assumed_exports = {}
8
+ exported = {}
9
+ catalog.resources.each do |resource|
10
+ next unless resource.is_a?(Puppet::Parser::Resource)
11
+ resource.eachparam do |param|
12
+ pclass = Puppet::Type.metaparamclass(param.name)
13
+ validate_relationship(resource, param, assumed_exports, exported) if !pclass.nil? && pclass < Puppet::Type::RelationshipMetaparam
14
+ end
15
+ end
16
+ assumed_exports.each_pair do |key, (param, cap)|
17
+ raise CatalogValidationError.new("Capability '#{cap}' referenced by '#{param.name}' is never exported", param.file, param.line) unless exported.include?(key)
18
+ end
19
+ nil
20
+ end
21
+
22
+ private
23
+
24
+ def validate_relationship(resource, param, assumed_exports, exported)
25
+ case param.name
26
+ when :require, :consume
27
+ add_capability_ref(param, param.value, assumed_exports)
28
+ when :export
29
+ add_exported(resource, param, param.value, exported)
30
+ end
31
+ end
32
+
33
+ def add_capability_ref(param, value, assumed_exports)
34
+ case value
35
+ when Array
36
+ value.each { |v| add_capability_ref(param, v, assumed_exports) }
37
+ when Puppet::Resource
38
+ rt = value.resource_type
39
+ unless rt.nil? || !rt.is_capability?
40
+ title_key = catalog.title_key_for_ref(value.ref)
41
+ assumed_exports[title_key] = [param, value]
42
+ end
43
+ nil
44
+ end
45
+ end
46
+
47
+ def add_exported(resource, param, value, hash)
48
+ case value
49
+ when Array
50
+ value.each { |v| add_exported(resource, param, v, hash) }
51
+ when Puppet::Resource
52
+ rt = value.resource_type
53
+ unless rt.nil? || !rt.is_capability?
54
+ title_key = catalog.title_key_for_ref(value.ref)
55
+ if hash.include?(title_key)
56
+ raise CatalogValidationError.new("'#{value}' is exported by both '#{hash[title_key]}' and '#{resource}'", param.file, param.line)
57
+ else
58
+ hash[title_key] = resource
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,38 @@
1
+ class Puppet::Parser::Compiler
2
+ # Validator that asserts that only 'require', 'consume', and 'export' is used when declaring relationships
3
+ # to capability resources.
4
+ class CatalogValidator::RelationshipValidator < CatalogValidator
5
+ def validate
6
+ catalog.resources.each do |resource|
7
+ next unless resource.is_a?(Puppet::Parser::Resource)
8
+ resource.eachparam do |param|
9
+ pclass = Puppet::Type.metaparamclass(param.name)
10
+ validate_relationship(param) if !pclass.nil? && pclass < Puppet::Type::RelationshipMetaparam
11
+ end
12
+ end
13
+ nil
14
+ end
15
+
16
+ private
17
+
18
+ def validate_relationship(param)
19
+ unless [:require, :consume, :export].find {|pname| pname == param.name }
20
+ raise CatalogValidationError.new("'#{param.name}' is not a valid relationship to a capability", param.file, param.line) if has_capability?(param.value)
21
+ end
22
+ end
23
+
24
+ def has_capability?(value)
25
+ case value
26
+ when Array
27
+ value.find { |v| has_capability?(v) }
28
+ when Puppet::Resource
29
+ rt = value.resource_type
30
+ !rt.nil? && rt.is_capability?
31
+ else
32
+ false
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+
@@ -0,0 +1,20 @@
1
+ class Puppet::Parser::Compiler
2
+ # Validator that asserts that only application components can appear inside a site.
3
+ class CatalogValidator::SiteValidator < CatalogValidator
4
+ def self.validation_stage?(stage)
5
+ PRE_FINISH.equal?(stage)
6
+ end
7
+
8
+ def validate
9
+ the_site_resource = catalog.resource('Site', 'site')
10
+ return unless the_site_resource
11
+
12
+ catalog.downstream_from_vertex(the_site_resource).keys.each do |r|
13
+ unless r.is_application_component? || r.resource_type.application?
14
+ raise CatalogValidationError.new("Only application components can appear inside a site - #{r} is not allowed", r.file, r.line)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,33 @@
1
+ # Abstract class for a catalog validator that can be registered with the compiler to run at
2
+ # a certain stage.
3
+ class Puppet::Parser::Compiler
4
+ class CatalogValidator
5
+ PRE_FINISH = :pre_finish
6
+ FINAL = :final
7
+
8
+ # Returns true if the validator should run at the given stage. The default
9
+ # implementation will only run at stage `FINAL`
10
+ #
11
+ # @param stage [Symbol] One of the stage constants defined in this class
12
+ # @return [Boolean] true if the validator should run at the given stage
13
+ #
14
+ def self.validation_stage?(stage)
15
+ FINAL.equal?(stage)
16
+ end
17
+
18
+ attr_reader :catalog
19
+
20
+ # @param catalog [Puppet::Resource::Catalog] The catalog to validate
21
+ def initialize(catalog)
22
+ @catalog = catalog
23
+ end
24
+
25
+ # Validate some aspect of the catalog and raise a `CatalogValidationError` on failure
26
+ def validate
27
+ end
28
+ end
29
+
30
+ class CatalogValidationError < Puppet::Error
31
+ include Puppet::ExternalFileError
32
+ end
33
+ end