chef 12.0.0.alpha.0-x86-mingw32 → 12.0.0.alpha.1-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (207) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +3 -5
  3. data/lib/chef/api_client.rb +1 -1
  4. data/lib/chef/application.rb +16 -8
  5. data/lib/chef/chef_fs/chef_fs_data_store.rb +1 -1
  6. data/lib/chef/chef_fs/command_line.rb +1 -1
  7. data/lib/chef/chef_fs/file_system.rb +1 -1
  8. data/lib/chef/chef_fs/file_system/acl_entry.rb +1 -1
  9. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +3 -3
  10. data/lib/chef/chef_fs/file_system/cookbook_file.rb +2 -2
  11. data/lib/chef/chef_fs/file_system/rest_list_dir.rb +2 -2
  12. data/lib/chef/chef_fs/file_system/rest_list_entry.rb +4 -4
  13. data/lib/chef/config.rb +6 -5
  14. data/lib/chef/config_fetcher.rb +1 -1
  15. data/lib/chef/cookbook/cookbook_version_loader.rb +126 -43
  16. data/lib/chef/cookbook/metadata.rb +102 -53
  17. data/lib/chef/cookbook/syntax_check.rb +1 -1
  18. data/lib/chef/cookbook_loader.rb +62 -14
  19. data/lib/chef/cookbook_site_streaming_uploader.rb +12 -1
  20. data/lib/chef/cookbook_version.rb +13 -4
  21. data/lib/chef/data_bag.rb +28 -15
  22. data/lib/chef/data_bag_item.rb +5 -7
  23. data/lib/chef/digester.rb +5 -9
  24. data/lib/chef/dsl/recipe.rb +14 -0
  25. data/lib/chef/encrypted_data_bag_item.rb +1 -0
  26. data/lib/chef/encrypted_data_bag_item/assertions.rb +57 -0
  27. data/lib/chef/encrypted_data_bag_item/decryptor.rb +52 -28
  28. data/lib/chef/encrypted_data_bag_item/encrypted_data_bag_item_assertions.rb +37 -0
  29. data/lib/chef/encrypted_data_bag_item/encryption_failure.rb +22 -0
  30. data/lib/chef/encrypted_data_bag_item/encryptor.rb +79 -8
  31. data/lib/chef/environment.rb +1 -3
  32. data/lib/chef/exceptions.rb +18 -3
  33. data/lib/chef/formatters/base.rb +7 -0
  34. data/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb +1 -1
  35. data/lib/chef/handler/json_file.rb +0 -1
  36. data/lib/chef/http/json_output.rb +1 -1
  37. data/lib/chef/json_compat.rb +24 -6
  38. data/lib/chef/knife/bootstrap.rb +2 -2
  39. data/lib/chef/knife/client_delete.rb +1 -1
  40. data/lib/chef/knife/cookbook_site_download.rb +1 -1
  41. data/lib/chef/knife/cookbook_site_list.rb +1 -1
  42. data/lib/chef/knife/cookbook_site_search.rb +1 -1
  43. data/lib/chef/knife/cookbook_site_share.rb +2 -2
  44. data/lib/chef/knife/cookbook_site_show.rb +3 -3
  45. data/lib/chef/knife/cookbook_site_unshare.rb +1 -1
  46. data/lib/chef/knife/core/node_editor.rb +2 -3
  47. data/lib/chef/knife/core/ui.rb +2 -2
  48. data/lib/chef/knife/deps.rb +2 -3
  49. data/lib/chef/mixin/shell_out.rb +1 -1
  50. data/lib/chef/mixin/windows_architecture_helper.rb +1 -0
  51. data/lib/chef/node.rb +1 -2
  52. data/lib/chef/platform/provider_mapping.rb +33 -6
  53. data/lib/chef/provider.rb +0 -2
  54. data/lib/chef/provider/cookbook_file/content.rb +1 -1
  55. data/lib/chef/provider/cron.rb +11 -0
  56. data/lib/chef/provider/deploy.rb +3 -2
  57. data/lib/chef/provider/deploy/revision.rb +2 -2
  58. data/lib/chef/provider/env.rb +1 -1
  59. data/lib/chef/provider/env/windows.rb +5 -9
  60. data/lib/chef/provider/file.rb +84 -33
  61. data/lib/chef/provider/git.rb +2 -1
  62. data/lib/chef/provider/group/aix.rb +17 -2
  63. data/lib/chef/provider/group/dscl.rb +27 -9
  64. data/lib/chef/provider/group/pw.rb +8 -1
  65. data/lib/chef/provider/http_request.rb +4 -4
  66. data/lib/chef/provider/log.rb +4 -14
  67. data/lib/chef/provider/mount/mount.rb +2 -2
  68. data/lib/chef/provider/package/ips.rb +17 -23
  69. data/lib/chef/provider/package/paludis.rb +2 -2
  70. data/lib/chef/provider/package/rpm.rb +2 -2
  71. data/lib/chef/provider/package/rubygems.rb +2 -0
  72. data/lib/chef/provider/package/yum.rb +2 -0
  73. data/lib/chef/provider/package/zypper.rb +1 -1
  74. data/lib/chef/provider/remote_file/cache_control_data.rb +2 -2
  75. data/lib/chef/provider/service/windows.rb +87 -21
  76. data/lib/chef/provider/user/aix.rb +95 -0
  77. data/lib/chef/provider/user/dscl.rb +544 -156
  78. data/lib/chef/provider/user/useradd.rb +1 -0
  79. data/lib/chef/providers.rb +1 -0
  80. data/lib/chef/resource.rb +4 -3
  81. data/lib/chef/resource/freebsd_package.rb +10 -2
  82. data/lib/chef/resource/paludis_package.rb +1 -0
  83. data/lib/chef/resource/scm.rb +10 -0
  84. data/lib/chef/resource/user.rb +27 -0
  85. data/lib/chef/resource/windows_service.rb +53 -0
  86. data/lib/chef/resource_collection.rb +23 -12
  87. data/lib/chef/resource_reporter.rb +10 -10
  88. data/lib/chef/resources.rb +1 -0
  89. data/lib/chef/role.rb +3 -3
  90. data/lib/chef/run_list.rb +6 -3
  91. data/lib/chef/user.rb +1 -1
  92. data/lib/chef/util/diff.rb +1 -2
  93. data/lib/chef/version.rb +1 -1
  94. data/lib/chef/version_constraint.rb +4 -4
  95. data/spec/data/cookbooks/angrybash/metadata.rb +2 -0
  96. data/spec/data/cookbooks/apache2/metadata.rb +2 -0
  97. data/spec/data/cookbooks/borken/metadata.rb +2 -0
  98. data/spec/data/cookbooks/ignorken/metadata.rb +2 -0
  99. data/spec/data/cookbooks/java/metadata.rb +2 -0
  100. data/spec/data/cookbooks/name-mismatch-versionnumber/README.md +4 -0
  101. data/spec/data/cookbooks/name-mismatch-versionnumber/metadata.rb +8 -0
  102. data/spec/data/cookbooks/name-mismatch-versionnumber/recipes/default.rb +8 -0
  103. data/spec/data/cookbooks/openldap/files/default/remotedir/not_a_template.erb +2 -0
  104. data/spec/data/cookbooks/preseed/metadata.rb +2 -0
  105. data/spec/data/incomplete-metadata-chef-repo/incomplete-metadata/README.md +4 -0
  106. data/spec/data/incomplete-metadata-chef-repo/incomplete-metadata/metadata.rb +13 -0
  107. data/spec/data/incomplete-metadata-chef-repo/incomplete-metadata/recipes/default.rb +8 -0
  108. data/spec/data/invalid-metadata-chef-repo/invalid-metadata/README.md +4 -0
  109. data/spec/data/invalid-metadata-chef-repo/invalid-metadata/metadata.rb +10 -0
  110. data/spec/data/invalid-metadata-chef-repo/invalid-metadata/recipes/default.rb +8 -0
  111. data/spec/data/mac_users/10.7-8.plist.xml +559 -0
  112. data/spec/data/mac_users/10.7-8.shadow.xml +11 -0
  113. data/spec/data/mac_users/10.7.plist.xml +559 -0
  114. data/spec/data/mac_users/10.7.shadow.xml +11 -0
  115. data/spec/data/mac_users/10.8.plist.xml +559 -0
  116. data/spec/data/mac_users/10.8.shadow.xml +21 -0
  117. data/spec/data/mac_users/10.9.plist.xml +560 -0
  118. data/spec/data/mac_users/10.9.shadow.xml +21 -0
  119. data/spec/data/object_loader/environments/test.json +2 -0
  120. data/spec/data/object_loader/environments/test_json_class.json +2 -0
  121. data/spec/data/object_loader/nodes/test.json +2 -0
  122. data/spec/data/object_loader/nodes/test_json_class.json +2 -0
  123. data/spec/data/object_loader/roles/test.json +2 -0
  124. data/spec/data/object_loader/roles/test_json_class.json +2 -0
  125. data/spec/functional/resource/bff_spec.rb +1 -1
  126. data/spec/functional/resource/cron_spec.rb +20 -1
  127. data/spec/functional/resource/env_spec.rb +137 -0
  128. data/spec/functional/resource/group_spec.rb +7 -5
  129. data/spec/functional/resource/remote_file_spec.rb +12 -1
  130. data/spec/functional/resource/user/dscl_spec.rb +198 -0
  131. data/spec/functional/resource/{user_spec.rb → user/useradd_spec.rb} +175 -37
  132. data/spec/integration/client/client_spec.rb +6 -4
  133. data/spec/integration/client/ipv6_spec.rb +16 -14
  134. data/spec/integration/knife/chef_fs_data_store_spec.rb +57 -46
  135. data/spec/integration/knife/chef_repo_path_spec.rb +105 -78
  136. data/spec/integration/knife/chef_repository_file_system_spec.rb +100 -84
  137. data/spec/integration/knife/chefignore_spec.rb +76 -46
  138. data/spec/integration/knife/common_options_spec.rb +16 -21
  139. data/spec/integration/knife/cookbook_api_ipv6_spec.rb +3 -3
  140. data/spec/integration/knife/delete_spec.rb +66 -46
  141. data/spec/integration/knife/deps_spec.rb +145 -94
  142. data/spec/integration/knife/diff_spec.rb +176 -110
  143. data/spec/integration/knife/download_spec.rb +229 -133
  144. data/spec/integration/knife/list_spec.rb +62 -54
  145. data/spec/integration/knife/raw_spec.rb +24 -9
  146. data/spec/integration/knife/redirection_spec.rb +2 -2
  147. data/spec/integration/knife/serve_spec.rb +2 -2
  148. data/spec/integration/knife/show_spec.rb +32 -26
  149. data/spec/integration/knife/upload_spec.rb +308 -165
  150. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +10 -8
  151. data/spec/integration/solo/solo_spec.rb +22 -11
  152. data/spec/spec_helper.rb +3 -0
  153. data/spec/support/lib/chef/resource/zen_follower.rb +46 -0
  154. data/spec/support/platform_helpers.rb +12 -0
  155. data/spec/support/shared/functional/file_resource.rb +10 -0
  156. data/spec/support/shared/integration/chef_zero_support.rb +130 -0
  157. data/spec/support/shared/integration/integration_helper.rb +100 -98
  158. data/spec/support/shared/integration/knife_support.rb +0 -1
  159. data/spec/support/shared/unit/provider/file.rb +6 -4
  160. data/spec/support/shared/unit/provider/useradd_based_user_provider.rb +10 -1
  161. data/spec/unit/api_client/registration_spec.rb +83 -74
  162. data/spec/unit/application_spec.rb +32 -9
  163. data/spec/unit/cookbook/cookbook_version_loader_spec.rb +179 -0
  164. data/spec/unit/cookbook/metadata_spec.rb +190 -150
  165. data/spec/unit/cookbook/syntax_check_spec.rb +3 -2
  166. data/spec/unit/cookbook_loader_spec.rb +114 -53
  167. data/spec/unit/{cookbook_site_streaming_uploader.rb → cookbook_site_streaming_uploader_spec.rb} +21 -1
  168. data/spec/unit/data_bag_spec.rb +88 -13
  169. data/spec/unit/deprecation_spec.rb +1 -2
  170. data/spec/unit/encrypted_data_bag_item_spec.rb +145 -9
  171. data/spec/unit/environment_spec.rb +1 -1
  172. data/spec/unit/formatters/base_spec.rb +48 -0
  173. data/spec/unit/json_compat_spec.rb +48 -17
  174. data/spec/unit/knife/client_delete_spec.rb +4 -4
  175. data/spec/unit/knife/client_show_spec.rb +15 -5
  176. data/spec/unit/knife/cookbook_site_download_spec.rb +1 -1
  177. data/spec/unit/knife/cookbook_site_share_spec.rb +3 -3
  178. data/spec/unit/knife/data_bag_from_file_spec.rb +0 -2
  179. data/spec/unit/knife/data_bag_show_spec.rb +23 -14
  180. data/spec/unit/knife/node_show_spec.rb +32 -15
  181. data/spec/unit/knife/role_show_spec.rb +59 -0
  182. data/spec/unit/platform_spec.rb +10 -0
  183. data/spec/unit/provider/deploy_spec.rb +4 -0
  184. data/spec/unit/provider/env_spec.rb +19 -0
  185. data/spec/unit/provider/git_spec.rb +22 -2
  186. data/spec/unit/provider/group/dscl_spec.rb +38 -1
  187. data/spec/unit/provider/group/pw_spec.rb +2 -2
  188. data/spec/unit/provider/http_request_spec.rb +8 -8
  189. data/spec/unit/provider/log_spec.rb +33 -53
  190. data/spec/unit/provider/mount/mount_spec.rb +12 -3
  191. data/spec/unit/provider/package/ips_spec.rb +96 -63
  192. data/spec/unit/provider/package/paludis_spec.rb +5 -5
  193. data/spec/unit/provider/package/rpm_spec.rb +12 -0
  194. data/spec/unit/provider/package/zypper_spec.rb +28 -16
  195. data/spec/unit/provider/service/windows_spec.rb +77 -17
  196. data/spec/unit/provider/user/dscl_spec.rb +659 -264
  197. data/spec/unit/provider/user/useradd_spec.rb +1 -0
  198. data/spec/unit/recipe_spec.rb +41 -0
  199. data/spec/unit/resource/scm_spec.rb +11 -0
  200. data/spec/unit/resource/user_spec.rb +4 -0
  201. data/spec/unit/resource/windows_service_spec.rb +46 -0
  202. data/spec/unit/resource_collection_spec.rb +33 -0
  203. data/spec/unit/resource_reporter_spec.rb +48 -0
  204. data/spec/unit/resource_spec.rb +9 -2
  205. data/spec/unit/role_spec.rb +6 -0
  206. data/spec/unit/version_constraint_spec.rb +28 -0
  207. metadata +61 -4
