diff --git a/octodns/processor/restrict.py b/octodns/processor/restrict.py index c23e038..8afc0a5 100644 --- a/octodns/processor/restrict.py +++ b/octodns/processor/restrict.py @@ -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}' diff --git a/tests/test_octodns_processor_restrict.py b/tests/test_octodns_processor_restrict.py index bab5b88..9aae744 100644 --- a/tests/test_octodns_processor_restrict.py +++ b/tests/test_octodns_processor_restrict.py @@ -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'} )