Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow knife to install cookbooks with metadata.json #2345

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/chef/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ class InvalidVersionConstraint < ArgumentError; end
class IllegalVersionConstraint < NotImplementedError; end

class MetadataNotValid < StandardError; end
class MetadataNotFound < StandardError
def initialize
super "No metadata.rb or metadata.json!"
end
end

# File operation attempted but no permissions to perform it
class InsufficientPermissions < RuntimeError; end
Expand Down
40 changes: 31 additions & 9 deletions lib/chef/knife/cookbook_site_install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,8 @@ def run
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
Expand Down Expand Up @@ -153,11 +150,36 @@ def clear_existing_files(cookbook_path)
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 Chef::Exceptions::MetadataNotFound
end
end
end
Expand Down