summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Doherty <cdoherty@chef.io>2015-12-08 15:52:12 -0800
committerChris Doherty <cdoherty@chef.io>2015-12-08 15:52:12 -0800
commit5302f698aa7ccf78d04660ea953237fd7444624e (patch)
tree5852495022a70e85167fbf1c4352bb79cfb0bc21
parent582f9ded02b928afade414749656ad2411e6d9fa (diff)
downloadchef-zero-5302f698aa7ccf78d04660ea953237fd7444624e.tar.gz
First stab at /cookbook_artifacts, passes create_spec only.
-rw-r--r--lib/chef_zero/endpoints/cookbook_artifacts_cookbook_endpoint.rb24
-rw-r--r--lib/chef_zero/endpoints/cookbook_artifacts_cookbook_identifier.rb35
-rw-r--r--lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb26
-rw-r--r--lib/chef_zero/server.rb8
4 files changed, 93 insertions, 0 deletions
diff --git a/lib/chef_zero/endpoints/cookbook_artifacts_cookbook_endpoint.rb b/lib/chef_zero/endpoints/cookbook_artifacts_cookbook_endpoint.rb
new file mode 100644
index 0000000..841f0c9
--- /dev/null
+++ b/lib/chef_zero/endpoints/cookbook_artifacts_cookbook_endpoint.rb
@@ -0,0 +1,24 @@
+require 'chef_zero/chef_data/data_normalizer'
+
+module ChefZero
+ module Endpoints
+ class CookbookArtifactsCookbookEndpoint < RestBase
+ # GET /organizations/ORG/cookbook_artifacts/COOKBOOK
+ def get(request)
+ cookbook_name = request.rest_path.last
+ cookbook_url = build_uri(request.base_uri, request.rest_path)
+ response_data = {}
+ versions = []
+
+ list_data(request).each do |identifier|
+ artifact_url = build_uri(request.base_uri, request.rest_path + [cookbook_name, identifier])
+ versions << { url: artifact_url, identifier: identifier }
+ end
+
+ response_data[cookbook_name] = { url: cookbook_url, versions: versions }
+
+ return json_response(200, response_data)
+ end
+ end
+ end
+end
diff --git a/lib/chef_zero/endpoints/cookbook_artifacts_cookbook_identifier.rb b/lib/chef_zero/endpoints/cookbook_artifacts_cookbook_identifier.rb
new file mode 100644
index 0000000..4bea4c1
--- /dev/null
+++ b/lib/chef_zero/endpoints/cookbook_artifacts_cookbook_identifier.rb
@@ -0,0 +1,35 @@
+require 'chef_zero/chef_data/data_normalizer'
+
+module ChefZero
+ module Endpoints
+ class CookbookArtifactsCookbookIdentifierEndpoint < RestBase
+ # GET /organizations/ORG/cookbook_artifacts/COOKBOOK/IDENTIFIER
+ def get(request)
+ cookbook_name, identifier = request.rest_path.last(2)
+
+ data = get_data(request)
+
+ return already_json_response(200, data)
+ end
+
+ # PUT /organizations/ORG/cookbook_artifacts/COOKBOOK/IDENTIFIER
+ def put(request)
+ cookbook_name, identifier = request.rest_path.last(2)
+
+ # pedant dictates that we not return the "json_class" element, so let's not store it.
+ identified_cookbook_json = to_json(parse_json(request.body).tap { |o| o.delete("json_class") })
+
+ set_data(request, nil, identified_cookbook_json, :create_dir)
+
+ return already_json_response(201, identified_cookbook_json)
+ end
+
+ # DELETE /organizations/ORG/cookbook_artifacts/COOKBOOK/IDENTIFIER
+ def delete(request)
+ delete_data(request)
+
+ return already_json_response(200, "{}")
+ end
+ end
+ end
+end
diff --git a/lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb b/lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb
new file mode 100644
index 0000000..c488f73
--- /dev/null
+++ b/lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb
@@ -0,0 +1,26 @@
+require 'chef_zero/chef_data/data_normalizer'
+
+module ChefZero
+ module Endpoints
+ class CookbookArtifactsEndpoint < RestBase
+ # GET /organizations/ORG/cookbook_artifacts
+ def get(request)
+ data = {}
+
+ list_data(request, request.rest_path).each do |cookbook_artifact|
+ cookbook_url = build_uri(request.base_uri, request.rest_path + [cookbook_artifact])
+
+ versions = []
+ list_data(request, request.rest_path + [cookbook_artifact]).each do |identifier|
+ artifact_url = build_uri(request.base_uri, request.rest_path + [cookbook_artifact, identifier])
+ versions << { url: artifact_url, identifier: identifier }
+ end
+
+ data[cookbook_artifact] = { url: cookbook_url, versions: versions }
+ end
+
+ return json_response(200, data)
+ end
+ end
+ end
+end
diff --git a/lib/chef_zero/server.rb b/lib/chef_zero/server.rb
index 2d84a52..2d25825 100644
--- a/lib/chef_zero/server.rb
+++ b/lib/chef_zero/server.rb
@@ -45,6 +45,11 @@ require 'chef_zero/endpoints/actor_endpoint'
require 'chef_zero/endpoints/cookbooks_endpoint'
require 'chef_zero/endpoints/cookbook_endpoint'
require 'chef_zero/endpoints/cookbook_version_endpoint'
+
+require 'chef_zero/endpoints/cookbook_artifacts_cookbook_endpoint'
+require 'chef_zero/endpoints/cookbook_artifacts_cookbook_identifier'
+require 'chef_zero/endpoints/cookbook_artifacts_endpoint'
+
require 'chef_zero/endpoints/containers_endpoint'
require 'chef_zero/endpoints/container_endpoint'
require 'chef_zero/endpoints/dummy_endpoint'
@@ -558,6 +563,9 @@ module ChefZero
[ "/organizations/*/cookbooks", CookbooksEndpoint.new(self) ],
[ "/organizations/*/cookbooks/*", CookbookEndpoint.new(self) ],
[ "/organizations/*/cookbooks/*/*", CookbookVersionEndpoint.new(self) ],
+ [ "/organizations/*/cookbook_artifacts", CookbookArtifactsEndpoint.new(self) ],
+ [ "/organizations/*/cookbook_artifacts/*", CookbookArtifactsCookbookEndpoint.new(self) ],
+ [ "/organizations/*/cookbook_artifacts/*/*", CookbookArtifactsCookbookIdentifierEndpoint.new(self) ],
[ "/organizations/*/data", DataBagsEndpoint.new(self) ],
[ "/organizations/*/data/*", DataBagEndpoint.new(self) ],
[ "/organizations/*/data/*/*", DataBagItemEndpoint.new(self) ],