RRs now have an id.

master
Philippe Pittoli 2023-05-08 16:36:21 +02:00
parent 346d979e03
commit 05aa4421b3
2 changed files with 17 additions and 9 deletions

View File

@ -6,6 +6,7 @@ class DNSManager::Storage::Zone
property domain : String
property resources = [] of DNSManager::Storage::Zone::ResourceRecord
property current_rrid : UInt32 = 0
# We don't want to accept less than 30 seconds TTL.
class_property ttl_limit_min = 30
@ -34,6 +35,7 @@ class DNSManager::Storage::Zone
# Used to discriminate between classes.
property rrtype : String = ""
property rrid : UInt32 = 0
property name : String
property ttl : UInt32
property target : String
@ -275,6 +277,12 @@ class DNSManager::Storage::Zone
end
end
def <<(rr : ResourceRecord)
rr.rrid = current_rrid
@resources << rr
@current_rrid += 1
end
def to_s(io : IO)
io << "domain: #{@domain}\n"
@resources.each do |rr|

View File

@ -19,23 +19,23 @@ zone = DSZ.new domain
# Add some values.
#
zone.resources << DSZ::SOA.new "#{domain}.", # name
zone << DSZ::SOA.new "#{domain}.", # name
60.to_u32, # TTL
"IN", # target (??)
"ns0.some-example.com.", # Master Name Server for the zone
"john\.doe.#{domain}" # admin email address
zone.resources << DSZ::A.new "www", 600.to_u32, "10.0.0.1"
zone.resources << DSZ::A.new "www2", 600.to_u32, "10.0.0.2"
zone.resources << DSZ::A.new "mail", 300.to_u32, "10.0.0.10"
zone << DSZ::A.new "www", 600.to_u32, "10.0.0.1"
zone << DSZ::A.new "www2", 600.to_u32, "10.0.0.2"
zone << DSZ::A.new "mail", 300.to_u32, "10.0.0.10"
zone.resources << DSZ::CNAME.new "mail2", 600.to_u32, "www"
zone << DSZ::CNAME.new "mail2", 600.to_u32, "www"
zone.resources << DSZ::NS.new "#{domain}.", 3600.to_u32, "ns1.some-example.com."
zone.resources << DSZ::NS.new "#{domain}.", 3600.to_u32, "ns0.some-example.com."
zone << DSZ::NS.new "#{domain}.", 3600.to_u32, "ns1.some-example.com."
zone << DSZ::NS.new "#{domain}.", 3600.to_u32, "ns0.some-example.com."
zone.resources << DSZ::MX.new "mail", 300.to_u32, "mail", 10
zone.resources << DSZ::MX.new "mail", 300.to_u32, "mail2", 5
zone << DSZ::MX.new "mail", 300.to_u32, "mail", 10
zone << DSZ::MX.new "mail", 300.to_u32, "mail2", 5
File.write("#{domain}.json", zone.to_json)