summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSeth Vargo <sethvargo@gmail.com>2014-11-03 09:49:39 -0500
committerBryan McLellan <btm@loftninjas.org>2014-12-15 13:49:13 -0500
commitdccc5d1a61597e7e34ed367d191c45b70f9aa18f (patch)
tree5f27902f2cea374abdb54ff4e7b0c1c59d5c0b01 /lib
parent3f178af707ac7112428c0f7d5e84d09d018c28ae (diff)
downloadchef-dccc5d1a61597e7e34ed367d191c45b70f9aa18f.tar.gz
Allow knife to install cookbooks with metadata.json
Previously `knife cookbook site install` would only install cookbooks that have a metadata.rb. This has a number of problems, mainly that compiled metadata is supported elsewhere in Chef. This commit adds support for parsing the metadata.json, even though the metadata.rb is still preferred (since that's what the rest of Chef does).
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/knife/cookbook_site_install.rb40
1 files changed, 31 insertions, 9 deletions
diff --git a/lib/chef/knife/cookbook_site_install.rb b/lib/chef/knife/cookbook_site_install.rb
index 913d171b3c..865f806593 100644
--- a/lib/chef/knife/cookbook_site_install.rb
+++ b/lib/chef/knife/cookbook_site_install.rb
@@ -107,11 +107,8 @@ class Chef
end
end
-
unless config[:no_deps]
- md = Chef::Cookbook::Metadata.new
- md.from_file(File.join(@install_path, @cookbook_name, "metadata.rb"))
- md.dependencies.each do |cookbook, version_list|
+ preferred_metadata.dependencies.each do |cookbook, version_list|
# Doesn't do versions.. yet
nv = self.class.new
nv.config = config
@@ -153,11 +150,36 @@ class Chef
end
def convert_path(upstream_file)
- if ENV['MSYSTEM'] == 'MINGW32'
- return upstream_file.sub(/^([[:alpha:]]):/, '/\1')
- else
- return Shellwords.escape upstream_file
- end
+ if ENV['MSYSTEM'] == 'MINGW32'
+ return upstream_file.sub(/^([[:alpha:]]):/, '/\1')
+ else
+ return Shellwords.escape upstream_file
+ end
+ end
+
+ # Get the preferred metadata path on disk. Chef prefers the metadata.rb
+ # over the metadata.json.
+ #
+ # @raise if there is no metadata in the cookbook
+ #
+ # @return [Chef::Cookbok::Metadata]
+ def preferred_metadata
+ md = Chef::Cookbook::Metadata.new
+
+ rb = File.join(@install_path, @cookbook_name, "metadata.rb")
+ if File.exist?(rb)
+ md.from_file(rb)
+ return md
+ end
+
+ json = File.join(@install_path, @cookbook_name, "metadata.json")
+ if File.exist?(json)
+ json = IO.read(json)
+ md.from_json(json)
+ return md
+ end
+
+ raise "No metadata.rb or metadata.json!"
end
end
end