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

Add Value to path in E6101 as we descend #3582

Merged
merged 1 commit into from
Aug 9, 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
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
Loading