diff options
author | Tim Hinderliter <tim@opscode.com> | 2011-03-07 09:27:49 -0800 |
---|---|---|
committer | Tim Hinderliter <tim@opscode.com> | 2011-03-17 16:58:04 -0700 |
commit | 6a39638c07e215f13f6a9a064fba8a0bedda5180 (patch) | |
tree | 0b1b2b1e2ac6613e6ba5716cb730133ea4a14e6f /chef-server-api/app | |
parent | 65ae97fab4193e7eb94473650585b1431a0cc5e7 (diff) | |
download | chef-6a39638c07e215f13f6a9a064fba8a0bedda5180.tar.gz |
added /environments/:env_id/cookbook_versions endpoint
* pass in a run_list and environment and get back the
cookbook versions after applying the environment's
version constraints
* RunList#expand_to_cookbook_versions is method used
to implement this
refactored RunList#expand and friends to require environment
argument instead of making it optional with default of '_default'
added RunList#
Diffstat (limited to 'chef-server-api/app')
-rw-r--r-- | chef-server-api/app/controllers/environments.rb | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/chef-server-api/app/controllers/environments.rb b/chef-server-api/app/controllers/environments.rb index d3d8a7da4d..baa7a74276 100644 --- a/chef-server-api/app/controllers/environments.rb +++ b/chef-server-api/app/controllers/environments.rb @@ -1,6 +1,7 @@ # # Author:: Stephen Delano (<stephen@opscode.com>) -# Copyright:: Copyright (c) 2010 Opscode, Inc. +# Author:: Tim Hinderliter (<tim@opscode.com>) +# Copyright:: Copyright (c) 2010, 2011 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -109,6 +110,71 @@ class Environments < Application }) end + # POST /environment/:environment_id/cookbook_versions + # + # Take the given run_list and return the versions of cookbooks that would + # be used after applying the constraints of the given environment. + # + # INPUT: + # :run_list = an Array of String's, e.g., + # ["recipe[apache2]", "recipe[runit]"] + # + # OUT: + # Hash of cookbook names to version/url hash, e.g., + # { + # "apache2": { + # "version": "1.2.3", + # "url" => "http://.../cookbooks/apache2/1.2.3" + # }, + # "runit": { + # "version": "2.3.4", + # "url" => "http://.../cookbooks/runit/2.3.4" + # } + # } + # + # NOTE: This method is a POST, not because it's a mutator (it's idempotent), + # but the run_list can likely exceed Merb's query string limit for GET + # of 1024 characters. + def cookbook_versions_for_run_list + begin + # not possible to be nil due to the route to get us to this API + # endpoint + environment_input = params[:environment_id] + + run_list_input = params[:run_list] + raise BadRequest, "Missing param: run_list" unless run_list_input + raise BadRequest, "Param run_list is not an Array: #{run_list_input.class}" unless run_list_input.is_a?(Array) + + # Convert the input array of strings to a RunList containing + # RunListItem's. + run_list = Chef::RunList.new + run_list_input.each do |run_list_item_string| + run_list << run_list_item_string + end + + # Expand the run list in the scope of the specified environment. + names_to_cookbook_version = run_list.expand_to_cookbook_versions(environment_input, 'couchdb') + rescue Chef::Exceptions::CouchDBNotFound + raise NotFound, "Cannot load environment #{params[:environment_id]}" + end + + # convert the hash which is + # name => CookbookVersion + # to + # name => {:version => version, :url => url} + names_to_url_and_version = names_to_cookbook_version.values.inject({}) do |res, cb_version| + name = cb_version.name + res[name] = { + :version => cb_version.version, + :url => absolute_url(:cookbook_version, :cookbook_name => name, :cookbook_version => cb_version.version) + } + res + end + + display(names_to_url_and_version) + end + + # GET /environments/:environment_id/cookbooks/:cookbook_id # returns data in the format of: # {"apache2" => { |