Class: Dps::DNS
- Inherits:
-
Object
show all
- Defined in:
- lib/dps/dns.rb
Defined Under Namespace
Classes: Endpoint, InvalidRecord, NoRecords, TooManyRecords
Class Method Summary
collapse
Class Method Details
.decode_txt_record(value) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/dps/dns.rb', line 12
def decode_txt_record(value)
parts = value.gsub('"', '').split
parts.reverse!
action = parts.pop
parts.reverse!
case action
when "dps:endpoint"
Endpoint.new(parts)
else
InvalidRecord.new("Unexpected action '#{action}'")
end
end
|
.get_endpoint(domain) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/dps/dns.rb', line 28
def get_endpoint(domain)
records = get_records(domain).select { |r| r.is_a?(Endpoint) }
if records.length > 1
TooManyRecords.new("Too many valid endpoint TXT records returned.")
elsif records.length == 0
NoRecords.new("No valid endpoint TXT records found.")
else
records[0]
end
end
|
.get_records(domain) ⇒ Object
7
8
9
10
|
# File 'lib/dps/dns.rb', line 7
def get_records(domain)
get_txt_records(domain).
collect { |value| decode_txt_record(value) }.select(&:valid?)
end
|