puppet 3.0.2 → 3.1.0.rc1

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

Potentially problematic release.


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

Files changed (320) hide show
  1. data/Gemfile +13 -11
  2. data/README.md +9 -7
  3. data/README_DEVELOPER.md +21 -30
  4. data/bin/extlookup2hiera +0 -0
  5. data/conf/auth.conf +42 -26
  6. data/conf/fileserver.conf +41 -0
  7. data/conf/tagmail.conf +16 -0
  8. data/examples/hiera/modules/data/manifests/common.pp +2 -1
  9. data/examples/hiera/modules/ntp/manifests/config.pp +4 -3
  10. data/examples/hiera/modules/ntp/manifests/data.pp +2 -1
  11. data/examples/hiera/modules/users/manifests/common.pp +2 -1
  12. data/examples/hiera/modules/users/manifests/dc1.pp +2 -1
  13. data/examples/hiera/modules/users/manifests/development.pp +2 -1
  14. data/examples/hiera/site.pp +1 -1
  15. data/ext/debian/fileserver.conf +39 -15
  16. data/ext/envpuppet +2 -0
  17. data/ext/gentoo/puppet/fileserver.conf +41 -12
  18. data/ext/ips/puppet-agent +1 -6
  19. data/ext/ips/puppetagent.xml +0 -4
  20. data/ext/osx/postflight.erb +109 -0
  21. data/ext/project_data.yaml +2 -2
  22. data/ext/redhat/fileserver.conf +41 -12
  23. data/ext/redhat/puppet.spec.erb +8 -13
  24. data/install.rb +2 -5
  25. data/lib/puppet.rb +30 -13
  26. data/lib/puppet/application.rb +34 -16
  27. data/lib/puppet/application/agent.rb +4 -4
  28. data/lib/puppet/application/master.rb +25 -5
  29. data/lib/puppet/defaults.rb +11 -7
  30. data/lib/puppet/dsl.rb +7 -3
  31. data/lib/puppet/dsl/actions.rb +283 -0
  32. data/lib/puppet/dsl/blank_slate.rb +55 -0
  33. data/lib/puppet/dsl/context.rb +393 -0
  34. data/lib/puppet/dsl/parser.rb +57 -0
  35. data/lib/puppet/dsl/resource_decorator.rb +56 -0
  36. data/lib/puppet/dsl/resource_reference.rb +95 -0
  37. data/lib/puppet/dsl/type_reference.rb +102 -0
  38. data/lib/puppet/error.rb +1 -1
  39. data/lib/puppet/face/help.rb +2 -4
  40. data/lib/puppet/face/man.rb +8 -2
  41. data/lib/puppet/feature/pson.rb +1 -3
  42. data/lib/puppet/indirector/catalog/active_record.rb +3 -0
  43. data/lib/puppet/indirector/catalog/compiler.rb +1 -2
  44. data/lib/puppet/indirector/catalog/queue.rb +4 -0
  45. data/lib/puppet/indirector/catalog/static_compiler.rb +30 -0
  46. data/lib/puppet/indirector/catalog/store_configs.rb +3 -0
  47. data/lib/puppet/indirector/certificate_request/rest.rb +1 -0
  48. data/lib/puppet/indirector/certificate_revocation_list/rest.rb +1 -0
  49. data/lib/puppet/indirector/certificate_status/file.rb +4 -0
  50. data/lib/puppet/indirector/certificate_status/rest.rb +1 -0
  51. data/lib/puppet/indirector/facts/active_record.rb +3 -0
  52. data/lib/puppet/indirector/facts/couch.rb +3 -0
  53. data/lib/puppet/indirector/facts/inventory_active_record.rb +4 -0
  54. data/lib/puppet/indirector/facts/store_configs.rb +3 -0
  55. data/lib/puppet/indirector/file_metadata/rest.rb +2 -0
  56. data/lib/puppet/indirector/instrumentation_data/local.rb +3 -0
  57. data/lib/puppet/indirector/instrumentation_data/rest.rb +3 -0
  58. data/lib/puppet/indirector/instrumentation_listener/local.rb +3 -0
  59. data/lib/puppet/indirector/instrumentation_listener/rest.rb +3 -0
  60. data/lib/puppet/indirector/instrumentation_probe/local.rb +3 -0
  61. data/lib/puppet/indirector/instrumentation_probe/rest.rb +3 -0
  62. data/lib/puppet/indirector/node/active_record.rb +3 -0
  63. data/lib/puppet/indirector/node/rest.rb +2 -2
  64. data/lib/puppet/indirector/node/store_configs.rb +3 -0
  65. data/lib/puppet/indirector/node/write_only_yaml.rb +32 -0
  66. data/lib/puppet/indirector/queue.rb +0 -1
  67. data/lib/puppet/indirector/request.rb +1 -2
  68. data/lib/puppet/indirector/resource/active_record.rb +4 -0
  69. data/lib/puppet/indirector/resource/ral.rb +3 -0
  70. data/lib/puppet/indirector/resource/rest.rb +3 -0
  71. data/lib/puppet/indirector/resource/store_configs.rb +3 -0
  72. data/lib/puppet/indirector/run/local.rb +3 -0
  73. data/lib/puppet/indirector/ssl_file.rb +16 -14
  74. data/lib/puppet/indirector/status/local.rb +3 -0
  75. data/lib/puppet/indirector/status/rest.rb +4 -0
  76. data/lib/puppet/interface.rb +78 -3
  77. data/lib/puppet/interface/action.rb +39 -3
  78. data/lib/puppet/interface/action_builder.rb +74 -1
  79. data/lib/puppet/interface/action_manager.rb +33 -3
  80. data/lib/puppet/interface/documentation.rb +116 -5
  81. data/lib/puppet/interface/face_collection.rb +6 -7
  82. data/lib/puppet/interface/option.rb +10 -1
  83. data/lib/puppet/interface/option_builder.rb +29 -1
  84. data/lib/puppet/interface/option_manager.rb +21 -6
  85. data/lib/puppet/metatype/manager.rb +47 -9
  86. data/lib/puppet/module_tool.rb +0 -1
  87. data/lib/puppet/network/formats.rb +0 -2
  88. data/lib/puppet/node.rb +2 -3
  89. data/lib/puppet/node/environment.rb +14 -1
  90. data/lib/puppet/parameter.rb +309 -44
  91. data/lib/puppet/parameter/package_options.rb +5 -0
  92. data/lib/puppet/parameter/path.rb +26 -3
  93. data/lib/puppet/parameter/value.rb +30 -6
  94. data/lib/puppet/parameter/value_collection.rb +82 -20
  95. data/lib/puppet/parser.rb +3 -0
  96. data/lib/puppet/parser/ast/definition.rb +2 -5
  97. data/lib/puppet/parser/ast/hostclass.rb +2 -3
  98. data/lib/puppet/parser/ast/node.rb +2 -5
  99. data/lib/puppet/parser/ast/resourceparam.rb +1 -1
  100. data/lib/puppet/parser/compiler.rb +10 -0
  101. data/lib/puppet/parser/functions.rb +111 -7
  102. data/lib/puppet/parser/functions/create_resources.rb +23 -2
  103. data/lib/puppet/parser/functions/defined.rb +1 -1
  104. data/lib/puppet/parser/functions/extlookup.rb +2 -1
  105. data/lib/puppet/parser/functions/fail.rb +1 -1
  106. data/lib/puppet/parser/functions/file.rb +1 -1
  107. data/lib/puppet/parser/functions/fqdn_rand.rb +1 -1
  108. data/lib/puppet/parser/functions/generate.rb +1 -1
  109. data/lib/puppet/parser/functions/hiera.rb +1 -1
  110. data/lib/puppet/parser/functions/hiera_array.rb +1 -1
  111. data/lib/puppet/parser/functions/hiera_hash.rb +1 -1
  112. data/lib/puppet/parser/functions/hiera_include.rb +1 -1
  113. data/lib/puppet/parser/functions/include.rb +1 -1
  114. data/lib/puppet/parser/functions/inline_template.rb +1 -1
  115. data/lib/puppet/parser/functions/md5.rb +1 -1
  116. data/lib/puppet/parser/functions/realize.rb +1 -1
  117. data/lib/puppet/parser/functions/regsubst.rb +54 -57
  118. data/lib/puppet/parser/functions/require.rb +1 -0
  119. data/lib/puppet/parser/functions/search.rb +1 -1
  120. data/lib/puppet/parser/functions/sha1.rb +1 -1
  121. data/lib/puppet/parser/functions/shellquote.rb +1 -1
  122. data/lib/puppet/parser/functions/split.rb +1 -2
  123. data/lib/puppet/parser/functions/sprintf.rb +7 -10
  124. data/lib/puppet/parser/functions/tag.rb +1 -1
  125. data/lib/puppet/parser/functions/tagged.rb +1 -1
  126. data/lib/puppet/parser/functions/template.rb +1 -1
  127. data/lib/puppet/parser/functions/versioncmp.rb +1 -5
  128. data/lib/puppet/parser/parser_support.rb +11 -27
  129. data/lib/puppet/parser/scope.rb +48 -4
  130. data/lib/puppet/parser/type_loader.rb +31 -7
  131. data/lib/puppet/property.rb +304 -70
  132. data/lib/puppet/property/ensure.rb +14 -1
  133. data/lib/puppet/property/keyvalue.rb +17 -8
  134. data/lib/puppet/property/list.rb +3 -0
  135. data/lib/puppet/property/ordered_list.rb +7 -0
  136. data/lib/puppet/provider.rb +275 -53
  137. data/lib/puppet/provider/augeas/augeas.rb +17 -3
  138. data/lib/puppet/provider/confiner.rb +30 -1
  139. data/lib/puppet/provider/group/pw.rb +2 -2
  140. data/lib/puppet/provider/package/pip.rb +0 -1
  141. data/lib/puppet/provider/package/pkgin.rb +2 -0
  142. data/lib/puppet/provider/service/bsd.rb +1 -1
  143. data/lib/puppet/provider/service/freebsd.rb +10 -6
  144. data/lib/puppet/provider/service/init.rb +1 -1
  145. data/lib/puppet/provider/service/service.rb +1 -1
  146. data/lib/puppet/provider/user/pw.rb +2 -2
  147. data/lib/puppet/provider/user/useradd.rb +2 -3
  148. data/lib/puppet/reference/configuration.rb +6 -0
  149. data/lib/puppet/reports.rb +44 -4
  150. data/lib/puppet/reports/tagmail.rb +1 -1
  151. data/lib/puppet/resource.rb +38 -25
  152. data/lib/puppet/resource/type.rb +14 -6
  153. data/lib/puppet/settings.rb +66 -142
  154. data/lib/puppet/settings/config_file.rb +99 -0
  155. data/lib/puppet/settings/file_setting.rb +92 -24
  156. data/lib/puppet/settings/value_translator.rb +15 -0
  157. data/lib/puppet/ssl/certificate_authority/interface.rb +2 -2
  158. data/lib/puppet/test/test_helper.rb +8 -3
  159. data/lib/puppet/transaction.rb +1 -2
  160. data/lib/puppet/transaction/report.rb +122 -13
  161. data/lib/puppet/type.rb +763 -150
  162. data/lib/puppet/type/augeas.rb +4 -0
  163. data/lib/puppet/type/file/ensure.rb +1 -1
  164. data/lib/puppet/type/file/group.rb +1 -1
  165. data/lib/puppet/type/file/mode.rb +2 -0
  166. data/lib/puppet/type/file/selcontext.rb +1 -0
  167. data/lib/puppet/type/group.rb +12 -0
  168. data/lib/puppet/type/mount.rb +2 -2
  169. data/lib/puppet/type/notify.rb +1 -1
  170. data/lib/puppet/type/router.rb +1 -1
  171. data/lib/puppet/type/service.rb +1 -0
  172. data/lib/puppet/type/ssh_authorized_key.rb +3 -1
  173. data/lib/puppet/type/user.rb +8 -1
  174. data/lib/puppet/util.rb +8 -0
  175. data/lib/puppet/util/autoload.rb +7 -10
  176. data/lib/puppet/util/classgen.rb +58 -33
  177. data/lib/puppet/util/command_line.rb +120 -77
  178. data/lib/puppet/util/constant_inflector.rb +2 -0
  179. data/lib/puppet/util/execution.rb +63 -33
  180. data/lib/puppet/util/filetype.rb +1 -1
  181. data/lib/puppet/util/manifest_filetype_helper.rb +22 -0
  182. data/lib/puppet/util/methodhelper.rb +19 -0
  183. data/lib/puppet/util/monkey_patches.rb +46 -0
  184. data/lib/puppet/util/plugins.rb +2 -2
  185. data/lib/puppet/util/provider_features.rb +24 -8
  186. data/lib/puppet/util/rubygems.rb +8 -1
  187. data/lib/puppet/util/zaml.rb +1 -1
  188. data/lib/puppet/version.rb +74 -3
  189. data/spec/integration/application/apply_spec.rb +1 -1
  190. data/spec/integration/defaults_spec.rb +1 -0
  191. data/spec/integration/dsl/classes_spec.rb +191 -0
  192. data/spec/integration/dsl/defaults_spec.rb +38 -0
  193. data/spec/integration/dsl/definitions_spec.rb +73 -0
  194. data/spec/integration/dsl/functions_spec.rb +95 -0
  195. data/spec/integration/dsl/nodes_spec.rb +96 -0
  196. data/spec/integration/dsl/params_spec.rb +146 -0
  197. data/spec/integration/dsl/relationships_spec.rb +46 -0
  198. data/spec/integration/dsl/resources_spec.rb +202 -0
  199. data/spec/integration/dsl/type_loading_spec.rb +64 -0
  200. data/spec/integration/indirector/catalog/queue_spec.rb +1 -1
  201. data/spec/integration/network/formats_spec.rb +32 -45
  202. data/spec/integration/parser/collector_spec.rb +105 -25
  203. data/spec/integration/parser/scope_spec.rb +64 -1
  204. data/spec/integration/resource/catalog_spec.rb +2 -4
  205. data/spec/integration/type/package_spec.rb +1 -1
  206. data/spec/lib/matchers/catalog.rb +50 -0
  207. data/spec/lib/puppet_spec/compiler.rb +11 -0
  208. data/spec/lib/puppet_spec/dsl.rb +29 -0
  209. data/spec/spec_helper.rb +17 -3
  210. data/spec/unit/application/agent_spec.rb +0 -1
  211. data/spec/unit/application/apply_spec.rb +1 -1
  212. data/spec/unit/application/face_base_spec.rb +11 -4
  213. data/spec/unit/application/indirection_base_spec.rb +4 -8
  214. data/spec/unit/application/kick_spec.rb +5 -2
  215. data/spec/unit/application/master_spec.rb +0 -6
  216. data/spec/unit/application_spec.rb +38 -14
  217. data/spec/unit/dsl/actions_spec.rb +402 -0
  218. data/spec/unit/dsl/blank_slate_spec.rb +27 -0
  219. data/spec/unit/dsl/context_spec.rb +678 -0
  220. data/spec/unit/dsl/parser_spec.rb +56 -0
  221. data/spec/unit/dsl/resource_decorator_spec.rb +94 -0
  222. data/spec/unit/dsl/resource_reference_spec.rb +150 -0
  223. data/spec/unit/dsl/type_reference_spec.rb +164 -0
  224. data/spec/unit/face/help_spec.rb +5 -7
  225. data/spec/unit/indirector/certificate_request/rest_spec.rb +4 -0
  226. data/spec/unit/indirector/certificate_revocation_list/rest_spec.rb +4 -0
  227. data/spec/unit/indirector/certificate_status/rest_spec.rb +4 -0
  228. data/spec/unit/indirector/file_metadata/rest_spec.rb +5 -0
  229. data/spec/unit/indirector/hiera_spec.rb +3 -1
  230. data/spec/unit/indirector/queue_spec.rb +1 -7
  231. data/spec/unit/indirector/ssl_file_spec.rb +66 -39
  232. data/spec/unit/module_spec.rb +1 -1
  233. data/spec/unit/network/authstore_spec.rb +22 -1
  234. data/spec/unit/network/formats_spec.rb +1 -1
  235. data/spec/unit/node/environment_spec.rb +13 -0
  236. data/spec/unit/parser/collector_spec.rb +1 -1
  237. data/spec/unit/parser/compiler_spec.rb +26 -0
  238. data/spec/unit/parser/functions/create_resources_spec.rb +12 -1
  239. data/spec/unit/parser/functions/extlookup_spec.rb +4 -4
  240. data/spec/unit/parser/functions/hiera_array_spec.rb +1 -1
  241. data/spec/unit/parser/functions/hiera_hash_spec.rb +1 -1
  242. data/spec/unit/parser/functions/hiera_include_spec.rb +1 -1
  243. data/spec/unit/parser/functions/hiera_spec.rb +1 -1
  244. data/spec/unit/parser/functions/regsubst_spec.rb +4 -4
  245. data/spec/unit/parser/functions/split_spec.rb +4 -4
  246. data/spec/unit/parser/functions/sprintf_spec.rb +2 -2
  247. data/spec/unit/parser/functions/versioncmp_spec.rb +4 -4
  248. data/spec/unit/parser/functions_spec.rb +51 -1
  249. data/spec/unit/parser/parser_spec.rb +0 -14
  250. data/spec/unit/parser/type_loader_spec.rb +15 -1
  251. data/spec/unit/provider/augeas/augeas_spec.rb +31 -0
  252. data/spec/unit/provider/package/apt_spec.rb +0 -2
  253. data/spec/unit/provider/package/pip_spec.rb +12 -2
  254. data/spec/unit/provider/service/freebsd_spec.rb +8 -0
  255. data/spec/unit/provider/service/gentoo_spec.rb +20 -20
  256. data/spec/unit/provider/service/openrc_spec.rb +20 -20
  257. data/spec/unit/provider/service/src_spec.rb +4 -4
  258. data/spec/unit/provider/service/systemd_spec.rb +0 -8
  259. data/spec/unit/provider/service/windows_spec.rb +1 -1
  260. data/spec/unit/provider/user/useradd_spec.rb +2 -9
  261. data/spec/unit/relationship_spec.rb +2 -2
  262. data/spec/unit/resource/catalog_spec.rb +2 -2
  263. data/spec/unit/resource/type_spec.rb +49 -25
  264. data/spec/unit/resource_spec.rb +34 -2
  265. data/spec/unit/settings/config_file_spec.rb +100 -0
  266. data/spec/unit/settings/file_setting_spec.rb +87 -84
  267. data/spec/unit/settings/value_translator_spec.rb +77 -0
  268. data/spec/unit/settings_spec.rb +96 -29
  269. data/spec/unit/type/file/ensure_spec.rb +75 -36
  270. data/spec/unit/type/file_spec.rb +0 -68
  271. data/spec/unit/type/group_spec.rb +10 -0
  272. data/spec/unit/util/autoload_spec.rb +6 -0
  273. data/spec/unit/util/command_line_spec.rb +54 -62
  274. data/spec/unit/util/manifest_filetype_helper_spec.rb +29 -0
  275. data/spec/unit/util/metric_spec.rb +0 -9
  276. data/spec/unit/util/posix_spec.rb +0 -4
  277. data/spec/unit/util/rdoc_spec.rb +0 -12
  278. data/spec/unit/util/zaml_spec.rb +188 -130
  279. data/spec/unit/version_spec.rb +42 -0
  280. metadata +123 -90
  281. data/README_HIERA.md +0 -148
  282. data/conf/epm.list +0 -8
  283. data/conf/namespaceauth.conf +0 -20
  284. data/conf/puppet-queue.conf +0 -10
  285. data/examples/allatonce +0 -13
  286. data/examples/assignments +0 -11
  287. data/examples/components +0 -73
  288. data/examples/etc/init.d/sleeper +0 -70
  289. data/examples/etc/otherfile +0 -0
  290. data/examples/etc/puppet/fileserver.conf +0 -13
  291. data/examples/etc/puppet/namespaceauth.conf +0 -20
  292. data/examples/etc/puppet/puppet.conf +0 -10
  293. data/examples/etc/puppet/tagmail.conf +0 -1
  294. data/examples/execs +0 -16
  295. data/examples/file.bl +0 -11
  296. data/examples/filedefaults +0 -10
  297. data/examples/fileparsing +0 -116
  298. data/examples/filerecursion +0 -15
  299. data/examples/functions +0 -3
  300. data/examples/groups +0 -7
  301. data/examples/head +0 -30
  302. data/examples/importing +0 -8
  303. data/examples/mac_dscl.pp +0 -28
  304. data/examples/mac_dscl_revert.pp +0 -26
  305. data/examples/mac_pkgdmg.pp +0 -7
  306. data/examples/modules/sample_module.pp +0 -10
  307. data/examples/modules/sample_module/lib/puppet/parser/functions/hostname_to_dn.rb +0 -36
  308. data/examples/modules/sample_module/manifests/init.pp +0 -12
  309. data/examples/modules/sample_module/templates/sample.erb +0 -5
  310. data/examples/nodes +0 -20
  311. data/examples/one +0 -8
  312. data/examples/relationships +0 -34
  313. data/examples/selectors +0 -28
  314. data/examples/simpletests +0 -11
  315. data/examples/svncommit +0 -13
  316. data/lib/puppet/dsl/resource_api.rb +0 -120
  317. data/lib/puppet/dsl/resource_type_api.rb +0 -34
  318. data/spec/integration/parser/ruby_manifest_spec.rb +0 -127
  319. data/spec/unit/dsl/resource_api_spec.rb +0 -180
  320. data/spec/unit/dsl/resource_type_api_spec.rb +0 -53
