RRUpdated + RRReadOnly.

master
Philippe Pittoli 2023-07-12 16:10:25 +02:00
parent 9be374b492
commit 203c6aed54
2 changed files with 24 additions and 4 deletions

View File

@ -86,5 +86,21 @@ class DNSManager::Response
end
end
DNSManager.responses << InvalidRR
IPC::JSON.message RRUpdated, 21 do
property domain : String
property rr : Storage::Zone::ResourceRecord
def initialize(@domain, @rr)
end
end
DNSManager.responses << RRUpdated
IPC::JSON.message RRReadOnly, 22 do
property domain : String
property rr : Storage::Zone::ResourceRecord
def initialize(@domain, @rr)
end
end
DNSManager.responses << RRReadOnly
end

View File

@ -205,19 +205,23 @@ class DNSManager::Storage
end
end
# TODO: verify that this rr.rrid isn't ReadOnly.
stored_rr = zone.resources.select { |x| x.rrid == rr.rrid }
unless stored_rr.size > 0
stored_rrs = zone.resources.select { |x| x.rrid == rr.rrid }
unless stored_rrs.size > 0
Baguette::Log.warning "modifying a RR that doesn't exist (#{rr.rrid}) in domain #{domain}"
return Response::RRNotFound.new
end
# Verify that this resource isn't ReadOnly.
stored_rrs.each do |stored_rr|
return Response::RRReadOnly.new domain, rr if stored_rr.readonly
end
zone.resources = zone.resources.map { |x| x.rrid == rr.rrid ? rr : x }
# Update the zone.
zones_by_domain.update_or_create zone.domain, zone
Response::Success.new
Response::RRUpdated.new domain, rr
rescue e
Baguette::Log.error "trying to replace a resource record in domain #{domain}: #{e}"
Response::Error.new "error while replacing a resource record in domain #{domain}"