summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@getchef.com>2014-08-11 17:27:41 -0700
committerdanielsdeleo <dan@getchef.com>2014-08-12 11:03:10 -0700
commita0777738b985314d1f4abadde6f7c9687178d61f (patch)
tree10c49903939af55bab148b54b4e408316557ed6c
parentc44d8826ea6fca1f90fdcdb78a4094d300a9a943 (diff)
downloadchef-a0777738b985314d1f4abadde6f7c9687178d61f.tar.gz
Add a fallback for metadata name for the chef-zero case
-rw-r--r--lib/chef/cookbook/cookbook_version_loader.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/chef/cookbook/cookbook_version_loader.rb b/lib/chef/cookbook/cookbook_version_loader.rb
index bf52781916..ddbcb785dc 100644
--- a/lib/chef/cookbook/cookbook_version_loader.rb
+++ b/lib/chef/cookbook/cookbook_version_loader.rb
@@ -263,6 +263,15 @@ class Chef
begin
data = Chef::JSONCompat.from_json(IO.read(file), :create_additions => false)
@metadata.from_hash(data['metadata'])
+ # the JSON cookbok metadata file is only used by chef-zero.
+ # The Chef Server API currently does not enforce that the metadata
+ # have a `name` field, but that will cause an error when attempting
+ # to load the cookbook. To keep compatibility, we fake it by setting
+ # the metadata name from the cookbook version object's name.
+ #
+ # This behavior can be removed if/when Chef Server enforces that the
+ # metadata contains a name key.
+ @metadata.name(data['cookbook_name']) unless data['metadata'].key?('name')
rescue Chef::Exceptions::JSON::ParseError
Chef::Log.error("Couldn't parse cookbook metadata JSON for #@inferred_cookbook_name in " + file)
raise