Class: Matchd::Rule::Passthrough
- Inherits:
-
Matchd::Rule
- Object
- Matchd::Rule
- Matchd::Rule::Passthrough
- Defined in:
- lib/matchd/rule/passthrough.rb
Constant Summary
Constants inherited from Matchd::Rule
NotImplementedError, REGEXP_MATCHER, REGEXP_OPTIONS
Instance Attribute Summary collapse
-
#passthrough_options ⇒ Object
readonly
Returns the value of attribute passthrough_options.
-
#resolver ⇒ Object
readonly
Returns the value of attribute resolver.
Attributes inherited from Matchd::Rule
Instance Method Summary collapse
-
#initialize(options) ⇒ Passthrough
constructor
A new instance of Passthrough.
-
#passthrough_resolver ⇒ Object
Lazy convert the #resolver into somethinge we can pass to Async::DNS::Transaction#passthrough!.
- #visit!(server, _name, _resource_class, transaction) ⇒ Object
Methods inherited from Matchd::Rule
#call, #match_name, #match_resource_classes, #matches?, parse_match, parse_resource_class
Constructor Details
#initialize(options) ⇒ Passthrough
Returns a new instance of Passthrough.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/matchd/rule/passthrough.rb', line 7 def initialize() super opts = .fetch("passthrough") if opts.is_a?(Hash) && opts.key?("resolver") @resolver = opts["resolver"] @passthrough_options = Matchd::Helpers.(%w(force name), opts) else @resolver = opts @passthrough_options = {} end end |
Instance Attribute Details
#passthrough_options ⇒ Object (readonly)
Returns the value of attribute passthrough_options.
20 21 22 |
# File 'lib/matchd/rule/passthrough.rb', line 20 def @passthrough_options end |
#resolver ⇒ Object (readonly)
Returns the value of attribute resolver.
20 21 22 |
# File 'lib/matchd/rule/passthrough.rb', line 20 def resolver @resolver end |
Instance Method Details
#passthrough_resolver ⇒ Object
Lazy convert the #resolver into somethinge we can pass to Async::DNS::Transaction#passthrough!
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/matchd/rule/passthrough.rb', line 40 def passthrough_resolver case resolver when Async::DNS::Resolver resolver when "system", :system, nil Async::DNS::Resolver.new(Async::DNS::System.nameservers) else Async::DNS::Resolver.new(Matchd::Glue::AsyncEndpoint.parse(resolver)) end end |
#visit!(server, _name, _resource_class, transaction) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/matchd/rule/passthrough.rb', line 22 def visit!(server, _name, _resource_class, transaction) transaction.passthrough!(passthrough_resolver, ) do |response| server.logger.debug ";; Passthrough to upstream resolver" server.logger.debug ";; Question" server.logger.debug(*response.question.map { |q, r| "#{q}\t#{r}" }) server.logger.debug ";; Answer" if response.answer.any? response.answer.each do |name_in_answer, ttl, record| server.logger.debug "#{name_in_answer}\t#{ttl}\t#{record.class}\t#{record.address if record.respond_to?(:address)}" end else server.logger.debug ";; Empty" end end end |