Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update rule E3049 to only trigger when host port is 0 #3543

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/cfnlint/rules/resources/ecs/ServiceDynamicPorts.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,13 @@ def _filter_port_mappings(
if not isinstance(container_port, (str, int)):
continue
if str(port) == str(container_port):
for _, host_part_validator in get_value_from_path(
for host_port, host_part_validator in get_value_from_path(
container_port_validator,
port_mapping,
path=deque(["HostPort"]),
):
yield host_part_validator
if str(host_port) == "0":
yield host_part_validator

def validate(
self, validator: Validator, _: Any, instance: Any, schema: dict[str, Any]
Expand Down Expand Up @@ -212,4 +213,5 @@ def validate(
"has to have a 'HealthCheckPort' of 'traffic-port'",
path_override=health_check_port_validator.context.path.path,
validator=err_validator,
rule=self,
)
26 changes: 26 additions & 0 deletions test/unit/rules/resources/ecs/test_service_dynamic_ports.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ def rule():
path_override=deque(
["Resources", "TargetGroup", "Properties", "HealthCheckPort"]
),
rule=ServiceDynamicPorts(),
)
],
),
Expand Down Expand Up @@ -330,6 +331,7 @@ def rule():
path_override=deque(
["Resources", "TargetGroup", "Properties", "HealthCheckPort"]
),
rule=ServiceDynamicPorts(),
)
],
),
Expand Down Expand Up @@ -359,6 +361,7 @@ def rule():
path_override=deque(
["Resources", "TargetGroup", "Properties", "HealthCheckPort"]
),
rule=ServiceDynamicPorts(),
)
],
),
Expand Down Expand Up @@ -552,6 +555,29 @@ def rule():
deque(["Resources", "Service", "Properties"]),
[],
),
(
{
"Resources": {
"TaskDefinition": jsonpatch.apply_patch(
dict(_task_definition),
[
{
"op": "replace",
"path": (
"/Properties/ContainerDefinitions/"
"0/PortMappings/0/HostPort"
),
"value": "30",
},
],
),
"TargetGroup": dict(_target_group),
"Service": dict(_service),
}
},
deque(["Resources", "Service", "Properties"]),
[],
),
],
indirect=["template"],
)
Expand Down
Loading