Commit f17d0d10 authored by Colin Shea's avatar Colin Shea

some rubocop style tweaks

parent ff60c042
require 'fileutils'
class ZoneGenerator
attr_accessor :config, :soa, :generated, :zones_dir, :template_dir
attr_reader :basedir
......@@ -10,14 +9,14 @@ class ZoneGenerator
@basedir = basedir
@soa = {
origin: "@",
ttl: "86400",
primary: "example.com.",
email: "hostmaster@example.com",
refresh: "8H",
retry: "2H",
expire: "1W",
minimumTTL: "11h"
origin: '@',
ttl: '86400',
primary: 'example.com.',
email: 'hostmaster@example.com',
refresh: '8H',
retry: '2H',
expire: '1W',
minimumTTL: '11h'
}.merge(@config['soa'])
@zones_dir = File.expand_path(@config['ruby_zones'], basedir)
......@@ -28,8 +27,8 @@ class ZoneGenerator
@tmp_zones = "#{@generated}/zones"
# Rewrite email address
if (email = @soa[:email]).include?("@")
@soa[:email] = email.sub("@",".") << "."
if (email = @soa[:email]).include?('@')
@soa[:email] = email.sub('@','.') << '.'
end
end
......@@ -44,28 +43,28 @@ class ZoneGenerator
# Generates all zones
def generate
ruby_zones = Dir.glob("#{@zones_dir}/**/*.rb").map {|z| File.basename(z, '.rb')+'.zone'}
text_zones = Dir.glob("#{@config['local_zones_dir']}/*.zone").map {|z| File.basename(z) }
old_zones = (text_zones-ruby_zones).map{|f| File.join(@config['local_zones_dir'], f)}
ruby_zones = Dir.glob("#{@zones_dir}/**/*.rb").map { |z| File.basename(z, '.rb') + '.zone' }
text_zones = Dir.glob("#{@config['local_zones_dir']}/*.zone").map { |z| File.basename(z) }
old_zones = (text_zones - ruby_zones).map { |f| File.join(@config['local_zones_dir'], f) }
old_zones.each do |old|
FileUtils.rm old
end
File.open(@tmp_named,"w") do |f|
File.open(@tmp_named, 'w') do |f|
Dir.glob("#{@zones_dir}/**/*.rb").sort.each do |file|
domain = File.basename(file).sub(/\.rb$/,"")
domain = File.basename(file).sub(/\.rb$/, nil)
puts "Parsing zone for #{domain}"
generate_zone(file, domain)
f.puts "zone \"#{domain}\" IN { type master; file \"#{@config['zones_dir']}/#{domain}.zone\"; };"
end
f.puts "\n# vim: set ft=named:"
f.puts '\n# vim: set ft=named:'
end
end
# Generates a single zone file
def generate_zone(file, domain)
zone = Zone.new(domain + ".", @template_dir, @soa)
zone = Zone.new(domain + '.', @template_dir, @soa)
zone.send :eval_file, file
new_zonefile = zone.zonefile
......@@ -73,7 +72,7 @@ class ZoneGenerator
old_file = "#{@config['local_zones_dir']}/#{domain}.zone"
# is there already a deployed version?
if File.exists?(old_file)
if File.exist?(old_file)
# parse the deployed version
old_output = File.read(old_file)
old_zonefile = Zonefile.new(old_output)
......@@ -99,6 +98,6 @@ class ZoneGenerator
# Write new zonefile
output_file_path = "#{@tmp_zones}/#{domain}.zone"
FileUtils.mkdir_p File.dirname(output_file_path)
File.open(output_file_path, "w"){|f| f.write new_output }
File.open(output_file_path, 'w'){|f| f.write new_output }
end
end
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