mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
Merge branch 'main' into ensure-trailing-dots-fix
This commit is contained in:
@@ -12,19 +12,26 @@ from .base import BaseProcessor
|
||||
|
||||
class AutoArpa(BaseProcessor):
|
||||
def __init__(
|
||||
self, name, ttl=3600, populate_should_replace=False, max_auto_arpa=999
|
||||
self,
|
||||
name,
|
||||
ttl=3600,
|
||||
populate_should_replace=False,
|
||||
max_auto_arpa=999,
|
||||
inherit_ttl=False,
|
||||
):
|
||||
super().__init__(name)
|
||||
self.log = getLogger(f'AutoArpa[{name}]')
|
||||
self.log.info(
|
||||
'__init__: ttl=%d, populate_should_replace=%s, max_auto_arpa=%d',
|
||||
'__init__: ttl=%d, populate_should_replace=%s, max_auto_arpa=%d, inherit_ttl=%s',
|
||||
ttl,
|
||||
populate_should_replace,
|
||||
max_auto_arpa,
|
||||
inherit_ttl,
|
||||
)
|
||||
self.ttl = ttl
|
||||
self.populate_should_replace = populate_should_replace
|
||||
self.max_auto_arpa = max_auto_arpa
|
||||
self.inherit_ttl = inherit_ttl
|
||||
self._records = defaultdict(list)
|
||||
|
||||
def process_source_zone(self, desired, sources):
|
||||
@@ -44,8 +51,12 @@ class AutoArpa(BaseProcessor):
|
||||
auto_arpa_priority = record.octodns.get(
|
||||
'auto_arpa_priority', 999
|
||||
)
|
||||
if self.inherit_ttl:
|
||||
record_ttl = record.ttl
|
||||
else:
|
||||
record_ttl = self.ttl
|
||||
self._records[f'{ptr}.'].append(
|
||||
(auto_arpa_priority, record.fqdn)
|
||||
(auto_arpa_priority, record_ttl, record.fqdn)
|
||||
)
|
||||
|
||||
return desired
|
||||
@@ -55,10 +66,10 @@ class AutoArpa(BaseProcessor):
|
||||
# order the fqdns making a copy so we can reset the list below
|
||||
ordered = sorted(fqdns)
|
||||
fqdns = []
|
||||
for _, fqdn in ordered:
|
||||
for _, record_ttl, fqdn in ordered:
|
||||
if fqdn in seen:
|
||||
continue
|
||||
fqdns.append(fqdn)
|
||||
fqdns.append((record_ttl, fqdn))
|
||||
seen.add(fqdn)
|
||||
if len(seen) >= max_auto_arpa:
|
||||
break
|
||||
@@ -79,12 +90,16 @@ class AutoArpa(BaseProcessor):
|
||||
for arpa, fqdns in self._records.items():
|
||||
if arpa.endswith(f'.{zone_name}'):
|
||||
name = arpa[:-n]
|
||||
# Note: this takes a list of (priority, fqdn) tuples and returns the ordered and uniqified list of fqdns.
|
||||
# Note: this takes a list of (priority, ttl, fqdn) tuples and returns the ordered and uniqified list of fqdns.
|
||||
fqdns = self._order_and_unique_fqdns(fqdns, self.max_auto_arpa)
|
||||
record = Record.new(
|
||||
zone,
|
||||
name,
|
||||
{'ttl': self.ttl, 'type': 'PTR', 'values': fqdns},
|
||||
{
|
||||
'ttl': fqdns[0][0],
|
||||
'type': 'PTR',
|
||||
'values': [fqdn[1] for fqdn in fqdns],
|
||||
},
|
||||
lenient=lenient,
|
||||
)
|
||||
zone.add_record(
|
||||
@@ -92,7 +107,6 @@ class AutoArpa(BaseProcessor):
|
||||
replace=self.populate_should_replace,
|
||||
lenient=lenient,
|
||||
)
|
||||
|
||||
self.log.info(
|
||||
'populate: found %s records', len(zone.records) - before
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user