Class: AuthDnsCheck::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/auth_dns_check/client.rb

Overview

TODO:

IPv6 not supported

Client for performing authoritative DNS checks

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(overrides: {}, default: Resolv::DNS.new("/etc/resolv.conf")) ⇒ Client

Initialize a new Client

Parameters:

  • overrides (Hash<String,Array<Resolv::DNS>>) (defaults to: {})

    authoritative name server overrides. Maps domain names to lists of name servers that should override those published for the domain. The special domain name Symbol :default may list the name servers that should override any other domain.

  • default (Resolv::DNS) (defaults to: Resolv::DNS.new("/etc/resolv.conf"))

    default resolver for finding authoritative name servers. Note that this is not the same as overrides[:default].



21
22
23
24
# File 'lib/auth_dns_check/client.rb', line 21

def initialize(overrides: {}, default: Resolv::DNS.new("/etc/resolv.conf"))
  @overrides = overrides
  @default = default
end

Instance Attribute Details

#defaultObject (readonly)

default resolver for finding authoritative name servers



12
13
14
# File 'lib/auth_dns_check/client.rb', line 12

def default
  @default
end

#overridesObject (readonly)

authoritative name server overrides



9
10
11
# File 'lib/auth_dns_check/client.rb', line 9

def overrides
  @overrides
end

Instance Method Details

#all?(fqdn) ⇒ Boolean

TODO:

Records of types other than A not yet supported

Check authoritative agreement for a name

Parameters:

  • fqdn (String)

    the name to check

Returns:

  • (Boolean)

    whether all authoritative agree that fqdn has the same non-empty set of records

Raises:

  • (Error)

    if authoritative name servers could not be found



32
33
34
35
# File 'lib/auth_dns_check/client.rb', line 32

def all?(fqdn)
  answers = get_addresses(fqdn)
  answers.all? { |x| x.any? and x == answers.first }
end

#has_ip?(fqdn, ip) ⇒ Boolean

Check authoritative agreement for the specific address for a name

Parameters:

  • fqdn (String)

    the name to check

  • ip (String)

    the expected address

Returns:

  • (Boolean)

    whether all authoritative name servers agree that the only address of name is ip

Raises:

  • (Error)

    if authoritative name servers could not be found



43
44
45
46
47
48
# File 'lib/auth_dns_check/client.rb', line 43

def has_ip?(fqdn, ip)
  answers = get_addresses(fqdn)
  answers.all? do |x|
    x.any? and x.all? { |i| i == ip }
  end
end