@@ -41,13 +41,22 @@ def params_helper
4141 include Chef ::Mixin ::Checksum
4242 include Merb ::TarballHelper
4343
44+ def index
45+ if request . env [ 'HTTP_X_CHEF_VERSION' ] =~ /0\. 9/
46+ index_09
47+ else
48+ index_010
49+ end
50+ end
51+
52+ # GET /cookbooks
4453 # returns data in the format of:
4554 # {"apache2" => {
4655 # :url => "http://url",
4756 # :versions => [{:url => "http://url/1.0.0", :version => "1.0.0"}, {:url => "http://url/0.0.1", :version=>"0.0.1"}]
4857 # }
4958 # }
50- def index
59+ def index_010
5160 cookbook_list = Chef ::CookbookVersion . cdb_list
5261 # cookbook_list is in the format of {"apache2" => [0.0.1, 0.0.0]} where the version numbers are DepSelector::Version objects
5362 num_versions = num_versions!
@@ -58,6 +67,22 @@ def index
5867 } )
5968 end
6069
70+ # GET /cookbooks
71+ #
72+ # returns data in the format of:
73+ # {
74+ # "apache2" => "http://url/apache2",
75+ # "python" => "http://url/python"
76+ # }
77+ def index_09
78+ cookbook_list = Chef ::CookbookVersion . cdb_list_latest ( false ) . keys . sort
79+ response = Hash . new
80+ cookbook_list . map! do |cookbook_name |
81+ response [ cookbook_name ] = absolute_url ( :cookbook , :cookbook_name => cookbook_name )
82+ end
83+ display response
84+ end
85+
6186 def index_recipes
6287 recipes_with_versions = Chef ::CookbookVersion . cdb_list ( true ) . inject ( { } ) do |memo , f |
6388 memo [ f . name ] ||= { }
@@ -67,6 +92,14 @@ def index_recipes
6792 display recipes_with_versions
6893 end
6994
95+ def show_versions
96+ if request . env [ 'HTTP_X_CHEF_VERSION' ] =~ /0\. 9/
97+ show_versions_09
98+ else
99+ show_versions_010
100+ end
101+ end
102+
70103 # GET /cookbooks/:cookbook_name
71104 #
72105 # returns data in the format of:
@@ -75,14 +108,25 @@ def index_recipes
75108 # :versions => [{:url => "http://url/1.0.0", :version => "1.0.0"}, {:url => "http://url/0.0.1", :version=>"0.0.1"}]
76109 # }
77110 # }
78- def show_versions
111+ def show_versions_010
79112 versions = Chef ::CookbookVersion . cdb_by_name ( cookbook_name )
80113 raise NotFound , "Cannot find a cookbook named #{ cookbook_name } " unless versions && versions . size > 0
81114 num_versions = num_versions! ( "all" )
82115 cb_versions = versions [ cookbook_name ] . map { |x | DepSelector ::Version . new ( x ) } . sort . reverse . map { |x | x . to_s }
83116 display ( { cookbook_name => expand_cookbook_urls ( cookbook_name , cb_versions , num_versions ) } )
84117 end
85118
119+ # GET /cookbooks/:cookbook_name
120+ #
121+ # returns data in the format of:
122+ # {"apache2" => ["1.0.0", "0.0.1"]}
123+ def show_versions_09
124+ versions = Chef ::CookbookVersion . cdb_by_name ( cookbook_name )
125+ raise NotFound , "Cannot find a cookbook named #{ requested_cookbook_name } " unless versions && versions . size > 0
126+
127+ display versions
128+ end
129+
86130 def show
87131 cookbook = get_cookbook_version ( cookbook_name , cookbook_version )
88132 display cookbook . generate_manifest_with_urls { |opts | absolute_url ( :cookbook_file , opts ) }
@@ -119,6 +163,12 @@ def update
119163 cookbook = params [ 'inflated_object' ]
120164 end
121165
166+ if cookbook . frozen_version? && params [ :force ] . nil?
167+ raise Conflict , "The cookbook #{ cookbook . name } at version #{ cookbook . version } is frozen. Use the 'force' option to override."
168+ end
169+
170+ cookbook . freeze_version if params [ "inflated_object" ] . frozen_version?
171+
122172 # ensure that all checksums referred to by the manifest have been uploaded.
123173 Chef ::CookbookVersion ::COOKBOOK_SEGMENTS . each do |segment |
124174 next unless cookbook . manifest [ segment ]
0 commit comments