Class: MythicBeasts::DNS

Inherits:
Object
  • Object
show all
Defined in:
lib/mythic_beasts/dns.rb,
lib/mythic_beasts/dns/email_auth.rb

Defined Under Namespace

Classes: EmailAuth

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ DNS

Returns a new instance of DNS.



7
8
9
# File 'lib/mythic_beasts/dns.rb', line 7

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/mythic_beasts/dns.rb', line 5

def client
  @client
end

Instance Method Details

#create_a_record(zone, host, ip, ttl: 300) ⇒ Object

Convenience methods for common record types



58
59
60
# File 'lib/mythic_beasts/dns.rb', line 58

def create_a_record(zone, host, ip, ttl: 300)
  create_records(zone, [{host: host, ttl: ttl, type: "A", data: ip}])
end

#create_aaaa_record(zone, host, ip, ttl: 300) ⇒ Object



62
63
64
# File 'lib/mythic_beasts/dns.rb', line 62

def create_aaaa_record(zone, host, ip, ttl: 300)
  create_records(zone, [{host: host, ttl: ttl, type: "AAAA", data: ip}])
end

#create_cname_record(zone, host, target, ttl: 300) ⇒ Object



66
67
68
# File 'lib/mythic_beasts/dns.rb', line 66

def create_cname_record(zone, host, target, ttl: 300)
  create_records(zone, [{host: host, ttl: ttl, type: "CNAME", data: target}])
end

#create_mx_record(zone, host, priority, mail_server, ttl: 300) ⇒ Object



70
71
72
# File 'lib/mythic_beasts/dns.rb', line 70

def create_mx_record(zone, host, priority, mail_server, ttl: 300)
  create_records(zone, [{host: host, ttl: ttl, type: "MX", data: "#{priority} #{mail_server}"}])
end

#create_records(zone, records) ⇒ Object

Create new DNS record(s) records: Array of hashes with keys: host, ttl, type, data Example: [{ host: 'www', ttl: 300, type: 'A', data: '1.2.3.4' }]



29
30
31
# File 'lib/mythic_beasts/dns.rb', line 29

def create_records(zone, records)
  client.post("/dns/v2/zones/#{zone}/records", body: {records: records})
end

#create_txt_record(zone, host, text, ttl: 300) ⇒ Object



74
75
76
# File 'lib/mythic_beasts/dns.rb', line 74

def create_txt_record(zone, host, text, ttl: 300)
  create_records(zone, [{host: host, ttl: ttl, type: "TXT", data: text}])
end

#delete_records(zone, host: nil, type: nil, data: nil) ⇒ Object

Delete record(s)



43
44
45
46
47
48
49
50
# File 'lib/mythic_beasts/dns.rb', line 43

def delete_records(zone, host: nil, type: nil, data: nil)
  path = "/dns/v2/zones/#{zone}/records"
  path += "/#{host}" if host
  path += "/#{type}" if type

  params = data ? {data: data} : {}
  client.delete(path, params: params)
end

#dynamic_update(host) ⇒ Object

Dynamic DNS update - updates A/AAAA record to client IP



53
54
55
# File 'lib/mythic_beasts/dns.rb', line 53

def dynamic_update(host)
  client.put("/dns/v2/dynamic/#{host}")
end

#get_record(zone, host, type) ⇒ Object

Get specific record(s) by host and type



22
23
24
# File 'lib/mythic_beasts/dns.rb', line 22

def get_record(zone, host, type)
  client.get("/dns/v2/zones/#{zone}/records/#{host}/#{type}")
end

#records(zone) ⇒ Object

Get all records for a zone



17
18
19
# File 'lib/mythic_beasts/dns.rb', line 17

def records(zone)
  client.get("/dns/v2/zones/#{zone}/records")
end

#update_records(zone, records, host: nil, type: nil) ⇒ Object

Replace record(s)



34
35
36
37
38
39
40
# File 'lib/mythic_beasts/dns.rb', line 34

def update_records(zone, records, host: nil, type: nil)
  path = "/dns/v2/zones/#{zone}/records"
  path += "/#{host}" if host
  path += "/#{type}" if type

  client.put(path, body: {records: records})
end

#verify_dkim(zone, selector) ⇒ MythicBeasts::DNS::EmailAuth::CheckResult

Verify DKIM record for a specific selector

Parameters:

  • zone (String)

    the domain to verify

  • selector (String)

    the DKIM selector

Returns:



108
109
110
# File 'lib/mythic_beasts/dns.rb', line 108

def verify_dkim(zone, selector)
  EmailAuth.new(self, zone).verify_dkim(selector)
end

#verify_dmarc(zone) ⇒ MythicBeasts::DNS::EmailAuth::CheckResult

Verify DMARC record for a zone

Parameters:

  • zone (String)

    the domain to verify

Returns:



99
100
101
# File 'lib/mythic_beasts/dns.rb', line 99

def verify_dmarc(zone)
  EmailAuth.new(self, zone).verify_dmarc
end

#verify_email_auth(zone, dkim_selectors: []) ⇒ MythicBeasts::DNS::EmailAuth::Result

Verify all email authentication records (SPF, DKIM, DMARC) for a zone

Parameters:

  • zone (String)

    the domain to verify

  • dkim_selectors (Array<String>) (defaults to: [])

    DKIM selectors to check

Returns:



83
84
85
# File 'lib/mythic_beasts/dns.rb', line 83

def verify_email_auth(zone, dkim_selectors: [])
  EmailAuth.new(self, zone).verify(dkim_selectors: dkim_selectors)
end

#verify_spf(zone) ⇒ MythicBeasts::DNS::EmailAuth::CheckResult

Verify SPF record for a zone

Parameters:

  • zone (String)

    the domain to verify

Returns:



91
92
93
# File 'lib/mythic_beasts/dns.rb', line 91

def verify_spf(zone)
  EmailAuth.new(self, zone).verify_spf
end

#zonesObject

List all DNS zones



12
13
14
# File 'lib/mythic_beasts/dns.rb', line 12

def zones
  client.get("/dns/v2/zones")
end