lib/invoker/power/dns.rb in invoker-1.0.4 vs lib/invoker/power/dns.rb in invoker-1.1.0
- old
+ new
@@ -1,37 +1,38 @@
require "logger"
+require 'rubydns'
module Invoker
-
module Power
-
- class DNS
- IN = Resolv::DNS::Resource::IN
+ class DNS < RubyDNS::Server
def self.server_ports
[
- [:udp, '127.0.0.1', Invoker::CONFIG.dns_port],
- [:tcp, '127.0.0.1', Invoker::CONFIG.dns_port]
+ [:udp, '127.0.0.1', Invoker.config.dns_port],
+ [:tcp, '127.0.0.1', Invoker.config.dns_port]
]
end
- def self.run_dns
- RubyDNS::run_server(:listen => server_ports) do
- on(:start) do
- @logger.level = ::Logger::WARN
- end
+ def initialize
+ @logger = ::Logger.new($stderr)
+ @logger.level = ::Logger::FATAL
+ end
- # For this exact address record, return an IP address
- match(/.*\.dev/, IN::A) do |transaction|
- transaction.respond!("127.0.0.1")
- end
-
- # Default DNS handler
- otherwise do |transaction|
- transaction.failure!(:NXDomain)
- end
+ def process(name, resource_class, transaction)
+ if name_matches?(name) && resource_class_matches?(resource_class)
+ transaction.respond!("127.0.0.1")
+ else
+ transaction.fail!(:NXDomain)
end
end
- end
+ private
+ def resource_class_matches?(resource_class)
+ resource_class == Resolv::DNS::Resource::IN::A
+ end
+
+ def name_matches?(name)
+ name =~ /.*\.dev/
+ end
+ end
end
end