@@ -18,12 +18,14 @@
18
18
  # limitations under the License.
19
19
  #
20
20
 
21
+ require 'chef/exceptions'
21
22
  require 'chef/mash'
22
23
  require 'chef/mixin/from_file'
23
24
  require 'chef/mixin/params_validate'
24
25
  require 'chef/log'
25
26
  require 'chef/version_class'
26
27
  require 'chef/version_constraint'
28
+ require 'chef/json_compat'
27
29
 
28
30
  class Chef
29
31
  class Cookbook
@@ -66,18 +68,17 @@ class Chef
66
68
  include Chef::Mixin::ParamsValidate
67
69
  include Chef::Mixin::FromFile
68
70
 
69
- attr_reader :cookbook,
70
- :platforms,
71
- :dependencies,
72
- :recommendations,
73
- :suggestions,
74
- :conflicting,
75
- :providing,
76
- :replacing,
77
- :attributes,
78
- :groupings,
79
- :recipes,
80
- :version
71
+ attr_reader :platforms
72
+ attr_reader :dependencies
73
+ attr_reader :recommendations
74
+ attr_reader :suggestions
75
+ attr_reader :conflicting
76
+ attr_reader :providing
77
+ attr_reader :replacing
78
+ attr_reader :attributes
79
+ attr_reader :groupings
80
+ attr_reader :recipes
81
+ attr_reader :version
81
82
 
