app/controllers/cookbooks.rb in chef-server-api-0.9.0.a4 vs app/controllers/cookbooks.rb in chef-server-api-0.9.0.a6

- old
+ new

@@ -17,12 +17,12 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # -require 'chef' / 'cookbook_loader' -require 'chef' / 'cookbook' / 'metadata' +require 'chef/cookbook_loader' +require 'chef/cookbook/metadata' class Cookbooks < Application provides :json @@ -38,16 +38,36 @@ include Chef::Mixin::Checksum include Merb::TarballHelper def index - cookbook_list = Chef::CookbookVersion.cdb_list + cookbook_list = Chef::CookbookVersion.cdb_list_latest.keys.sort response = Hash.new - cookbook_list.each do |cookbook_name| - cookbook_name =~ /^(.+)-(\d+\.\d+\.\d+)$/ - response[$1] = absolute_url(:cookbook, :cookbook_name => $1) + cookbook_list.map! do |cookbook_name| + response[cookbook_name] = absolute_url(:cookbook, :cookbook_name => cookbook_name) end - display response + display response + end + + #FIXME: this is different from the rest of our API, but in a useful way... + def index_latest + cookbook_list = Chef::CookbookVersion.cdb_list_latest(true) + response = Hash.new + cookbook_list.map! do |cookbook_name, cookbook_version| + response[cookbook_name]={ :url=>absolute_url(:cookbook, :cookbook_name => cookbook_name, :cookbook_version => cookbook_version), + :cookbook_name => cookbook_name, :cookbook_version=>cookbook_version} + end + display response + end + + def index_recipes #FIXME: is this cool to do w/ access control on platform? + all_cookbooks = Array(Chef::CookbookVersion.cdb_list_latest(true)) + all_cookbooks.map! do |cookbook| + cookbook.manifest["recipes"].map { |r| "#{cookbook.name}::#{r['name']}" } + end + all_cookbooks.flatten! + all_cookbooks.sort! + display all_cookbooks end def show_versions versions = Chef::CookbookVersion.cdb_by_name(cookbook_name) raise NotFound, "Cannot find a cookbook named #{cookbook_name}" unless versions && versions.size > 0