Browse Source

Add lenient support to TtlRestrictionFilter

pull/933/head
Ross McFarland 3 years ago
parent
commit
cabdd1222a
No known key found for this signature in database GPG Key ID: 943B179E15D3B22A
2 changed files with 34 additions and 1 deletions
  1. +14
    -0
      octodns/processor/restrict.py
  2. +20
    -1
      tests/test_octodns_processor_restrict.py

+ 14
- 0
octodns/processor/restrict.py View File

@ -38,6 +38,18 @@ class TtlRestrictionFilter(BaseProcessor):
- min-max-ttl
targets:
- azure
The restriction can be skipped for specific records by setting the lenient
flag, e.g.
a:
octodns:
lenient: true
ttl: 0
value: 1.2.3.4
The higher level lenient flags are not checked as it would make more sense
to just avoid enabling the processor in those cases.
'''
SEVEN_DAYS = 60 * 60 * 24 * 7
@ -49,6 +61,8 @@ class TtlRestrictionFilter(BaseProcessor):
def process_source_zone(self, zone, *args, **kwargs):
for record in zone.records:
if record._octodns.get('lenient'):
continue
if record.ttl < self.min_ttl:
raise RestrictionException(
f'{record.fqdn} ttl={record.ttl} too low, min_ttl={self.min_ttl}'


+ 20
- 1
tests/test_octodns_processor_restrict.py View File

@ -40,6 +40,7 @@ class TestTtlRestrictionFilter(TestCase):
restricted = restrictor.process_source_zone(zone)
self.assertEqual(zone.records, restricted.records)
# too low
low = Record.new(
zone, 'low', {'type': 'A', 'ttl': 16, 'value': '1.2.3.4'}
)
@ -51,6 +52,23 @@ class TestTtlRestrictionFilter(TestCase):
'low.unit.tests. ttl=16 too low, min_ttl=32', str(ctx.exception)
)
# with lenient set, we can go lower
lenient = Record.new(
zone,
'low',
{
'octodns': {'lenient': True},
'type': 'A',
'ttl': 16,
'value': '1.2.3.4',
},
)
copy = zone.copy()
copy.add_record(lenient)
restricted = restrictor.process_source_zone(copy)
self.assertEqual(copy.records, restricted.records)
# too high
high = Record.new(
zone, 'high', {'type': 'A', 'ttl': 2048, 'value': '1.2.3.4'}
)
@ -63,7 +81,7 @@ class TestTtlRestrictionFilter(TestCase):
str(ctx.exception),
)
# defaults
# too low defaults
restrictor = TtlRestrictionFilter('test')
low = Record.new(
zone, 'low', {'type': 'A', 'ttl': 0, 'value': '1.2.3.4'}
@ -76,6 +94,7 @@ class TestTtlRestrictionFilter(TestCase):
'low.unit.tests. ttl=0 too low, min_ttl=1', str(ctx.exception)
)
# too high defaults
high = Record.new(
zone, 'high', {'type': 'A', 'ttl': 999999, 'value': '1.2.3.4'}
)


Loading…
Cancel
Save