Skip to content

Commit

Permalink
fix(template): validate manifests against jsonschema
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pallabpain committed Jul 31, 2024
1 parent 0da99d6 commit c97a174
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
8 changes: 7 additions & 1 deletion riocli/apply/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions riocli/apply/template.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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()
3 changes: 2 additions & 1 deletion riocli/apply/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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:
Expand Down

0 comments on commit c97a174

Please sign in to comment.