@@ -1,5 +1,9 @@
1
1
  require 'puppet/parameter'
2
2
 
3
+ # This specialized {Puppet::Parameter} handles munging of package options.
4
+ # Package options are passed as an array of key value pairs. Special munging is
5
+ # required as the keys and values needs to be quoted in a safe way.
6
+ #
3
7
  class Puppet::Parameter::PackageOptions < Puppet::Parameter
4
8
  def unsafe_munge(values)
5
9
  values = [values] unless values.is_a? Array
@@ -20,6 +24,7 @@ class Puppet::Parameter::PackageOptions < Puppet::Parameter
20
24
  end
21
25
  end
22
26
 
27
+ # @api private
23
28
  def quote(value)
24
29
  value.include?(' ') ? %Q["#{value.gsub(/"/, '\"')}"] : value
25
30
  end
@@ -1,6 +1,13 @@
1
1
  require 'puppet/parameter'
2
2
 
3
+ # This specialized {Puppet::Parameter} handles validation and munging of paths.
4
+ # By default, a single path is accepted, and by calling {accept_arrays} it is possible to
5
+ # allow an array of paths.
6
+ #
3
7
  class Puppet::Parameter::Path < Puppet::Parameter
8
+ # Specifies whether multiple paths are accepted or not.
9
+ # @dsl type
10
+ #
4
11
  def self.accept_arrays(bool = true)
