Sha256: c6126baa9cafe1a577ca942d16b9dfd1114a790a8e8e23b99c61737c2dccec19

Contents?: true

Size: 841 Bytes

Versions: 10

Compression:

Stored size: 841 Bytes

Contents

require "logger"
require 'rubydns'

module Invoker
  module Power
    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]
        ]
      end

      def initialize
        @logger = ::Logger.new($stderr)
        @logger.level = ::Logger::FATAL
      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

      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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
invoker-1.4.1 lib/invoker/power/dns.rb
invoker-1.4.0 lib/invoker/power/dns.rb
invoker-1.3.2 lib/invoker/power/dns.rb
invoker-1.3.1 lib/invoker/power/dns.rb
invoker-1.3.0 lib/invoker/power/dns.rb
invoker-1.2.0 lib/invoker/power/dns.rb
invoker-1.2.0.pre2 lib/invoker/power/dns.rb
invoker-1.2.0.pre1 lib/invoker/power/dns.rb
invoker-1.2.0.pre lib/invoker/power/dns.rb
invoker-1.1.0 lib/invoker/power/dns.rb