Browse Source

Merge pull request #343 from adhawkins/tinydns-additions

Tinydns additions
pull/354/head
Ross McFarland 7 years ago
committed by GitHub
parent
commit
1deb63bb8c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 80 additions and 3 deletions
  1. +39
    -1
      octodns/source/tinydns.py
  2. +32
    -2
      tests/test_octodns_source_tinydns.py
  3. +9
    -0
      tests/zones/tinydns/example.com

+ 39
- 1
octodns/source/tinydns.py View File

@ -11,6 +11,7 @@ from os import listdir
from os.path import join from os.path import join
import logging import logging
import re import re
import textwrap
from ..record import Record from ..record import Record
from ..zone import DuplicateRecordException, SubzoneRecordException from ..zone import DuplicateRecordException, SubzoneRecordException
@ -20,7 +21,7 @@ from .base import BaseSource
class TinyDnsBaseSource(BaseSource): class TinyDnsBaseSource(BaseSource):
SUPPORTS_GEO = False SUPPORTS_GEO = False
SUPPORTS_DYNAMIC = False SUPPORTS_DYNAMIC = False
SUPPORTS = set(('A', 'CNAME', 'MX', 'NS'))
SUPPORTS = set(('A', 'CNAME', 'MX', 'NS', 'TXT', 'AAAA'))
split_re = re.compile(r':+') split_re = re.compile(r':+')
@ -45,6 +46,40 @@ class TinyDnsBaseSource(BaseSource):
'values': values, 'values': values,
} }
def _data_for_AAAA(self, _type, records):
values = []
for record in records:
# TinyDNS files have the ipv6 address written in full, but with the
# colons removed. This inserts a colon every 4th character to make
# the address correct.
values.append(u":".join(textwrap.wrap(record[0], 4)))
try:
ttl = records[0][1]
except IndexError:
ttl = self.default_ttl
return {
'ttl': ttl,
'type': _type,
'values': values,
}
def _data_for_TXT(self, _type, records):
values = []
for record in records:
new_value = record[0].decode('unicode-escape').replace(";", "\\;")
values.append(new_value)
try:
ttl = records[0][1]
except IndexError:
ttl = self.default_ttl
return {
'ttl': ttl,
'type': _type,
'values': values,
}
def _data_for_CNAME(self, _type, records): def _data_for_CNAME(self, _type, records):
first = records[0] first = records[0]
try: try:
@ -104,6 +139,9 @@ class TinyDnsBaseSource(BaseSource):
'C': 'CNAME', 'C': 'CNAME',
'+': 'A', '+': 'A',
'@': 'MX', '@': 'MX',
'\'': 'TXT',
'3': 'AAAA',
'6': 'AAAA',
} }
name_re = re.compile(r'((?P<name>.+)\.)?{}$'.format(zone.name[:-1])) name_re = re.compile(r'((?P<name>.+)\.)?{}$'.format(zone.name[:-1]))


+ 32
- 2
tests/test_octodns_source_tinydns.py View File

@ -20,7 +20,7 @@ class TestTinyDnsFileSource(TestCase):
def test_populate_normal(self): def test_populate_normal(self):
got = Zone('example.com.', []) got = Zone('example.com.', [])
self.source.populate(got) self.source.populate(got)
self.assertEquals(11, len(got.records))
self.assertEquals(17, len(got.records))
expected = Zone('example.com.', []) expected = Zone('example.com.', [])
for name, data in ( for name, data in (
@ -86,6 +86,36 @@ class TestTinyDnsFileSource(TestCase):
'exchange': 'smtp-2-host.example.com.', 'exchange': 'smtp-2-host.example.com.',
}] }]
}), }),
('', {
'type': 'TXT',
'ttl': 300,
'value': 'test TXT',
}),
('colon', {
'type': 'TXT',
'ttl': 300,
'value': 'test : TXT',
}),
('nottl', {
'type': 'TXT',
'ttl': 3600,
'value': 'nottl test TXT',
}),
('ipv6-3', {
'type': 'AAAA',
'ttl': 300,
'value': '2a02:1348:017c:d5d0:0024:19ff:fef3:5742',
}),
('ipv6-6', {
'type': 'AAAA',
'ttl': 3600,
'value': '2a02:1348:017c:d5d0:0024:19ff:fef3:5743',
}),
('semicolon', {
'type': 'TXT',
'ttl': 300,
'value': 'v=DKIM1\\; k=rsa\\; p=blah',
}),
): ):
record = Record.new(expected, name, data) record = Record.new(expected, name, data)
expected.add_record(record) expected.add_record(record)
@ -173,4 +203,4 @@ class TestTinyDnsFileSource(TestCase):
def test_ignores_subs(self): def test_ignores_subs(self):
got = Zone('example.com.', ['sub']) got = Zone('example.com.', ['sub'])
self.source.populate(got) self.source.populate(got)
self.assertEquals(10, len(got.records))
self.assertEquals(16, len(got.records))

+ 9
- 0
tests/zones/tinydns/example.com View File

@ -46,3 +46,12 @@ Ccname.other.foo:www.other.foo
+a1.blah-asdf.subtest.com:10.2.3.5 +a1.blah-asdf.subtest.com:10.2.3.5
+a2.blah-asdf.subtest.com:10.2.3.6 +a2.blah-asdf.subtest.com:10.2.3.6
+a3.asdf.subtest.com:10.2.3.7 +a3.asdf.subtest.com:10.2.3.7
'example.com:test TXT:300
'colon.example.com:test \072 TXT:300
'nottl.example.com:nottl test TXT
3ipv6-3.example.com:2a021348017cd5d0002419fffef35742:300
6ipv6-6.example.com:2a021348017cd5d0002419fffef35743
'semicolon.example.com:v=DKIM1; k=rsa; p=blah:300

Loading…
Cancel
Save