Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark only supported record types as proxied #117

Merged
merged 4 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions octodns_cloudflare/processor/ttl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#
#

from octodns.processor.base import BaseProcessor, ProcessorException
from octodns.processor.base import BaseProcessor

from octodns_cloudflare import _PROXIABLE_RECORD_TYPES


class TtlToProxy(BaseProcessor):
Expand Down Expand Up @@ -34,11 +36,12 @@ def __init__(self, name, ttl=0):
def process_source_zone(self, zone, *args, **kwargs):
for record in zone.records:
if record.ttl == self.ttl:
attr = {'auto-ttl': True}
if record._type in _PROXIABLE_RECORD_TYPES:
attr['proxied'] = True

record = record.copy()
record._octodns['cloudflare'] = {
'proxied': True,
'auto-ttl': True,
}
record._octodns['cloudflare'] = attr
record.ttl = 1
# Ensure we set to valid TTL.
zone.add_record(record, replace=True, lenient=True)
Expand Down
18 changes: 18 additions & 0 deletions tests/test_octodns_provider_cloudflare_processor_ttl.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ def test_ttl_to_proxy(self):
with_ttl = Record.new(
zone, 'good', {'type': 'A', 'ttl': 0, 'value': '1.2.3.4'}
)
with_ttl_type_other = Record.new(
zone, 'ttl-only', {'type': 'TXT', 'ttl': 0, 'value': 'acme'}
)
without_ttl = Record.new(
zone, 'bad', {'type': 'A', 'ttl': 10, 'value': '1.2.3.4'}
)
zone.add_record(with_ttl)
zone.add_record(with_ttl_type_other)
zone.add_record(without_ttl)

expected_with = Record.new(
Expand All @@ -32,10 +36,21 @@ def test_ttl_to_proxy(self):
'_octodns': {'cloudflare': {'proxied': True, 'auto-ttl': True}},
},
)
expected_with_ttl_only = Record.new(
zone,
'ttl-only',
{
'type': 'TXT',
'ttl': 0,
'value': '1.2.3.4',
'_octodns': {'cloudflare': {'auto-ttl': True}},
},
)
expected_without = Record.new(
zone, 'bad', {'type': 'A', 'ttl': 10, 'value': '1.2.3.4'}
)
zone_expected.add_record(expected_with)
zone_expected.add_record(expected_with_ttl_only)
zone_expected.add_record(expected_without)

added_proxy = processor.process_source_zone(zone)
Expand All @@ -45,6 +60,9 @@ def test_ttl_to_proxy(self):
self.assertEqual(
{'cloudflare': {'proxied': True, 'auto-ttl': True}}, good._octodns
)
ttl_only = next(r for r in added_proxy.records if r.name == 'ttl-only')
self.assertEqual(1, good.ttl)
self.assertEqual({'cloudflare': {'auto-ttl': True}}, ttl_only._octodns)
bad = next(r for r in added_proxy.records if r.name == 'bad')
self.assertEqual(10, bad.ttl)
self.assertFalse('cloudflare' in bad._octodns)
Loading