Bug 1421050: Verify that workerType and provisionerId are of the proper form as part of task generation r=dustin draft
authorChris AtLee <catlee@mozilla.com>
Mon, 27 Nov 2017 15:59:35 -0500
changeset 703837 be583f28b1dd2d1bd0d9e486aef4d2d9004621bd
parent 703204 c15f17881cd5dec9d58c84551e9d0bfd2d1f4820
child 741923 d96a80f47a306abd1e51848e07141e7231afaec6
push id90986
push usercatlee@mozilla.com
push dateMon, 27 Nov 2017 21:00:34 +0000
reviewersdustin
bugs1421050
milestone59.0a1
Bug 1421050: Verify that workerType and provisionerId are of the proper form as part of task generation r=dustin MozReview-Commit-ID: 1t5BG86fy7f
taskcluster/taskgraph/transforms/task.py
--- a/taskcluster/taskgraph/transforms/task.py
+++ b/taskcluster/taskgraph/transforms/task.py
@@ -1440,16 +1440,31 @@ def build_task(config, tasks):
             'label': task['label'],
             'task': task_def,
             'dependencies': task.get('dependencies', {}),
             'attributes': attributes,
             'optimization': task.get('optimization', None),
         }
 
 
+@transforms.add
+def check_task_identifiers(config, tasks):
+    """Ensures that all tasks have well defined identifiers:
+       ^[a-zA-Z0-9_-]{1,22}$
+    """
+    e = re.compile("^[a-zA-Z0-9_-]{1,22}$")
+    for task in tasks:
+        for attr in ('workerType', 'provisionerId'):
+            if not e.match(task['task'][attr]):
+                raise Exception(
+                    'task {}.{} is not a valid identifier: {}'.format(
+                        task['label'], attr, task['task'][attr]))
+        yield task
+
+
 def check_caches_are_volumes(task):
     """Ensures that all cache paths are defined as volumes.
 
     Caches and volumes are the only filesystem locations whose content
     isn't defined by the Docker image itself. Some caches are optional
     depending on the job environment. We want paths that are potentially
     caches to have as similar behavior regardless of whether a cache is
     used. To help enforce this, we require that all paths used as caches