summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Doherty <cdoherty@chef.io>2015-12-10 13:44:52 -0800
committerChris Doherty <cdoherty@chef.io>2015-12-10 13:44:52 -0800
commite89295d77337e379c1a7017e2a1748803166b9ac (patch)
tree7850c94759ee47287d277b9c1cf806135c597535
parent845299d9577dd19857898a12832f4dd7a6a3d53f (diff)
downloadchef-zero-cd/cookbook_artifacts.tar.gz
Re-use CookbookVersionEndpoint's code for deleting files.cd/cookbook_artifacts
-rw-r--r--lib/chef_zero/endpoints/cookbook_artifacts_cookbook_identifier.rb10
-rw-r--r--lib/chef_zero/endpoints/cookbook_version_endpoint.rb8
2 files changed, 8 insertions, 10 deletions
diff --git a/lib/chef_zero/endpoints/cookbook_artifacts_cookbook_identifier.rb b/lib/chef_zero/endpoints/cookbook_artifacts_cookbook_identifier.rb
index cb6413e..4d22d08 100644
--- a/lib/chef_zero/endpoints/cookbook_artifacts_cookbook_identifier.rb
+++ b/lib/chef_zero/endpoints/cookbook_artifacts_cookbook_identifier.rb
@@ -2,7 +2,7 @@ require 'chef_zero/chef_data/data_normalizer'
module ChefZero
module Endpoints
- class CookbookArtifactsCookbookIdentifierEndpoint < RestBase
+ class CookbookArtifactsCookbookIdentifierEndpoint < ChefZero::Endpoints::CookbookVersionEndpoint
# these endpoints are almost, but not quite, not entirely unlike the corresponding /cookbooks endpoints.
# it could all be refactored for maximum reuse, but they're short REST methods with well-defined
# behavioral specs (pedant), so there's not a huge benefit.
@@ -27,14 +27,12 @@ module ChefZero
# DELETE /organizations/ORG/cookbook_artifacts/COOKBOOK/IDENTIFIER
def delete(request)
begin
- identified_cookbook_data = normalize(request, parse_json(get_data(request)))
+ doomed_cookbook_json = get_data(request)
+ identified_cookbook_data = normalize(request, parse_json(doomed_cookbook_json))
delete_data(request)
# go through the recipes and delete stuff in the file store.
- identified_cookbook_data["recipes"].each do |r|
- file_path = make_file_store_path(request.rest_path, r)
- delete_data(request, file_path)
- end
+ hoover_unused_checksums(get_checksums(doomed_cookbook_json), request, 'cookbook_artifacts')
# if this was the last revision, delete the directory so future requests will 404, instead of
# returning 200 with an empty list.
diff --git a/lib/chef_zero/endpoints/cookbook_version_endpoint.rb b/lib/chef_zero/endpoints/cookbook_version_endpoint.rb
index 8dad508..e78d44c 100644
--- a/lib/chef_zero/endpoints/cookbook_version_endpoint.rb
+++ b/lib/chef_zero/endpoints/cookbook_version_endpoint.rb
@@ -85,10 +85,10 @@ module ChefZero
private
- def hoover_unused_checksums(deleted_checksums, request)
- data_store.list(request.rest_path[0..1] + ['cookbooks']).each do |cookbook_name|
- data_store.list(request.rest_path[0..1] + ['cookbooks', cookbook_name]).each do |version|
- cookbook = data_store.get(request.rest_path[0..1] + ['cookbooks', cookbook_name, version], request)
+ def hoover_unused_checksums(deleted_checksums, request, data_type='cookbooks')
+ data_store.list(request.rest_path[0..1] + [data_type]).each do |cookbook_name|
+ data_store.list(request.rest_path[0..1] + [data_type, cookbook_name]).each do |version|
+ cookbook = data_store.get(request.rest_path[0..1] + [data_type, cookbook_name, version], request)
deleted_checksums = deleted_checksums - get_checksums(cookbook)
end
end