Migration request.
This commit is contained in:
parent
8119bf7f57
commit
749889aad8
39
src/requests/migration.cr
Normal file
39
src/requests/migration.cr
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user