diff options
Diffstat (limited to 'lib/chef_zero')
-rw-r--r-- | lib/chef_zero/endpoints/cookbook_artifacts_cookbook_identifier.rb | 10 | ||||
-rw-r--r-- | lib/chef_zero/endpoints/cookbook_version_endpoint.rb | 8 |
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 |