From 44b7c6880dcf4e793fc18d05cf0fb2afe163dc29 Mon Sep 17 00:00:00 2001 From: Ross McFarland Date: Thu, 5 Aug 2021 08:57:29 -0700 Subject: [PATCH] Implement AcmeIgnoringProcessor --- octodns/processor/acme.py | 33 ++++++++++++++++++ tests/test_octodns_processor_acme.py | 51 ++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 octodns/processor/acme.py create mode 100644 tests/test_octodns_processor_acme.py diff --git a/octodns/processor/acme.py b/octodns/processor/acme.py new file mode 100644 index 0000000..e786859 --- /dev/null +++ b/octodns/processor/acme.py @@ -0,0 +1,33 @@ +# +# +# + +from __future__ import absolute_import, division, print_function, \ + unicode_literals + +from logging import getLogger + +from .base import BaseProcessor + + +class AcmeIgnoringProcessor(BaseProcessor): + log = getLogger('AcmeIgnoringProcessor') + + def __init__(self, name): + super(AcmeIgnoringProcessor, self).__init__(name) + + def _process(self, zone, *args, **kwargs): + ret = self._clone_zone(zone) + for record in zone.records: + # Uses a startswith rather than == to ignore subdomain challenges, + # e.g. _acme-challenge.foo.domain.com when managing domain.com + if record._type == 'TXT' and \ + record.name.startswith('_acme-challenge'): + self.log.info('_process: ignoring %s', record.fqdn) + continue + ret.add_record(record) + + return ret + + process_source_zone = _process + process_target_zone = _process diff --git a/tests/test_octodns_processor_acme.py b/tests/test_octodns_processor_acme.py new file mode 100644 index 0000000..aae55ba --- /dev/null +++ b/tests/test_octodns_processor_acme.py @@ -0,0 +1,51 @@ +# +# +# + +from __future__ import absolute_import, division, print_function, \ + unicode_literals + +from unittest import TestCase + +from octodns.processor.acme import AcmeIgnoringProcessor +from octodns.record import Record +from octodns.zone import Zone + +zone = Zone('unit.tests.', []) +for record in [ + # Will be ignored + Record.new(zone, '_acme-challenge', { + 'ttl': 30, + 'type': 'TXT', + 'value': 'magic bit', + }), + # Not TXT so will live + Record.new(zone, '_acme-challenge.aaaa', { + 'ttl': 30, + 'type': 'AAAA', + 'value': '::1', + }), + # Will be ignored + Record.new(zone, '_acme-challenge.foo', { + 'ttl': 30, + 'type': 'TXT', + 'value': 'magic bit', + }), + # Not acme-challenge so will live + Record.new(zone, 'txt', { + 'ttl': 30, + 'type': 'TXT', + 'value': 'Hello World!', + }), +]: + zone.add_record(record) + + +class TestAcmeIgnoringProcessor(TestCase): + + def test_basics(self): + acme = AcmeIgnoringProcessor('acme') + + got = acme.process_source_zone(zone) + self.assertEquals(['_acme-challenge.aaaa', 'txt'], + sorted([r.name for r in got.records]))