From 349c8b6f56d90855d49c908ff8df57a120450381 Mon Sep 17 00:00:00 2001 From: Ross McFarland Date: Fri, 4 Aug 2023 15:57:44 -0700 Subject: [PATCH 1/3] Add -all option to octodns-validate, to enable showing of all record validation issues --- octodns/cmds/validate.py | 29 ++++++++++++++++++++++++++--- octodns/manager.py | 4 ++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/octodns/cmds/validate.py b/octodns/cmds/validate.py index b69f856..8120835 100755 --- a/octodns/cmds/validate.py +++ b/octodns/cmds/validate.py @@ -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__': diff --git a/octodns/manager.py b/octodns/manager.py index 3291437..e429fe2 100644 --- a/octodns/manager.py +++ b/octodns/manager.py @@ -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) From 3ffd4070f24814ed2ee7d1132fe98d3b2cca6ca2 Mon Sep 17 00:00:00 2001 From: Ross McFarland Date: Sun, 6 Aug 2023 09:23:01 -0700 Subject: [PATCH 2/3] changelog entry for --all opttion to octodns-validate --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 059e940..c22651e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ Some problem at filename.yaml, line 42, column 14. Our custom Yaml Loaders attach this context information, arbitrary string. Other providers may do so by creating ContextDict to pass as `data` into Record.new. +* Add --all option to octodns-validate to enable showing all record validation + errors (as warnings) rather than exiting on the first. Exit code is non-zero + when there are any validation errors. ## v1.0.0 - 2023-07-30 - The One From fbc7c42efb35298fa40e0990698a123811ad501c Mon Sep 17 00:00:00 2001 From: Ross McFarland Date: Sun, 6 Aug 2023 09:23:50 -0700 Subject: [PATCH 3/3] Fix strict_supports README doc & link --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 87fe467..b6670a8 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ The architecture is pluggable and the tooling is flexible to make it applicable + [Notes](#notes) - [Compatibility and Compliance](#compatibilty-and-compliance) * [`lenient`](#-lenient-) - * [`strict_supports` (Work In Progress)](#-strict-supports---work-in-progress-) + * [`strict_supports`](#-strict-supports-) * [Configuring `strict_supports`](#configuring--strict-supports-) - [Custom Sources and Providers](#custom-sources-and-providers) - [Other Uses](#other-uses) @@ -266,7 +266,7 @@ octoDNS supports automatically generating PTR records from the `A`/`AAAA` record `lenient` mostly focuses on the details of `Record`s and standards compliance. When set to `true` octoDNS will allow allow non-compliant configurations & values where possible. For example CNAME values that don't end with a `.`, label length restrictions, and invalid geo codes on `dynamic` records. When in lenient mode octoDNS will log validation problems at `WARNING` and try and continue with the configuration or source data as it exists. See [Lenience](/docs/records.md#lenience) for more information on the concept and how it can be configured. -### `strict_supports` (Work In Progress) +### `strict_supports` `strict_supports` is a `Provider` level parameter that comes into play when a provider has been asked to create a record that it is unable to support. The simplest case of this would be record type, e.g. `SSHFP` not being supported by `AzureProvider`. If such a record is passed to an `AzureProvider` as a target the provider will take action based on the `strict_supports`. When `true` it will throw an exception saying that it's unable to create the record, when set to `false` it will log at `WARNING` with information about what it's unable to do and how it is attempting to working around it. Other examples of things that cannot be supported would be `dynamic` records on a provider that only supports simple or the lack of support for specific geos in a provider, e.g. Route53Provider does not support `NA-CA-*`.