mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
populating existing provider state is lenient
- adds lenient flag to Record.new, problems during validation are just warnings if it's true - target populate calls during the plan phase pass lenient=True - make all of the provider.populate call logging consistent including both target and lenient - add source=self to Record.new in a few places that were missing it
This commit is contained in:
@@ -23,6 +23,14 @@ class BaseSource(object):
|
||||
def populate(self, zone, target=False):
|
||||
'''
|
||||
Loads all zones the provider knows about
|
||||
|
||||
When `target` is True the populate call is being made to load the
|
||||
current state of the provider.
|
||||
|
||||
When `lenient` is True the populate call may skip record validation and
|
||||
do a "best effort" load of data. That will allow through some common,
|
||||
but not best practices stuff that we otherwise would reject. E.g. no
|
||||
trailing . or mising escapes for ;.
|
||||
'''
|
||||
raise NotImplementedError('Abstract base class, populate method '
|
||||
'missing')
|
||||
|
@@ -81,19 +81,21 @@ class TinyDnsBaseSource(BaseSource):
|
||||
'values': ['{}.'.format(r[0]) for r in records]
|
||||
}
|
||||
|
||||
def populate(self, zone, target=False):
|
||||
self.log.debug('populate: zone=%s', zone.name)
|
||||
def populate(self, zone, target=False, lenient=False):
|
||||
self.log.debug('populate: name=%s, target=%s, lenient=%s', zone.name,
|
||||
target, lenient)
|
||||
|
||||
before = len(zone.records)
|
||||
|
||||
if zone.name.endswith('in-addr.arpa.'):
|
||||
self._populate_in_addr_arpa(zone)
|
||||
self._populate_in_addr_arpa(zone, lenient)
|
||||
else:
|
||||
self._populate_normal(zone)
|
||||
self._populate_normal(zone, lenient)
|
||||
|
||||
self.log.info('populate: found %s records',
|
||||
len(zone.records) - before)
|
||||
|
||||
def _populate_normal(self, zone):
|
||||
def _populate_normal(self, zone, lenient):
|
||||
type_map = {
|
||||
'=': 'A',
|
||||
'^': None,
|
||||
@@ -129,14 +131,15 @@ class TinyDnsBaseSource(BaseSource):
|
||||
data_for = getattr(self, '_data_for_{}'.format(_type))
|
||||
data = data_for(_type, d)
|
||||
if data:
|
||||
record = Record.new(zone, name, data, source=self)
|
||||
record = Record.new(zone, name, data, source=self,
|
||||
lenient=lenient)
|
||||
try:
|
||||
zone.add_record(record)
|
||||
except SubzoneRecordException:
|
||||
self.log.debug('_populate_normal: skipping subzone '
|
||||
'record=%s', record)
|
||||
|
||||
def _populate_in_addr_arpa(self, zone):
|
||||
def _populate_in_addr_arpa(self, zone, lenient):
|
||||
name_re = re.compile('(?P<name>.+)\.{}$'.format(zone.name[:-1]))
|
||||
|
||||
for line in self._lines():
|
||||
@@ -170,7 +173,7 @@ class TinyDnsBaseSource(BaseSource):
|
||||
'ttl': ttl,
|
||||
'type': 'PTR',
|
||||
'value': value
|
||||
}, source=self)
|
||||
}, source=self, lenient=lenient)
|
||||
try:
|
||||
zone.add_record(record)
|
||||
except DuplicateRecordException:
|
||||
|
Reference in New Issue
Block a user