Add configurable deckhand render validation
Currently deckhand render validation is disabled by default with no option to override that behavior from the command line. Resolve this by: 1. Adding CLI render flag 'validate', default=True 2. Updating CLI documentation 3. Update pegleg.engine.site.render method to include configurable validate flag 4. Update pegleg.engine.util.deckhand.deckhand_render method to validate=True by default (previously False) 5. Update pegleg.engine.util.deckhand.deckhand_render method to perform deckhand's validate all function on rendered documents NOTE: Validation logic is handled in deckhand, see https://opendev.org/airship/deckhand/src/branch/master/deckhand/engine/layering.py https://opendev.org/airship/deckhand/src/branch/master/deckhand/engine/document_validation.py Change-Id: I042fad4b2bf08c88e3a2eef6a54dede5d45c28f5
This commit is contained in:
parent
291c114493
commit
9f824f878d
@ -337,6 +337,12 @@ Name of site.
|
|||||||
|
|
||||||
Where to output.
|
Where to output.
|
||||||
|
|
||||||
|
**-v/--validate** (Optional). Default is True.
|
||||||
|
|
||||||
|
Whether to pre-validate documents using built-in schema validation.
|
||||||
|
Skips over externally registered DataSchema documents to avoid
|
||||||
|
false positives.
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
./pegleg <command> <options> render site_name
|
./pegleg <command> <options> render site_name
|
||||||
|
@ -313,9 +313,19 @@ def show(*, output_stream, site_name):
|
|||||||
default=sys.stdout,
|
default=sys.stdout,
|
||||||
show_default=True,
|
show_default=True,
|
||||||
help='Where to output.')
|
help='Where to output.')
|
||||||
|
@click.option(
|
||||||
|
'-v',
|
||||||
|
'--validate',
|
||||||
|
'validate',
|
||||||
|
is_flag=True,
|
||||||
|
default=True,
|
||||||
|
show_default=True,
|
||||||
|
help='Whether to pre-validate documents using built-in schema validation. '
|
||||||
|
'Skips over externally registered DataSchema documents to avoid '
|
||||||
|
'false positives.')
|
||||||
@SITE_REPOSITORY_ARGUMENT
|
@SITE_REPOSITORY_ARGUMENT
|
||||||
def render(*, output_stream, site_name):
|
def render(*, output_stream, site_name, validate):
|
||||||
engine.site.render(site_name, output_stream)
|
engine.site.render(site_name, output_stream, validate)
|
||||||
|
|
||||||
|
|
||||||
@site.command('lint', help='Lint a given site in a repository')
|
@site.command('lint', help='Lint a given site in a repository')
|
||||||
|
@ -83,14 +83,14 @@ def collect(site_name, save_location):
|
|||||||
_collect_to_stdout(site_name)
|
_collect_to_stdout(site_name)
|
||||||
|
|
||||||
|
|
||||||
def render(site_name, output_stream):
|
def render(site_name, output_stream, validate):
|
||||||
documents = []
|
documents = []
|
||||||
for filename in util.definition.site_files(site_name):
|
for filename in util.definition.site_files(site_name):
|
||||||
with open(filename) as f:
|
with open(filename) as f:
|
||||||
documents.extend(list(yaml.safe_load_all(f)))
|
documents.extend(list(yaml.safe_load_all(f)))
|
||||||
|
|
||||||
rendered_documents, errors = util.deckhand.deckhand_render(
|
rendered_documents, errors = util.deckhand.deckhand_render(
|
||||||
documents=documents)
|
documents=documents, validate=validate)
|
||||||
err_msg = ''
|
err_msg = ''
|
||||||
if errors:
|
if errors:
|
||||||
for err in errors:
|
for err in errors:
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
|
||||||
|
from deckhand.engine import document_validation
|
||||||
from deckhand.engine import layering
|
from deckhand.engine import layering
|
||||||
from deckhand import errors as dh_errors
|
from deckhand import errors as dh_errors
|
||||||
|
|
||||||
@ -43,7 +44,7 @@ def load_schemas_from_docs(documents):
|
|||||||
|
|
||||||
def deckhand_render(documents=None,
|
def deckhand_render(documents=None,
|
||||||
fail_on_missing_sub_src=False,
|
fail_on_missing_sub_src=False,
|
||||||
validate=False):
|
validate=True):
|
||||||
documents = documents or []
|
documents = documents or []
|
||||||
errors = []
|
errors = []
|
||||||
rendered_documents = []
|
rendered_documents = []
|
||||||
@ -57,6 +58,17 @@ def deckhand_render(documents=None,
|
|||||||
fail_on_missing_sub_src=fail_on_missing_sub_src,
|
fail_on_missing_sub_src=fail_on_missing_sub_src,
|
||||||
validate=validate)
|
validate=validate)
|
||||||
rendered_documents = [dict(d) for d in deckhand_eng.render()]
|
rendered_documents = [dict(d) for d in deckhand_eng.render()]
|
||||||
|
if validate:
|
||||||
|
validator = document_validation.DocumentValidation(
|
||||||
|
rendered_documents)
|
||||||
|
results = validator.validate_all()
|
||||||
|
for result in results:
|
||||||
|
if result['errors']:
|
||||||
|
errors.append(
|
||||||
|
(DECKHAND_RENDER_EXCEPTION,
|
||||||
|
'During rendering Deckhand was unable to validate '
|
||||||
|
'the following document, details: %s.' % (
|
||||||
|
result['errors'])))
|
||||||
except dh_errors.DeckhandException as e:
|
except dh_errors.DeckhandException as e:
|
||||||
errors.append(
|
errors.append(
|
||||||
(DECKHAND_RENDER_EXCEPTION,
|
(DECKHAND_RENDER_EXCEPTION,
|
||||||
|
Loading…
Reference in New Issue
Block a user