summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2014-08-20 20:45:14 -0700
committerJohn Keiser <jkeiser@opscode.com>2014-08-22 09:20:50 -0700
commit3372e864b4d705a4bbca3e52e7edea4656dd89ba (patch)
treec50891dd74b65979e114e2df921cbf24fb535f7f
parent9da161dbb67168da835c1a36263aac61b2512810 (diff)
downloadchef-zero-3372e864b4d705a4bbca3e52e7edea4656dd89ba.tar.gz
Get users endpoint passing oc-chef-pedant
-rw-r--r--lib/chef_zero/chef_data/default_creator.rb6
-rw-r--r--lib/chef_zero/endpoints/actor_endpoint.rb13
-rw-r--r--lib/chef_zero/endpoints/rest_object_endpoint.rb1
-rw-r--r--lib/chef_zero/endpoints/verify_password_endpoint.rb22
-rw-r--r--lib/chef_zero/rest_base.rb2
5 files changed, 36 insertions, 8 deletions
diff --git a/lib/chef_zero/chef_data/default_creator.rb b/lib/chef_zero/chef_data/default_creator.rb
index 555c520..0c82bf3 100644
--- a/lib/chef_zero/chef_data/default_creator.rb
+++ b/lib/chef_zero/chef_data/default_creator.rb
@@ -110,11 +110,7 @@ module ChefZero
[ 'containers', 'users' ]
when 'users'
- result = superusers
- data.list([ 'organizations' ]).each do |org|
- result += data.list([ 'organizations', org, 'users' ]).uniq
- end
- result
+ superusers
when 'organizations'
if path.size == 1
diff --git a/lib/chef_zero/endpoints/actor_endpoint.rb b/lib/chef_zero/endpoints/actor_endpoint.rb
index 4f213d3..ded6530 100644
--- a/lib/chef_zero/endpoints/actor_endpoint.rb
+++ b/lib/chef_zero/endpoints/actor_endpoint.rb
@@ -8,6 +8,19 @@ module ChefZero
# /organizations/ORG/users/NAME
# /users/NAME
class ActorEndpoint < RestObjectEndpoint
+ def delete(request)
+ result = super
+ if request.rest_path[0] == 'users'
+ list_data(request, [ 'organizations' ]).each do |org|
+ begin
+ delete_data(request, [ 'organizations', org, 'users', request.rest_path[1] ], :data_store_exceptions)
+ rescue DataStore::DataNotFoundError
+ end
+ end
+ end
+ result
+ end
+
def put(request)
# Find out if we're updating the public key.
request_body = JSON.parse(request.body, :create_additions => false)
diff --git a/lib/chef_zero/endpoints/rest_object_endpoint.rb b/lib/chef_zero/endpoints/rest_object_endpoint.rb
index 41cf3ed..4fb42e3 100644
--- a/lib/chef_zero/endpoints/rest_object_endpoint.rb
+++ b/lib/chef_zero/endpoints/rest_object_endpoint.rb
@@ -30,7 +30,6 @@ module ChefZero
begin
create_data(request, request.rest_path[0..-2], key, request.body, :data_store_exceptions)
rescue DataStore::DataAlreadyExistsError
- puts $!.backtrace.join("\n")
return error(409, "Cannot rename '#{request.rest_path[-1]}' to '#{key}': '#{key}' already exists")
end
delete_data(request)
diff --git a/lib/chef_zero/endpoints/verify_password_endpoint.rb b/lib/chef_zero/endpoints/verify_password_endpoint.rb
new file mode 100644
index 0000000..107870a
--- /dev/null
+++ b/lib/chef_zero/endpoints/verify_password_endpoint.rb
@@ -0,0 +1,22 @@
+require 'json'
+require 'chef_zero/rest_base'
+
+module ChefZero
+ module Endpoints
+ # /verify_password
+ class VerifyPasswordEndpoint < RestBase
+ def post(request)
+ request_json = JSON.parse(request.body, :create_additions => false)
+ name = request_json['user_id_to_verify']
+ password = request_json['password']
+ user = get_data(request, request.rest_path[0..-2] + ['users', name], :nil)
+ if !user
+ raise RestErrorResponse.new(403, "Nonexistent user")
+ end
+
+ user = JSON.parse(user, :create_additions => false)
+ json_response(200, { 'password_is_correct' => user['password'] == password })
+ end
+ end
+ end
+end
diff --git a/lib/chef_zero/rest_base.rb b/lib/chef_zero/rest_base.rb
index eabc07e..f64343b 100644
--- a/lib/chef_zero/rest_base.rb
+++ b/lib/chef_zero/rest_base.rb
@@ -136,7 +136,6 @@ module ChefZero
raise RestErrorResponse.new(404, "Parent not found: #{build_uri(request.base_uri, request.rest_path)}")
end
rescue DataStore::DataAlreadyExistsError
- puts $!.backtrace.join("\n")
if options.include?(:data_store_exceptions)
raise
else
@@ -156,7 +155,6 @@ module ChefZero
raise RestErrorResponse.new(404, "Parent not found: #{build_uri(request.base_uri, request.rest_path)}")
end
rescue DataStore::DataAlreadyExistsError
- puts $!.backtrace.join("\n")
if options.include?(:data_store_exceptions)
raise
else