Skip to content

Commit

Permalink
Endpoints is now first argument of server class.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Jul 30, 2017
1 parent a7b5cd0 commit 2e55c84
Show file tree
Hide file tree
Showing 15 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -47,7 +47,7 @@ IN = Resolv::DNS::Resource::IN
UPSTREAM = RubyDNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])

# Start the RubyDNS server
RubyDNS::run_server(:listen => INTERFACES) do
RubyDNS::run_server(INTERFACES) do
match(%r{test.local}, IN::A) do |transaction|
transaction.respond!("10.0.0.80")
end
Expand Down
2 changes: 1 addition & 1 deletion examples/basic-dns.rb
Expand Up @@ -12,7 +12,7 @@
UPSTREAM = RubyDNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])

# Start the RubyDNS server
RubyDNS::run_server(:listen => INTERFACES) do
RubyDNS::run_server(INTERFACES) do
match(%r{test.local}, IN::A) do |transaction|
transaction.respond!("10.0.0.80")
end
Expand Down
2 changes: 1 addition & 1 deletion examples/cname.rb
Expand Up @@ -13,7 +13,7 @@

UPSTREAM = RubyDNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])

RubyDNS::run_server(:listen => INTERFACES) do
RubyDNS::run_server(INTERFACES) do
# How to respond to something other than what was requested.
match(//, IN::A) do |transaction|
transaction.respond!(Name.create('foo.bar'), resource_class: IN::CNAME)
Expand Down
2 changes: 1 addition & 1 deletion examples/flakey-dns.rb
Expand Up @@ -38,7 +38,7 @@ class FlakeyDNS < Process::Daemon
IN = Resolv::DNS::Resource::IN

def startup
RubyDNS.run_server(listen: INTERFACES) do
RubyDNS.run_server(INTERFACES) do
# Use a Celluloid supervisor so the system recovers if the actor dies
fallback_resolver_supervisor =
RubyDNS::Resolver.supervise(RubyDNS::System.nameservers)
Expand Down
2 changes: 1 addition & 1 deletion examples/geoip-dns.rb
Expand Up @@ -57,7 +57,7 @@ class GeoIPDNS < Process::Daemon
IN = Resolv::DNS::Resource::IN

def startup
RubyDNS.run_server(listen: INTERFACES) do
RubyDNS.run_server(INTERFACES) do
fallback_resolver_supervisor = RubyDNS::Resolver.supervise(RubyDNS::System.nameservers)

match(//, IN::A) do |transaction|
Expand Down
2 changes: 1 addition & 1 deletion examples/simple.rb
Expand Up @@ -13,7 +13,7 @@
UPSTREAM = RubyDNS::Resolver.new([[:udp, '8.8.8.8', 53], [:tcp, '8.8.8.8', 53]])

# Start the RubyDNS server
RubyDNS.run_server(listen: INTERFACES) do
RubyDNS.run_server(INTERFACES) do
match(/test.mydomain.org/, IN::A) do |transaction|
transaction.respond!('10.0.0.80')
end
Expand Down
2 changes: 1 addition & 1 deletion examples/soa-dns.rb
Expand Up @@ -27,7 +27,7 @@
Name = Resolv::DNS::Name
IN = Resolv::DNS::Resource::IN

RubyDNS.run_server(listen: [[:udp, '0.0.0.0', 5400]]) do
RubyDNS.run_server([[:udp, '0.0.0.0', 5400]]) do
# SOA Record
# dig @localhost -p 5400 SOA mydomain.org
match('mydomain.org', IN::SOA) do |transaction|
Expand Down
2 changes: 1 addition & 1 deletion examples/test-dns-1.rb
Expand Up @@ -37,7 +37,7 @@
# [:tcp, '::0', 5300],
]

RubyDNS.run_server(listen: INTERFACES) do
RubyDNS.run_server(INTERFACES) do
# % dig +nocmd +noall +answer @localhost ANY dev.mydomain.org
# dev.mydomain.org. 16000 IN A 10.0.0.80
# dev.mydomain.org. 16000 IN MX 10 mail.mydomain.org.
Expand Down
2 changes: 1 addition & 1 deletion examples/test-dns-2.rb
Expand Up @@ -61,7 +61,7 @@ def startup
$stderr.sync = true

# Start the RubyDNS server
RubyDNS.run_server(listen: INTERFACES) do
RubyDNS.run_server(INTERFACES) do
on(:start) do
RExec.change_user(RUN_AS)
end
Expand Down
9 changes: 7 additions & 2 deletions lib/rubydns.rb
Expand Up @@ -28,8 +28,13 @@ module RubyDNS
Resolver = Async::DNS::Resolver

# Run a server with the given rules.
def self.run_server (server_class: RuleBasedServer, **options, &block)
server = server_class.new(**options, &block)
def self.run_server (*args, server_class: RuleBasedServer, **options, &block)
if listen = options.delete(:listen)
warn "Using `listen:` option is deprecated, please pass as the first argument."
args.unshift(listen)
end

server = server_class.new(*args, **options, &block)

server.run
end
Expand Down
4 changes: 2 additions & 2 deletions lib/rubydns/rule_based_server.rb
Expand Up @@ -100,8 +100,8 @@ def to_s
# end
# end
#
def initialize(options = {}, &block)
super(options)
def initialize(*args, &block)
super(*args)

@events = {}
@rules = []
Expand Down
2 changes: 1 addition & 1 deletion rubydns.gemspec
Expand Up @@ -30,7 +30,7 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = '>= 2.2.6'

spec.add_dependency("async-dns", "~> 0.12")
spec.add_dependency("async-dns", "~> 1.0")
spec.add_development_dependency("async-rspec", "~> 1.0")

spec.add_development_dependency "bundler", "~> 1.3"
Expand Down
2 changes: 1 addition & 1 deletion spec/rubydns/daemon_spec.rb
Expand Up @@ -38,7 +38,7 @@ def reactor

def startup
reactor.run do
RubyDNS::run_server(listen: SERVER_PORTS) do
RubyDNS::run_server(SERVER_PORTS) do
match("test.local", IN::A) do |transaction|
transaction.respond!("192.168.1.1")
end
Expand Down
2 changes: 1 addition & 1 deletion spec/rubydns/injected_supervisor_spec.rb
Expand Up @@ -38,7 +38,7 @@ def test_message

let(:server) do
# Start the RubyDNS server
RubyDNS::run_server(listen: SERVER_PORTS, server_class: TestServer) do
RubyDNS::run_server(SERVER_PORTS, server_class: TestServer) do
match("test_message", IN::TXT) do |transaction|
transaction.respond!(*test_message.chunked)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/rubydns/passthrough_spec.rb
Expand Up @@ -31,7 +31,7 @@ module RubyDNS::PassthroughSpec
include_context Async::RSpec::Reactor

def run_server
task = RubyDNS::run_server(:listen => SERVER_PORTS) do
task = RubyDNS::run_server(listen: SERVER_PORTS) do
resolver = RubyDNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])

match(/.*\.com/, IN::A) do |transaction|
Expand Down

0 comments on commit 2e55c84

Please sign in to comment.