New request: NewDomain.

master
Philippe Pittoli 2023-06-17 12:57:51 +02:00
parent 009fdea353
commit 22f83b8729
3 changed files with 10 additions and 4 deletions

View File

@ -6,7 +6,7 @@ class DNSManager::Request
IPC::JSON.message NewDomain, 9 do IPC::JSON.message NewDomain, 9 do
property domain : String property domain : String
def initialize(@zone) def initialize(@domain)
end end
def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) : IPC::JSON def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) : IPC::JSON

View File

@ -12,4 +12,10 @@ class DNSManager::Response
end end
end end
DNSManager.responses << ErrorInvalidToken DNSManager.responses << ErrorInvalidToken
IPC::JSON.message DomainAlreadyExists, 3 do
def initialize()
end
end
DNSManager.responses << ErrorInvalidToken
end end

View File

@ -54,11 +54,11 @@ class DNSManager::Storage
Response::Success.new Response::Success.new
end end
def add_or_update_zone(user_id : Int32, domain : String) : IPC::JSON def new_domain(user_id : Int32, domain : String) : IPC::JSON
# User must exist. # User must exist.
user_data = user_data_by_uid.get? user_id.to_s user_data = user_data_by_uid.get? user_id.to_s
unless user_data unless user_data
Baguette::Log.warning "unknown user #{user_id} tries to add -or update- zone #{zone.domain}" Baguette::Log.warning "unknown user #{user_id} tries to add domain #{domain}"
return Response::UnknownUser.new return Response::UnknownUser.new
end end
@ -66,7 +66,7 @@ class DNSManager::Storage
Response::DomainAlreadyExists.new Response::DomainAlreadyExists.new
else else
# Add the domain to the user's domain. # Add the domain to the user's domain.
user_data.domains << zone.domain user_data.domains << domain
# Actually write data on-disk. # Actually write data on-disk.
update_user_data user_data update_user_data user_data