82
83
  # Builds a new Chef::Cookbook::Metadata object.
83
84
  #
@@ -89,14 +90,16 @@ class Chef
89
90
  #
90
91
  # === Returns
91
92
  # metadata<Chef::Cookbook::Metadata>
92
- def initialize(cookbook=nil, maintainer='YOUR_COMPANY_NAME', maintainer_email='YOUR_EMAIL', license='none')
93
- @cookbook = cookbook
94
- @name = cookbook ? cookbook.name : ""
95
- @long_description = ""
96
- self.maintainer(maintainer)
97
- self.maintainer_email(maintainer_email)
98
- self.license(license)
99
- self.description('A fabulous new cookbook')
93
+ def initialize
94
+ @name = nil
95
+
96
+ @description = ''
97
+ @long_description = ''
98
+ @license = 'All rights reserved'
99
+
100
+ @maintainer = nil
101
+ @maintainer_email = nil
102
+
100
103
  @platforms = Mash.new
101
104
  @dependencies = Mash.new
102
105
  @recommendations = Mash.new
@@ -107,15 +110,9 @@ class Chef
107
110
  @attributes = Mash.new
108
111
  @groupings = Mash.new
109
112
  @recipes = Mash.new
110
- @version = Version.new "0.0.0"
111
- if cookbook
112
- @recipes = cookbook.fully_qualified_recipe_names.inject({}) do |r, e|
113
- e = self.name.to_s if e =~ /::default$/
114
- r[e] ||= ""
115
- self.provides e
116
- r
117
- end
118
- end
113
+ @version = Version.new("0.0.0")
114
+
115
+ @errors = []
119
116
  end
