summaryrefslogtreecommitdiff
path: root/lib/chef/knife
diff options
context:
space:
mode:
authorThom May <thom@chef.io>2016-05-16 16:30:51 +0100
committerThom May <thom@chef.io>2016-05-16 17:31:30 +0100
commit949c563287fd91dea15a01b3ddc8769aba7df966 (patch)
tree021cfe6c4f5cf731f8629959ce37da819984a40e /lib/chef/knife
parentfb6e8bdc38ab125c6806cbe8765a60140c5f6673 (diff)
downloadchef-949c563287fd91dea15a01b3ddc8769aba7df966.tar.gz
Load cookbook versions correctly for knifetm/fix_cb_show
Fixes #4934 Signed-off-by: Thom May <thom@may.lt>
Diffstat (limited to 'lib/chef/knife')
-rw-r--r--lib/chef/knife/cookbook_show.rb16
1 files changed, 6 insertions, 10 deletions
diff --git a/lib/chef/knife/cookbook_show.rb b/lib/chef/knife/cookbook_show.rb
index 5fab7c303f..a20e62ffc2 100644
--- a/lib/chef/knife/cookbook_show.rb
+++ b/lib/chef/knife/cookbook_show.rb
@@ -51,6 +51,10 @@ class Chef
:description => "Show corresponding URIs"
def run
+ cookbook_name, cookbook_version, segment, filename = @name_args
+
+ cookbook = Chef::CookbookVersion.load(cookbook_name, cookbook_version) unless cookbook_version.nil?
+
case @name_args.length
when 4 # We are showing a specific file
node = Hash.new
@@ -64,10 +68,6 @@ class Chef
end
end
- cookbook_name, segment, filename = @name_args[0], @name_args[2], @name_args[3]
- cookbook_version = @name_args[1] == "latest" ? "_latest" : @name_args[1]
-
- cookbook = rest.get("cookbooks/#{cookbook_name}/#{cookbook_version}")
manifest_entry = cookbook.preferred_manifest_record(node, segment, filename)
temp_file = rest.streaming_request(manifest_entry[:url])
@@ -76,14 +76,10 @@ class Chef
pretty_print(temp_file.read)
when 3 # We are showing a specific part of the cookbook
- cookbook_version = @name_args[1] == "latest" ? "_latest" : @name_args[1]
- result = rest.get("cookbooks/#{@name_args[0]}/#{cookbook_version}")
- output(result.manifest[@name_args[2]])
+ output(cookbook.manifest[segment])
when 2 # We are showing the whole cookbook data
- cookbook_version = @name_args[1] == "latest" ? "_latest" : @name_args[1]
- output(rest.get("cookbooks/#{@name_args[0]}/#{cookbook_version}"))
+ output(cookbook)
when 1 # We are showing the cookbook versions (all of them)
- cookbook_name = @name_args[0]
env = config[:environment]
api_endpoint = env ? "environments/#{env}/cookbooks/#{cookbook_name}" : "cookbooks/#{cookbook_name}"
output(format_cookbook_list_for_display(rest.get(api_endpoint)))