From 22d110d45d08a53dc3152679dab442b43158f7b4 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Sun, 7 May 2023 20:23:34 +0200 Subject: [PATCH] DeleteZone --- src/client/lib/dnsmanager-client.cr | 11 +++++++++-- src/client/main.cr | 2 +- src/storage.cr | 16 ++++++++++------ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/client/lib/dnsmanager-client.cr b/src/client/lib/dnsmanager-client.cr index e61e476..7c7d5a1 100644 --- a/src/client/lib/dnsmanager-client.cr +++ b/src/client/lib/dnsmanager-client.cr @@ -29,14 +29,21 @@ class DNSManager::Client < IPC def login(token : String) request = DNSManager::Request::Login.new token send_now request - parse_message [ DNSManager::Response::Success ], read + parse_message [ Response::Success ], read end # Adding a full zone. def user_zone_add(zone : DNSManager::Storage::Zone) request = DNSManager::Request::AddOrUpdateZone.new zone send_now request - parse_message [ DNSManager::Response::Success, DNSManager::Response::InvalidZone ], read + parse_message [ Response::Success ], read + end + + # Removing a zone. + def user_zone_del(domain : String) + request = DNSManager::Request::DeleteZone.new domain + send_now request + parse_message [ Response::Success ], read end # diff --git a/src/client/main.cr b/src/client/main.cr index e6d4d07..b0fac5f 100644 --- a/src/client/main.cr +++ b/src/client/main.cr @@ -85,7 +85,7 @@ class Actions domains.each do |domain| begin pp! domain - #pp! @dnsmanagerd.user_zone_del domain + pp! @dnsmanagerd.user_zone_del domain rescue e puts "error for user_zone_del: #{e.message}" end diff --git a/src/storage.cr b/src/storage.cr index 8df6312..b9e3b3e 100644 --- a/src/storage.cr +++ b/src/storage.cr @@ -102,15 +102,19 @@ class DNSManager::Storage # User must own the domain. unless user_data.domains.includes? domain - Baguette::Log.warning "user #{user_id} tries to delete domain #{domain} doesn't own it" + Baguette::Log.warning "user #{user_id} tries to delete domain #{domain} but doesn't own it" return Response::NoOwnership.new end - # TODO: remove this domain from the list of user's domains. - # TODO: remove the related zone. - #unless errors = Storage::Zone.is_domain_valid? domain - # return Response::InvalidZone.new errors - #end + # Remove this domain from the list of user's domains. + user_data.domains.delete domain + + # Update on-disk user data. + update_user_data user_data + + # Remove the related zone. + zones_by_domain.delete domain + Response::Success.new rescue e Baguette::Log.error "trying to delete a domain #{domain}: #{e}"