Skip to content

Commit 9927f18

Browse files
committed
feat: Support RFC extensions in environment templates
Signed-off-by: David Leong <116610336+leongdl@users.noreply.github.com>
1 parent 26b08ef commit 9927f18

4 files changed

Lines changed: 37 additions & 7 deletions

File tree

src/openjd/cli/_check/_check_command.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ def do_check(args: Namespace) -> OpenJDCliResult:
4141
if TemplateSpecificationVersion.is_job_template(template_version):
4242
decode_job_template(template=template_object, supported_extensions=extensions)
4343
elif TemplateSpecificationVersion.is_environment_template(template_version):
44-
decode_environment_template(template=template_object)
44+
# Pass `extensions` so env templates can declare e.g.
45+
# WRAP_ACTIONS (RFC 0008) — without this the model rejects
46+
# the extension declaration even though the CLI accepts it.
47+
decode_environment_template(template=template_object, supported_extensions=extensions)
4548
else:
4649
return OpenJDCliResult(
4750
status="error",

src/openjd/cli/_common/_extensions.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,17 @@
33
from argparse import ArgumentParser
44
from typing import Optional
55

6-
# This is the list of Open Job Description extensions with implemented support
7-
SUPPORTED_EXTENSIONS = ["TASK_CHUNKING", "REDACTED_ENV_VARS", "FEATURE_BUNDLE_1"]
6+
# This is the list of Open Job Description extensions with implemented support.
7+
# EXPR (RFCs 0005/0006) and WRAP_ACTIONS (RFC 0008) are added so the CLI can run
8+
# templates that declare them. WRAP_ACTIONS implies EXPR; the model library
9+
# handles that implication when it parses the template.
10+
SUPPORTED_EXTENSIONS = [
11+
"TASK_CHUNKING",
12+
"REDACTED_ENV_VARS",
13+
"FEATURE_BUNDLE_1",
14+
"EXPR",
15+
"WRAP_ACTIONS",
16+
]
817

918

1019
def add_extensions_argument(run_parser: ArgumentParser):

src/openjd/cli/_common/_validation_utils.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22

3-
from typing import Any
3+
from typing import Any, Optional
44
from pathlib import Path
55

66
from openjd.model import (
@@ -70,15 +70,29 @@ def read_job_template(template_file: Path, *, supported_extensions: list[str]) -
7070
return template
7171

7272

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:
7478
"""Open a JSON or YAML-formatted file and attempt to parse it into an EnvironmentTemplate object.
7579
Raises a RuntimeError if the file doesn't exist or can't be opened, and raises a
7680
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.
7787
"""
7888
# Raises RuntimeError
7989
template_object = read_template(template_file)
8090

91+
decode_kwargs: dict[str, list[str]] = {}
92+
if supported_extensions is not None:
93+
decode_kwargs["supported_extensions"] = supported_extensions
94+
8195
# Raises: DecodeValidationError
82-
template = decode_environment_template(template=template_object)
96+
template = decode_environment_template(template=template_object, **decode_kwargs)
8397

8498
return template

src/openjd/cli/_run/_run_command.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,11 @@ def do_run(args: Namespace) -> OpenJDCliResult:
415415
filename = Path(env).expanduser()
416416
try:
417417
# Raises: RuntimeError, DecodeValidationError
418-
env_template = read_environment_template(filename)
418+
# Pass `extensions` so env templates can declare e.g.
419+
# WRAP_ACTIONS (RFC 0008) — without this they're parsed
420+
# against the default model surface and reject the
421+
# extension declaration.
422+
env_template = read_environment_template(filename, supported_extensions=extensions)
419423
environments.append(env_template)
420424
except (RuntimeError, DecodeValidationError) as e:
421425
return OpenJDCliResult(status="error", message=str(e))

0 commit comments

Comments
 (0)