mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
Merge pull request #325 from yzguy/cloudflare_unpack
CloudflareProvider: unpack long SRV records correctly
This commit is contained in:
@@ -340,13 +340,24 @@ class CloudflareProvider(BaseProvider):
|
||||
}
|
||||
|
||||
def _contents_for_SRV(self, record):
|
||||
service, proto = record.name.split('.', 2)
|
||||
try:
|
||||
service, proto, subdomain = record.name.split('.', 2)
|
||||
# We have a SRV in a sub-zone
|
||||
except ValueError:
|
||||
# We have a SRV in the zone
|
||||
service, proto = record.name.split('.', 1)
|
||||
subdomain = None
|
||||
|
||||
name = record.zone.name
|
||||
if subdomain:
|
||||
name = subdomain
|
||||
|
||||
for value in record.values:
|
||||
yield {
|
||||
'data': {
|
||||
'service': service,
|
||||
'proto': proto,
|
||||
'name': record.zone.name,
|
||||
'name': name,
|
||||
'priority': value.priority,
|
||||
'weight': value.weight,
|
||||
'port': value.port,
|
||||
|
||||
@@ -509,6 +509,64 @@ class TestCloudflareProvider(TestCase):
|
||||
'fc12ab34cd5611334422ab3322997653')
|
||||
])
|
||||
|
||||
def test_srv(self):
|
||||
provider = CloudflareProvider('test', 'email', 'token')
|
||||
|
||||
zone = Zone('unit.tests.', [])
|
||||
# SRV record not under a sub-domain
|
||||
srv_record = Record.new(zone, '_example._tcp', {
|
||||
'ttl': 300,
|
||||
'type': 'SRV',
|
||||
'value': {
|
||||
'port': 1234,
|
||||
'priority': 0,
|
||||
'target': 'nc.unit.tests.',
|
||||
'weight': 5
|
||||
}
|
||||
})
|
||||
# SRV record under a sub-domain
|
||||
srv_record_with_sub = Record.new(zone, '_example._tcp.sub', {
|
||||
'ttl': 300,
|
||||
'type': 'SRV',
|
||||
'value': {
|
||||
'port': 1234,
|
||||
'priority': 0,
|
||||
'target': 'nc.unit.tests.',
|
||||
'weight': 5
|
||||
}
|
||||
})
|
||||
|
||||
srv_record_contents = provider._gen_data(srv_record)
|
||||
srv_record_with_sub_contents = provider._gen_data(srv_record_with_sub)
|
||||
self.assertEquals({
|
||||
'name': '_example._tcp.unit.tests',
|
||||
'ttl': 300,
|
||||
'type': 'SRV',
|
||||
'data': {
|
||||
'service': '_example',
|
||||
'proto': '_tcp',
|
||||
'name': 'unit.tests.',
|
||||
'priority': 0,
|
||||
'weight': 5,
|
||||
'port': 1234,
|
||||
'target': 'nc.unit.tests'
|
||||
}
|
||||
}, list(srv_record_contents)[0])
|
||||
self.assertEquals({
|
||||
'name': '_example._tcp.sub.unit.tests',
|
||||
'ttl': 300,
|
||||
'type': 'SRV',
|
||||
'data': {
|
||||
'service': '_example',
|
||||
'proto': '_tcp',
|
||||
'name': 'sub',
|
||||
'priority': 0,
|
||||
'weight': 5,
|
||||
'port': 1234,
|
||||
'target': 'nc.unit.tests'
|
||||
}
|
||||
}, list(srv_record_with_sub_contents)[0])
|
||||
|
||||
def test_alias(self):
|
||||
provider = CloudflareProvider('test', 'email', 'token')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user