|
1 | 1 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
2 | 2 |
|
3 | | -from typing import Any |
| 3 | +from typing import Any, Optional |
4 | 4 | from pathlib import Path |
5 | 5 |
|
6 | 6 | from openjd.model import ( |
@@ -70,15 +70,29 @@ def read_job_template(template_file: Path, *, supported_extensions: list[str]) - |
70 | 70 | return template |
71 | 71 |
|
72 | 72 |
|
73 | | -def read_environment_template(template_file: Path) -> EnvironmentTemplate: |
| 73 | +def read_environment_template( |
| 74 | + template_file: Path, |
| 75 | + *, |
| 76 | + supported_extensions: Optional[list[str]] = None, |
| 77 | +) -> EnvironmentTemplate: |
74 | 78 | """Open a JSON or YAML-formatted file and attempt to parse it into an EnvironmentTemplate object. |
75 | 79 | Raises a RuntimeError if the file doesn't exist or can't be opened, and raises a |
76 | 80 | DecodeValidationError if its contents can't be parsed into a valid EnvironmentTemplate. |
| 81 | +
|
| 82 | + Environment templates may declare extensions just like job templates do |
| 83 | + (e.g. ``WRAP_ACTIONS`` for RFC 0008's wrap hooks). Pass the CLI's allow-list |
| 84 | + via ``supported_extensions`` so the model accepts those declarations; |
| 85 | + omitting the argument preserves the legacy behavior of accepting only the |
| 86 | + default model surface. |
77 | 87 | """ |
78 | 88 | # Raises RuntimeError |
79 | 89 | template_object = read_template(template_file) |
80 | 90 |
|
| 91 | + decode_kwargs: dict[str, list[str]] = {} |
| 92 | + if supported_extensions is not None: |
| 93 | + decode_kwargs["supported_extensions"] = supported_extensions |
| 94 | + |
81 | 95 | # Raises: DecodeValidationError |
82 | | - template = decode_environment_template(template=template_object) |
| 96 | + template = decode_environment_template(template=template_object, **decode_kwargs) |
83 | 97 |
|
84 | 98 | return template |
0 commit comments