8
8
import enum
9
9
import os
10
10
import re
11
- from typing import Any , Dict , List , Optional , Pattern , Set , Tuple
11
+ from typing import Any , Dict , List , Optional , Set , Tuple
12
12
13
13
import jsonschema
14
14
import yaml
46
46
REPO_TYPE_GITLAB : str = "gitlab"
47
47
_REPO_TYPES : List [str ] = [REPO_TYPE_GITHUB , REPO_TYPE_GITLAB ]
48
48
49
- _GITHUB_REF_RE : Pattern [str ] = re .compile (r"/([^/]+)/data-manager/" )
49
+ _GITHUB_REF_RE : re .Pattern = re .compile (r"/([^/]+)/data-manager/" )
50
+
51
+ # Patterns for Collection and Job names
52
+ _COLLECTION_NAME_RE : re .Pattern = re .compile (r"([a-z]{1}[a-z0-9-]{0,79})" )
53
+ _JOB_NAME_RE : re .Pattern = re .compile (r"([a-z]{1}[a-z0-9-]{0,79})" )
50
54
51
55
_JOB_KEY_DELIMITER : str = "|"
52
56
@@ -57,6 +61,16 @@ class TextEncoding(enum.Enum):
57
61
JINJA2_3_0 = 1 # Encoding that complies with Jinja2 v3.0.x
58
62
59
63
64
+ def is_valid_collection_name (collection : str ) -> bool :
65
+ """Returns True if the collection name is valid"""
66
+ return _COLLECTION_NAME_RE .fullmatch (collection ) is not None
67
+
68
+
69
+ def is_valid_job_name (job : str ) -> bool :
70
+ """Returns True if the collection name is valid"""
71
+ return _JOB_NAME_RE .fullmatch (job ) is not None
72
+
73
+
60
74
def get_job_key (* , collection : str , job : str ) -> str :
61
75
"""Returns the job Key, a string formed from "<collection>|<job>."""
62
76
return f"{ collection } { _JOB_KEY_DELIMITER } { job } "
0 commit comments