Skip to content

Commit 51c34b6

Browse files
authored
Merge pull request #117 from alehaa/fix/proxy-ttl
Mark only supported record types as proxied
2 parents 61a4b40 + a4a539e commit 51c34b6

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

octodns_cloudflare/processor/ttl.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
#
33
#
44

5-
from octodns.processor.base import BaseProcessor, ProcessorException
5+
from octodns.processor.base import BaseProcessor
6+
7+
from octodns_cloudflare import _PROXIABLE_RECORD_TYPES
68

79

810
class TtlToProxy(BaseProcessor):
@@ -34,11 +36,12 @@ def __init__(self, name, ttl=0):
3436
def process_source_zone(self, zone, *args, **kwargs):
3537
for record in zone.records:
3638
if record.ttl == self.ttl:
39+
attr = {'auto-ttl': True}
40+
if record._type in _PROXIABLE_RECORD_TYPES:
41+
attr['proxied'] = True
42+
3743
record = record.copy()
38-
record._octodns['cloudflare'] = {
39-
'proxied': True,
40-
'auto-ttl': True,
41-
}
44+
record._octodns['cloudflare'] = attr
4245
record.ttl = 1
4346
# Ensure we set to valid TTL.
4447
zone.add_record(record, replace=True, lenient=True)

tests/test_octodns_provider_cloudflare_processor_ttl.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@ def test_ttl_to_proxy(self):
1616
with_ttl = Record.new(
1717
zone, 'good', {'type': 'A', 'ttl': 0, 'value': '1.2.3.4'}
1818
)
19+
with_ttl_type_other = Record.new(
20+
zone, 'ttl-only', {'type': 'TXT', 'ttl': 0, 'value': 'acme'}
21+
)
1922
without_ttl = Record.new(
2023
zone, 'bad', {'type': 'A', 'ttl': 10, 'value': '1.2.3.4'}
2124
)
2225
zone.add_record(with_ttl)
26+
zone.add_record(with_ttl_type_other)
2327
zone.add_record(without_ttl)
2428

2529
expected_with = Record.new(
@@ -32,10 +36,21 @@ def test_ttl_to_proxy(self):
3236
'_octodns': {'cloudflare': {'proxied': True, 'auto-ttl': True}},
3337
},
3438
)
39+
expected_with_ttl_only = Record.new(
40+
zone,
41+
'ttl-only',
42+
{
43+
'type': 'TXT',
44+
'ttl': 0,
45+
'value': '1.2.3.4',
46+
'_octodns': {'cloudflare': {'auto-ttl': True}},
47+
},
48+
)
3549
expected_without = Record.new(
3650
zone, 'bad', {'type': 'A', 'ttl': 10, 'value': '1.2.3.4'}
3751
)
3852
zone_expected.add_record(expected_with)
53+
zone_expected.add_record(expected_with_ttl_only)
3954
zone_expected.add_record(expected_without)
4055

4156
added_proxy = processor.process_source_zone(zone)
@@ -45,6 +60,9 @@ def test_ttl_to_proxy(self):
4560
self.assertEqual(
4661
{'cloudflare': {'proxied': True, 'auto-ttl': True}}, good._octodns
4762
)
63+
ttl_only = next(r for r in added_proxy.records if r.name == 'ttl-only')
64+
self.assertEqual(1, good.ttl)
65+
self.assertEqual({'cloudflare': {'auto-ttl': True}}, ttl_only._octodns)
4866
bad = next(r for r in added_proxy.records if r.name == 'bad')
4967
self.assertEqual(10, bad.ttl)
5068
self.assertFalse('cloudflare' in bad._octodns)

0 commit comments

Comments
 (0)