From 749889aad81454b8d23ba5c513ee5505d1346597 Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Mon, 10 Jun 2024 13:47:31 +0200 Subject: [PATCH] Migration request. --- src/requests/migration.cr | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/requests/migration.cr diff --git a/src/requests/migration.cr b/src/requests/migration.cr new file mode 100644 index 0000000..b603f20 --- /dev/null +++ b/src/requests/migration.cr @@ -0,0 +1,39 @@ +require "ipc/json" +require "grok" + +class DNSManager::Request + + IPC::JSON.message Migration, 24 do + property login : String + property domain : String + + def initialize(@login, @domain) + end + + def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) : IPC::JSON + user = dnsmanagerd.get_logged_user event + return Response::ErrorUserNotLogged.new unless user + dnsmanagerd.storage.user_must_be_admin! user.uid + + response = dnsmanagerd.authd.get_user? @login + migrated_user = case response + when AuthD::Response::User + response.user + when AuthD::Response::ErrorMustBeAuthenticated + Baguette::Log.error "migration: not authenticated to authd" + return Response::UnknownUser.new + when AuthD::Response::ErrorUserNotFound + Baguette::Log.error "migration: user not found in authd" + return Response::UnknownUser.new + else + Baguette::Log.error "migration: unknown error while requesting authd for a user" + return Response::UnknownUser.new + end + + return Response::UnknownUser.new unless migrated_user + + dnsmanagerd.storage.new_domain migrated_user.uid, @domain + end + end + DNSManager.requests << Migration +end