diff options
Diffstat (limited to 'lib/chef_zero/endpoints/organization_endpoint.rb')
-rw-r--r-- | lib/chef_zero/endpoints/organization_endpoint.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/chef_zero/endpoints/organization_endpoint.rb b/lib/chef_zero/endpoints/organization_endpoint.rb index a5512db..c600f88 100644 --- a/lib/chef_zero/endpoints/organization_endpoint.rb +++ b/lib/chef_zero/endpoints/organization_endpoint.rb @@ -33,6 +33,9 @@ module ChefZero def delete(request) org = get_data(request, request.rest_path + [ 'org' ]) delete_data_dir(request, request.rest_path, :recursive) + + delete_validator_client!(request, request.rest_path[-1]) + already_json_response(200, populate_defaults(request, org)) end @@ -41,6 +44,30 @@ module ChefZero org = ChefData::DataNormalizer.normalize_organization(org, request.rest_path[1]) FFI_Yajl::Encoder.encode(org, :pretty => true) end + + private + + def validator_name(org_name) + "#{org_name}-validator" + end + + def delete_validator_client!(request, org_name) + client_path = [ *request.rest_path, 'clients', validator_name(org_name) ] + client_data = get_data(request, client_path, :nil) + + if client_data + delete_data(request, client_path, :data_store_exceptions) + end + + delete_validator_client_keys!(request, org_name) + rescue DataStore::DataNotFoundError + end + + def delete_validator_client_keys!(request, org_name) + keys_path = [ "client_keys", validator_name(org_name) ] + delete_data_dir(request, keys_path, :recursive, :data_store_exceptions) + rescue DataStore::DataNotFoundError + end end end end |