From 05aa4421b3357d9a0e9f09f5347ec67516b49a66 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Mon, 8 May 2023 16:36:21 +0200 Subject: [PATCH] RRs now have an id. --- src/storage/zone.cr | 8 ++++++++ tools/write-zone-file.cr | 18 +++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/storage/zone.cr b/src/storage/zone.cr index ed93d3e..2556655 100644 --- a/src/storage/zone.cr +++ b/src/storage/zone.cr @@ -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| diff --git a/tools/write-zone-file.cr b/tools/write-zone-file.cr index 02d61ec..43b0c6c 100644 --- a/tools/write-zone-file.cr +++ b/tools/write-zone-file.cr @@ -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)