120
117
 
121
118
  def ==(other)
@@ -124,6 +121,32 @@ class Chef
124
121
  end
125
122
  end
126
123
 
124
+ # Whether this metadata is valid. In order to be valid, all required
125
+ # fields must be set. Chef's validation implementation checks the content
126
+ # of a given field when setting (and raises an error if the content does
127
+ # not meet the criteria), so the content of the fields is not considered
128
+ # when checking validity.
129
+ #
130
+ # === Returns
131
+ # valid<Boolean>:: Whether this metadata object is valid
132
+ def valid?
133
+ run_validation
134
+ @errors.empty?
135
+ end
136
+
137
+ # A list of validation errors for this metadata object. See #valid? for
138
+ # comments about the validation criteria.
139
+ #
140
+ # If there are any validation errors, one or more error strings will be
141
+ # returned. Otherwise an empty array is returned.
142
+ #
143
+ # === Returns
144
+ # error messages<Array>:: Whether this metadata object is valid
145
+ def errors
146
+ run_validation
147
+ @errors
148
+ end
149
+
127
150
  # Sets the cookbooks maintainer, or returns it.
128
151
  #
129
152
  # === Parameters
@@ -242,8 +265,8 @@ class Chef
242
265
  # versions<Array>:: Returns the list of versions for the platform
