mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
c5a9ba518b
* `Processors.process_zone_config` method added to allow processors that work with the zone config data. Configured with `manager.zone-processors: []`, default is ['dynamic-zone-config'] * Converted dynamic zone config to be a processors ^, if zone-processors are explicitely configured and dynamic zone config is desired `dyanmic-zone-config` must be included in the list as the desired position * Loads of additional testin/vetting for the above functionality
46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
#
|
|
#
|
|
#
|
|
|
|
from logging import getLogger
|
|
|
|
from .base import BaseProcessor, ProcessorException
|
|
|
|
|
|
class DynamicZoneConfigProcessor(BaseProcessor):
|
|
log = getLogger('DynamicZoneConfigProcessor')
|
|
|
|
def process_zone_config(self, zones, get_sources):
|
|
for name, config in list(zones.items()):
|
|
if not name.startswith('*'):
|
|
continue
|
|
# we've found a dynamic config element
|
|
|
|
# find its sources
|
|
found_sources = get_sources(name, config)
|
|
|
|
self.log.info(
|
|
'sync: dynamic zone=%s, sources=%s', name, found_sources
|
|
)
|
|
for source in found_sources:
|
|
if not hasattr(source, 'list_zones'):
|
|
raise ProcessorException(
|
|
f'dynamic zone={name} includes a source, {source.id}, that does not support `list_zones`'
|
|
)
|
|
for zone_name in source.list_zones():
|
|
if zone_name in zones:
|
|
self.log.info(
|
|
'sync: zone=%s already in config, ignoring',
|
|
zone_name,
|
|
)
|
|
continue
|
|
self.log.info(
|
|
'sync: adding dynamic zone=%s', zone_name
|
|
)
|
|
zones[zone_name] = config
|
|
|
|
# remove the dynamic config element so we don't try and populate it
|
|
del zones[name]
|
|
|
|
return zones
|