Minor changes. Cleaner code.
This commit is contained in:
parent
ff29717bbd
commit
e36e408f8e
@ -75,6 +75,7 @@ class DNSManager::Storage
|
|||||||
def generate_all_zonefiles() : IPC::JSON
|
def generate_all_zonefiles() : IPC::JSON
|
||||||
Baguette::Log.info "writing all zone files in #{@zonefiledir}/"
|
Baguette::Log.info "writing all zone files in #{@zonefiledir}/"
|
||||||
zones.each do |zone|
|
zones.each do |zone|
|
||||||
|
# TODO: safe write.
|
||||||
File.open("#{@zonefiledir}/#{zone.domain}", "w") do |file|
|
File.open("#{@zonefiledir}/#{zone.domain}", "w") do |file|
|
||||||
zone.to_bind9 file
|
zone.to_bind9 file
|
||||||
end
|
end
|
||||||
@ -88,6 +89,7 @@ class DNSManager::Storage
|
|||||||
return Response::DomainNotFound.new unless zone
|
return Response::DomainNotFound.new unless zone
|
||||||
|
|
||||||
Baguette::Log.info "writing zone file #{@zonefiledir}/#{zone.domain}"
|
Baguette::Log.info "writing zone file #{@zonefiledir}/#{zone.domain}"
|
||||||
|
# TODO: safe write.
|
||||||
File.open("#{@zonefiledir}/#{zone.domain}", "w") do |file|
|
File.open("#{@zonefiledir}/#{zone.domain}", "w") do |file|
|
||||||
zone.to_bind9 file
|
zone.to_bind9 file
|
||||||
end
|
end
|
||||||
@ -263,6 +265,13 @@ class DNSManager::Storage
|
|||||||
return Response::NoOwnership.new
|
return Response::NoOwnership.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Verify the RR exists.
|
||||||
|
stored_rr = zone.get_rr rr.rrid
|
||||||
|
return Response::RRNotFound.new unless stored_rr
|
||||||
|
|
||||||
|
# Verify the RR isn't read only.
|
||||||
|
return Response::RRReadOnly.new domain, stored_rr if stored_rr.readonly
|
||||||
|
|
||||||
# Test RR validity.
|
# Test RR validity.
|
||||||
rr.get_errors.tap do |errors|
|
rr.get_errors.tap do |errors|
|
||||||
unless errors.empty?
|
unless errors.empty?
|
||||||
@ -271,16 +280,7 @@ class DNSManager::Storage
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
stored_rrs = zone.resources.select { |x| x.rrid == rr.rrid }
|
zone.update_rr rr
|
||||||
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 }
|
zone.resources = zone.resources.map { |x| x.rrid == rr.rrid ? rr : x }
|
||||||
|
|
||||||
@ -310,6 +310,17 @@ class DNSManager::Storage
|
|||||||
return Response::NoOwnership.new
|
return Response::NoOwnership.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Verify the RR exists.
|
||||||
|
rr = zone.get_rr rrid
|
||||||
|
return Response::RRNotFound.new unless rr
|
||||||
|
|
||||||
|
# Verify the RR isn't read only.
|
||||||
|
return Response::RRReadOnly.new domain, rr if rr.readonly
|
||||||
|
|
||||||
|
# Remove token from the db.
|
||||||
|
if token_uuid = rr.token
|
||||||
|
tokens_by_uuid.delete token_uuid
|
||||||
|
end
|
||||||
zone.resources.select! { |x| x.rrid != rrid }
|
zone.resources.select! { |x| x.rrid != rrid }
|
||||||
|
|
||||||
update_zone zone
|
update_zone zone
|
||||||
@ -390,8 +401,6 @@ class DNSManager::Storage
|
|||||||
end
|
end
|
||||||
|
|
||||||
def new_token(user_id : Int32, domain : String, rrid : UInt32) : IPC::JSON
|
def new_token(user_id : Int32, domain : String, rrid : UInt32) : IPC::JSON
|
||||||
puts "new token for domain #{domain} rrid #{rrid}"
|
|
||||||
|
|
||||||
# 0. verifications: must exist: user, zone, RR. Zone must be owned by user.
|
# 0. verifications: must exist: user, zone, RR. Zone must be owned by user.
|
||||||
|
|
||||||
# User must exist.
|
# User must exist.
|
||||||
|
@ -630,9 +630,7 @@ class DNSManager::Storage::Zone
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update_rr(rr : ResourceRecord)
|
def update_rr(rr : ResourceRecord)
|
||||||
puts "updating rr #{rr.rrid}"
|
@resources.map! { |x| x.rrid != rr.rrid ? x : rr }
|
||||||
@resources.select! { |x| x.rrid != rr.rrid }
|
|
||||||
@resources << rr
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s(io : IO)
|
def to_s(io : IO)
|
||||||
|
Loading…
Reference in New Issue
Block a user