Skip to content

Commit

Permalink
Add Value to path in E6101 as we descend
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong committed Aug 9, 2024
1 parent ae4ff30 commit a7d24bf
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/cfnlint/rules/outputs/Value.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def __init__(self):
)

def validate(self, validator: Validator, _: Any, instance: Any, schema: Any):
value = instance.get("Value")
key = "Value"
value = instance.get(key)
if not value:
return

Expand All @@ -42,6 +43,10 @@ def validate(self, validator: Validator, _: Any, instance: Any, schema: Any):
conditions=validator.context.conditions.evolve(
conditions,
),
path=validator.context.path.descend(
path=key,
cfn_path=key,
),
),
schema={
"type": ["array", "string"],
Expand All @@ -52,5 +57,5 @@ def validate(self, validator: Validator, _: Any, instance: Any, schema: Any):
)

for err in self._iter_errors(validator, value):
err.path.appendleft("Value")
err.path.appendleft(key)
yield err
37 changes: 36 additions & 1 deletion test/unit/rules/outputs/test_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@

import pytest

from cfnlint.context import Path
from cfnlint.jsonschema import CfnTemplateValidator, ValidationError
from cfnlint.rules.functions.Cidr import Cidr
from cfnlint.rules.functions.ImportValue import ImportValue
from cfnlint.rules.functions.Join import Join
from cfnlint.rules.functions.Ref import Ref
from cfnlint.rules.functions.RefResolved import RefResolved
from cfnlint.rules.outputs.ImportValue import ImportValue as OutputsImportValue
from cfnlint.rules.outputs.Value import Value # pylint: disable=E0401


Expand Down Expand Up @@ -54,19 +57,34 @@ def template():


@pytest.fixture
def validator(cfn):
def path():
return Path(
path=deque(["Outputs", "Test"]),
value_path=deque(),
cfn_path=deque(["Outputs", "*"]),
)


@pytest.fixture
def validator(cfn, context):

ref = Ref()
ref.child_rules["W1030"] = RefResolved()

importvalue = ImportValue()
importvalue.child_rules["W6001"] = OutputsImportValue()

yield CfnTemplateValidator(schema={}).extend(
validators={
"fn_join": Join().fn_join,
"ref": ref.ref,
"fn_cidr": Cidr().fn_cidr,
"fn_importvalue": importvalue.fn_importvalue,
}
)(
schema={},
cfn=cfn,
context=context,
)


Expand Down Expand Up @@ -143,6 +161,23 @@ def validator(cfn):
)
],
),
(
{
"Value": {"Fn::ImportValue": "test-stack-value"},
},
[
ValidationError(
(
"The output value {'Fn::ImportValue': 'test-stack-value'} "
"is an import from another output"
),
validator="fn_importvalue",
schema_path=deque(["fn_importvalue"]),
path=deque(["Value", "Fn::ImportValue"]),
rule=OutputsImportValue(),
)
],
),
(
{
"Condition": "isAdditionalVpc",
Expand Down

0 comments on commit a7d24bf

Please sign in to comment.