Class: MonoVM::Whois::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/monovm/whois/configuration.rb

Overview

Every knob in one place, plus the defaults for the objects Client depends on.

Client takes its collaborators by injection, which is what makes it testable — but nobody wants to assemble a registry, a transport factory, an analyzer and a parser selector just to look up one domain. This class is the seam between those two needs: it holds the settings and builds sensible collaborators from them, while leaving every one of them replaceable.

MonoVM::Whois.configure do |config|
config.prefer = :whois
config.throttle_interval = 1.0
config.rules.insert_before("registry_marker", MyRule.new)
end

Constant Summary collapse

DEFAULT_UNICODE_QUERY_TLDS =

TLDs whose registry wants an internationalised name in Unicode rather than Punycode, over port 43.

DENIC answers Status: invalid for xn--mnchen-3ya.de but resolves münchen.de correctly. Almost every other registry is the reverse — Verisign answers "No match" to a UTF-8 query, which reads as availability — so Punycode is the default and this is the short exception list. URLs are always ASCII, so it never applies to RDAP.

[".de"].freeze
[".com", ".net", ".org", ".info"].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/monovm/whois/configuration.rb', line 58

def initialize
  @socket_connect_timeout = Transport::WhoisSocket::DEFAULT_CONNECT_TIMEOUT
  @socket_read_timeout = Transport::WhoisSocket::DEFAULT_READ_TIMEOUT
  @http_open_timeout = Transport::RdapHttp::DEFAULT_OPEN_TIMEOUT
  @http_read_timeout = Transport::RdapHttp::DEFAULT_READ_TIMEOUT
  @verify_ssl = true
  @user_agent = nil

  # RDAP first: a structured answer beats pattern-matching registry prose.
  @prefer = :rdap
  @follow_referrals = true
  @max_referrals = 1
  @unicode_query_tlds = DEFAULT_UNICODE_QUERY_TLDS.dup
  @popular_tlds = DEFAULT_POPULAR_TLDS.dup
  @concurrency = 8
  @override_path = Paths.override

  @cache = true
  @cache_ttl = Transport::Middleware::Cache::DEFAULT_TTL
  @cache_max_entries = Transport::Middleware::Cache::DEFAULT_MAX_ENTRIES
  @throttle_interval = Transport::Middleware::Throttle::DEFAULT_INTERVAL
  @retry_attempts = Transport::Middleware::Retry::DEFAULT_ATTEMPTS
  @retry_backoff = Transport::Middleware::Retry::DEFAULT_BACKOFF
  @instrumentation = nil
end

Instance Attribute Details

#analyzerObject



92
93
94
# File 'lib/monovm/whois/configuration.rb', line 92

def analyzer
  @analyzer ||= Availability::Analyzer.new(rules: rules)
end

#cacheObject

Middleware



52
53
54
# File 'lib/monovm/whois/configuration.rb', line 52

def cache
  @cache
end

#cache_max_entriesObject

Middleware



52
53
54
# File 'lib/monovm/whois/configuration.rb', line 52

def cache_max_entries
  @cache_max_entries
end

#cache_ttlObject

Middleware



52
53
54
# File 'lib/monovm/whois/configuration.rb', line 52

def cache_ttl
  @cache_ttl
end

#concurrencyObject

Behaviour



48
49
50
# File 'lib/monovm/whois/configuration.rb', line 48

def concurrency
  @concurrency
end

#follow_referralsObject

Behaviour



48
49
50
# File 'lib/monovm/whois/configuration.rb', line 48

def follow_referrals
  @follow_referrals
end

#http_open_timeoutObject

Transport



44
45
46
# File 'lib/monovm/whois/configuration.rb', line 44

def http_open_timeout
  @http_open_timeout
end

#http_read_timeoutObject

Transport



44
45
46
# File 'lib/monovm/whois/configuration.rb', line 44

def http_read_timeout
  @http_read_timeout
end

#instrumentationObject

Middleware



52
53
54
# File 'lib/monovm/whois/configuration.rb', line 52

def instrumentation
  @instrumentation
end

#max_referralsObject

Behaviour



48
49
50
# File 'lib/monovm/whois/configuration.rb', line 48

def max_referrals
  @max_referrals
end

#override_pathObject

Behaviour



48
49
50
# File 'lib/monovm/whois/configuration.rb', line 48

def override_path
  @override_path
end

#parsersObject



96
97
98
# File 'lib/monovm/whois/configuration.rb', line 96

def parsers
  @parsers ||= Parser::Selector.default
end

Behaviour



48
49
50
# File 'lib/monovm/whois/configuration.rb', line 48

def popular_tlds
  @popular_tlds
end

#preferObject

Behaviour



48
49
50
# File 'lib/monovm/whois/configuration.rb', line 48

def prefer
  @prefer
end

#retry_attemptsObject

Middleware



52
53
54
# File 'lib/monovm/whois/configuration.rb', line 52

def retry_attempts
  @retry_attempts
end

#retry_backoffObject

Middleware



52
53
54
# File 'lib/monovm/whois/configuration.rb', line 52

def retry_backoff
  @retry_backoff
end

#rulesObject



88
89
90
# File 'lib/monovm/whois/configuration.rb', line 88

def rules
  @rules ||= Availability::RuleSet.default
end

#server_registryObject



84
85
86
# File 'lib/monovm/whois/configuration.rb', line 84

def server_registry
  @server_registry ||= Registry::ServerRegistry.default(override_path: override_path)
end

#socket_connect_timeoutObject

Transport



44
45
46
# File 'lib/monovm/whois/configuration.rb', line 44

def socket_connect_timeout
  @socket_connect_timeout
end

#socket_read_timeoutObject

Transport



44
45
46
# File 'lib/monovm/whois/configuration.rb', line 44

def socket_read_timeout
  @socket_read_timeout
end

#throttle_intervalObject

Middleware



52
53
54
# File 'lib/monovm/whois/configuration.rb', line 52

def throttle_interval
  @throttle_interval
end

#transport_factoryObject



100
101
102
103
104
105
# File 'lib/monovm/whois/configuration.rb', line 100

def transport_factory
  @transport_factory ||= Transport::Factory.new(
    transports: default_transports,
    middleware: default_middleware
  )
end

#unicode_query_tldsObject

Behaviour



48
49
50
# File 'lib/monovm/whois/configuration.rb', line 48

def unicode_query_tlds
  @unicode_query_tlds
end

#user_agentObject

Transport



44
45
46
# File 'lib/monovm/whois/configuration.rb', line 44

def user_agent
  @user_agent
end

#verify_sslObject

Transport



44
45
46
# File 'lib/monovm/whois/configuration.rb', line 44

def verify_ssl
  @verify_ssl
end

Instance Method Details

#dupObject

A copy, so a per-call override cannot mutate the global default.



113
114
115
116
117
118
# File 'lib/monovm/whois/configuration.rb', line 113

def dup
  copy = super
  copy.unicode_query_tlds = unicode_query_tlds.dup
  copy.popular_tlds = popular_tlds.dup
  copy
end

#unicode_query?(tld) ⇒ Boolean

True when +tld+'s registry wants the Unicode form over port 43.

Returns:

  • (Boolean)


108
109
110
# File 'lib/monovm/whois/configuration.rb', line 108

def unicode_query?(tld)
  unicode_query_tlds.include?(tld)
end