mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
Utilize shallow copies in Provider._process_desired_zone and Route53Provider._process_desired_zone
This commit is contained in:
@@ -5,8 +5,6 @@
|
||||
from __future__ import absolute_import, division, print_function, \
|
||||
unicode_literals
|
||||
|
||||
from ..zone import Zone
|
||||
|
||||
|
||||
class BaseProcessor(object):
|
||||
|
||||
|
@@ -34,21 +34,29 @@ class BaseProvider(BaseSource):
|
||||
|
||||
def _process_desired_zone(self, desired):
|
||||
'''
|
||||
An opportunity for providers to modify that desired zone records before
|
||||
planning.
|
||||
An opportunity for providers to modify the desired zone records before
|
||||
planning. `desired` is a "shallow" copy, see `Zone.copy` for more
|
||||
information
|
||||
|
||||
- Must do their work and then call super with the results of that work
|
||||
- Must not modify the `desired` parameter or its records and should
|
||||
make a copy of anything it's modifying
|
||||
- Must do their work and then call `super` with the results of that
|
||||
work, returning the result of the `super` call.
|
||||
- Must not modify `desired` directly, should call `desired.copy` and
|
||||
modify the shallow copy returned from that.
|
||||
- Must not modify records directly, `record.copy` should be called,
|
||||
the results of which can be modified, and then `Zone.add_record` may
|
||||
be used with `replace=True`
|
||||
- Must call `Zone.remove_record` to remove records from the copy of
|
||||
`desired`
|
||||
- Must call supports_warn_or_except with information about any changes
|
||||
that are made to have them logged or throw errors depending on the
|
||||
configuration
|
||||
provider configuration
|
||||
'''
|
||||
if self.SUPPORTS_MUTLIVALUE_PTR:
|
||||
# nothing do here
|
||||
return desired
|
||||
|
||||
new_desired = Zone(desired.name, desired.sub_zones)
|
||||
# Shallow copy
|
||||
new_desired = desired.copy()
|
||||
for record in desired.records:
|
||||
if record._type == 'PTR' and len(record.values) > 1:
|
||||
# replace with a single-value copy
|
||||
@@ -59,8 +67,7 @@ class BaseProvider(BaseSource):
|
||||
self.supports_warn_or_except(msg, fallback)
|
||||
record = record.copy()
|
||||
record.values = [record.value]
|
||||
|
||||
new_desired.add_record(record)
|
||||
new_desired.add_record(record, replace=True)
|
||||
|
||||
return new_desired
|
||||
|
||||
|
@@ -19,7 +19,6 @@ from six import text_type
|
||||
from ..equality import EqualityTupleMixin
|
||||
from ..record import Record, Update
|
||||
from ..record.geo import GeoCodes
|
||||
from ..zone import Zone
|
||||
from .base import BaseProvider
|
||||
|
||||
octal_re = re.compile(r'\\(\d\d\d)')
|
||||
@@ -926,11 +925,10 @@ class Route53Provider(BaseProvider):
|
||||
return data
|
||||
|
||||
def _process_desired_zone(self, desired):
|
||||
ret = Zone(desired.name, desired.sub_zones)
|
||||
ret = desired.copy()
|
||||
for record in desired.records:
|
||||
if getattr(record, 'dynamic', False):
|
||||
# Make a copy of the record in case we have to muck with it
|
||||
record = record.copy()
|
||||
dynamic = record.dynamic
|
||||
rules = []
|
||||
for i, rule in enumerate(dynamic.rules):
|
||||
@@ -957,9 +955,10 @@ class Route53Provider(BaseProvider):
|
||||
rule.data['geos'] = filtered_geos
|
||||
rules.append(rule)
|
||||
|
||||
dynamic.rules = rules
|
||||
|
||||
ret.add_record(record)
|
||||
if rules != dynamic.rules:
|
||||
record = record.copy()
|
||||
record.dynamic.rules = rules
|
||||
ret.add_record(record, replace=True)
|
||||
|
||||
return super(Route53Provider, self)._process_desired_zone(ret)
|
||||
|
||||
|
Reference in New Issue
Block a user