243
266
  def supports(platform, *version_args)
244
267
  version = new_args_format(:supports, platform, version_args)
245
- normalized_version = normalize_version_constraint(:supports, platform, version)
246
- @platforms[platform] = normalized_version
268
+ constraint = validate_version_constraint(:supports, platform, version)
269
+ @platforms[platform] = constraint.to_s
247
270
  @platforms[platform]
248
271
  end
249
272
 
@@ -259,8 +282,8 @@ class Chef
259
282
  # versions<Array>:: Returns the list of versions for the platform
260
283
  def depends(cookbook, *version_args)
261
284
  version = new_args_format(:depends, cookbook, version_args)
262
- normalized_version = normalize_version_constraint(:depends, cookbook, version)
263
- @dependencies[cookbook] = normalized_version
285
+ constraint = validate_version_constraint(:depends, cookbook, version)
286
+ @dependencies[cookbook] = constraint.to_s
264
287
  @dependencies[cookbook]
265
288
  end
266
289
 
@@ -276,8 +299,8 @@ class Chef
276
299
  # versions<Array>:: Returns the list of versions for the platform
277
300
  def recommends(cookbook, *version_args)
278
301
  version = new_args_format(:recommends, cookbook, version_args)
279
- normalized_version = normalize_version_constraint(:recommends, cookbook, version)
280
- @recommendations[cookbook] = normalized_version
302
+ constraint = validate_version_constraint(:recommends, cookbook, version)
303
+ @recommendations[cookbook] = constraint.to_s
281
304
  @recommendations[cookbook]
282
305
  end
283
306
 
@@ -293,8 +316,8 @@ class Chef
293
316
  # versions<Array>:: Returns the list of versions for the platform
294
317
  def suggests(cookbook, *version_args)
295
318
  version = new_args_format(:suggests, cookbook, version_args)
