From 93809175d24fca961920b3a663662a9e450de8dd Mon Sep 17 00:00:00 2001 From: Adam Souzis Date: Fri, 25 Oct 2024 09:41:51 -0700 Subject: [PATCH] Validate that node templates and artifacts assigned the proper TOSCA entity type (fixes #342 but disabled for now unless UNFURL_VALIDATION_MODE env var includes "types"). Enable this in unit tests. --- tosca-parser | 2 +- tox.ini | 2 +- unfurl/spec.py | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tosca-parser b/tosca-parser index cd4c6378..94a85b6c 160000 --- a/tosca-parser +++ b/tosca-parser @@ -1 +1 @@ -Subproject commit cd4c6378de6da42b0990d688a977bea644604d0e +Subproject commit 94a85b6c63a7afbd2a438f15c72a2247b94b319e diff --git a/tox.ini b/tox.ini index 51cbf848..00c09e0b 100644 --- a/tox.ini +++ b/tox.ini @@ -14,7 +14,7 @@ setenv = UNFURL_TMPDIR={envtmpdir} UNFURL_NORUNTIME=1 UNFURL_APPROVE=1 - UNFURL_VALIDATION_MODE=additionalProperties + UNFURL_VALIDATION_MODE="additionalProperties types" UNFURL_RAISE_LOGGING_EXCEPTIONS=1 XDG_CACHE_HOME={envtmpdir}/.cache XDG_CONFIG_HOME={envtmpdir}/.config diff --git a/unfurl/spec.py b/unfurl/spec.py index fb980baf..64673ac6 100644 --- a/unfurl/spec.py +++ b/unfurl/spec.py @@ -227,10 +227,13 @@ def _parse_template( # need to set a path for the import loader mode = os.getenv("UNFURL_VALIDATION_MODE") additionalProperties = False + validate_type_type = False if mode is not None: additionalProperties = "additionalProperties" in mode + validate_type_type = "types" in mode ToscaTemplate.strict = "reqcheck" in mode EntityTemplate.additionalProperties = additionalProperties + EntityTemplate.validate_type_type = validate_type_type if resolver: # hack! set this now so the find_matching_node callback is invoked resolver.manifest.tosca = self @@ -1768,6 +1771,8 @@ def add_node_template(self, name, tpl, discovered=True): custom_types = tpl.pop("custom_types") if custom_types: # XXX check for conflicts, throw error + # add to "types" so EntityTemplate validation passes + cast(dict, self.spec.template.tpl).setdefault("types", {}).update(custom_types) self.topology_template.custom_defs.update(custom_types) nodeTemplate = self.topology_template.add_template(name, tpl)