Commit 4e5fdb21 authored by Julian Kornberger's avatar Julian Kornberger

Add method to set SOA values

parent 27147db6
soa minimumTTL: 3600*12
template "example-dns"
# A records
......
class Zone
SOA_FIELDS = %i(
ttl
origin
ttl
primary
email
serial
refresh
retry
expire
minimumTTL
)
attr_reader :zonefile
def initialize(domain, template_dir)
def initialize(domain, template_dir, soa={})
@domain = domain
@zonefile = Zonefile.new("","output/#{domain}", domain)
@zonefile.soa.merge! soa
@template_dir = template_dir
end
......@@ -13,6 +27,14 @@ class Zone
eval_file "#{@template_dir}/#{name}.rb"
end
# Merge
def soa(**options)
if (invalid_keys = options.keys - SOA_FIELDS).any?
raise ArgumentError, "invalid options: #{invalid_keys.inspect}"
end
@zonefile.soa.merge! options
end
# 1.2.3.4 - host
# 1.2.3.4, 600 - host with TTL
# www, 1.2.3.4, 600 - name, host and TTL
......
......@@ -46,10 +46,9 @@ class ZoneGenerator
# Generates a single zone file
def generate_zone(file, domain)
zone = Zone.new(domain, @template_dir)
zone = Zone.new(domain, @template_dir, @soa)
zone.send :eval_file, file
new_zonefile = zone.zonefile
new_zonefile.soa.merge! @soa
# path to the deployed version
old_file = "#{@config[:zones_dir]}/#{domain}"
......
......@@ -7,6 +7,13 @@ describe Zone do
Zone.new("example.com",nil)
end
describe "soa" do
it "should create host" do
subject.soa ttl: "42m"
subject.zonefile.output.must_include "42m IN SOA"
end
end
describe "a record" do
it "should create host" do
subject.a "127.0.0.1"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment