Skip to content

Commit

Permalink
Schema validation
Browse files Browse the repository at this point in the history
  • Loading branch information
luismedel committed Nov 17, 2024
1 parent b626ee6 commit 4ae6d14
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
14 changes: 3 additions & 11 deletions src/bluish/actions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions src/bluish/contexts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
6 changes: 4 additions & 2 deletions src/bluish/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
},
}

Expand Down

0 comments on commit 4ae6d14

Please sign in to comment.