1
0
mirror of https://github.com/github/octodns.git synced 2024-05-11 05:55:00 +00:00

Add -all option to octodns-validate, to enable showing of all record validation issues

This commit is contained in:
Ross McFarland
2023-08-04 15:57:44 -07:00
parent fc76b1d604
commit 349c8b6f56
2 changed files with 28 additions and 5 deletions

View File

@@ -3,12 +3,23 @@
Octo-DNS Validator
'''
from logging import WARN
from logging import WARNING, getLogger
from sys import exit
from octodns.cmds.args import ArgumentParser
from octodns.manager import Manager
class FlaggingHandler:
level = WARNING
def __init__(self):
self.flag = False
def handle(self, record):
self.flag = True
def main():
parser = ArgumentParser(description=__doc__.split('\n')[1])
@@ -17,11 +28,23 @@ def main():
required=True,
help='The Manager configuration file to use',
)
parser.add_argument(
'--all',
action='store_true',
default=False,
help='Validate records in lenient mode, printing warnings so that all validation issues are shown',
)
args = parser.parse_args(WARN)
args = parser.parse_args(WARNING)
flagging = FlaggingHandler()
getLogger('Record').addHandler(flagging)
manager = Manager(args.config_file)
manager.validate_configs()
manager.validate_configs(lenient=args.all)
if flagging.flag:
exit(1)
if __name__ == '__main__':

View File

@@ -807,7 +807,7 @@ class Manager(object):
plan = Plan(zone, zone, [], False)
target.apply(plan)
def validate_configs(self):
def validate_configs(self, lenient=False):
# TODO: this code can probably be shared with stuff in sync
for zone_name, config in self.config['zones'].items():
decoded_zone_name = idna_decode(zone_name)
@@ -836,7 +836,6 @@ class Manager(object):
source_zone = source_zone
continue
lenient = config.get('lenient', False)
try:
sources = config['sources']
except KeyError:
@@ -857,6 +856,7 @@ class Manager(object):
f'Zone {decoded_zone_name}, unknown source: ' + source
)
lenient = lenient or config.get('lenient', False)
for source in sources:
if isinstance(source, YamlProvider):
source.populate(zone, lenient=lenient)