5
12
  @accept_arrays = !!bool
6
13
  end
@@ -8,6 +15,13 @@ class Puppet::Parameter::Path < Puppet::Parameter
8
15
  @accept_arrays
9
16
  end
10
17
 
18
+ # Performs validation of the given paths.
19
+ # If the concrete parameter defines a validation method, it may call this method to perform
20
+ # path validation.
21
+ # @raise [Puppet::Error] if this property is configured for single paths and an array is given
22
+ # @raise [Puppet::Error] if a path is not an absolute path
23
+ # @return [Array<String>] the given paths
24
+ #
11
25
  def validate_path(paths)
12
26
  if paths.is_a?(Array) and ! self.class.arrays? then
13
27
  fail "#{name} only accepts a single path, not an array of paths"
@@ -18,13 +32,22 @@ class Puppet::Parameter::Path < Puppet::Parameter
18
32
  paths
19
33
  end
20
34
 
21
- # This will be overridden if someone uses the validate option, which is why
22
- # it just delegates to the other, useful, method.
35
+ # This is the default implementation of the `validate` method.
36
+ # It will be overridden if the validate option is used when defining the parameter.
37
+ # @return [void]
38
+ #
23
39
  def unsafe_validate(paths)
24
40
  validate_path(paths)
25
41
  end
