Skip to content

Commit fbbea5c

Browse files
authored
Add Value to path in E6101 as we descend (#3582)
1 parent ae4ff30 commit fbbea5c

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

src/cfnlint/rules/outputs/Value.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ def __init__(self):
2828
)
2929

3030
def validate(self, validator: Validator, _: Any, instance: Any, schema: Any):
31-
value = instance.get("Value")
31+
key = "Value"
32+
value = instance.get(key)
3233
if not value:
3334
return
3435

@@ -42,6 +43,10 @@ def validate(self, validator: Validator, _: Any, instance: Any, schema: Any):
4243
conditions=validator.context.conditions.evolve(
4344
conditions,
4445
),
46+
path=validator.context.path.descend(
47+
path=key,
48+
cfn_path=key,
49+
),
4550
),
4651
schema={
4752
"type": ["array", "string"],
@@ -52,5 +57,5 @@ def validate(self, validator: Validator, _: Any, instance: Any, schema: Any):
5257
)
5358

5459
for err in self._iter_errors(validator, value):
55-
err.path.appendleft("Value")
60+
err.path.appendleft(key)
5661
yield err

test/unit/rules/outputs/test_value.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77

88
import pytest
99

10+
from cfnlint.context import Path
1011
from cfnlint.jsonschema import CfnTemplateValidator, ValidationError
1112
from cfnlint.rules.functions.Cidr import Cidr
13+
from cfnlint.rules.functions.ImportValue import ImportValue
1214
from cfnlint.rules.functions.Join import Join
1315
from cfnlint.rules.functions.Ref import Ref
1416
from cfnlint.rules.functions.RefResolved import RefResolved
17+
from cfnlint.rules.outputs.ImportValue import ImportValue as OutputsImportValue
1518
from cfnlint.rules.outputs.Value import Value # pylint: disable=E0401
1619

1720

@@ -54,19 +57,34 @@ def template():
5457

5558

5659
@pytest.fixture
57-
def validator(cfn):
60+
def path():
61+
return Path(
62+
path=deque(["Outputs", "Test"]),
63+
value_path=deque(),
64+
cfn_path=deque(["Outputs", "*"]),
65+
)
66+
67+
68+
@pytest.fixture
69+
def validator(cfn, context):
5870

5971
ref = Ref()
6072
ref.child_rules["W1030"] = RefResolved()
73+
74+
importvalue = ImportValue()
75+
importvalue.child_rules["W6001"] = OutputsImportValue()
76+
6177
yield CfnTemplateValidator(schema={}).extend(
6278
validators={
6379
"fn_join": Join().fn_join,
6480
"ref": ref.ref,
6581
"fn_cidr": Cidr().fn_cidr,
82+
"fn_importvalue": importvalue.fn_importvalue,
6683
}
6784
)(
6885
schema={},
6986
cfn=cfn,
87+
context=context,
7088
)
7189

7290

@@ -143,6 +161,23 @@ def validator(cfn):
143161
)
144162
],
145163
),
164+
(
165+
{
166+
"Value": {"Fn::ImportValue": "test-stack-value"},
167+
},
168+
[
169+
ValidationError(
170+
(
171+
"The output value {'Fn::ImportValue': 'test-stack-value'} "
172+
"is an import from another output"
173+
),
174+
validator="fn_importvalue",
175+
schema_path=deque(["fn_importvalue"]),
176+
path=deque(["Value", "Fn::ImportValue"]),
177+
rule=OutputsImportValue(),
178+
)
179+
],
180+
),
146181
(
147182
{
148183
"Condition": "isAdditionalVpc",

0 commit comments

Comments
 (0)