summaryrefslogtreecommitdiff
path: root/lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb')
-rw-r--r--lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb34
1 files changed, 34 insertions, 0 deletions
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..d9fdb20
--- /dev/null
+++ b/lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb
@@ -0,0 +1,34 @@
+require 'chef_zero/chef_data/data_normalizer'
+
+module ChefZero
+ module Endpoints
+ class CookbookArtifactsEndpoint < RestBase
+ # GET /organizations/ORG/cookbook_artifacts
+ def get(request)
+ data = {}
+
+ artifacts = begin
+ list_data(request)
+ rescue Exception => e
+ if e.response_code == 404
+ return already_json_response(200, "{}")
+ end
+ end
+
+ artifacts.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