26
42
 
27
- # Likewise, this might be overridden, but by default...
43
+ # This is the default implementation of `munge`.
44
+ # If the concrete parameter defines a `munge` method, this default implementation will be overridden.
45
+ # This default implementation does not perform any munging, it just checks the one/many paths
46
+ # constraints. A derived implementation can perform this check as:
47
+ # `paths.is_a?(Array) and ! self.class.arrays?` and raise a {Puppet::Error}.
48
+ # @param [String, Array<String>] one of multiple paths
49
+ # @return [String, Array<String>] the given paths
50
+ # @raise [Puppet::Error] if the given paths does not comply with the on/many paths rule.
28
51
  def unsafe_munge(paths)
29
52
  if paths.is_a?(Array) and ! self.class.arrays? then
30
53
  fail "#{name} only accepts a single path, not an array of paths"
@@ -1,25 +1,42 @@
1
1
  require 'puppet/parameter/value_collection'
2
2
 
3
- # An individual Value class.
3
+ # Describes an acceptable value for a parameter or property.
4
+ # An acceptable value is either specified as a literal value or a regular expression.
5
+ # @note this class should be used via the api methods in {Puppet::Parameter} and {Puppet::Property}
6
+ # @api private
7
+ #
4
8
  class Puppet::Parameter::Value
