New Domain message: WIP.

This commit is contained in:
Philippe Pittoli 2023-06-16 18:41:20 +02:00
parent eb5879f5de
commit 009fdea353
2 changed files with 41 additions and 0 deletions

View File

@ -3,6 +3,19 @@ require "grok"
class DNSManager::Request class DNSManager::Request
IPC::JSON.message NewDomain, 9 do
property domain : String
def initialize(@zone)
end
def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) : IPC::JSON
user = dnsmanagerd.get_logged_user event
raise NotLoggedException.new if user.nil?
dnsmanagerd.storage.new_domain user.uid, @domain
end
end
IPC::JSON.message AddOrUpdateZone, 10 do IPC::JSON.message AddOrUpdateZone, 10 do
property zone : DNSManager::Storage::Zone property zone : DNSManager::Storage::Zone

View File

@ -54,6 +54,34 @@ class DNSManager::Storage
Response::Success.new Response::Success.new
end end
def add_or_update_zone(user_id : Int32, domain : String) : IPC::JSON
# User must exist.
user_data = user_data_by_uid.get? user_id.to_s
unless user_data
Baguette::Log.warning "unknown user #{user_id} tries to add -or update- zone #{zone.domain}"
return Response::UnknownUser.new
end
if zones_by_domain.get? domain
Response::DomainAlreadyExists.new
else
# Add the domain to the user's domain.
user_data.domains << zone.domain
# Actually write data on-disk.
update_user_data user_data
# TODO: Fill a template zone.
## # 2 NS
## zone << rr
## # Update the zone.
## zones_by_domain.update_or_create zone.domain, zone
Response::Success.new
end
end
def add_or_update_zone(user_id : Int32, zone : Zone) : IPC::JSON def add_or_update_zone(user_id : Int32, zone : Zone) : IPC::JSON
# Test zone validity. # Test zone validity.
if errors = zone.get_errors? if errors = zone.get_errors?