From 4ae6d1462f1f2e59dbb042b6bf0498b07284f659 Mon Sep 17 00:00:00 2001 From: Luis Medel Date: Mon, 18 Nov 2024 00:14:55 +0100 Subject: [PATCH] Schema validation --- src/bluish/actions/base.py | 14 +++----------- src/bluish/contexts/__init__.py | 4 +--- src/bluish/schemas.py | 6 ++++-- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/bluish/actions/base.py b/src/bluish/actions/base.py index e09e2ab..d2281b6 100644 --- a/src/bluish/actions/base.py +++ b/src/bluish/actions/base.py @@ -25,14 +25,6 @@ def _key_exists(key: str, attrs: Definition) -> bool: class Action: FQN: str = "" - COMMON_SCHEMA = { - "type": dict, - "properties": { - "echo_commands": [bool, None], - "echo_output": [bool, None], - "set": [KV, None], - }, - } SCHEMA: dict = {} INPUTS_SCHEMA: dict = {} SENSITIVE_INPUTS: Sequence[str] = tuple() @@ -45,9 +37,9 @@ def run( def execute( self, step: bluish.contexts.step.StepContext ) -> bluish.process.ProcessResult: - validate_schema(self.COMMON_SCHEMA, step.attrs.as_dict()) - validate_schema(self.SCHEMA, step.attrs.as_dict()) - if step.attrs._with: + if self.SCHEMA: + validate_schema(self.SCHEMA, step.attrs.as_dict()) + if self.INPUTS_SCHEMA and step.attrs._with: validate_schema(self.INPUTS_SCHEMA, step.attrs._with) step.sensitive_inputs.update(self.SENSITIVE_INPUTS) diff --git a/src/bluish/contexts/__init__.py b/src/bluish/contexts/__init__.py index 5f935df..008416d 100644 --- a/src/bluish/contexts/__init__.py +++ b/src/bluish/contexts/__init__.py @@ -24,9 +24,7 @@ class Definition: def __init__(self, attrs: dict[str, Any]): self.__dict__["_attrs"] = attrs - remaining = self._validate_attrs(attrs) - if remaining: - raise ValueError(f"Invalid attributes: {remaining.keys()}") + _ = self._validate_attrs(attrs) def as_dict(self) -> dict[str, Any]: return self.__dict__["_attrs"] diff --git a/src/bluish/schemas.py b/src/bluish/schemas.py index 710bda3..6319823 100644 --- a/src/bluish/schemas.py +++ b/src/bluish/schemas.py @@ -21,10 +21,12 @@ "secrets_file": [str, None], "env_file": [str, None], "uses": [str, None], - "run": [str, None], - "with": [Any, None], "if": [str, None], "continue_on_error": [bool, None], + "set": [KV, None], + "echo_commands": [bool, None], + "echo_output": [bool, None], + "with": [Any, None], }, }