296
- normalized_version = normalize_version_constraint(:suggests, cookbook, version)
297
- @suggestions[cookbook] = normalized_version
319
+ constraint = validate_version_constraint(:suggests, cookbook, version)
320
+ @suggestions[cookbook] = constraint.to_s
298
321
  @suggestions[cookbook]
299
322
  end
300
323
 
@@ -310,8 +333,8 @@ class Chef
310
333
  # versions<Array>:: Returns the list of versions for the platform
311
334
  def conflicts(cookbook, *version_args)
312
335
  version = new_args_format(:conflicts, cookbook, version_args)
313
- normalized_version = normalize_version_constraint(:conflicts, cookbook, version)
314
- @conflicting[cookbook] = normalized_version
336
+ constraint = validate_version_constraint(:conflicts, cookbook, version)
337
+ @conflicting[cookbook] = constraint.to_s
315
338
  @conflicting[cookbook]
316
339
  end
317
340
 
@@ -331,8 +354,8 @@ class Chef
331
354
  # versions<Array>:: Returns the list of versions for the platform
332
355
  def provides(cookbook, *version_args)
333
356
  version = new_args_format(:provides, cookbook, version_args)
334
- normalized_version = normalize_version_constraint(:provides, cookbook, version)
335
- @providing[cookbook] = normalized_version
357
+ constraint = validate_version_constraint(:provides, cookbook, version)
358
+ @providing[cookbook] = constraint.to_s
336
359
  @providing[cookbook]
337
360
  end
338
361
 
@@ -347,8 +370,8 @@ class Chef
347
370
  # versions<Array>:: Returns the list of versions for the platform
348
371
  def replaces(cookbook, *version_args)
349
372
  version = new_args_format(:replaces, cookbook, version_args)
350
- normalized_version = normalize_version_constraint(:replaces, cookbook, version)
351
- @replacing[cookbook] = normalized_version
373
+ constraint = validate_version_constraint(:replaces, cookbook, version)
374
+ @replacing[cookbook] = constraint.to_s
352
375
  @replacing[cookbook]
353
376
  end
354
377
 
@@ -364,6 +387,32 @@ class Chef
364
387
  @recipes[name] = description
365
388
  end
366
389
 
390
+ # Sets the cookbook's recipes to the list of recipes in the given
391
+ # +cookbook+. Any recipe that already has a description (if set by the
392
+ # #recipe method) will not be updated.
393
+ #
394
+ # === Parameters
395
+ # cookbook<CookbookVersion>:: CookbookVersion object representing the cookbook
396
+ # description<String>:: The description of the recipe
397
+ #
398
+ # === Returns
399
+ # recipe_unqualified_names<Array>:: An array of the recipe names given by the cookbook
400
+ def recipes_from_cookbook_version(cookbook)
401
+ cookbook.fully_qualified_recipe_names.map do |recipe_name|
402
+ unqualified_name =
403
+ if recipe_name =~ /::default$/
404
+ self.name.to_s
405
+ else
406
+ recipe_name
407
+ end
408
+
409
+ @recipes[unqualified_name] ||= ""
410
+ provides(unqualified_name)
411
+
412
+ unqualified_name
413
+ end
414
+ end
415
+
367
416
  # Adds an attribute )hat a user needs to configure for this cookbook. Takes
368
417
  # a name (with the / notation for a nested attribute), followed by any of
369
418
  # these options
@@ -441,7 +490,7 @@ class Chef
441
490
  end
442
491
 
443
492
  def to_json(*a)
444
- self.to_hash.to_json(*a)
493
+ Chef::JSONCompat.to_json(to_hash, *a)
445
494
  end
446
495
 
447
496
  def self.from_hash(o)
@@ -479,9 +528,9 @@ class Chef
479
528
  def self.validate_json(json_str)
480
529
  o = Chef::JSONCompat.from_json(json_str)
481
530
  metadata = new()
482
- VERSION_CONSTRAINTS.each do |method_name, hash_key|
483
- if constraints = o[hash_key]
484
- constraints.each do |cb_name, constraints|
531
+ VERSION_CONSTRAINTS.each do |dependency_type, hash_key|
532
+ if dependency_group = o[hash_key]
533
+ dependency_group.each do |cb_name, constraints|
485
534
  metadata.send(method_name, cb_name, *Array(constraints))
486
535
  end
487
536
  end
