From c97a1748b35039c421e6262fc5b5b72b6a2aa93d Mon Sep 17 00:00:00 2001 From: Pallab Pain Date: Thu, 1 Aug 2024 00:12:13 +0530 Subject: [PATCH] fix(template): validate manifests against jsonschema The rio template command doesn't validate the manifest against the jsonschema before printing them. It helps in catching missing values in the templates, but doesn't help with incorrect manifests. This commit fixes that and should help users validate the manifests before applying them. Wrike Ticket: https://www.wrike.com/open.htm?id=1464064144 --- riocli/apply/parse.py | 8 +++++++- riocli/apply/template.py | 6 +++--- riocli/apply/util.py | 3 ++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/riocli/apply/parse.py b/riocli/apply/parse.py index 427a6e92..f861c59f 100644 --- a/riocli/apply/parse.py +++ b/riocli/apply/parse.py @@ -143,7 +143,13 @@ def delete(self, *args, **kwargs): spinner.red.fail(Symbols.ERROR) def print_resolved_manifests(self): - manifests = [o for _, o in self.objects.items()] + """Validates and prints the resolved manifests""" + manifests = [] + for _, o in self.objects.items(): + kls = get_model(o) + kls.validate(o) + manifests.append(o) + dump_all_yaml(manifests) def parse_dependencies(self): diff --git a/riocli/apply/template.py b/riocli/apply/template.py index 82909219..417c45ad 100644 --- a/riocli/apply/template.py +++ b/riocli/apply/template.py @@ -1,4 +1,4 @@ -# Copyright 2022 Rapyuta Robotics +# Copyright 2024 Rapyuta Robotics # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -46,5 +46,5 @@ def template(values: str, secrets: str, files: Iterable[str]) -> None: click.secho('No files specified', fg=Colors.RED) raise SystemExit(1) - rc = Applier(glob_files, abs_values, abs_secrets) - rc.print_resolved_manifests() + applier = Applier(glob_files, abs_values, abs_secrets) + applier.print_resolved_manifests() diff --git a/riocli/apply/util.py b/riocli/apply/util.py index d92b39db..654139f4 100644 --- a/riocli/apply/util.py +++ b/riocli/apply/util.py @@ -33,6 +33,7 @@ from riocli.static_route.model import StaticRoute from riocli.usergroup.model import UserGroup from riocli.utils import tabulate_data +from riocli.model import Model KIND_TO_CLASS = { 'project': Project, @@ -48,7 +49,7 @@ } -def get_model(data: dict) -> typing.Any: +def get_model(data: dict) -> Model: """Get the model class based on the kind""" kind = data.get('kind', None) if kind is None: