New Domain message: WIP.
This commit is contained in:
parent
eb5879f5de
commit
009fdea353
@ -3,6 +3,19 @@ require "grok"
|
||||
|
||||
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
|
||||
property zone : DNSManager::Storage::Zone
|
||||
|
||||
|
@ -54,6 +54,34 @@ class DNSManager::Storage
|
||||
Response::Success.new
|
||||
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
|
||||
# Test zone validity.
|
||||
if errors = zone.get_errors?
|
||||
|
Loading…
Reference in New Issue
Block a user