Class: Mongo::Srv::Result Private
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
|
|
Inherits: | Object |
Defined in: | lib/mongo/srv/result.rb |
Overview
SRV record lookup result.
Contains server addresses that the query resolved to, and minimum TTL of the DNS records.
Constant Summary
-
MISMATCHED_DOMAINNAME =
"Parent domain name in SRV record result (%s) does not match " + "that of the hostname (%s)".freeze
Class Method Summary
-
.new(hostname) ⇒ Result
constructor
Internal use only
Create a new object to keep track of the SRV records of the hostname.
Instance Attribute Summary
- #address_strs ⇒ Array<String> readonly Internal use only
-
#empty? ⇒ Boolean
readonly
Internal use only
Checks whether there are any records.
- #min_ttl ⇒ Integer | nil rw Internal use only
- #query_hostname ⇒ String readonly Internal use only
Instance Method Summary
-
#add_record(record)
Internal use only
Adds a new record.
-
#normalize_hostname(host)
private
Internal use only
Transforms the provided hostname to simplify its validation later on.
-
#validate_same_origin!(record_host)
private
Internal use only
Ensures that a record’s domain name matches that of the hostname.
::Mongo::Address::Validator
- Included
#validate_address_str! | Takes an address string in ipv4/ipv6/hostname/socket path format and validates its format. |
#validate_hostname! | Validates format of the hostname, in particular for further use as the origin in same origin verification. |
#validate_port_str! |
Instance Attribute Details
#address_strs ⇒ Array
<String
> (readonly)
# File 'lib/mongo/srv/result.rb', line 40
attr_reader :address_strs
#empty? ⇒ Boolean
(readonly)
Checks whether there are any records.
# File 'lib/mongo/srv/result.rb', line 58
def empty? @address_strs.empty? end
#min_ttl ⇒ Integer
| nil
(rw)
# File 'lib/mongo/srv/result.rb', line 44
attr_accessor :min_ttl
#query_hostname ⇒ String
(readonly)
# File 'lib/mongo/srv/result.rb', line 36
attr_reader :query_hostname
Instance Method Details
#add_record(record)
Adds a new record.
# File 'lib/mongo/srv/result.rb', line 65
def add_record(record) record_host = normalize_hostname(record.target.to_s) port = record.port validate_hostname!(record_host) validate_same_origin!(record_host) address_str = if record_host.index(':') # IPV6 address "[#{record_host}]:#{port}" else "#{record_host}:#{port}" end @address_strs << address_str if @min_ttl.nil? @min_ttl = record.ttl else @min_ttl = [@min_ttl, record.ttl].min end nil end
#normalize_hostname(host) (private)
Transforms the provided hostname to simplify its validation later on.
This method is safe to call during both initial DNS seed list discovery and during SRV monitoring, in that it does not convert invalid hostnames into valid ones.
-
Converts the hostname to lower case.
-
Removes one trailing dot, if there is exactly one. If the hostname has multiple trailing dots, it is unchanged.
# File 'lib/mongo/srv/result.rb', line 100
def normalize_hostname(host) host = host.downcase unless host.end_with?('..') host = host.sub(/\.\z/, '') end host end
#validate_same_origin!(record_host) (private)
Ensures that a record’s domain name matches that of the hostname.
A hostname’s domain name consists of each of the ‘.’ delineated parts after the first. For example, the hostname ‘foo.bar.baz’ has the domain name ‘bar.baz’.
# File 'lib/mongo/srv/result.rb', line 118
def validate_same_origin!(record_host) domain_name ||= query_hostname.split('.')[1..-1] host_parts = record_host.split('.') unless (host_parts.size > domain_name.size) && (domain_name == host_parts[-domain_name.length..-1]) raise Error::MismatchedDomain.new(MISMATCHED_DOMAINNAME % [record_host, domain_name]) end end