5
9
  attr_reader :name, :options, :event
6
10
  attr_accessor :block, :call, :method, :required_features
7
11
 
8
- # Add an alias for this value.
12
+ # Adds an alias for this value.
13
+ # Makes the given _name_ be an alias for this acceptable value.
14
+ # @param name [Symbol] the additonal alias this value should be known as
15
+ # @api private
16
+ #
9
17
  def alias(name)
10
18
  @aliases << convert(name)
11
19
  end
12
20
 
13
- # Return all aliases.
21
+ # @return [Array<Symbol>] Returns all aliases (or an empty array).
22
+ # @api private
23
+ #
14
24
  def aliases
15
25
  @aliases.dup
16
26
  end
17
27
 
18
- # Store the event that our value generates, if it does so.
28
+ # Stores the event that our value generates, if it does so.
29
+ # @api private
30
+ #
19
31
  def event=(value)
20
32
  @event = convert(value)
21
33
  end
22
34
 
35
+ # Initializes the instance with a literal accepted value, or a regular expression.
36
+ # If anything else is passed, it is turned into a String, and then made into a Symbol.
37
+ # @param [Symbol, Regexp, Object] the value to accept, Symbol, a regular expression, or object to convert.
38
+ # @api private
39
+ #
23
40
  def initialize(name)
24
41
  if name.is_a?(Regexp)
25
42
  @name = name
@@ -34,7 +51,10 @@ class Puppet::Parameter::Value
34
51
  @call = :instead
35
52
  end
36
53
 
37
- # Does a provided value match our value?
54
+ # Checks if the given value matches the acceptance rules (literal value, regular expression, or one
55
+ # of the aliases.
56
+ # @api private
57
+ #
38
58
  def match?(value)
39
59
  if regex?
40
60
  return true if name =~ value.to_s
@@ -43,7 +63,9 @@ class Puppet::Parameter::Value
43
63
  end
44
64
  end
45
65
 
46
- # Is our value a regex?
66
+ # @return [Boolean] whether the accepted value is a regular expression or not.
67
+ # @api private
68
+ #
47
69
  def regex?
48
70
  @name.is_a?(Regexp)
49
71
  end
@@ -52,6 +74,8 @@ class Puppet::Parameter::Value
52
74
 
53
75
  # A standard way of converting all of our values, so we're always
54
76
  # comparing apples to apples.
77
+ # @api private
78
+ #
55
79
  def convert(value)
56
80
  case value
57
81
  when Symbol, '' # can't intern an empty string
@@ -1,9 +1,21 @@
1
1
  require 'puppet/parameter/value'
2
2
 
3
- # A collection of values and regexes, used for specifying
4
- # what values are allowed in a given parameter.
3
+ # A collection of values and regular expressions, used for specifying allowed values
4
+ # in a given parameter.
5
+ # @note This class is considered part of the internal implementation of {Puppet::Parameter}, and
6
+ # {Puppet::Property} and the functionality provided by this class should be used via their interfaces.
7
+ # @comment This class probably have several problems when trying to use it with a combination of
8
+ # regular expressions and aliases as it finds an acceptable value holder vi "name" which may be
9
+ # a regular expression...
10
+ #
11
+ # @api private
12
+ #
5
13
  class Puppet::Parameter::ValueCollection
6
14
 
15
+ # Aliases the given existing _other_ value with the additional given _name_.
16
+ # @return [void]
17
+ # @api private
18
+ #
7
19
  def aliasvalue(name, other)
8
20
  other = other.to_sym
9
21
  unless value = match?(other)
@@ -13,7 +25,10 @@ class Puppet::Parameter::ValueCollection
13
25
  value.alias(name)
14
26
  end
15
27
 
16
- # Return a doc string for all of the values in this parameter/property.
28
+ # Returns a doc string (enumerating the acceptable values) for all of the values in this parameter/property.
29
+ # @return [String] a documentation string.
30
+ # @api private
31
+ #
17
32
  def doc
18
33
  unless defined?(@doc)
19
34
  @doc = ""
@@ -34,11 +49,15 @@ class Puppet::Parameter::ValueCollection
34
49
  @doc
35
50
  end
36
51
 
37
- # Does this collection contain any value definitions?
52
+ # @return [Boolean] Returns whether the set of allowed values is empty or not.
53
+ # @api private
54
+ #
38
55
  def empty?
39
56
  @values.empty?
40
57
  end
41
58
 
59
+ # @api private
60
+ #
42
61
  def initialize
43
62
  # We often look values up by name, so a hash makes more sense.
44
63
  @values = {}
@@ -49,7 +68,15 @@ class Puppet::Parameter::ValueCollection
49
68
  @strings = []
50
69
  end
51
70
 