@@ -496,6 +545,12 @@ class Chef
496
545
 
497
546
  private
498
547
 
548
+ def run_validation
549
+ if name.nil?
550
+ @errors = ["The `name' attribute is required in cookbook metadata"]
551
+ end
552
+ end
553
+
499
554
  def new_args_format(caller_name, dep_name, version_constraints)
500
555
  if version_constraints.empty?
501
556
  ">= 0.0.0"
@@ -533,11 +588,6 @@ INVALID
533
588
  raise Exceptions::InvalidVersionConstraint, msg
534
589
  end
535
590
 
536
- def normalize_version_constraint(caller_name, dep_name, constraint_str)
537
- version_constraint = validate_version_constraint(caller_name, dep_name, constraint_str)
538
- "#{version_constraint.op} #{version_constraint.raw_version}"
539
- end
540
-
541
591
  # Verify that the given array is an array of strings
542
592
  #
543
593
  # Raise an exception if the members of the array are not Strings
@@ -656,6 +706,5 @@ INVALID
656
706
  end
657
707
  end
658
708
 
659
-
660
709
  end
661
710
  end
@@ -125,7 +125,7 @@ class Chef
125
125
  end
126
126
 
127
127
  def template_files
128
- remove_ignored_files Dir[File.join(cookbook_path, '**', '*.erb')]
128
+ remove_ignored_files Dir[File.join(cookbook_path, '**/templates/**', '*.erb')]
129
129
  end
130
130
 
131
131
  def untested_template_files
@@ -50,6 +50,9 @@ class Chef
50
50
  repo_path = File.expand_path(repo_path)
51
51
  end
52
52
 
53
+ @preloaded_cookbooks = false
54
+ @loaders_by_name = {}
55
+
53
56
  # Used to track which cookbooks appear in multiple places in the cookbook repos
54
57
  # and are merged in to a single cookbook by file shadowing. This behavior is
55
58
  # deprecated, so users of this class may issue warnings to the user by checking
@@ -64,25 +67,25 @@ class Chef
64
67
  end
65
68
 
66
69
  def load_cookbooks
67
- @repo_paths.each do |repo_path|
68
- Dir[File.join(repo_path, "*")].each do |cookbook_path|
69
- load_cookbook(File.basename(cookbook_path), [repo_path])
70
- end
70
+ preload_cookbooks
71
+ @loaders_by_name.each do |cookbook_name, _loaders|
72
+ load_cookbook(cookbook_name)
71
73
  end
72
74
  @cookbooks_by_name
73
75
  end
74
76
 
75
- def load_cookbook(cookbook_name, repo_paths=nil)
76
- repo_paths ||= @repo_paths
77
- repo_paths.each do |repo_path|
78
- @chefignores[repo_path] ||= Cookbook::Chefignore.new(repo_path)
79
- cookbook_path = File.join(repo_path, cookbook_name.to_s)
80
- next unless File.directory?(cookbook_path) and Dir[File.join(repo_path, "*")].include?(cookbook_path)
81
- loader = Cookbook::CookbookVersionLoader.new(cookbook_path, @chefignores[repo_path])
82
- loader.load_cookbooks
77
+ def load_cookbook(cookbook_name)
78
+ preload_cookbooks
79
+
80
+ return nil unless @loaders_by_name.key?(cookbook_name.to_s)
81
+
82
+ cookbook_loaders_for(cookbook_name).each do |loader|
83
+ loader.load
84
+
83
85
  next if loader.empty?
84
- cookbook_name = loader.cookbook_name
85
- @cookbooks_paths[cookbook_name] << cookbook_path # for deprecation warnings
86
+
87
+ @cookbooks_paths[cookbook_name] << loader.cookbook_path # for deprecation warnings
88
+
86
89
  if @loaded_cookbooks.key?(cookbook_name)
87
90
  @merged_cookbooks << cookbook_name # for deprecation warnings
88
91
  @loaded_cookbooks[cookbook_name].merge!(loader)
@@ -130,5 +133,50 @@ class Chef
130
133
  end
131
134
  alias :cookbooks :values
132
135
 
