mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
Allow proxied records with the same name
This commit is contained in:
@@ -227,6 +227,15 @@ class CloudflareProvider(BaseProvider):
|
||||
|
||||
record = Record.new(zone, name, data, source=self,
|
||||
lenient=lenient)
|
||||
|
||||
# only one rewrite is needed for names where the proxy is
|
||||
# enabled at multiple records with a different type but
|
||||
# the same name
|
||||
if (self.cdn and records[0]['proxied'] and
|
||||
record in zone._records[name]):
|
||||
self.log.info('CDN rewrite %s already in zone', name)
|
||||
continue
|
||||
|
||||
zone.add_record(record)
|
||||
|
||||
self.log.info('populate: found %s records',
|
||||
@@ -240,12 +249,18 @@ class CloudflareProvider(BaseProvider):
|
||||
if new == existing:
|
||||
return False
|
||||
|
||||
# If this is a record to enable to Cloudflare CDN don't update as
|
||||
# If this is a record to enable Cloudflare CDN don't update as
|
||||
# we don't know the original values.
|
||||
if (hasattr(change.new, '_type') and (change.new._type == 'CNAME' or
|
||||
change.new._type == 'ALIAS') and
|
||||
if (hasattr(change.new, '_type') and
|
||||
(change.new._type == 'CNAME' or
|
||||
change.new._type == 'ALIAS') and
|
||||
change.new.value.endswith('.cdn.cloudflare.net.')):
|
||||
return False
|
||||
if (hasattr(change.existing, '_type') and
|
||||
(change.existing._type == 'CNAME' or
|
||||
change.existing._type == 'ALIAS') and
|
||||
change.existing.value.endswith('.cdn.cloudflare.net.')):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@@ -541,21 +541,61 @@ class TestCloudflareProvider(TestCase):
|
||||
"auto_added": False
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "fc12ab34cd5611334422ab3322997642",
|
||||
"type": "A",
|
||||
"name": "multi.unit.tests",
|
||||
"content": "1.1.1.3",
|
||||
"proxiable": True,
|
||||
"proxied": True,
|
||||
"ttl": 300,
|
||||
"locked": False,
|
||||
"zone_id": "ff12ab34cd5611334422ab3322997650",
|
||||
"zone_name": "unit.tests",
|
||||
"modified_on": "2017-03-11T18:01:43.420689Z",
|
||||
"created_on": "2017-03-11T18:01:43.420689Z",
|
||||
"meta": {
|
||||
"auto_added": False
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "fc12ab34cd5611334422ab3322997642",
|
||||
"type": "AAAA",
|
||||
"name": "multi.unit.tests",
|
||||
"content": "::1",
|
||||
"proxiable": True,
|
||||
"proxied": True,
|
||||
"ttl": 300,
|
||||
"locked": False,
|
||||
"zone_id": "ff12ab34cd5611334422ab3322997650",
|
||||
"zone_name": "unit.tests",
|
||||
"modified_on": "2017-03-11T18:01:43.420689Z",
|
||||
"created_on": "2017-03-11T18:01:43.420689Z",
|
||||
"meta": {
|
||||
"auto_added": False
|
||||
}
|
||||
},
|
||||
])
|
||||
|
||||
zone = Zone('unit.tests.', [])
|
||||
provider.populate(zone)
|
||||
|
||||
# the two A records get merged into one CNAME record poining to the CDN
|
||||
self.assertEquals(2, len(zone.records))
|
||||
self.assertEquals(3, len(zone.records))
|
||||
|
||||
record = list(zone.records)[0]
|
||||
self.assertEquals('multi', record.name)
|
||||
self.assertEquals('multi.unit.tests.', record.fqdn)
|
||||
self.assertEquals('CNAME', record._type)
|
||||
self.assertEquals('multi.unit.tests.cdn.cloudflare.net.', record.value)
|
||||
|
||||
record = list(zone.records)[1]
|
||||
self.assertEquals('cname', record.name)
|
||||
self.assertEquals('cname.unit.tests.', record.fqdn)
|
||||
self.assertEquals('CNAME', record._type)
|
||||
self.assertEquals('cname.unit.tests.cdn.cloudflare.net.', record.value)
|
||||
|
||||
record = list(zone.records)[1]
|
||||
record = list(zone.records)[2]
|
||||
self.assertEquals('a', record.name)
|
||||
self.assertEquals('a.unit.tests.', record.fqdn)
|
||||
self.assertEquals('CNAME', record._type)
|
||||
@@ -574,6 +614,11 @@ class TestCloudflareProvider(TestCase):
|
||||
'type': 'CNAME',
|
||||
'value': 'new.unit.tests.cdn.cloudflare.net.'
|
||||
}))
|
||||
wanted.add_record(Record.new(wanted, 'created', {
|
||||
'ttl': 300,
|
||||
'type': 'CNAME',
|
||||
'value': 'www.unit.tests.'
|
||||
}))
|
||||
|
||||
plan = provider.plan(wanted)
|
||||
self.assertEquals(1, len(plan.changes))
|
||||
|
||||
Reference in New Issue
Block a user