mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
Merge pull request #343 from adhawkins/tinydns-additions
Tinydns additions
This commit is contained in:
Regular → Executable
+39
-1
@@ -11,6 +11,7 @@ from os import listdir
|
||||
from os.path import join
|
||||
import logging
|
||||
import re
|
||||
import textwrap
|
||||
|
||||
from ..record import Record
|
||||
from ..zone import DuplicateRecordException, SubzoneRecordException
|
||||
@@ -20,7 +21,7 @@ from .base import BaseSource
|
||||
class TinyDnsBaseSource(BaseSource):
|
||||
SUPPORTS_GEO = False
|
||||
SUPPORTS_DYNAMIC = False
|
||||
SUPPORTS = set(('A', 'CNAME', 'MX', 'NS'))
|
||||
SUPPORTS = set(('A', 'CNAME', 'MX', 'NS', 'TXT', 'AAAA'))
|
||||
|
||||
split_re = re.compile(r':+')
|
||||
|
||||
@@ -45,6 +46,40 @@ class TinyDnsBaseSource(BaseSource):
|
||||
'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):
|
||||
first = records[0]
|
||||
try:
|
||||
@@ -104,6 +139,9 @@ class TinyDnsBaseSource(BaseSource):
|
||||
'C': 'CNAME',
|
||||
'+': 'A',
|
||||
'@': 'MX',
|
||||
'\'': 'TXT',
|
||||
'3': 'AAAA',
|
||||
'6': 'AAAA',
|
||||
}
|
||||
name_re = re.compile(r'((?P<name>.+)\.)?{}$'.format(zone.name[:-1]))
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ class TestTinyDnsFileSource(TestCase):
|
||||
def test_populate_normal(self):
|
||||
got = Zone('example.com.', [])
|
||||
self.source.populate(got)
|
||||
self.assertEquals(11, len(got.records))
|
||||
self.assertEquals(17, len(got.records))
|
||||
|
||||
expected = Zone('example.com.', [])
|
||||
for name, data in (
|
||||
@@ -86,6 +86,36 @@ class TestTinyDnsFileSource(TestCase):
|
||||
'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)
|
||||
expected.add_record(record)
|
||||
@@ -173,4 +203,4 @@ class TestTinyDnsFileSource(TestCase):
|
||||
def test_ignores_subs(self):
|
||||
got = Zone('example.com.', ['sub'])
|
||||
self.source.populate(got)
|
||||
self.assertEquals(10, len(got.records))
|
||||
self.assertEquals(16, len(got.records))
|
||||
|
||||
Regular → Executable
+9
@@ -46,3 +46,12 @@ Ccname.other.foo:www.other.foo
|
||||
+a1.blah-asdf.subtest.com:10.2.3.5
|
||||
+a2.blah-asdf.subtest.com:10.2.3.6
|
||||
+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
|
||||
|
||||
Reference in New Issue
Block a user