52
- # Can we match a given value?
71
+ # Checks if the given value is acceptable (matches one of the literal values or patterns) and returns
72
+ # the "matcher" that matched.
73
+ # Literal string matchers are tested first, if both a literal and a regexp match would match, the literal
74
+ # match wins.
75
+ #
76
+ # @param test_value [Object] the value to test if it complies with the configured rules
77
+ # @return [Puppet::Parameter::Value, nil] The instance of Puppet::Parameter::Value that matched the given value, or nil if there was no match.
78
+ # @api private
79
+ #
53
80
  def match?(test_value)
54
81
  # First look for normal values
55
82
  if value = @strings.find { |v| v.match?(test_value) }
@@ -60,7 +87,14 @@ class Puppet::Parameter::ValueCollection
60
87
  @regexes.find { |v| v.match?(test_value) }
61
88
  end
62
89
 
63
- # If the specified value is allowed, then munge appropriately.
90
+ # Munges the value if it is valid, else produces the same value.
91
+ # @param value [Object] the value to munge
92
+ # @return [Object] the munged value, or the given value
93
+ # @todo This method does not seem to do any munging. It just returns the value if it matches the
94
+ # regexp, or the (most likely Symbolic) allowed value if it matches (which is more of a replacement
95
+ # of one instance with an equal one. Is the intent that this method should be specialized?
96
+ # @api private
97
+ #
64
98
  def munge(value)
65
99
  return value if empty?
66
100
 
@@ -75,17 +109,25 @@ class Puppet::Parameter::ValueCollection
75
109
  end
76
110
  end
77
111
 
78
- # Define a new valid value for a property. You must provide the value itself,
79
- # usually as a symbol, or a regex to match the value.
112
+ # Defines a new valid value for a {Puppet::Property}.
113
+ # A valid value is specified as a literal (typically a Symbol), but can also be
114
+ # specified with a regexp.
115
+ #
116
+ # @param name [Symbol, Regexp] a valid literal value, or a regexp that matches a value
117
+ # @param options [Hash] a hash with options
118
+ # @option options [Symbol] :event The event that should be emitted when this value is set.
119
+ # @todo Option :event original comment says "event should be returned...", is "returned" the correct word
120
+ # to use?
121
+ # @option options [Symbol] :call When to call any associated block. The default value is `:instead` which
122
+ # means that the block should be called instead of the provider. In earlier versions (before 20081031) it
123
+ # was possible to specify a value of `:before` or `:after` for the purpose of calling
124
+ # both the block and the provider. Use of these deprecated options will now raise an exception later
125
+ # in the process when the _is_ value is set (see Puppet::Property#set).
126
+ # @option options [Object] _any_ Any other option is treated as a call to a setter having the given
127
+ # option name (e.g. `:required_features` calls `required_features=` with the option's value as an
128
+ # argument).
129
+ # @api private
80
130
  #
81
- # The first argument to the method is either the value itself or a regex.
82
- # The second argument is an option hash; valid options are:
83
- # * <tt>:event</tt>: The event that should be returned when this value is set.
84
- # * <tt>:call</tt>: When to call any associated block. The default value
85
- # is ``instead``, which means to call the value instead of calling the
86
- # provider. You can also specify ``before`` or ``after``, which will
87
- # call both the block and the provider, according to the order you specify
88
- # (the ``first`` refers to when the block is called, not the provider).
89
131
  def newvalue(name, options = {}, &block)
90
132
  value = Puppet::Parameter::Value.new(name)
91
133
  @values[value.name] = value
@@ -107,16 +149,27 @@ class Puppet::Parameter::ValueCollection
107
149
  value
108
150
  end
109
151
 
110
- # Define one or more new values for our parameter.
152
+ # Defines one or more valid values (literal or regexp) for a parameter or property.
153
+ # @return [void]
154
+ # @dsl type
155
+ # @api private
156
+ #
111
157
  def newvalues(*names)
112
158
  names.each { |name| newvalue(name) }
113
159
  end
114
160
 
161
+ # @return [Array<String>] An array of the regular expressions in string form, configured as matching valid values.
162
+ # @api private
163
+ #
115
164
  def regexes
116
165
  @regexes.collect { |r| r.name.inspect }
117
166
  end
118
167
 
119
- # Verify that the passed value is valid.
168
+ # Validates the given value against the set of valid literal values and regular expressions.
169
+ # @raise [ArgumentError] if the value is not accepted
170
+ # @return [void]
171
+ # @api private
172
+ #
120
173
  def validate(value)
121
174
  return if empty?
122
175
 
@@ -131,12 +184,21 @@ class Puppet::Parameter::ValueCollection
131
184
  end
132
185
  end
133
186
 
134
- # Return a single value instance.
187
+ # Returns a valid value matcher (a literal or regular expression)
188
+ # @todo This looks odd, asking for an instance that matches a symbol, or a instance that has
189
+ # a regexp. What is the intention here? Marking as api private...
190
+ #
191
+ # @return [Puppet::Parameter::Value] a valid valud matcher
192
+ # @api private
193
+ #
135
194
  def value(name)
136
195
  @values[name]
137
196
  end
138
197
 
139
- # Return the list of valid values.
198
+ # @return [Array<Symbol>] Returns a list of valid literal values.
199
+ # @see regexes
200
+ # @api private
201
+ #
140
202
  def values
141
203
  @strings.collect { |s| s.name }
142
204
  end
@@ -1,3 +1,6 @@
1
+ # @api public
2
+ module Puppet::Parser; end
3
+
1
4
  require 'puppet/parser/parser'
2
5
  require 'puppet/parser/compiler'
3
6
  require 'puppet/resource/type_collection'
@@ -3,15 +3,12 @@ require 'puppet/parser/ast/top_level_construct'
3
3
  class Puppet::Parser::AST::Definition < Puppet::Parser::AST::TopLevelConstruct
4
4
  attr_accessor :context
5
5
 
6
- def initialize(name, context = {}, &ruby_code)
6
+ def initialize(name, context = {})
7
7
  @name = name
8
8
  @context = context
9
- @ruby_code = ruby_code
10
9
  end
11
10
 
12
11
  def instantiate(modname)
13
- new_definition = Puppet::Resource::Type.new(:definition, @name, @context.merge(:module_name => modname))
14
- new_definition.ruby_code = @ruby_code if @ruby_code
15
- [new_definition]
12
+ [Puppet::Resource::Type.new(:definition, @name, @context.merge(:module_name => modname))]
16
13
  end
