diff options
author | jkeiser <jkeiser@opscode.com> | 2012-12-19 23:22:54 -0800 |
---|---|---|
committer | jkeiser <jkeiser@opscode.com> | 2012-12-19 23:23:21 -0800 |
commit | 666374b272a8851a2c57530a71a6183d4d06a648 (patch) | |
tree | b53efd8134aa36ab0d459f3e4e87e1a6bbd1fe21 /lib/chef_zero/endpoints/data_bags_endpoint.rb | |
download | chef-zero-666374b272a8851a2c57530a71a6183d4d06a648.tar.gz |
Initial commit (moved/split up from jk/tiny-chef-server branch of jkeiser/chef)
Diffstat (limited to 'lib/chef_zero/endpoints/data_bags_endpoint.rb')
-rw-r--r-- | lib/chef_zero/endpoints/data_bags_endpoint.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/chef_zero/endpoints/data_bags_endpoint.rb b/lib/chef_zero/endpoints/data_bags_endpoint.rb new file mode 100644 index 0000000..8cf015b --- /dev/null +++ b/lib/chef_zero/endpoints/data_bags_endpoint.rb @@ -0,0 +1,21 @@ +require 'json' +require 'chef_zero/endpoints/rest_list_endpoint' + +module ChefZero + module Endpoints + # /data + class DataBagsEndpoint < RestListEndpoint + def post(request) + container = get_data(request) + contents = request.body + name = JSON.parse(contents, :create_additions => false)[identity_key] + if container[name] + error(409, "Object already exists") + else + container[name] = {} + json_response(201, {"uri" => "#{build_uri(request.base_uri, request.rest_path + [name])}"}) + end + end + end + end +end |