Class: Mongo::Srv::Resolver Private
- Inherits:
-
Object
- Object
- Mongo::Srv::Resolver
- Includes:
- Loggable
- Defined in:
- build/ruby-driver-v2.17/lib/mongo/srv/resolver.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Encapsulates the necessary behavior for querying SRV records as required by the driver.
Constant Summary collapse
- RECORD_PREFIX =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Returns RECORD_PREFIX The prefix prepended to each hostname before querying SRV records.
'_mongodb._tcp.'.freeze
Constants included from Loggable
Instance Attribute Summary collapse
-
#options ⇒ Hash
readonly
private
Resolver options.
Instance Method Summary collapse
-
#get_records(hostname) ⇒ Mongo::Srv::Result
private
Obtains all of the SRV records for a given hostname.
-
#get_txt_options_string(hostname) ⇒ nil | String
private
Obtains the TXT records of a host.
-
#initialize(**opts) ⇒ Resolver
constructor
private
Creates a new Resolver.
- #timeout ⇒ Object private
Methods included from Loggable
#log_debug, #log_error, #log_fatal, #log_info, #log_warn, #logger
Constructor Details
#initialize(**opts) ⇒ Resolver
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a new Resolver.
41 42 43 44 45 |
# File 'build/ruby-driver-v2.17/lib/mongo/srv/resolver.rb', line 41 def initialize(**opts) @options = opts.freeze @resolver = Resolv::DNS.new(@options[:resolv_options]) @resolver.timeouts = timeout end |
Instance Attribute Details
#options ⇒ Hash (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Resolver options.
48 49 50 |
# File 'build/ruby-driver-v2.17/lib/mongo/srv/resolver.rb', line 48 def @options end |
Instance Method Details
#get_records(hostname) ⇒ Mongo::Srv::Result
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Obtains all of the SRV records for a given hostname.
In the event that a record with a mismatched domain is found or no records are found, if the :raise_on_invalid option is true, an exception will be raised, otherwise a warning will be logged.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'build/ruby-driver-v2.17/lib/mongo/srv/resolver.rb', line 69 def get_records(hostname) query_name = RECORD_PREFIX + hostname resources = @resolver.getresources(query_name, Resolv::DNS::Resource::IN::SRV) # Collect all of the records into a Result object, raising an error # or logging a warning if a record with a mismatched domain is found. # Note that in the case a warning is raised, the record is _not_ # added to the Result object. result = Srv::Result.new(hostname) resources.each do |record| begin result.add_record(record) rescue Error::MismatchedDomain => e if raise_on_invalid? raise else log_warn(e.) end end end # If no records are found, either raise an error or log a warning # based on the Resolver's :raise_on_invalid option. if result.empty? if raise_on_invalid? raise Error::NoSRVRecords.new(URI::SRVProtocol::NO_SRV_RECORDS % hostname) else log_warn(URI::SRVProtocol::NO_SRV_RECORDS % hostname) end end result end |
#get_txt_options_string(hostname) ⇒ nil | String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Obtains the TXT records of a host.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'build/ruby-driver-v2.17/lib/mongo/srv/resolver.rb', line 111 def (hostname) records = @resolver.getresources(hostname, Resolv::DNS::Resource::IN::TXT) if records.empty? return nil end if records.length > 1 msg = "Only one TXT record is allowed: querying hostname #{hostname} returned #{records.length} records" raise Error::InvalidTXTRecord, msg end records[0].strings.join end |
#timeout ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
50 51 52 |
# File 'build/ruby-driver-v2.17/lib/mongo/srv/resolver.rb', line 50 def timeout [:timeout] || Monitor::DEFAULT_TIMEOUT end |