evt-dns-resolve_host 0.0.0.0 → 0.1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dns/resolve_host.rb +7 -2
- data/lib/dns/resolve_host/controls/server.rb +1 -3
- data/lib/dns/resolve_host/log_attributes.rb +15 -0
- data/lib/dns/resolve_host/resolution_error.rb +5 -0
- data/lib/dns/resolve_host/resolve_host.rb +48 -21
- data/lib/dns/resolve_host/static_resolver.rb +39 -0
- data/lib/dns/resolve_host/substitute.rb +15 -2
- metadata +6 -4
- data/lib/dns/resolve_host/nameserver.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae6e00ea579cee629e25ccd99a53b4c317c626fe
|
4
|
+
data.tar.gz: b128cc7ae8cbf445fa7d7cfc44e450b8a34b51cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a69ac9ab686e8f9164f63383a192c150a6e806c05bc03abd57fe42df6ea60dce69da04b6e612460002d74186ebd6a9bfeea83bcc887ae8d298f7efb9e4badb29
|
7
|
+
data.tar.gz: 740b17b05105e2246b250bd84c957d94bf6d496568c43d1e338ac686df302524c5211ab838d45c1760ff7e8e4806389ceb2538f618d6b4394bb84d7eb451c363
|
data/lib/dns/resolve_host.rb
CHANGED
@@ -1,9 +1,14 @@
|
|
1
|
+
require 'ipaddr'
|
2
|
+
require 'resolv'
|
3
|
+
|
1
4
|
require 'configure'; Configure.activate
|
2
|
-
require '
|
5
|
+
require 'settings'; Settings.activate
|
3
6
|
|
4
7
|
require 'dns/resolve_host/log'
|
5
8
|
|
6
9
|
require 'dns/resolve_host/defaults'
|
7
|
-
require 'dns/resolve_host/
|
10
|
+
require 'dns/resolve_host/log_attributes'
|
8
11
|
require 'dns/resolve_host/resolve_host'
|
12
|
+
require 'dns/resolve_host/resolution_error'
|
9
13
|
require 'dns/resolve_host/substitute'
|
14
|
+
require 'dns/resolve_host/static_resolver'
|
@@ -21,9 +21,7 @@ module DNS
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
block.(nameserver)
|
24
|
+
block.(bind_address, port)
|
27
25
|
|
28
26
|
# The rubydns library does not properly unbind its server socket when
|
29
27
|
# the actor terminates. See the following github issue:
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module DNS
|
2
|
+
class ResolveHost
|
3
|
+
module LogAttributes
|
4
|
+
def self.get(resolve_host, hostname)
|
5
|
+
if resolve_host.nameserver_address
|
6
|
+
nameserver = "#{resolve_host.nameserver_address}:#{resolve_host.nameserver_port}"
|
7
|
+
else
|
8
|
+
nameserver = "(system)"
|
9
|
+
end
|
10
|
+
|
11
|
+
"Hostname: #{hostname}, Nameserver: #{nameserver}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -4,44 +4,71 @@ module DNS
|
|
4
4
|
|
5
5
|
configure :resolve_host
|
6
6
|
|
7
|
-
attr_accessor :
|
7
|
+
attr_accessor :nameserver_address
|
8
|
+
attr_writer :nameserver_port
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
dependency :hosts_resolver, Resolv::Hosts
|
11
|
+
|
12
|
+
def self.build(address: nil, port: nil, hosts_file: nil)
|
13
|
+
if address.nil? and not port.nil?
|
14
|
+
raise ArgumentError, "Cannot specify port without address"
|
14
15
|
end
|
15
16
|
|
17
|
+
instance = new
|
18
|
+
|
19
|
+
StaticResolver.configure instance, hosts_file, attr_name: :hosts_resolver
|
20
|
+
|
21
|
+
instance.nameserver_address = address if address
|
22
|
+
instance.nameserver_port = port if port
|
23
|
+
|
24
|
+
instance
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.call(hostname, &block)
|
28
|
+
instance = new
|
29
|
+
instance.(hostname, &block)
|
30
|
+
end
|
31
|
+
|
32
|
+
def call(hostname, &block)
|
16
33
|
logger.trace { "Resolving host (#{LogAttributes.get self, hostname})" }
|
17
34
|
|
18
|
-
Resolv::DNS.open
|
19
|
-
|
35
|
+
Resolv::DNS.open dns_resolver_options do |dns_resolver|
|
36
|
+
resolver = Resolv.new [hosts_resolver, dns_resolver]
|
37
|
+
|
38
|
+
block.(dns_resolver) if block
|
20
39
|
|
21
|
-
addresses =
|
40
|
+
addresses = resolver.getaddresses hostname
|
22
41
|
|
23
42
|
addresses.map! &:to_s
|
24
43
|
|
25
44
|
if addresses.empty?
|
26
|
-
|
27
|
-
|
28
|
-
|
45
|
+
error_message = "Could not resolve host (#{LogAttributes.get self, hostname})"
|
46
|
+
logger.error { error_message }
|
47
|
+
raise ResolutionError, error_message
|
29
48
|
end
|
30
49
|
|
50
|
+
logger.info { "Resolved host (#{LogAttributes.get self, hostname}, Address#{'es' unless addresses.count == 1}: #{addresses * ', '})" }
|
51
|
+
|
31
52
|
return addresses
|
32
53
|
end
|
33
54
|
end
|
34
55
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
"Hostname: #{hostname}, Nameserver: #{nameserver}"
|
56
|
+
def dns_resolver_options
|
57
|
+
if nameserver_address
|
58
|
+
{ :nameserver_port => [nameserver] }
|
59
|
+
else
|
60
|
+
# Resolv::DNS.new expects the options argument to be *nil* when the
|
61
|
+
# system nameservers are meant to be used [Nathan Ladd, Mon 2 Jan 2017]
|
62
|
+
nil
|
44
63
|
end
|
45
64
|
end
|
65
|
+
|
66
|
+
def nameserver
|
67
|
+
[nameserver_address, nameserver_port]
|
68
|
+
end
|
69
|
+
|
70
|
+
def nameserver_port
|
71
|
+
@nameserver_port ||= Defaults.port
|
72
|
+
end
|
46
73
|
end
|
47
74
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module DNS
|
2
|
+
class ResolveHost
|
3
|
+
module StaticResolver
|
4
|
+
def self.get(hosts_file=nil)
|
5
|
+
logger.trace { "Constructing static resolver (HostsFile: #{hosts_file.inspect})" }
|
6
|
+
|
7
|
+
if hosts_file.nil?
|
8
|
+
hosts_file = Resolv::Hosts::DefaultFileName
|
9
|
+
elsif !File.exist?(hosts_file)
|
10
|
+
File.open(hosts_file) { }
|
11
|
+
end
|
12
|
+
|
13
|
+
static_resolver = Resolv::Hosts.new hosts_file
|
14
|
+
|
15
|
+
logger.trace { "Static resolver constructed (HostsFile: #{hosts_file})" }
|
16
|
+
|
17
|
+
static_resolver
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.configure(receiver, hosts_file=nil, attr_name: nil)
|
21
|
+
attr_name ||= :static_resolver
|
22
|
+
|
23
|
+
instance = get hosts_file
|
24
|
+
receiver.public_send "#{attr_name}=", instance
|
25
|
+
instance
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.logger
|
29
|
+
@logger ||= Log.get self
|
30
|
+
end
|
31
|
+
|
32
|
+
module Assertions
|
33
|
+
def file?(file)
|
34
|
+
@filename == file
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -7,7 +7,20 @@ module DNS
|
|
7
7
|
|
8
8
|
class ResolveHost
|
9
9
|
def call(hostname)
|
10
|
-
map
|
10
|
+
if map.key? hostname
|
11
|
+
map[hostname]
|
12
|
+
elsif ip_address? hostname
|
13
|
+
[hostname]
|
14
|
+
else
|
15
|
+
raise ResolutionError
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def ip_address?(string)
|
20
|
+
IPAddr.new string
|
21
|
+
true
|
22
|
+
rescue IPAddr::InvalidAddressError
|
23
|
+
false
|
11
24
|
end
|
12
25
|
|
13
26
|
def set(hostname, ip_addresses)
|
@@ -19,7 +32,7 @@ module DNS
|
|
19
32
|
end
|
20
33
|
|
21
34
|
def map
|
22
|
-
@map ||=
|
35
|
+
@map ||= {}
|
23
36
|
end
|
24
37
|
end
|
25
38
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evt-dns-resolve_host
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Eventide Project
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: evt-configure
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: evt-
|
28
|
+
name: evt-settings
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -79,8 +79,10 @@ files:
|
|
79
79
|
- lib/dns/resolve_host/controls/server.rb
|
80
80
|
- lib/dns/resolve_host/defaults.rb
|
81
81
|
- lib/dns/resolve_host/log.rb
|
82
|
-
- lib/dns/resolve_host/
|
82
|
+
- lib/dns/resolve_host/log_attributes.rb
|
83
|
+
- lib/dns/resolve_host/resolution_error.rb
|
83
84
|
- lib/dns/resolve_host/resolve_host.rb
|
85
|
+
- lib/dns/resolve_host/static_resolver.rb
|
84
86
|
- lib/dns/resolve_host/substitute.rb
|
85
87
|
homepage: https://github.com/eventide-project/dns-resolve-host
|
86
88
|
licenses:
|