Skip to content

Commit ae6635d

Browse files
authored
Keep resource names to the resource name (#4002)
1 parent 06ba6aa commit ae6635d

File tree

2 files changed

+76
-5
lines changed

2 files changed

+76
-5
lines changed

src/cfnlint/rules/resources/codepipeline/PipelineArtifactNames.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ def __init__(self) -> None:
3030
"Resources/AWS::CodePipeline::Pipeline/Properties/Stages/*/Actions/*/OutputArtifacts/*/Name",
3131
],
3232
)
33-
self._output_artifact_names: list[tuple[str, dict]] = []
33+
self._output_artifact_names: dict[str, list[tuple[str, dict]]] = {}
3434

3535
def initialize(self, cfn):
36-
self._output_artifact_names = []
36+
self._output_artifact_names = {}
3737
return super().initialize(cfn)
3838

3939
def validate(
@@ -42,8 +42,17 @@ def validate(
4242
if not validator.is_type(instance, "string"):
4343
return
4444

45+
resource_name = validator.context.path.path[1]
46+
if not isinstance(resource_name, str):
47+
return
48+
49+
if resource_name not in self._output_artifact_names:
50+
self._output_artifact_names[resource_name] = []
51+
4552
if "OutputArtifacts" in validator.context.path.path:
46-
for output_name, output_condition in self._output_artifact_names:
53+
for output_name, output_condition in self._output_artifact_names[
54+
resource_name
55+
]:
4756
if output_name != instance:
4857
continue
4958
try:
@@ -62,11 +71,13 @@ def validate(
6271
except Unsatisfiable:
6372
pass
6473

65-
self._output_artifact_names.append(
74+
self._output_artifact_names[resource_name].append(
6675
(instance, validator.context.conditions.status)
6776
)
6877
elif "InputArtifacts" in validator.context.path.path:
69-
for output_name, output_condition in self._output_artifact_names:
78+
for output_name, output_condition in self._output_artifact_names[
79+
resource_name
80+
]:
7081
if output_name != instance:
7182
continue
7283
try:

test/unit/rules/resources/codepipeline/test_pipeline_artifact_names.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,66 @@ def _append_queues(queue1: Iterable, queue2: Iterable) -> deque:
100100
],
101101
[],
102102
),
103+
(
104+
[
105+
(
106+
"Foo",
107+
_append_queues(
108+
_standard_path, [0, "Actions", 0, "OutputArtifacts", 0, "Name"]
109+
),
110+
{},
111+
),
112+
(
113+
"Foo",
114+
deque(
115+
[
116+
"Resources",
117+
1,
118+
"Properties",
119+
"Stages",
120+
0,
121+
"Actions",
122+
0,
123+
"OutputArtifacts",
124+
0,
125+
"Name",
126+
]
127+
),
128+
{},
129+
),
130+
],
131+
[],
132+
),
133+
(
134+
[
135+
(
136+
"Foo",
137+
_append_queues(
138+
_standard_path, [0, "Actions", 0, "OutputArtifacts", 0, "Name"]
139+
),
140+
{},
141+
),
142+
(
143+
"Foo",
144+
deque(
145+
[
146+
"Resources",
147+
"AnotherPipeline",
148+
"Properties",
149+
"Stages",
150+
0,
151+
"Actions",
152+
0,
153+
"OutputArtifacts",
154+
0,
155+
"Name",
156+
]
157+
),
158+
{},
159+
),
160+
],
161+
[],
162+
),
103163
(
104164
[
105165
(

0 commit comments

Comments
 (0)