summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@getchef.com>2015-01-28 17:55:36 -0800
committerdanielsdeleo <dan@getchef.com>2015-01-28 17:58:01 -0800
commitff6c5d36be4f84bf284bcdb5470323b167d150a4 (patch)
tree4945de1eebf1e0f5db2d0392f5a409e379ce32b3
parentfef75d564476d868438ac80889a3bbc65de6d845 (diff)
downloadchef-zero-ff6c5d36be4f84bf284bcdb5470323b167d150a4.tar.gz
Check before create/update to determine correct status code
The memore store and ChefFS store have different behaviors when writing to an existing object, so work around that by checking for the existence of the item before creating/updating.
-rw-r--r--lib/chef_zero/endpoints/policies_endpoint.rb19
1 files changed, 9 insertions, 10 deletions
diff --git a/lib/chef_zero/endpoints/policies_endpoint.rb b/lib/chef_zero/endpoints/policies_endpoint.rb
index c115398..992d5ae 100644
--- a/lib/chef_zero/endpoints/policies_endpoint.rb
+++ b/lib/chef_zero/endpoints/policies_endpoint.rb
@@ -19,7 +19,15 @@ module ChefZero
error = validate(request)
return error if error
- code = create_or_update(request)
+ code =
+ if data_store.exists?(request.rest_path)
+ set_data(request, request.rest_path, request.body, :data_store_exceptions)
+ 200
+ else
+ name = request.rest_path[4]
+ data_store.create(request.rest_path[0..3], name, request.body, :create_dir)
+ 201
+ end
already_json_response(code, request.body)
end
@@ -29,15 +37,6 @@ module ChefZero
already_json_response(200, result)
end
- def create_or_update(request)
- set_data(request, request.rest_path, request.body, :data_store_exceptions)
- 200
- rescue ChefZero::DataStore::DataNotFoundError
- name = request.rest_path[4]
- data_store.create(request.rest_path[0..3], name, request.body, :create_dir)
- 201
- end
-
private
def validate(request)