Verify accepted domain templates at startup.

This commit is contained in:
Philippe Pittoli 2023-06-28 17:59:13 +02:00
parent 009dcb0da7
commit 3580073fda
4 changed files with 38 additions and 9 deletions

View File

@ -7,6 +7,9 @@ class Baguette::Configuration
property recreate_indexes : Bool = false property recreate_indexes : Bool = false
property storage_directory : String = "storage" property storage_directory : String = "storage"
# List of all accepted domains. Example: netlib.re.
property accepted_domains : Array(String)? = nil
# New domains require to load a template so the user won't have to enter some # New domains require to load a template so the user won't have to enter some
# necessary entries himself. For example, SOA and NS RRs should be pre-loaded # necessary entries himself. For example, SOA and NS RRs should be pre-loaded
# and updated by an administrator when required. # and updated by an administrator when required.

View File

@ -213,6 +213,31 @@ def main
end end
end end
dir = configuration.template_directory
accepted_domains = configuration.accepted_domains
unless accepted_domains
Baguette::Log.error "Not even a single accepted domain configured. Probably an error."
exit 1
end
accepted_domains.each do |domain|
template_file = "#{dir}/#{domain}.json"
Baguette::Log.error "TODO: check for #{template_file}"
zone = DNSManager::Storage::Zone.from_json File.read "#{template_file}"
puts "zone #{domain}: #{zone}"
rescue e
Baguette::Log.error "error reading template #{template_file}: #{e}"
exit 1
#if File.exists? "./templates"
#else
# Baguette::Log.error "tried template directory './templates', but doesn't exist either"
# exit 1
#end
end
exit 1
if simulation if simulation
pp! configuration pp! configuration
exit 0 exit 0

View File

@ -21,15 +21,15 @@ class DNSManager::Storage::Zone
include JSON::Serializable include JSON::Serializable
use_json_discriminator "rrtype", { use_json_discriminator "rrtype", {
a: A, A: A,
aaaa: AAAA, AAAA: AAAA,
soa: SOA, SOA: SOA,
txt: TXT, TXT: TXT,
ptr: PTR, PTR: PTR,
ns: NS, NS: NS,
cname: CNAME, CNAME: CNAME,
mx: MX, MX: MX,
srv: SRV SRV: SRV
} }
# Used to discriminate between classes. # Used to discriminate between classes.

View File

@ -0,0 +1 @@
{"domain":"example.com","current_rrid":3,"resources":[{"rrtype":"SOA","rrid":0,"name":"example.com.","ttl":3600,"target":"","readonly":true,"mname":"ns0.example.com.","rname":"dnsmaster.example.com.","serial":2023070100,"refresh":3600,"retry":600,"expire":2419200,"minttl":600},{"rrtype":"NS","rrid":1,"name":"example.com.","ttl":3600,"target":"ns0.arn-fai.net.","readonly":true},{"rrtype":"NS","rrid":2,"name":"example.com.","ttl":3600,"target":"alsace.tetaneutral.net.","readonly":true}]}