|
6 | 6 | import logging
|
7 | 7 | import sys
|
8 | 8 | from abc import ABC, abstractmethod
|
| 9 | +from textwrap import dedent |
9 | 10 |
|
10 | 11 | import attr
|
11 | 12 |
|
12 | 13 | from taskgraph.config import GraphConfig
|
13 | 14 | from taskgraph.parameters import Parameters
|
14 | 15 | from taskgraph.taskgraph import TaskGraph
|
15 | 16 | from taskgraph.util.attributes import match_run_on_projects
|
| 17 | +from taskgraph.util.taskcluster import get_current_scopes |
16 | 18 | from taskgraph.util.treeherder import join_symbol
|
17 | 19 |
|
18 | 20 | logger = logging.getLogger(__name__)
|
@@ -281,3 +283,46 @@ def verify_always_optimized(task, taskgraph, scratch_pad, graph_config, paramete
|
281 | 283 | return
|
282 | 284 | if task.task.get("workerType") == "always-optimized":
|
283 | 285 | raise Exception(f"Could not optimize the task {task.label!r}")
|
| 286 | + |
| 287 | + |
| 288 | +@verifications.add("decision") |
| 289 | +def verify_scopes_satisfaction(task, taskgraph, scratch_pad, graph_config, parameters): |
| 290 | + if task is None: |
| 291 | + if not scratch_pad: |
| 292 | + return |
| 293 | + |
| 294 | + s = "s" if len(scratch_pad) else "" |
| 295 | + are = "are" if len(scratch_pad) else "is" |
| 296 | + |
| 297 | + failstr = "" |
| 298 | + for label, scopes in scratch_pad.items(): |
| 299 | + failstr += "\n" + f" {label}:" |
| 300 | + failstr += ( |
| 301 | + " \n" + "\n ".join([f" {s}" for s in sorted(scopes)]) + "\n" |
| 302 | + ) |
| 303 | + |
| 304 | + msg = dedent( |
| 305 | + f""" |
| 306 | + Required scopes are missing! |
| 307 | +
|
| 308 | + The Decision task does not have all of the scopes necessary to |
| 309 | + perform this request. The following task{s} {are} requesting scopes |
| 310 | + the Decision task does not have: |
| 311 | + """ |
| 312 | + ) |
| 313 | + msg += failstr |
| 314 | + raise Exception(msg) |
| 315 | + |
| 316 | + current_scopes = get_current_scopes() |
| 317 | + missing = set() |
| 318 | + for required in task.task["scopes"]: |
| 319 | + for current in current_scopes: |
| 320 | + if current == required: |
| 321 | + break |
| 322 | + if current[-1] == "*" and required.startswith(current[:-1]): |
| 323 | + break |
| 324 | + else: |
| 325 | + missing.add(required) |
| 326 | + |
| 327 | + if missing: |
| 328 | + scratch_pad[task.label] = sorted(missing) |
0 commit comments