Class: DockerBoss::Module::DNS::Server

Inherits:
RubyDNS::Server
  • Object
show all
Defined in:
lib/docker_boss/modules/dns.rb

Constant Summary collapse

IN =
Resolv::DNS::Resource::IN

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Server

Returns a new instance of Server.



63
64
65
66
67
68
69
70
71
72
# File 'lib/docker_boss/modules/dns.rb', line 63

def initialize(options = {})
  super(options)
  @manager = options[:manager]

  @ttl = options[:ttl].to_i
  @zones = options[:zones]
  servers = options[:upstream_dns].map { |ip| [:udp, ip, 53] }
  servers.concat(options[:upstream_dns].map { |ip| [:tcp, ip, 53] })
  @resolver = RubyDNS::Resolver.new(servers)
end

Instance Attribute Details

#recordsObject



59
60
61
# File 'lib/docker_boss/modules/dns.rb', line 59

def records
  @manager.records
end

Instance Method Details

#process(name, resource_class, transaction) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/docker_boss/modules/dns.rb', line 74

def process(name, resource_class, transaction)
  zone = @zones.find { |z| name =~ /#{z}$/ }
  if records.has_key? name
    # XXX: revisit whenever docker supports IPv6, for AAAA records...
    if [IN::A].include? resource_class
      transaction.respond!(records[name], :ttl => @ttl)
    else
      transaction.fail!(:NXDomain)
    end
  elsif zone
    soa = Resolv::DNS::Resource::IN::SOA.new(Resolv::DNS::Name.create("#{zone}"), Resolv::DNS::Name.create("dockerboss."), 1, @ttl, @ttl, @ttl, @ttl)
    transaction.add([soa], :name => "#{zone}.", :ttl => @ttl, :section => :authority)
    transaction.fail!(:NXDomain)
  else
    transaction.passthrough!(@resolver)
  end
end