summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Doherty <cdoherty@chef.io>2016-01-21 10:50:46 -0800
committerChris Doherty <cdoherty@chef.io>2016-01-21 15:52:48 -0800
commit0a7f183d534ecc998d4e886d06db9c472ab0b666 (patch)
tree9398c3df8af045985622a511a28e1b061c1ea1d5
parent180dc06ba3ae6f005854a75abe248971c22509b6 (diff)
downloadchef-zero-0a7f183d534ecc998d4e886d06db9c472ab0b666.tar.gz
Implement POST /containers to create a container with the given 'id' or 'container_name'.
-rw-r--r--lib/chef_zero/endpoints/containers_endpoint.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/chef_zero/endpoints/containers_endpoint.rb b/lib/chef_zero/endpoints/containers_endpoint.rb
index 3f7af87..931fe6c 100644
--- a/lib/chef_zero/endpoints/containers_endpoint.rb
+++ b/lib/chef_zero/endpoints/containers_endpoint.rb
@@ -8,6 +8,19 @@ module ChefZero
def initialize(server)
super(server, %w(id containername))
end
+
+ # create a container.
+ # input: {"containername"=>"new-container", "containerpath"=>"/"}
+ def post(request)
+ data = parse_json(request.body)
+ # if they don't match, id wins.
+ container_name = data["id"] || data["containername"]
+ container_path_suffix = data["containerpath"].split("/").reject { |o| o.empty? }
+ container_data_path = request.rest_path + container_path_suffix
+ create_data(request, container_data_path, container_name, to_json({}), :create_dir)
+
+ json_response(201, { uri: build_uri(request.base_uri, request.rest_path + container_path_suffix + [container_name]) })
+ end
end
end
end