Browse Source

Merge pull request #325 from yzguy/cloudflare_unpack

CloudflareProvider: unpack long SRV records correctly
pull/329/head
Ross McFarland 7 years ago
committed by GitHub
parent
commit
bbe57f8ccc
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 71 additions and 2 deletions
  1. +13
    -2
      octodns/provider/cloudflare.py
  2. +58
    -0
      tests/test_octodns_provider_cloudflare.py

+ 13
- 2
octodns/provider/cloudflare.py View File

@ -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,


+ 58
- 0
tests/test_octodns_provider_cloudflare.py View File

@ -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')


Loading…
Cancel
Save