15
15
# The modules are expected to be called 'decode_<TextEncoding.lower()>'
16
16
from . import decode_jinja2_3_0
17
17
18
- # The (built-in) Job Definition schema ...
18
+ # The (built-in) schemas ...
19
19
# from the same directory as us.
20
- _SCHEMA_FILE : str = os .path .join (os .path .dirname (__file__ ), 'schema.yaml' )
20
+ _JD_SCHEMA_FILE : str = os .path .join (os .path .dirname (__file__ ),
21
+ 'job-definition-schema.yaml' )
22
+ _MANIFEST_SCHEMA_FILE : str = os .path .join (os .path .dirname (__file__ ),
23
+ 'manifest-schema.yaml' )
21
24
22
- # Load the schema YAML file now.
25
+ # Load the JD schema YAML file now.
23
26
# This must work as the file is installed along with this module.
24
- _JOB_SCHEMA : Dict [str , Any ] = {}
25
- assert os .path .isfile (_SCHEMA_FILE )
26
- with open (_SCHEMA_FILE , 'r' , encoding = 'utf8' ) as schema_file :
27
- _JOB_SCHEMA = yaml .load (schema_file , Loader = yaml .FullLoader )
28
- assert _JOB_SCHEMA
27
+ assert os .path .isfile (_JD_SCHEMA_FILE )
28
+ with open (_JD_SCHEMA_FILE , 'r' , encoding = 'utf8' ) as schema_file :
29
+ _JOB_DEFINITION_SCHEMA : Dict [str , Any ] = \
30
+ yaml .load (schema_file , Loader = yaml .FullLoader )
31
+ assert _JOB_DEFINITION_SCHEMA
32
+
33
+ # Load the Manifest schema YAML file now.
34
+ # This must work as the file is installed along with this module.
35
+ assert os .path .isfile (_MANIFEST_SCHEMA_FILE )
36
+ with open (_MANIFEST_SCHEMA_FILE , 'r' , encoding = 'utf8' ) as schema_file :
37
+ _MANIFEST_SCHEMA : Dict [str , Any ] = \
38
+ yaml .load (schema_file , Loader = yaml .FullLoader )
39
+ assert _MANIFEST_SCHEMA
29
40
30
41
31
42
class TextEncoding (enum .Enum ):
@@ -34,16 +45,33 @@ class TextEncoding(enum.Enum):
34
45
JINJA2_3_0 = 1 # Encoding that complies with Jinja2 v3.0.x
35
46
36
47
48
+ def validate_manifest_schema (manifest : Dict [str , Any ]) -> Optional [str ]:
49
+ """Checks the Job Definition Manifest (a preloaded job-definition dictionary)
50
+ against the built-in schema. If there's an error the error text is
51
+ returned, otherwise None.
52
+ """
53
+ assert isinstance (manifest , dict )
54
+
55
+ # Validate the Manifest against our schema
56
+ try :
57
+ jsonschema .validate (manifest , schema = _MANIFEST_SCHEMA )
58
+ except jsonschema .ValidationError as ex :
59
+ return str (ex .message )
60
+
61
+ # OK if we get here
62
+ return None
63
+
64
+
37
65
def validate_job_schema (job_definition : Dict [str , Any ]) -> Optional [str ]:
38
66
"""Checks the Job Definition (a preloaded job-definition dictionary)
39
67
against the built-in schema. If there's an error the error text is
40
68
returned, otherwise None.
41
69
"""
42
- assert job_definition
70
+ assert isinstance ( job_definition , dict )
43
71
44
72
# Validate the Job Definition against our schema
45
73
try :
46
- jsonschema .validate (job_definition , schema = _JOB_SCHEMA )
74
+ jsonschema .validate (job_definition , schema = _JOB_DEFINITION_SCHEMA )
47
75
except jsonschema .ValidationError as ex :
48
76
return str (ex .message )
49
77
0 commit comments