|
5 | 5 | from enum import Enum
|
6 | 6 | from typing import Any
|
7 | 7 |
|
8 |
| -from .decoder import validate_schema |
| 8 | +from .decoder import get_variable_names, validate_schema |
9 | 9 |
|
10 | 10 |
|
11 | 11 | class ValidationLevel(Enum):
|
@@ -39,38 +39,39 @@ def validate(
|
39 | 39 | *,
|
40 | 40 | level: ValidationLevel,
|
41 | 41 | workflow_definition: dict[str, Any],
|
42 |
| - workflow_inputs: dict[str, Any] | None = None, |
| 42 | + variables: dict[str, Any] | None = None, |
43 | 43 | ) -> ValidationResult:
|
44 | 44 | """Validates the workflow definition (and inputs)
|
45 | 45 | based on the provided 'level'."""
|
46 | 46 | assert level in ValidationLevel
|
47 | 47 | assert isinstance(workflow_definition, dict)
|
48 |
| - if workflow_inputs: |
49 |
| - assert isinstance(workflow_inputs, dict) |
| 48 | + if variables: |
| 49 | + assert isinstance(variables, dict) |
50 | 50 |
|
51 |
| - # ALl levels require a schema validation |
| 51 | + # ALl levels need to pass schema validation |
52 | 52 | if error := validate_schema(workflow_definition):
|
53 | 53 | return ValidationResult(error_num=1, error_msg=[error])
|
54 | 54 |
|
| 55 | + # Now level-specific validation... |
55 | 56 | if level == ValidationLevel.RUN:
|
56 | 57 | run_level_result: ValidationResult = WorkflowValidator._validate_run_level(
|
57 | 58 | workflow_definition=workflow_definition,
|
58 |
| - workflow_inputs=workflow_inputs, |
| 59 | + variables=variables, |
59 | 60 | )
|
60 | 61 | if run_level_result.error_num:
|
61 | 62 | return run_level_result
|
62 | 63 |
|
| 64 | + # OK if we get here |
63 | 65 | return _VALIDATION_SUCCESS
|
64 | 66 |
|
65 | 67 | @classmethod
|
66 | 68 | def _validate_run_level(
|
67 | 69 | cls,
|
68 | 70 | *,
|
69 | 71 | workflow_definition: dict[str, Any],
|
70 |
| - workflow_inputs: dict[str, Any] | None = None, |
| 72 | + variables: dict[str, Any] | None = None, |
71 | 73 | ) -> ValidationResult:
|
72 | 74 | assert workflow_definition
|
73 |
| - del workflow_inputs |
74 | 75 |
|
75 | 76 | # RUN level requires that each step specification is a valid JSON string.
|
76 | 77 | # and contains properties for 'collection', 'job', and 'version'.
|
@@ -104,4 +105,16 @@ def _validate_run_level(
|
104 | 105 | error_msg=[f"Specification is missing: {', '.join(missing_keys)}"],
|
105 | 106 | )
|
106 | 107 |
|
| 108 | + # We must have values for all the inputs defined in the workflow. |
| 109 | + wf_variables: list[str] = get_variable_names(workflow_definition) |
| 110 | + missing_values: list[str] = [] |
| 111 | + for wf_variable in wf_variables: |
| 112 | + if not variables or wf_variable not in variables: |
| 113 | + missing_values.append(wf_variable) |
| 114 | + if missing_values: |
| 115 | + return ValidationResult( |
| 116 | + error_num=3, |
| 117 | + error_msg=[f"Missing input values for: {', '.join(missing_values)}"], |
| 118 | + ) |
| 119 | + |
107 | 120 | return _VALIDATION_SUCCESS
|
0 commit comments