136
+ private
137
+
138
+ def preload_cookbooks
139
+ return false if @preloaded_cookbooks
140
+
141
+ all_directories_in_repo_paths.each do |cookbook_path|
142
+ preload_cookbook(cookbook_path)
143
+ end
144
+ @preloaded_cookbooks = true
145
+ true
146
+ end
147
+
148
+ def preload_cookbook(cookbook_path)
149
+ repo_path = File.dirname(cookbook_path)
150
+ @chefignores[repo_path] ||= Cookbook::Chefignore.new(repo_path)
151
+ loader = Cookbook::CookbookVersionLoader.new(cookbook_path, @chefignores[repo_path])
152
+ add_cookbook_loader(loader)
153
+ end
154
+
155
+ def all_directories_in_repo_paths
156
+ @all_directories_in_repo_paths ||=
157
+ all_files_in_repo_paths.select { |path| File.directory?(path) }
158
+ end
159
+
160
+ def all_files_in_repo_paths
161
+ @all_files_in_repo_paths ||=
162
+ begin
163
+ @repo_paths.inject([]) do |all_children, repo_path|
164
+ all_children += Dir[File.join(repo_path, "*")]
165
+ end
166
+ end
167
+ end
168
+
169
+ def add_cookbook_loader(loader)
170
+ cookbook_name = loader.cookbook_name
171
+
172
+ @loaders_by_name[cookbook_name.to_s] ||= []
173
+ @loaders_by_name[cookbook_name.to_s] << loader
174
+ loader
175
+ end
176
+
177
+ def cookbook_loaders_for(cookbook_name)
178
+ @loaders_by_name[cookbook_name.to_s]
179
+ end
180
+
133
181
  end
134
182
  end
@@ -143,7 +143,7 @@ class Chef
143
143
  http = Net::HTTP.new(url.host, url.port)
144
144
  if url.scheme == "https"
145
145
  http.use_ssl = true
146
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
146
+ http.verify_mode = verify_mode
147
147
  end
148
148
  res = http.request(req)
149
149
  #res = http.start {|http_proc| http_proc.request(req) }
@@ -165,6 +165,17 @@ class Chef
165
165
  res
166
166
  end
167
167
 
168
+ private
169
+
170
+ def verify_mode
171
+ verify_mode = Chef::Config[:ssl_verify_mode]
172
+ if verify_mode == :verify_none
173
+ OpenSSL::SSL::VERIFY_NONE
174
+ elsif verify_mode == :verify_peer
175
+ OpenSSL::SSL::VERIFY_PEER
176
+ end
177
+ end
178
+
168
179
  end
169
180
 
170
181
  class StreamPart
@@ -51,10 +51,14 @@ class Chef
51
51
  attr_accessor :provider_filenames
52
52
  attr_accessor :root_filenames
53
53
  attr_accessor :name
54
- attr_accessor :metadata
55
54
  attr_accessor :metadata_filenames
56
55
  attr_accessor :status
57
56
 
57
+ # A Chef::Cookbook::Metadata object. It has a setter that fixes up the
58
+ # metadata to add descriptions of the recipes contained in this
59
+ # CookbookVersion.
60
+ attr_reader :metadata
61
+
58
62
  # attribute_filenames also has a setter that has non-default
59
63
  # functionality.
60
64
  attr_reader :attribute_filenames
@@ -195,6 +199,12 @@ class Chef
195
199
  attribute_filenames
196
200
  end
197
201
 
202
+ def metadata=(metadata)
203
+ @metadata = metadata
204
+ @metadata.recipes_from_cookbook_version(self)
205
+ @metadata
206
+ end
207
+
198
208
  ## BACKCOMPAT/DEPRECATED - Remove these and fix breakage before release [DAN - 5/20/2010]##
199
209
  alias :attribute_files :attribute_filenames
200
210
  alias :attribute_files= :attribute_filenames=
@@ -405,7 +415,6 @@ class Chef
405
415
  records_by_pref[best_pref]
406
416
  end
407
417
 
408
-
409
418
  # Given a node, segment and path (filename or directory name),
410
419
  # return the priority-ordered list of preference locations to
411
420
  # look.
@@ -458,9 +467,9 @@ class Chef
458
467
  end
459
468
 
460
469
  def to_json(*a)
461
- result = self.to_hash
470
+ result = to_hash
462
471
  result['json_class'] = self.class.name
463
- result.to_json(*a)
472
+ Chef::JSONCompat.to_json(result, *a)
464
473
  end
465
474
 
466
475
  def self.json_create(o)