17
14
  end
@@ -3,15 +3,13 @@ require 'puppet/parser/ast/top_level_construct'
3
3
  class Puppet::Parser::AST::Hostclass < Puppet::Parser::AST::TopLevelConstruct
4
4
  attr_accessor :name, :context
5
5
 
6
- def initialize(name, context = {}, &ruby_code)
6
+ def initialize(name, context = {})
7
7
  @context = context
8
8
  @name = name
9
- @ruby_code = ruby_code
10
9
  end
11
10
 
12
11
  def instantiate(modname)
13
12
  new_class = Puppet::Resource::Type.new(:hostclass, @name, @context.merge(:module_name => modname))
14
- new_class.ruby_code = @ruby_code if @ruby_code
15
13
  all_types = [new_class]
16
14
  if code
17
15
  code.each do |nested_ast_node|
@@ -20,6 +18,7 @@ class Puppet::Parser::AST::Hostclass < Puppet::Parser::AST::TopLevelConstruct
20
18
  end
21
19
  end
22
20
  end
21
+
23
22
  return all_types
24
23
  end
25
24
 
@@ -3,18 +3,15 @@ require 'puppet/parser/ast/top_level_construct'
3
3
  class Puppet::Parser::AST::Node < Puppet::Parser::AST::TopLevelConstruct
4
4
  attr_accessor :names, :context
5
5
 
6
- def initialize(names, context = {}, &ruby_code)
6
+ def initialize(names, context = {})
7
7
  raise ArgumentError, "names should be an array" unless names.is_a? Array
8
8
  @names = names
9
9
  @context = context
10
- @ruby_code = ruby_code
11
10
  end
12
11
 
13
12
  def instantiate(modname)
14
13
  @names.collect do |name|
15
- new_node = Puppet::Resource::Type.new(:node, name, @context.merge(:module_name => modname))
16
- new_node.ruby_code = @ruby_code if @ruby_code
17
- new_node
14
+ Puppet::Resource::Type.new(:node, name, @context.merge(:module_name => modname))
18
15
  end
19
16
  end
20
17
  end
@@ -11,7 +11,7 @@ class Puppet::Parser::AST
11
11
 
12
12
  # Return the parameter and the value.
13
13
  def evaluate(scope)
