summaryrefslogtreecommitdiff
path: root/chef-server-api/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'chef-server-api/app/controllers')
-rw-r--r--chef-server-api/app/controllers/application.rb137
-rw-r--r--chef-server-api/app/controllers/clients.rb118
-rw-r--r--chef-server-api/app/controllers/cookbooks.rb231
-rw-r--r--chef-server-api/app/controllers/data_bags.rb75
-rw-r--r--chef-server-api/app/controllers/data_item.rb108
-rw-r--r--chef-server-api/app/controllers/environments.rb207
-rw-r--r--chef-server-api/app/controllers/exceptions.rb40
-rw-r--r--chef-server-api/app/controllers/main.rb25
-rw-r--r--chef-server-api/app/controllers/nodes.rb115
-rw-r--r--chef-server-api/app/controllers/roles.rb91
-rw-r--r--chef-server-api/app/controllers/sandboxes.rb161
-rw-r--r--chef-server-api/app/controllers/search.rb58
-rw-r--r--chef-server-api/app/controllers/users.rb78
13 files changed, 0 insertions, 1444 deletions
diff --git a/chef-server-api/app/controllers/application.rb b/chef-server-api/app/controllers/application.rb
deleted file mode 100644
index 66e3d760a2..0000000000
--- a/chef-server-api/app/controllers/application.rb
+++ /dev/null
@@ -1,137 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Author:: Christopher Brown (<cb@opscode.com>)
-# Author:: Christopher Walters (<cw@opscode.com>)
-# Author:: Tim Hinderliter (<tim@opscode.com>)
-# Copyright:: Copyright (c) 2008-2010 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# 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/mixin/checksum"
-require "chef/cookbook_loader"
-require "mixlib/authentication/signatureverification"
-require 'chef/json_compat'
-
-class Application < Merb::Controller
-
- include Chef::Mixin::Checksum
-
- def authenticate_every
- begin
- # Raises an error if required auth headers are missing
- authenticator = Mixlib::Authentication::SignatureVerification.new(request)
-
- username = authenticator.user_id
- Chef::Log.info("Authenticating client #{username}")
-
- user = Chef::ApiClient.cdb_load(username)
- user_key = OpenSSL::PKey::RSA.new(user.public_key)
- Chef::Log.debug "Authenticating Client:\n #{user.inspect}\n"
-
- # Store this for later..
- @auth_user = user
- authenticator.authenticate_request(user_key)
- rescue Mixlib::Authentication::MissingAuthenticationHeader => e
- Chef::Log.debug "Authentication failed: #{e.class.name}: #{e.message}\n#{e.backtrace.join("\n")}"
- raise BadRequest, "#{e.class.name}: #{e.message}"
- rescue StandardError => se
- Chef::Log.debug "Authentication failed: #{se}, #{se.backtrace.join("\n")}"
- raise Unauthorized, "Failed to authenticate. Ensure that your client key is valid."
- end
-
- unless authenticator.valid_request?
- if authenticator.valid_timestamp?
- raise Unauthorized, "Failed to authenticate. Ensure that your client key is valid."
- else
- raise Unauthorized, "Failed to authenticate. Please synchronize the clock on your client"
- end
- end
- true
- end
-
- def is_admin
- if @auth_user.admin
- true
- else
- raise Forbidden, "You are not allowed to take this action."
- end
- end
-
- def is_admin_or_validator
- if @auth_user.admin || @auth_user.name == Chef::Config[:validation_client_name]
- true
- else
- raise Forbidden, "You are not allowed to take this action."
- end
- end
-
- def admin_or_requesting_node
- if @auth_user.admin || @auth_user.name == params[:id]
- true
- else
- raise Forbidden, "You are not the correct node (auth_user name: #{@auth_user.name}, params[:id]: #{params[:id]}), or are not an API administrator (admin: #{@auth_user.admin})."
- end
- end
-
- # Store the URI of the current request in the session.
- #
- # We can return to this location by calling #redirect_back_or_default.
- def store_location
- session[:return_to] = request.uri
- end
-
- # Redirect to the URI stored by the most recent store_location call or
- # to the passed default.
- def redirect_back_or_default(default)
- loc = session[:return_to] || default
- session[:return_to] = nil
- redirect loc
- end
-
- def access_denied
- raise Unauthorized, "You must authenticate first!"
- end
-
- def get_available_recipes
- all_cookbooks_list = Chef::CookbookVersion.cdb_list(true)
- available_recipes = all_cookbooks_list.sort{ |a,b| a.name.to_s <=> b.name.to_s }.inject([]) do |result, element|
- element.recipes.sort.each do |r|
- if r =~ /^(.+)::default$/
- result << $1
- else
- result << r
- end
- end
- result
- end
- available_recipes
- end
-
- # Fix CHEF-1292/PL-538; cause Merb to pass the max nesting constant into
- # obj.to_json, which it calls by default based on the original request's
- # accept headers and the type passed into Merb::Controller.display
- #--
- # TODO: tim, 2010-11-24: would be nice to instead have Merb call
- # Chef::JSONCompat.to_json, instead of obj.to_json, but changing that
- # behavior is convoluted in Merb. This override is assuming that
- # Merb is eventually calling obj.to_json, which takes the :max_nesting
- # option.
- override! :display
- def display(obj)
- super(obj, nil, {:max_nesting => Chef::JSONCompat::JSON_MAX_NESTING})
- end
-
-end
-
diff --git a/chef-server-api/app/controllers/clients.rb b/chef-server-api/app/controllers/clients.rb
deleted file mode 100644
index eafeb15c36..0000000000
--- a/chef-server-api/app/controllers/clients.rb
+++ /dev/null
@@ -1,118 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Author:: Nuo Yan (<nuo@opscode.com>)
-# Copyright:: Copyright (c) 2008 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# 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/api_client'
-
-class Clients < Application
- provides :json
-
- before :authenticate_every
- before :is_admin, :only => [ :index, :update ]
- before :is_admin_or_validator, :only => [ :create ]
- before :admin_or_requesting_node, :only => [ :show, :destroy ]
-
- # GET /clients
- def index
- @list = Chef::ApiClient.cdb_list(true)
- display(@list.inject({}) { |result, element| result[element.name] = absolute_url(:client, :id => element.name); result })
- end
-
- # GET /clients/:id
- def show
- begin
- @client = Chef::ApiClient.cdb_load(params[:id])
- rescue Chef::Exceptions::CouchDBNotFound => e
- raise NotFound, "Cannot load client #{params[:id]}"
- end
- #display({ :name => @client.name, :admin => @client.admin, :public_key => @client.public_key })
- display @client
- end
-
- # POST /clients
- def create
- exists = true
- if params.has_key?(:inflated_object)
- params[:name] ||= params[:inflated_object].name
- params[:admin] ||= params[:inflated_object].admin
- end
-
- # We can only create clients if we're the admin or the validator.
- # But only allow creating admin clients if we're already an admin.
- if params[:admin] == true && @auth_user.admin != true
- raise Forbidden, "You are not allowed to take this action."
- end
-
- begin
- Chef::ApiClient.cdb_load(params[:name])
- rescue Chef::Exceptions::CouchDBNotFound
- exists = false
- end
- raise Conflict, "Client already exists" if exists
-
- @client = Chef::ApiClient.new
- @client.name(params[:name])
- @client.admin(params[:admin]) if params[:admin]
- @client.create_keys
- @client.cdb_save
-
- self.status = 201
- headers['Location'] = absolute_url(:client, @client.name)
- display({ :uri => absolute_url(:client, @client.name), :private_key => @client.private_key })
- end
-
- # PUT /clients/:id
- def update
- if params.has_key?(:inflated_object)
- params[:private_key] ||= params[:inflated_object].private_key
- params[:admin] ||= params[:inflated_object].admin
- end
-
- begin
- @client = Chef::ApiClient.cdb_load(params[:id])
- rescue Chef::Exceptions::CouchDBNotFound => e
- raise NotFound, "Cannot load client #{params[:id]}"
- end
-
- @client.admin(params[:admin]) unless params[:admin].nil?
-
- results = { :name => @client.name, :admin => @client.admin }
-
- if params[:private_key] == true
- @client.create_keys
- results[:private_key] = @client.private_key
- end
-
- @client.cdb_save
-
- display(results)
- end
-
- # DELETE /clients/:id
- def destroy
- begin
- @client = Chef::ApiClient.cdb_load(params[:id])
- rescue Chef::Exceptions::CouchDBNotFound => e
- raise NotFound, "Cannot load client #{params[:id]}"
- end
- @client.cdb_destroy
- display({ :name => @client.name })
- end
-
-end
-
diff --git a/chef-server-api/app/controllers/cookbooks.rb b/chef-server-api/app/controllers/cookbooks.rb
deleted file mode 100644
index 7d4993d60a..0000000000
--- a/chef-server-api/app/controllers/cookbooks.rb
+++ /dev/null
@@ -1,231 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Author:: Christopher Brown (<cb@opscode.com>)
-# Author:: Christopher Walters (<cw@opscode.com>)
-# Author:: Tim Hinderliter (<tim@opscode.com>)
-# Copyright:: Copyright (c) 2008, 2009, 2010 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# 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'
-
-class Cookbooks < Application
-
- include Merb::CookbookVersionHelper
-
- provides :json
-
- before :authenticate_every
- before :params_helper
- before :is_admin, :only => [ :update, :destroy ]
-
- attr_accessor :cookbook_name, :cookbook_version
-
- def params_helper
- self.cookbook_name = params[:cookbook_name]
- self.cookbook_version = params[:cookbook_version]
- end
-
- include Chef::Mixin::Checksum
- include Merb::TarballHelper
-
- def index
- if request.env['HTTP_X_CHEF_VERSION'] =~ /0\.9/
- index_09
- else
- index_010
- end
- end
-
- # GET /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 index_010
- cookbook_list = Chef::CookbookVersion.cdb_list
- # cookbook_list is in the format of {"apache2" => [0.0.1, 0.0.0]} where the version numbers are DepSelector::Version objects
- num_versions = num_versions!
- display(cookbook_list.inject({}) {|res, (cookbook_name, versions)|
- versions = versions.map{ |x| DepSelector::Version.new(x) }.sort.reverse.map{ |x| x.to_s }
- res[cookbook_name] = expand_cookbook_urls(cookbook_name, versions, num_versions)
- res
- })
- end
-
- # GET /cookbooks
- #
- # returns data in the format of:
- # {
- # "apache2" => "http://url/apache2",
- # "python" => "http://url/python"
- # }
- def index_09
- cookbook_list = Chef::CookbookVersion.cdb_list_latest(false).keys.sort
- response = Hash.new
- cookbook_list.map! do |cookbook_name|
- response[cookbook_name] = absolute_url(:cookbook, :cookbook_name => cookbook_name)
- end
- display response
- end
-
- def index_recipes
- recipes_with_versions = Chef::CookbookVersion.cdb_list(true).inject({}) do|memo, f|
- memo[f.name] ||= {}
- memo[f.name][f.version] = f.recipe_filenames_by_name.keys
- memo
- end
- display recipes_with_versions
- end
-
- def show_versions
- if request.env['HTTP_X_CHEF_VERSION'] =~ /0\.9/
- show_versions_09
- else
- show_versions_010
- end
- end
-
- # GET /cookbooks/:cookbook_name
- #
- # 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 show_versions_010
- versions = Chef::CookbookVersion.cdb_by_name(cookbook_name)
- raise NotFound, "Cannot find a cookbook named #{cookbook_name}" unless versions && versions.size > 0
- num_versions = num_versions!("all")
- cb_versions = versions[cookbook_name].map{ |x| DepSelector::Version.new(x) }.sort.reverse.map{ |x| x.to_s }
- display({ cookbook_name => expand_cookbook_urls(cookbook_name, cb_versions, num_versions) })
- end
-
- # GET /cookbooks/:cookbook_name
- #
- # returns data in the format of:
- # {"apache2" => ["1.0.0", "0.0.1"]}
- def show_versions_09
- versions = Chef::CookbookVersion.cdb_by_name(cookbook_name)
- raise NotFound, "Cannot find a cookbook named #{requested_cookbook_name}" unless versions && versions.size > 0
-
- display versions
- end
-
- def show
- cookbook = get_cookbook_version(cookbook_name, cookbook_version)
- display cookbook.generate_manifest_with_urls { |opts| absolute_url(:cookbook_file, opts) }
- end
-
- def show_file
- cookbook = get_cookbook_version(cookbook_name, cookbook_version)
-
- checksum = params[:checksum]
- raise NotFound, "Cookbook #{cookbook_name} version #{cookbook_version} does not contain a file with checksum #{checksum}" unless cookbook.checksums.keys.include?(checksum)
-
- begin
- filename = Chef::Checksum.new(checksum).storage.file_location
-
- send_file(filename)
- rescue Errno::ENOENT => e
- raise InternalServerError, "File with checksum #{checksum} not found in the repository (this should not happen)"
- end
- end
-
- def update
- raise(BadRequest, "You didn't pass me a valid object!") unless params.has_key?('inflated_object')
- raise(BadRequest, "You didn't pass me a Chef::CookbookVersion object!") unless params['inflated_object'].kind_of?(Chef::CookbookVersion)
- unless params["inflated_object"].name == cookbook_name
- raise(BadRequest, "You said the cookbook was named #{params['inflated_object'].name}, but the URL says it should be #{cookbook_name}.")
- end
-
- unless params["inflated_object"].version == cookbook_version
- raise(BadRequest, "You said the cookbook was version #{params['inflated_object'].version}, but the URL says it should be #{cookbook_version}.")
- end
-
- begin
- cookbook = Chef::CookbookVersion.cdb_load(cookbook_name, cookbook_version)
- cookbook.manifest = params['inflated_object'].manifest
- new_cookbook = false
- rescue Chef::Exceptions::CouchDBNotFound => e
- Chef::Log.debug("Cookbook #{cookbook_name} version #{cookbook_version} does not exist")
- cookbook = params['inflated_object']
- new_cookbook = true
- end
-
- unless new_cookbook
- if cookbook.frozen_version? && params[:force].nil?
- raise Conflict, "The cookbook #{cookbook.name} at version #{cookbook.version} is frozen. Use the 'force' option to override."
- end
- end
-
- cookbook.freeze_version if params["inflated_object"].frozen_version?
-
- # ensure that all checksums referred to by the manifest have been uploaded.
- Chef::CookbookVersion::COOKBOOK_SEGMENTS.each do |segment|
- next unless cookbook.manifest[segment]
- cookbook.manifest[segment].each do |manifest_record|
- checksum = manifest_record[:checksum]
- path = manifest_record[:path]
-
- begin
- checksum_obj = Chef::Checksum.cdb_load(checksum)
- rescue Chef::Exceptions::CouchDBNotFound => cdbx
- checksum_obj = nil
- end
-
- raise BadRequest, "Manifest has checksum #{checksum} (path #{path}) but it hasn't yet been uploaded" unless checksum_obj
- end
- end
-
- raise InternalServerError, "Error saving cookbook" unless cookbook.cdb_save
-
- display cookbook
- end
-
- def destroy
- begin
- cookbook = get_cookbook_version(cookbook_name, cookbook_version)
- rescue ArgumentError => e
- raise NotFound, "Cannot find a cookbook named #{cookbook_name} with version #{cookbook_version}"
- end
-
- if params["purge"] == "true"
- display cookbook.purge
- else
- display cookbook.cdb_destroy
- end
- end
-
- private
-
- def get_cookbook_version(name, version)
- Chef::CookbookVersion.cdb_load(name, version)
- rescue Chef::Exceptions::CouchDBNotFound => e
- raise NotFound, "Cannot find a cookbook named #{name} with version #{version}"
- rescue Net::HTTPServerException => e
- if e.to_s =~ /^404/
- raise NotFound, "Cannot find a cookbook named #{name} with version #{version}"
- else
- raise
- end
- end
-
-end
-
diff --git a/chef-server-api/app/controllers/data_bags.rb b/chef-server-api/app/controllers/data_bags.rb
deleted file mode 100644
index 8a4a8e015a..0000000000
--- a/chef-server-api/app/controllers/data_bags.rb
+++ /dev/null
@@ -1,75 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Author:: Christopher Brown (<cb@opscode.com>)
-# Copyright:: Copyright (c) 2008 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# 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/data_bag'
-
-class DataBags < Application
-
- provides :json
-
- before :authenticate_every
- before :is_admin, :only => [ :create, :destroy ]
-
- def index
- @bag_list = Chef::DataBag.cdb_list(false)
- display(@bag_list.inject({}) { |r,b| r[b] = absolute_url(:datum, :id => b); r })
-
- end
-
- def show
- begin
- @data_bag = Chef::DataBag.cdb_load(params[:id])
- rescue Chef::Exceptions::CouchDBNotFound => e
- raise NotFound, "Cannot load data bag #{params[:id]}"
- end
- display(@data_bag.list.inject({}) { |res, i| res[i] = absolute_url(:data_bag_item, :data_bag_id => @data_bag.name, :id => i); res })
- end
-
- def create
- @data_bag = nil
- if params.has_key?("inflated_object")
- @data_bag = params["inflated_object"]
- else
- @data_bag = Chef::DataBag.new
- @data_bag.name(params["name"])
- end
- exists = true
- begin
- Chef::DataBag.cdb_load(@data_bag.name)
- rescue Chef::Exceptions::CouchDBNotFound
- exists = false
- end
- raise Conflict, "Data bag already exists" if exists
- self.status = 201
- @data_bag.cdb_save
- display({ :uri => absolute_url(:datum, :id => @data_bag.name) })
- end
-
- def destroy
- begin
- @data_bag = Chef::DataBag.cdb_load(params[:id])
- rescue Chef::Exceptions::CouchDBNotFound => e
- raise NotFound, "Cannot load data bag #{params[:id]}"
- end
- @data_bag.cdb_destroy
- @data_bag.couchdb_rev = nil
- display @data_bag
- end
-
-end
diff --git a/chef-server-api/app/controllers/data_item.rb b/chef-server-api/app/controllers/data_item.rb
deleted file mode 100644
index f88a2507e8..0000000000
--- a/chef-server-api/app/controllers/data_item.rb
+++ /dev/null
@@ -1,108 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Author:: Christopher Brown (<cb@opscode.com>)
-# Author:: Nuo Yan (<nuo@opscode.com>)
-# Copyright:: Copyright (c) 2008 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# 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/data_bag'
-require 'chef/data_bag_item'
-
-class DataItem < Application
-
- provides :json
-
- before :populate_data_bag
- before :authenticate_every
- before :is_admin, :only => [ :create, :update, :destroy ]
-
- def populate_data_bag
- begin
- @data_bag = Chef::DataBag.cdb_load(params[:data_bag_id])
- rescue Chef::Exceptions::CouchDBNotFound => e
- raise NotFound, "Cannot load data bag #{params[:data_bag_id]}"
- end
- end
-
- def show
- begin
- @data_bag_item = Chef::DataBagItem.cdb_load(params[:data_bag_id], params[:id])
- rescue Chef::Exceptions::CouchDBNotFound => e
- raise NotFound, "Cannot load data bag #{params[:data_bag_id]} item #{params[:id]}"
- end
- display @data_bag_item.raw_data
- end
-
- def create
- raw_data = nil
- if params.has_key?("inflated_object")
- raw_data = params["inflated_object"].raw_data
- else
- raw_data = params
- raw_data.delete(:action)
- raw_data.delete(:controller)
- raw_data.delete(:data_bag_id)
- end
- @data_bag_item = nil
- begin
- @data_bag_item = Chef::DataBagItem.cdb_load(@data_bag.name, params[:id])
- rescue Chef::Exceptions::CouchDBNotFound
- @data_bag_item = Chef::DataBagItem.new
- @data_bag_item.data_bag(@data_bag.name)
- else
- raise Conflict, "Databag Item #{params[:id]} already exists" if @data_bag_item
- end
- @data_bag_item.raw_data = raw_data
- @data_bag_item.cdb_save
- display @data_bag_item.raw_data
- end
-
- def update
- raw_data = nil
- if params.has_key?("inflated_object")
- raw_data = params["inflated_object"].raw_data
- else
- raw_data = params
- raw_data.delete(:action)
- raw_data.delete(:controller)
- raw_data.delete(:data_bag_id)
- end
-
- begin
- @data_bag_item = Chef::DataBagItem.cdb_load(@data_bag.name, params[:id])
- rescue Chef::Exceptions::CouchDBNotFound => e
- raise NotFound, "Cannot load Databag Item #{params[:id]}"
- end
-
- @data_bag_item.raw_data = raw_data
- @data_bag_item.cdb_save
- display @data_bag_item.raw_data
-
- end
-
-
- def destroy
- begin
- @data_bag_item = Chef::DataBagItem.cdb_load(params[:data_bag_id], params[:id])
- rescue Chef::Exceptions::CouchDBNotFound => e
- raise NotFound, "Cannot load data bag #{params[:data_bag_id]} item #{params[:id]}"
- end
- @data_bag_item.cdb_destroy
- @data_bag_item.couchdb_rev = nil
- display @data_bag_item
- end
-
-end
diff --git a/chef-server-api/app/controllers/environments.rb b/chef-server-api/app/controllers/environments.rb
deleted file mode 100644
index d5e20171fe..0000000000
--- a/chef-server-api/app/controllers/environments.rb
+++ /dev/null
@@ -1,207 +0,0 @@
-#
-# Author:: Stephen Delano (<stephen@opscode.com>)
-# 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");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# 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/environment'
-require 'chef/cookbook_version_selector'
-
-class Environments < Application
-
- include Merb::CookbookVersionHelper
-
- provides :json
-
- before :authenticate_every
- before :is_admin, :only => [ :create, :update, :destroy ]
-
- # GET /environments
- def index
- environment_list = Chef::Environment.cdb_list(true)
- display(environment_list.inject({}) { |res, env| res[env.name] = absolute_url(:environment, env.name); res })
- end
-
- # GET /environments/:id
- def show
- begin
- environment = Chef::Environment.cdb_load(params[:id])
- rescue Chef::Exceptions::CouchDBNotFound => e
- raise NotFound, "Cannot load environment #{params[:id]}"
- end
- environment.couchdb_rev = nil
- display environment
- end
-
- # POST /environments
- def create
- env = params["inflated_object"]
- exists = true
- begin
- Chef::Environment.cdb_load(env.name)
- rescue Chef::Exceptions::CouchDBNotFound
- exists = false
- end
- raise Conflict, "Environment already exists" if exists
-
- env.cdb_save
- self.status = 201
- display({:uri => absolute_url(:environment, env.name)})
- end
-
- # PUT /environments/:id
- def update
- raise MethodNotAllowed if params[:id] == "_default"
- begin
- env = Chef::Environment.cdb_load(params[:id])
- rescue Chef::Exceptions::CouchDBNotFound
- raise NotFound, "Cannot load environment #{params[:id]}"
- end
-
- env.update_from!(params["inflated_object"])
- env.cdb_save
- env.couchdb_rev = nil
- self.status = 200
- display(env)
- end
-
- # DELETE /environments/:id
- def destroy
- raise MethodNotAllowed if params[:id] == "_default"
- begin
- env = Chef::Environment.cdb_load(params[:id])
- rescue Chef::Exceptions::CouchDBNotFound
- raise NotFound, "Cannot load environment #{params[:id]}"
- end
- env.cdb_destroy
- display(env)
- 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 = num_versions!
- display(filtered_cookbooks.inject({}) {|res, (cookbook_name,versions)|
- versions.map!{|v| v.version.to_s}
- res[cookbook_name] = expand_cookbook_urls(cookbook_name, versions, num_versions)
- res
- })
- end
-
- # GET /environments/:environment_id/cookbooks/:cookbook_id
- # 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 cookbook
- cookbook_name = params[:cookbook_id]
- 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
- raise NotFound, "Cannot load cookbook #{cookbook_name}" unless filtered_cookbooks.has_key?(cookbook_name)
- versions = filtered_cookbooks[cookbook_name].map{|v| v.version.to_s}
- num_versions = num_versions!("all")
- display({ cookbook_name => expand_cookbook_urls(cookbook_name, versions, num_versions) })
- end
-
- # GET /environments/:environment/recipes
- def list_recipes
- display(Chef::Environment.cdb_load_filtered_recipe_list(params[:environment_id]))
- end
-
- # GET /environments/:environment_id/nodes
- def list_nodes
- 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
- role = Chef::Role.cdb_load(params[:role_id])
- rescue Chef::Exceptions::CouchDBNotFound
- raise NotFound, "Cannot load role #{params[:role_id]}"
- end
- display("run_list" => role.env_run_lists[params[:environment_id]])
- end
-
- # POST /environments/: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 cookbook manifest
- #
- # 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 = Chef::CookbookVersionSelector.expand_to_cookbook_versions(run_list, environment_input)
- rescue Chef::Exceptions::CouchDBNotFound
- raise NotFound, "Cannot load environment #{params[:environment_id]}"
- rescue Chef::Exceptions::CookbookVersionSelection::InvalidRunListItems => e
- raise PreconditionFailed, e.to_json
- rescue Chef::Exceptions::CookbookVersionSelection::UnsatisfiableRunListItem => e
- raise PreconditionFailed, e.to_json
- end
-
- # Convert from
- # name => CookbookVersion
- # to
- # name => cookbook manifest
- # and display.
- display(names_to_cookbook_version.inject({}) do |res, (cookbook_name, cookbook_version)|
- res[cookbook_name] = cookbook_version.generate_manifest_with_urls {|opts| absolute_url(:cookbook_file, opts) }
- res
- end)
- end
-end
diff --git a/chef-server-api/app/controllers/exceptions.rb b/chef-server-api/app/controllers/exceptions.rb
deleted file mode 100644
index db1acdb167..0000000000
--- a/chef-server-api/app/controllers/exceptions.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Author:: Christopher Brown (<cb@opscode.com>)
-# Copyright:: Copyright (c) 2008 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# 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.
-#
-
-class Exceptions < Application
-
- provides :json
-
- def not_acceptable
- if request.accept =~ /application\/json/
- display({ "error" => request.exceptions })
- else
- render
- end
- end
-
- def standard_error
- if request.accept =~ /application\/json/
- display({ "error" => request.exceptions })
- else
- raise request.exceptions.first
- end
- end
-
-end
diff --git a/chef-server-api/app/controllers/main.rb b/chef-server-api/app/controllers/main.rb
deleted file mode 100644
index 2c5158fc21..0000000000
--- a/chef-server-api/app/controllers/main.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-class Main < Application
-
- provides :html, :json
-
- def index
- case content_type
- when :json
- display absolute_url(:nodes) => "Manage Nodes",
- absolute_url(:roles) => "Manage Roles",
- absolute_url(:cookbooks) => "Manage Cookbooks",
- absolute_url(:data) => "Manage Data Bags",
- absolute_url(:search) => "Search"
- else
- @webui_url = if Chef::Config[:chef_webui_url]
- Chef::Config[:chef_webui_url]
- elsif request.host =~ /(.*):4000/
- absolute_url(:top, :host => "#{$1}:4040")
- else
- nil
- end
- render
- end
- end
-
-end
diff --git a/chef-server-api/app/controllers/nodes.rb b/chef-server-api/app/controllers/nodes.rb
deleted file mode 100644
index 72564f02fe..0000000000
--- a/chef-server-api/app/controllers/nodes.rb
+++ /dev/null
@@ -1,115 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Author:: Christopher Brown (<cb@opscode.com>)
-# Copyright:: Copyright (c) 2008 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# 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/node'
-require 'chef/version_class'
-require 'chef/version_constraint'
-require 'chef/cookbook_version_selector'
-
-class Nodes < Application
-
- provides :json
-
- before :authenticate_every
- before :admin_or_requesting_node, :only => [ :update, :destroy, :cookbooks ]
-
- def index
- @node_list = Chef::Node.cdb_list
- display(@node_list.inject({}) do |r,n|
- r[n] = absolute_url(:node, n); r
- end)
- end
-
- def show
- begin
- @node = Chef::Node.cdb_load(params[:id])
- rescue Chef::Exceptions::CouchDBNotFound => e
- raise NotFound, "Cannot load node #{params[:id]}"
- end
- @node.couchdb_rev = nil
- display @node
- end
-
- def create
- @node = params["inflated_object"]
- begin
- Chef::Node.cdb_load(@node.name)
- raise Conflict, "Node already exists"
- rescue Chef::Exceptions::CouchDBNotFound
- end
- self.status = 201
- @node.cdb_save
- display({ :uri => absolute_url(:node, @node.name) })
- end
-
- def update
- begin
- @node = Chef::Node.cdb_load(params[:id])
- rescue Chef::Exceptions::CouchDBNotFound => e
- raise NotFound, "Cannot load node #{params[:id]}"
- end
-
- @node.update_from!(params['inflated_object'])
- @node.cdb_save
- @node.couchdb_rev = nil
- display(@node)
- end
-
- def destroy
- begin
- @node = Chef::Node.cdb_load(params[:id])
- rescue Chef::Exceptions::CouchDBNotFound => e
- raise NotFound, "Cannot load node #{params[:id]}"
- end
- @node.cdb_destroy
- @node.couchdb_rev = nil
- display @node
- end
-
- # Return a hash, cookbook_name => cookbook manifest, of the cookbooks
- # appropriate for this node, using its run_list and environment.
- def cookbooks
- begin
- @node = Chef::Node.cdb_load(params[:id])
- rescue Chef::Exceptions::CouchDBNotFound => e
- raise NotFound, "Cannot load node #{params[:id]}"
- end
-
- # Get the mapping of cookbook_name => CookbookVersion applicable to
- # this node's run_list and its environment.
- begin
- included_cookbooks = Chef::CookbookVersionSelector.expand_to_cookbook_versions(@node.run_list, @node.chef_environment)
- rescue Chef::Exceptions::CookbookVersionSelection::InvalidRunListItems => e
- raise PreconditionFailed, e.to_json
- rescue Chef::Exceptions::CookbookVersionSelection::UnsatisfiableRunListItem => e
- raise PreconditionFailed, e.to_json
- end
-
- # Convert from
- # name => CookbookVersion
- # to
- # name => cookbook manifest
- # and display.
- display(included_cookbooks.inject({}) do |acc, (cookbook_name, cookbook_version)|
- acc[cookbook_name.to_s] = cookbook_version.generate_manifest_with_urls{|opts| absolute_url(:cookbook_file, opts) }
- acc
- end)
- end
-
-end
diff --git a/chef-server-api/app/controllers/roles.rb b/chef-server-api/app/controllers/roles.rb
deleted file mode 100644
index 6dfe5ec03e..0000000000
--- a/chef-server-api/app/controllers/roles.rb
+++ /dev/null
@@ -1,91 +0,0 @@
-require 'chef/role'
-
-class Roles < Application
- provides :json
-
- before :authenticate_every
- before :is_admin, :only => [ :create, :update, :destroy ]
-
- # GET /roles
- def index
- @role_list = Chef::Role.cdb_list(true)
- display(@role_list.inject({}) { |r,role| r[role.name] = absolute_url(:role, role.name); r })
- end
-
- # GET /roles/:id
- def show
- begin
- @role = Chef::Role.cdb_load(params[:id])
- rescue Chef::Exceptions::CouchDBNotFound => e
- raise NotFound, "Cannot load role #{params[:id]}"
- end
- @role.couchdb_rev = nil
- display @role
- end
-
- # POST /roles
- def create
- @role = params["inflated_object"]
- exists = true
- begin
- Chef::Role.cdb_load(@role.name)
- rescue Chef::Exceptions::CouchDBNotFound
- exists = false
- end
- raise Conflict, "Role already exists" if exists
-
- @role.cdb_save
-
- self.status = 201
- display({ :uri => absolute_url(:role, :id => @role.name) })
- end
-
- # PUT /roles/:id
- def update
- begin
- @role = Chef::Role.cdb_load(params[:id])
- rescue Chef::Exceptions::CouchDBNotFound => e
- raise NotFound, "Cannot load role #{params[:id]}"
- end
-
- @role.update_from!(params["inflated_object"])
- @role.cdb_save
- self.status = 200
- @role.couchdb_rev = nil
- display(@role)
- end
-
- # DELETE /roles/:id
- def destroy
- begin
- @role = Chef::Role.cdb_load(params[:id])
- rescue Chef::Exceptions::CouchDBNotFound => e
- raise NotFound, "Cannot load role #{params[:id]}"
- end
- @role.cdb_destroy
- display @role
- end
-
- # GET /roles/:id/environments/:env_id
- def environment
- begin
- @role = Chef::Role.cdb_load(params[:role_id])
- rescue Chef::Exceptions::CouchDBNotFound => e
- raise NotFound, "Cannot load role #{params[:role_id]}"
- end
- display("run_list" => @role.env_run_lists[params[:env_id]])
- end
-
- # GET /roles/:id/environments
- def environments
- begin
- @role = Chef::Role.cdb_load(params[:role_id])
- rescue Chef::Exceptions::CouchDBNotFound => e
- raise NotFound, "Cannot load role #{params[:role_id]}"
- end
-
- display(@role.env_run_lists.keys.sort)
- end
-
-
-end
diff --git a/chef-server-api/app/controllers/sandboxes.rb b/chef-server-api/app/controllers/sandboxes.rb
deleted file mode 100644
index c1eb552b9c..0000000000
--- a/chef-server-api/app/controllers/sandboxes.rb
+++ /dev/null
@@ -1,161 +0,0 @@
-#
-# Author:: Tim Hinderliter (<tim@opscode.com>)
-# Copyright:: Copyright (c) 2010 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# 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/sandbox'
-require 'chef/checksum'
-
-# Sandboxes are used to upload files to the server (e.g., cookbook upload).
-class Sandboxes < Application
-
- provides :json
-
- before :authenticate_every
-
- include Chef::Mixin::Checksum
- include Merb::TarballHelper
-
- def index
- couch_sandbox_list = Chef::Sandbox::cdb_list(true)
-
- sandbox_list = Hash.new
- couch_sandbox_list.each do |sandbox|
- sandbox_list[sandbox.guid] = absolute_url(:sandbox, :sandbox_id => sandbox.guid)
- end
- display sandbox_list
- end
-
- def show
- begin
- sandbox = Chef::Sandbox.cdb_load(params[:sandbox_id])
- rescue Chef::Exceptions::CouchDBNotFound => e
- raise NotFound, "Cannot find a sandbox named #{params[:sandbox_id]}"
- end
-
- display sandbox
- end
-
- def create
- checksums = params[:checksums]
-
- raise BadRequest, "missing required parameter: checksums" unless checksums
- raise BadRequest, "required parameter checksums is not a hash: #{checksums.class.name}" unless checksums.is_a?(Hash)
-
- new_sandbox = Chef::Sandbox.new
- result_checksums = Hash.new
-
- all_existing_checksums = Chef::Checksum.cdb_all_checksums
- checksums.keys.each do |checksum|
- if all_existing_checksums[checksum]
- result_checksums[checksum] = {
- :needs_upload => false
- }
- else
- result_checksums[checksum] = {
- :url => absolute_url(:sandbox_checksum, :sandbox_id => new_sandbox.guid, :checksum => checksum),
- :needs_upload => true
- }
- new_sandbox.checksums << checksum
- end
- end
-
- FileUtils.mkdir_p(sandbox_location(new_sandbox.guid))
-
- new_sandbox.cdb_save
-
- # construct successful response
- self.status = 201
- location = absolute_url(:sandbox, :sandbox_id => new_sandbox.guid)
- headers['Location'] = location
- result = { 'uri' => location, 'checksums' => result_checksums, 'sandbox_id' => new_sandbox.guid }
- #result = { 'uri' => location }
-
- display result
- end
-
- def upload_checksum
- sandbox_file = ChefServerApi::SandboxFile.new(self.request.env["rack.input"], params)
- raise BadRequest, sandbox_file.error if sandbox_file.invalid_params?
- raise NotFound, sandbox_file.error if sandbox_file.invalid_sandbox?
- raise BadRequest, sandbox_file.error if sandbox_file.invalid_file?
-
- sandbox_file.commit_to(sandbox_checksum_location(sandbox_file.sandbox_id, sandbox_file.expected_checksum))
-
- url = absolute_url(:sandbox_checksum, sandbox_file.resource_params)
- result = { 'uri' => url }
- display result
- end
-
- def update
- # look up the sandbox by its guid
- existing_sandbox = Chef::Sandbox.cdb_load(params[:sandbox_id])
- raise NotFound, "cannot find sandbox with guid #{params[:sandbox_id]}" unless existing_sandbox
-
- if existing_sandbox.is_completed
- Chef::Log.warn("Sandbox finalization: #{params[:sandbox_id]} is already complete, ignoring")
- return display(existing_sandbox)
- end
-
- if params[:is_completed]
- existing_sandbox.is_completed = (params[:is_completed] == true)
-
- if existing_sandbox.is_completed
- # Check if files were uploaded to sandbox directory before we
- # commit the sandbox. Fail if any weren't.
- existing_sandbox.checksums.each do |checksum|
- checksum_filename = sandbox_checksum_location(existing_sandbox.guid, checksum)
- if !File.exists?(checksum_filename)
- raise BadRequest, "cannot update sandbox #{params[:sandbox_id]}: checksum #{checksum} was not uploaded"
- end
- end
-
- # If we've gotten here all the files have been uploaded.
- # Track the steps to undo everything we've done. If any steps fail,
- # we will undo the successful steps that came before it
- begin
- undo_steps = Array.new
- existing_sandbox.checksums.each do |file_checksum|
- checksum_filename_in_sandbox = sandbox_checksum_location(existing_sandbox.guid, file_checksum)
- checksum = Chef::Checksum.new(file_checksum)
-
- checksum.commit_sandbox_file(checksum_filename_in_sandbox)
-
- undo_steps << proc { checksum.revert_sandbox_file_commit }
- end
- rescue
- # undo the successful moves we did before
- Chef::Log.error("Sandbox finalization: got exception moving files, undoing previous changes: #{$!} -- #{$!.backtrace.join("\n")}")
- undo_steps.each do |undo_step|
- undo_step.call
- end
- raise
- end
-
- end
- end
-
- existing_sandbox.cdb_save
-
- display existing_sandbox
- end
-
- def destroy
- raise NotFound, "Destroy not implemented"
- end
-
-end
-
diff --git a/chef-server-api/app/controllers/search.rb b/chef-server-api/app/controllers/search.rb
deleted file mode 100644
index 77f83d0da0..0000000000
--- a/chef-server-api/app/controllers/search.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Author:: Christopher Brown (<cb@opscode.com>)
-# Copyright:: Copyright (c) 2008 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# 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/solr_query'
-
-class Search < Application
- provides :json
-
- before :authenticate_every
- before :is_admin, :only => [:reindex]
-
- def index
- indexes = valid_indexes
- display(indexes.inject({}) { |r,i| r[i] = absolute_url(:search_show, i); r })
- end
-
- def valid_indexes
- indexes = Chef::DataBag.cdb_list(false)
- indexes += %w{ role node client environment}
- end
-
- def show
- unless valid_indexes.include?(params[:id])
- raise NotFound, "I don't know how to search for #{params[:id]} data objects."
- end
- params[:type] = params.delete(:id)
- display(Chef::SolrQuery.from_params(params).search)
- rescue Chef::Exceptions::QueryParseError => e
- # we set status rather than raising BadRequest to avoid a
- # stacktrace in the server log
- self.status = 400
- e_msg = e.message.gsub(/\n/, " ")
- msg = "invalid search query: '#{params[:q]}' #{e_msg}"
- Chef::Log.warn("400 #{msg}")
- display({ "error" => [msg] })
- end
-
- def reindex
- display(Chef::SolrQuery.new.rebuild_index)
- end
-
-end
diff --git a/chef-server-api/app/controllers/users.rb b/chef-server-api/app/controllers/users.rb
deleted file mode 100644
index a336f04f03..0000000000
--- a/chef-server-api/app/controllers/users.rb
+++ /dev/null
@@ -1,78 +0,0 @@
-#
-# Author:: Nuo Yan (<nuo@opscode.com>)
-# Copyright:: Copyright (c) 2009 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# 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 File.join("chef", "webui_user")
-
-class Users < Application
- provides :json
-
- before :authenticate_every
- before :is_admin, :only => [ :create, :destroy, :update ]
-
- # GET to /users
- def index
- @user_list = Chef::WebUIUser.cdb_list
- display(@user_list.inject({}) { |r,n| r[n] = absolute_url(:user, n); r })
- end
-
- # GET to /users/:id
- def show
- begin
- @user = Chef::WebUIUser.cdb_load(params[:id])
- rescue Chef::Exceptions::CouchDBNotFound => e
- raise NotFound, "Cannot load user #{params[:id]}"
- end
- display @user
- end
-
- # PUT to /users/:id
- def update
- begin
- Chef::WebUIUser.cdb_load(params[:id])
- rescue Chef::Exceptions::CouchDBNotFound => e
- raise NotFound, "Cannot load user #{params[:id]}"
- end
- @user = params['inflated_object']
- @user.cdb_save
- display(@user)
- end
-
- # POST to /users
- def create
- @user = params["inflated_object"]
- begin
- Chef::WebUIUser.cdb_load(@user.name)
- rescue Chef::Exceptions::CouchDBNotFound
- @user.cdb_save
- self.status = 201
- else
- raise Conflict, "User already exists"
- end
- display({ :uri => absolute_url(:user, @user.name) })
- end
-
- def destroy
- begin
- @user = Chef::WebUIUser.cdb_load(params[:id])
- rescue Chef::Exceptions::CouchDBNotFound => e
- raise NotFound, "Cannot load user #{params[:id]}"
- end
- @user.cdb_destroy
- display @user
- end
-end