diff options
author | Nuo Yan <nuo@opscode.com> | 2011-02-08 17:28:24 -0800 |
---|---|---|
committer | Nuo Yan <nuo@opscode.com> | 2011-02-08 17:28:24 -0800 |
commit | 005d8e77e18235a5500808137250b32b481b3364 (patch) | |
tree | a93b25a764116de2e59062859dc949dce87f5ff1 /chef-server-api/app | |
parent | 52fba378d0d8f02d38bdec1aea1df6d5f47fc374 (diff) | |
download | chef-005d8e77e18235a5500808137250b32b481b3364.tar.gz |
CHEF-2028 API change on /cookbooks and /environments/:env_id/cookbooks
Diffstat (limited to 'chef-server-api/app')
-rw-r--r-- | chef-server-api/app/controllers/cookbooks.rb | 14 | ||||
-rw-r--r-- | chef-server-api/app/controllers/environments.rb | 16 |
2 files changed, 20 insertions, 10 deletions
diff --git a/chef-server-api/app/controllers/cookbooks.rb b/chef-server-api/app/controllers/cookbooks.rb index 47e53738aa..cdfeb6a6ab 100644 --- a/chef-server-api/app/controllers/cookbooks.rb +++ b/chef-server-api/app/controllers/cookbooks.rb @@ -39,11 +39,19 @@ class Cookbooks < Application include Chef::Mixin::Checksum include Merb::TarballHelper + # returns data in the format of: + # {"apache2" => { + # :url => "http://url", + # :versions => [{:url => "http://url/1.0.0", :version => "1.0.0"}, {:url => "http://url/0.0.1", :version=>"0.0.1"}] + # } + # } def index - cookbook_list = Chef::CookbookVersion.cdb_list_latest.keys.sort + cookbook_list = Chef::CookbookVersion.cdb_list + # cookbook_list is in the format of {"apache2" => ["0.0.1", "0.0.0"]} + num_versions = params[:num_versions].nil? || params[:num_versions].empty? || params[:num_versions].to_i < 0 ? "1" : params[:num_versions] response = Hash.new - cookbook_list.map! do |cookbook_name| - response[cookbook_name] = absolute_url(:cookbook, :cookbook_name => cookbook_name) + cookbook_list.each do |k, v| + response[k] = {:url=>absolute_url(:cookbook, :cookbook_name => k), :versions => v.inject([]){ |r,val| r.push({:url => absolute_url(:cookbook_version, :cookbook_name => k, :cookbook_version => val), :version => val}) if num_versions.to_i > r.size; r}} end display response end diff --git a/chef-server-api/app/controllers/environments.rb b/chef-server-api/app/controllers/environments.rb index 4941449173..c902d05360 100644 --- a/chef-server-api/app/controllers/environments.rb +++ b/chef-server-api/app/controllers/environments.rb @@ -87,19 +87,21 @@ class Environments < Application end # GET /environments/:environment_id/cookbooks + # returns data in the format of: + # {"apache2" => { + # :url => "http://url", + # :versions => [{:url => "http://url/1.0.0", :version => "1.0.0"}, {:url => "http://url/0.0.1", :version=>"0.0.1"}] + # } + # } def list_cookbooks begin filtered_cookbooks = Chef::Environment.cdb_load_filtered_cookbook_versions(params[:environment_id]) rescue Chef::Exceptions::CouchDBNotFound raise NotFound, "Cannot load environment #{params[:environment_id]}" end - + num_versions = params[:num_versions].nil? || params[:num_versions].empty? || params[:num_versions].to_i < 0 ? "1" : params[:num_versions] display(filtered_cookbooks.inject({}) {|res, (cookbook_name,versions)| - # TODO: - # For now, we are only displaying the last cookbook in the sorted list (the newest version). - # We should display every cookbook version that is available in a given environment - # [stephen 9/2/10] - res[cookbook_name] = absolute_url(:cookbook_version, :cookbook_name=>cookbook_name, :cookbook_version=>versions.last.version) + res[cookbook_name] = {:url => absolute_url(:cookbook, :cookbook_name => cookbook_name), :versions => versions.inject([]){|r, val| r.push({:url => absolute_url(:cookbook_version, :cookbook_name => cookbook_name, :cookbook_version => val.version), :version => val.version}) if num_versions.to_i > r.size; r}} res }) end @@ -114,7 +116,7 @@ class Environments < Application node_list = Chef::Node.cdb_list_by_environment(params[:environment_id]) display(node_list.inject({}) {|r,n| r[n] = absolute_url(:node, n); r}) end - + # GET /environments/:environment_id/roles/:role_id def role begin |