14
- return Puppet::Parser::Resource::Param.new(
14
+ Puppet::Parser::Resource::Param.new(
15
15
  :name => @param,
16
16
  :value => @value.safeevaluate(scope),
17
17
  :source => scope.source, :line => self.line, :file => self.file,
@@ -3,8 +3,10 @@ require 'forwardable'
3
3
  require 'puppet/node'
4
4
  require 'puppet/resource/catalog'
5
5
  require 'puppet/util/errors'
6
+ require 'puppet/util/manifest_filetype_helper'
6
7
 
7
8
  require 'puppet/resource/type_collection_helper'
9
+ require 'puppet/dsl/parser'
8
10
 
9
11
  # Maintain a graph of scopes, along with a bunch of data
10
12
  # about the individual catalog we're compiling.
@@ -90,6 +92,7 @@ class Puppet::Parser::Compiler
90
92
  # This is the main entry into our catalog.
91
93
  def compile
92
94
  # Set the client's parameters into the top scope.
95
+
93
96
  set_node_parameters
94
97
  create_settings_scope
95
98
 
@@ -110,6 +113,10 @@ class Puppet::Parser::Compiler
110
113
 
111
114
  def_delegator :@collections, :delete, :delete_collection
112
115
 
116
+ def assign_ruby_code(file)
117
+ Puppet::DSL::Parser.prepare_for_evaluation @main, File.read(file), file
118
+ end
119
+
113
120
  # Return the node's environment.
114
121
  def environment
115
122
  unless defined?(@environment)
@@ -279,6 +286,9 @@ class Puppet::Parser::Compiler
279
286
 
280
287
  add_resource(@topscope, @main_resource)
281
288
 
289
+ file = Puppet.settings.value :manifest, environment
290
+ assign_ruby_code file if Puppet::Util::ManifestFiletypeHelper.is_ruby_filename? file
291
+
282
292
  @main_resource.evaluate
283
293
  end
284
294
 
@@ -5,6 +5,8 @@ require 'monitor'
5
5
  # A module for managing parser functions. Each specified function
6
6
  # is added to a central module that then gets included into the Scope
7
7
  # class.
8
+ #
9
+ # @api public
8
10
  module Puppet::Parser::Functions
9
11
  Environment = Puppet::Node::Environment
10
12
 
@@ -12,7 +14,9 @@ module Puppet::Parser::Functions
12
14
  include Puppet::Util
13
15
  end
14
16
 
15
- # This is used by tests
17
+ # Reset the list of loaded functions.
18
+ #
19
+ # @api private
16
20
  def self.reset
17
21
  @functions = Hash.new { |h,k| h[k] = {} }.extend(MonitorMixin)
18
22
  @modules = Hash.new.extend(MonitorMixin)
@@ -25,12 +29,19 @@ module Puppet::Parser::Functions
25
29
  end
26
30
  end
27
31
 
32
+ # Accessor for singleton autoloader
33
+ #
34
+ # @api private
28
35
  def self.autoloader
29
36
  @autoloader ||= Puppet::Util::Autoload.new(
30
37
  self, "puppet/parser/functions", :wrap => false
31
38
  )
32
39
  end
33
40
 
41
+ # Get the module that functions are mixed into corresponding to an
42
+ # environment
43
+ #
44
+ # @api private
34
45
  def self.environment_module(env = nil)
35
46
  if env and ! env.is_a?(Puppet::Node::Environment)
36
47
  env = Puppet::Node::Environment.new(env)
@@ -40,12 +51,79 @@ module Puppet::Parser::Functions
40
51
  }
41
52
  end
42
53
 
43
- # Create a new function type.
54
+ # Create a new Puppet DSL function.
55
+ #
56
+ # **The {newfunction} method provides a public API.**
57
+ #
58
+ # This method is used both internally inside of Puppet to define parser
59
+ # functions. For example, template() is defined in
60
+ # {file:lib/puppet/parser/functions/template.rb template.rb} using the
61
+ # {newfunction} method. Third party Puppet modules such as
62
+ # [stdlib](https://forge.puppetlabs.com/puppetlabs/stdlib) use this method to
63
+ # extend the behavior and functionality of Puppet.
64
+ #
65
+ # See also [Docs: Custom
66
+ # Functions](http://docs.puppetlabs.com/guides/custom_functions.html)
67
+ #
68
+ # @example Define a new Puppet DSL Function
69
+ # >> Puppet::Parser::Functions.newfunction(:double, :arity => 1,
70
+ # :doc => "Doubles an object, typically a number or string.",
71
+ # :type => :rvalue) {|i| i[0]*2 }
72
+ # => {:arity=>1, :type=>:rvalue,
73
+ # :name=>"function_double",
74
+ # :doc=>"Doubles an object, typically a number or string."}
75
+ #
76
+ # @example Invoke the double function from irb as is done in RSpec examples:
77
+ # >> scope = Puppet::Parser::Scope.new_for_test_harness('example')
78
+ # => Scope()
79
+ # >> scope.function_double([2])
80
+ # => 4
81
+ # >> scope.function_double([4])
82
+ # => 8
83
+ # >> scope.function_double([])
84
+ # ArgumentError: double(): Wrong number of arguments given (0 for 1)
85
+ # >> scope.function_double([4,8])
86
+ # ArgumentError: double(): Wrong number of arguments given (2 for 1)
87
+ # >> scope.function_double(["hello"])
88
+ # => "hellohello"
89
+ #
90
+ # @param [Symbol] name the name of the function represented as a ruby Symbol.
91
+ # The {newfunction} method will define a Ruby method based on this name on
92
+ # the parser scope instance.
93
+ #
94
+ # @param [Proc] block the block provided to the {newfunction} method will be
95
+ # executed when the Puppet DSL function is evaluated during catalog
96
+ # compilation. The arguments to the function will be passed as an array to
97
+ # the first argument of the block. The return value of the block will be
98
+ # the return value of the Puppet DSL function for `:rvalue` functions.
99
+ #
100
+ # @option options [:rvalue, :statement] :type (:statement) the type of function.
101
+ # Either `:rvalue` for functions that return a value, or `:statement` for
102
+ # functions that do not return a value.
103
+ #
104
+ # @option options [String] :doc ('') the documentation for the function.
105
+ # This string will be extracted by documentation generation tools.
106
+ #
107
+ # @option options [Integer] :arity (-1) the
108
+ # [arity](http://en.wikipedia.org/wiki/Arity) of the function. When
109
+ # specified as a positive integer the function is expected to receive
110
+ # _exactly_ the specified number of arguments. When specified as a
111
+ # negative number, the function is expected to receive _at least_ the
112
+ # absolute value of the specified number of arguments incremented by one.
113
+ # For example, a function with an arity of `-4` is expected to receive at
114
+ # minimum 3 arguments. A function with the default arity of `-1` accepts
115
+ # zero or more arguments. A function with an arity of 2 must be provided
116
+ # with exactly two arguments, no more and no less. Added in Puppet 3.1.0.
117
+ #
118
+ # @return [Hash] describing the function.
119
+ #
120
+ # @api public
44
121
  def self.newfunction(name, options = {}, &block)
45
122
  name = name.intern
46
123
 
47
124
  Puppet.warning "Overwriting previous definition for function #{name}" if get_function(name)
48
125
 
126
+ arity = options[:arity] || -1
49
127
  ftype = options[:type] || :statement
50
128
 
51
129
  unless ftype == :statement or ftype == :rvalue
@@ -60,22 +138,32 @@ module Puppet::Parser::Functions
60
138
  fname = "function_#{name}"
61
139
  environment_module.send(:define_method, fname) do |*args|
62
140
  if args[0].is_a? Array
141
+ if arity >= 0 and args[0].size != arity
142
+ raise ArgumentError, "#{name}(): Wrong number of arguments given (#{args[0].size} for #{arity})"
143
+ elsif arity < 0 and args[0].size < (arity+1).abs
144
+ raise ArgumentError, "#{name}(): Wrong number of arguments given (#{args[0].size} for minimum #{(arity+1).abs})"
145
+ end
63
146
  self.send(real_fname, args[0])
64
147
  else
65
148
  raise ArgumentError, "custom functions must be called with a single array that contains the arguments. For example, function_example([1]) instead of function_example(1)"
66
149
  end
67
150
  end
68
151
 
69
- # Someday we'll support specifying an arity, but for now, nope
70
- #functions[name] = {:arity => arity, :type => ftype}
71
- func = {:type => ftype, :name => fname}
152
+ func = {:arity => arity, :type => ftype, :name => fname}
72
153
  func[:doc] = options[:doc] if options[:doc]
73
154
 
74
155
  add_function(name, func)
75
156
  func
76
157
  end
77
158
 
78
- # Determine if a given name is a function
159
+ # Determine if a function is defined
160
+ #
161
+ # @param [Symbol] name the function
162
+ #
163
+ # @return [Symbol, false] The name of the function if it's defined,
164
+ # otherwise false.
165
+ #
166
+ # @api public
79
167
  def self.function(name)
80
168
  name = name.intern
81
169
 
@@ -113,12 +201,28 @@ module Puppet::Parser::Functions
113
201
  ret
114
202
  end
115
203
 
116
- # Determine if a given function returns a value or not.
204
+ # Determine whether a given function returns a value.
205
+ #
206
+ # @param [Symbol] name the function
207
+ #
208
+ # @api public
117
209
  def self.rvalue?(name)
118
210
  func = get_function(name)
119
211
  func ? func[:type] == :rvalue : false
120
212
  end
121
213
 
214
+ # Return the number of arguments a function expects.
215
+ #
216
+ # @param [Symbol] name the function
217
+ # @return [Integer] The arity of the function. See {newfunction} for
218
+ # the meaning of negative values.
219
+ #
220
+ # @api public
221
+ def self.arity(name)
222
+ func = get_function(name)
223
+ func ? func[:arity] : -1
224
+ end
225
+
122
226
  class << self
123
227
  private
124
228