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