File tree Expand file tree Collapse file tree
chef-server-api/app/controllers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -40,6 +40,16 @@ def index
4040 end
4141
4242 def show
43+ begin
44+ cookbook = Chef ::Cookbook . cdb_load ( params [ :id ] , params [ :version ] )
45+ rescue Chef ::Exceptions ::CouchDBNotFound => e
46+ raise NotFound , "Cannot find a cookbook named #{ params [ :id ] } with version #{ params [ :version ] } "
47+ end
48+ cookbook . generate_manifest { |opts | absolute_slice_url ( :cookbook_segment , opts ) }
49+ display cookbook
50+ end
51+
52+ def show_versions
4353 begin
4454 cookbook = Chef ::Cookbook . cdb_load ( params [ :id ] , params [ :version ] )
4555 rescue ArgumentError => e
@@ -211,14 +221,13 @@ def update
211221 end
212222
213223 def destroy
214- cookbook_name = params [ :id ]
215- cookbook_path = cookbook_location ( cookbook_name )
216- raise NotFound , "Cannot find cookbook named #{ cookbook_name } " unless File . directory? cookbook_path
217-
218- FileUtils . rm_rf ( cookbook_path )
219- FileUtils . rm_f ( cookbook_tarball_location ( cookbook_name ) )
224+ begin
225+ cookbook = Chef ::Cookbook . cdb_load ( params [ :id ] , params [ :version ] )
226+ rescue ArgumentError => e
227+ raise NotFound , "Cannot find a cookbook named #{ params [ :id ] } with version #{ params [ :version ] } "
228+ end
220229
221- display Hash . new
230+ display cookbook . cdb_destroy
222231 end
223232
224233end
Original file line number Diff line number Diff line change @@ -307,7 +307,8 @@ def self.json_create(o)
307307 o . delete ( "_id" )
308308 end
309309 cookbook . manifest = o
310- cookbook . metadata = o [ "metadata" ]
310+ # We want the Chef::Cookbook::Metadata object to always be inflated
311+ cookbook . metadata = Chef ::Cookbook ::Metadata . from_hash ( o [ "metadata" ] )
311312 cookbook . version = o [ "version" ]
312313 cookbook
313314 end
Original file line number Diff line number Diff line change @@ -22,11 +22,11 @@ class Chef
2222 class Knife
2323 class CookbookDelete < Knife
2424
25- banner "Sub-Command: cookbook delete COOKBOOK (options)"
25+ banner "Sub-Command: cookbook delete COOKBOOK VERSION (options)"
2626
27- def run
28- delete_object ( Chef ::Cookbook , @name_args [ 0 ] , "cookbook" ) do
29- rest . delete_rest ( "cookbooks/#{ @name_args [ 0 ] } " )
27+ def run
28+ delete_object ( Chef ::Cookbook , " #{ @name_args [ 0 ] } #{ @name_args [ 1 ] } " , "cookbook" ) do
29+ rest . delete_rest ( "cookbooks/#{ @name_args [ 0 ] } / #{ @name_args [ 1 ] } " )
3030 end
3131 end
3232
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ class Chef
2424 class Knife
2525 class CookbookShow < Knife
2626
27- banner "Sub-Command: cookbook show COOKBOOK [PART] [FILENAME] (options)"
27+ banner "Sub-Command: cookbook show COOKBOOK [VERSION] [ PART] [FILENAME] (options)"
2828
2929 option :fqdn ,
3030 :short => "-f FQDN" ,
@@ -43,17 +43,20 @@ class CookbookShow < Knife
4343
4444 def run
4545 case @name_args . length
46- when 3 # We are showing a specific file
46+ when 4 # We are showing a specific file
4747 arguments = { :id => @name_args [ 2 ] }
4848 arguments [ :fqdn ] = config [ :fqdn ] if config . has_key? ( :fqdn )
4949 arguments [ :platform ] = config [ :platform ] if config . has_key? ( :platform )
5050 arguments [ :version ] = config [ :platform_version ] if config . has_key? ( :platform_version )
5151 result = rest . get_rest ( "cookbooks/#{ @name_args [ 0 ] } /#{ @name_args [ 1 ] } ?#{ make_query_params ( arguments ) } " )
5252 pretty_print ( result )
53- when 2 # We are showing a specific part of the cookbook
53+ when 3 # We are showing a specific part of the cookbook
5454 result = rest . get_rest ( "cookbooks/#{ @name_args [ 0 ] } " )
5555 output ( result [ @name_args [ 1 ] ] )
56- when 1 # We are showing the whole cookbook data
56+ when 2 # We are showing the whole cookbook data
57+ cookbook_version = @name_args [ 1 ] == 'latest' ? '_latest' : @name_args [ 1 ]
58+ output ( rest . get_rest ( "cookbooks/#{ @name_args [ 0 ] } /#{ cookbook_version } " ) )
59+ when 1 # We are showing the cookbook versions
5760 output ( rest . get_rest ( "cookbooks/#{ @name_args [ 0 ] } " ) )
5861 end
5962 end
You can’t perform that action at this time.
0 commit comments