1
0
mirror of https://github.com/github/octodns.git synced 2024-05-11 05:55:00 +00:00

Explicit handling of SRV & CAA in _gen_key, tests for those cases

This commit is contained in:
Ross McFarland
2018-10-16 07:08:01 -07:00
parent 0c33d3acac
commit aee786dd01
2 changed files with 49 additions and 23 deletions

View File

@@ -341,19 +341,26 @@ class CloudflareProvider(BaseProvider):
yield content yield content
def _gen_key(self, data): def _gen_key(self, data):
# Note that all CF records have a `content` field the value of which # Note that most CF record data has a `content` field the value of
# appears to be a unique/hashable string for the record's. It includes # which is a unique/hashable string for the record's. It includes all
# all the "value" bits, but not the secondary stuff like TTL's. E.g. # the "value" bits, but not the secondary stuff like TTL's. E.g. for
# for an A it'll include the value, for a CAA it'll include the flags, # an A it'll include the value, for a CAA it'll include the flags, tag,
# tag, and value, ... We'll take advantage of this to try and match up # and value, ... We'll take advantage of this to try and match up old &
# old & new records cleanly. In general when there are multiple records # new records cleanly. In general when there are multiple records for a
# for a name & type each will have a distinct/consistent `content` that # name & type each will have a distinct/consistent `content` that can
# can serve as a unique identifier. # serve as a unique identifier.
# BUT... there's an exception. For some reason MX doesn't include # BUT... there are exceptions. MX, CAA, and SRV don't have a simple
# priority in its `content` so it's an odd-ball. I haven't found any # content as things are currently implemented so we need to handle
# others so hopefully they don't exist :-( # those explicitly and create unique/hashable strings for them.
if data['type'] == 'MX': _type = data['type']
return '{} {}'.format(data['priority'], data['content']) if _type == 'MX':
return '{priority} {content}'.format(**data)
elif _type == 'CAA':
data = data['data']
return '{flags} {tag} {value}'.format(**data)
elif _type == 'SRV':
data = data['data']
return '{port} {priority} {target} {weight}'.format(**data)
return data['content'] return data['content']
def _apply_Create(self, change): def _apply_Create(self, change):

View File

@@ -539,16 +539,35 @@ class TestCloudflareProvider(TestCase):
def test_gen_key(self): def test_gen_key(self):
provider = CloudflareProvider('test', 'email', 'token') provider = CloudflareProvider('test', 'email', 'token')
self.assertEqual('10 foo.bar.com.', provider._gen_key({ for expected, data in (
'content': 'foo.bar.com.', ('foo.bar.com.', {
'priority': 10, 'content': 'foo.bar.com.',
'type': 'MX', 'type': 'CNAME',
})) }),
('10 foo.bar.com.', {
self.assertEqual('foo.bar.com.', provider._gen_key({ 'content': 'foo.bar.com.',
'content': 'foo.bar.com.', 'priority': 10,
'type': 'CNAME', 'type': 'MX',
})) }),
('0 tag some-value', {
'data': {
'flags': 0,
'tag': 'tag',
'value': 'some-value',
},
'type': 'CAA',
}),
('42 100 thing-were-pointed.at 101', {
'data': {
'port': 42,
'priority': 100,
'target': 'thing-were-pointed.at',
'weight': 101,
},
'type': 'SRV',
}),
):
self.assertEqual(expected, provider._gen_key(data))
def test_cdn(self): def test_cdn(self):
provider = CloudflareProvider('test', 'email', 'token', True) provider = CloudflareProvider('test', 'email', 'token', True)