From bda2a08b4daf4960725b82cc867a3b40a1978385 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Sun, 7 May 2023 17:28:11 +0200 Subject: [PATCH] Can compile again. --- src/main.cr | 18 ++++++++---------- src/requests/admin.cr | 2 +- src/requests/zone.cr | 3 +++ src/storage.cr | 1 + 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main.cr b/src/main.cr index 495e534..b4b5754 100644 --- a/src/main.cr +++ b/src/main.cr @@ -69,22 +69,20 @@ class DNSManager::Service < IPC reqname = request.class.name.sub /^DNSManager::Request::/, "" Baguette::Log.debug "<< #{reqname}" - response = DNSManager::Response::Error.new "generic error" - - begin - response = request.handle self, event + response = begin + request.handle self, event rescue e : AuthorizationException Baguette::Log.error "#{reqname} authorization error" - response = DNSManager::Response::Error.new "authorization error" + Response::Error.new "authorization error" rescue e : AdminAuthorizationException Baguette::Log.error "#{reqname} no admin authorization" - response = DNSManager::Response::Error.new "admin authorization error" + Response::Error.new "admin authorization error" rescue e : NotLoggedException Baguette::Log.error "#{reqname} user not logged" - response = DNSManager::Response::Error.new "user not logged" - # Do not handle generic exception case: do not provide a response. - # rescue e # Generic case - # Baguette::Log.error "#{reqname} generic error #{e}" + Response::Error.new "user not logged" + rescue e # Generic case + Baguette::Log.error "#{reqname} generic error #{e}" + DNSManager::Response::Error.new "generic error" end # If clients sent requests with an “id” field, it is copied diff --git a/src/requests/admin.cr b/src/requests/admin.cr index 6dc2348..04b0c7b 100644 --- a/src/requests/admin.cr +++ b/src/requests/admin.cr @@ -13,7 +13,7 @@ class DNSManager::Request def initialize(@key, @subject) end - def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) + def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) : IPC::JSON+ # This request means serious business. raise AdminAuthorizationException.new if key != dnsmanagerd.authd.key diff --git a/src/requests/zone.cr b/src/requests/zone.cr index 0bff366..2816f08 100644 --- a/src/requests/zone.cr +++ b/src/requests/zone.cr @@ -1,3 +1,4 @@ +require "ipc/json" require "grok" class DNSManager::Request @@ -9,6 +10,7 @@ class DNSManager::Request end def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) + return Response::Success.new user = dnsmanagerd.get_logged_user event raise NotLoggedException.new if user.nil? dnsmanagerd.storage.add_or_update_zone user.uid, zone @@ -23,6 +25,7 @@ class DNSManager::Request end def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) + return Response::Success.new user = dnsmanagerd.get_logged_user event raise NotLoggedException.new if user.nil? dnsmanagerd.storage.delete_domain user.uid, @domain diff --git a/src/storage.cr b/src/storage.cr index 8254fe1..edd9e53 100644 --- a/src/storage.cr +++ b/src/storage.cr @@ -108,6 +108,7 @@ class DNSManager::Storage #unless errors = Storage::Zone.is_domain_valid? domain # return Response::InvalidZone.new errors #end + Response::Success.new rescue e Baguette::Log.error "trying to delete a domain #{domain}: #{e}" Response::Error.new "error while deleting the domain #{domain}"