summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2016-01-15 13:31:52 -0800
committerJohn Keiser <john@johnkeiser.com>2016-01-15 13:31:52 -0800
commit6123100d8a93ee9fad8c3b0530065e9bb376dcef (patch)
tree0de45647345c47f4ccc97865a34c342895459c34
parent0fdffc7918d944a0d58362ee70eef85bc1ab59da (diff)
parentd1a451d5dc4d564e14706a759cd0416d3678e4a7 (diff)
downloadchef-zero-6123100d8a93ee9fad8c3b0530065e9bb376dcef.tar.gz
Merge branch 'jk/cookbook-artifacts-hoover'
-rw-r--r--lib/chef_zero/endpoints/cookbook_artifact_endpoint.rb (renamed from lib/chef_zero/endpoints/cookbook_artifacts_cookbook_endpoint.rb)2
-rw-r--r--lib/chef_zero/endpoints/cookbook_artifact_identifier_endpoint.rb (renamed from lib/chef_zero/endpoints/cookbook_artifacts_cookbook_identifier.rb)11
-rw-r--r--lib/chef_zero/endpoints/cookbook_version_endpoint.rb23
-rw-r--r--lib/chef_zero/server.rb8
4 files changed, 27 insertions, 17 deletions
diff --git a/lib/chef_zero/endpoints/cookbook_artifacts_cookbook_endpoint.rb b/lib/chef_zero/endpoints/cookbook_artifact_endpoint.rb
index 841f0c9..e17fea2 100644
--- a/lib/chef_zero/endpoints/cookbook_artifacts_cookbook_endpoint.rb
+++ b/lib/chef_zero/endpoints/cookbook_artifact_endpoint.rb
@@ -2,7 +2,7 @@ require 'chef_zero/chef_data/data_normalizer'
module ChefZero
module Endpoints
- class CookbookArtifactsCookbookEndpoint < RestBase
+ class CookbookArtifactEndpoint < RestBase
# GET /organizations/ORG/cookbook_artifacts/COOKBOOK
def get(request)
cookbook_name = request.rest_path.last
diff --git a/lib/chef_zero/endpoints/cookbook_artifacts_cookbook_identifier.rb b/lib/chef_zero/endpoints/cookbook_artifact_identifier_endpoint.rb
index 4d22d08..b70e2c4 100644
--- a/lib/chef_zero/endpoints/cookbook_artifacts_cookbook_identifier.rb
+++ b/lib/chef_zero/endpoints/cookbook_artifact_identifier_endpoint.rb
@@ -2,7 +2,7 @@ require 'chef_zero/chef_data/data_normalizer'
module ChefZero
module Endpoints
- class CookbookArtifactsCookbookIdentifierEndpoint < ChefZero::Endpoints::CookbookVersionEndpoint
+ class CookbookArtifactIdentifierEndpoint < 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.
@@ -32,13 +32,14 @@ module ChefZero
delete_data(request)
# go through the recipes and delete stuff in the file store.
- hoover_unused_checksums(get_checksums(doomed_cookbook_json), request, 'cookbook_artifacts')
+ hoover_unused_checksums(get_checksums(doomed_cookbook_json), request)
# if this was the last revision, delete the directory so future requests will 404, instead of
# returning 200 with an empty list.
- artifact_path = request.rest_path[0..-2]
- if list_data(request, artifact_path).size == 0
- delete_data_dir(request, artifact_path)
+ # Last one out turns out the lights: delete /organizations/ORG/cookbooks/COOKBOOK if it no longer has versions
+ cookbook_path = request.rest_path[0..3]
+ if exists_data_dir?(request, cookbook_path) && list_data(request, cookbook_path).size == 0
+ delete_data_dir(request, cookbook_path)
end
json_response(200, identified_cookbook_data)
diff --git a/lib/chef_zero/endpoints/cookbook_version_endpoint.rb b/lib/chef_zero/endpoints/cookbook_version_endpoint.rb
index e78d44c..5502ba0 100644
--- a/lib/chef_zero/endpoints/cookbook_version_endpoint.rb
+++ b/lib/chef_zero/endpoints/cookbook_version_endpoint.rb
@@ -58,8 +58,8 @@ module ChefZero
deleted_cookbook = get_data(request)
response = super(request)
- cookbook_name = request.rest_path[3]
- cookbook_path = request.rest_path[0..1] + ['cookbooks', cookbook_name]
+ # Last one out turns out the lights: delete /organizations/ORG/cookbooks/NAME if it no longer has versions
+ cookbook_path = request.rest_path[0..3]
if exists_data_dir?(request, cookbook_path) && list_data(request, cookbook_path).size == 0
delete_data_dir(request, cookbook_path)
end
@@ -85,11 +85,20 @@ module ChefZero
private
- 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)
+ def hoover_unused_checksums(deleted_checksums, request)
+ %w(cookbooks cookbook_artifacts).each do |cookbook_type|
+ begin
+ cookbooks = data_store.list(request.rest_path[0..1] + [cookbook_type])
+ rescue ChefZero::DataStore::DataNotFoundError
+ # Not all chef versions support cookbook_artifacts
+ raise unless cookbook_type == "cookbook_artifacts"
+ cookbooks = []
+ end
+ cookbooks.each do |cookbook_name|
+ data_store.list(request.rest_path[0..1] + [cookbook_type, cookbook_name]).each do |version|
+ cookbook = data_store.get(request.rest_path[0..1] + [cookbook_type, cookbook_name, version], request)
+ deleted_checksums = deleted_checksums - get_checksums(cookbook)
+ end
end
end
deleted_checksums.each do |checksum|
diff --git a/lib/chef_zero/server.rb b/lib/chef_zero/server.rb
index 3326420..df97c88 100644
--- a/lib/chef_zero/server.rb
+++ b/lib/chef_zero/server.rb
@@ -45,9 +45,9 @@ 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/cookbook_artifact_endpoint'
+require 'chef_zero/endpoints/cookbook_artifact_identifier_endpoint'
require 'chef_zero/endpoints/containers_endpoint'
require 'chef_zero/endpoints/container_endpoint'
require 'chef_zero/endpoints/dummy_endpoint'
@@ -567,8 +567,8 @@ module ChefZero
[ "/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/*/cookbook_artifacts/*", CookbookArtifactEndpoint.new(self) ],
+ [ "/organizations/*/cookbook_artifacts/*/*", CookbookArtifactIdentifierEndpoint.new(self) ],
[ "/organizations/*/data", DataBagsEndpoint.new(self) ],
[ "/organizations/*/data/*", DataBagEndpoint.new(self) ],
[ "/organizations/*/data/*/*", DataBagItemEndpoint.new(self) ],