Skip to content

Commit a33106f

Browse files
authored
Update graph labels (#3752)
1 parent dfb4390 commit a33106f

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/cfnlint/graph.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from __future__ import annotations
99

10+
import json
1011
import logging
1112
import warnings
1213
from typing import Any
@@ -53,6 +54,9 @@ def _pydot_string_convert(self, value: str | int) -> str | int:
5354

5455
return value
5556

57+
def _pydot_list_convert(self, value: list[str | int]) -> str:
58+
return json.dumps(json.dumps(value))
59+
5660
def subgraph_view(self, graph) -> networkx.MultiDiGraph:
5761
view = networkx.MultiDiGraph(name="template")
5862
resources: list[str] = [
@@ -69,9 +73,9 @@ def subgraph_view(self, graph) -> networkx.MultiDiGraph:
6973

7074
for edge_1, edge_2, edge_data in graph.edges(data=True):
7175
if edge_1 in resources and edge_2 in resources:
72-
edge_data["source_paths"] = [
73-
self._pydot_string_convert(p) for p in edge_data["source_paths"]
74-
]
76+
edge_data["source_paths"] = self._pydot_list_convert(
77+
edge_data["source_paths"]
78+
)
7579
view.add_edge(
7680
edge_1,
7781
edge_2,

test/unit/module/template/test_template.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ def test_build_graph(self):
5454
CustomResource [label="CustomResource\\n<Custom::Function>", color=black, shape=ellipse, type=Resource];
5555
WaitCondition [label="WaitCondition\\n<AWS::CloudFormation::WaitCondition>", color=black, shape=ellipse, type=Resource];
5656
LambdaFunction [label="LambdaFunction\\n<AWS::Lambda::Function>", color=black, shape=ellipse, type=Resource];
57-
RolePolicies -> RootRole [key=0, source_paths="['Properties', 'Roles', 0]", label=Ref, color=black];
58-
RootInstanceProfile -> RootRole [key=0, source_paths="['Properties', 'Roles', 0]", label=Ref, color=black];
59-
MyEC2Instance -> RootInstanceProfile [key=0, source_paths="['Properties', 'IamInstanceProfile']", label=Ref, color=black];
60-
ElasticLoadBalancer -> MyEC2Instance [key=0, source_paths="['Properties', 'Instances', 0]", label=Ref, color=black];
57+
RolePolicies -> RootRole [key=0, source_paths="[\\"Properties\\", \\"Roles\\", 0]", label=Ref, color=black];
58+
RootInstanceProfile -> RootRole [key=0, source_paths="[\\"Properties\\", \\"Roles\\", 0]", label=Ref, color=black];
59+
MyEC2Instance -> RootInstanceProfile [key=0, source_paths="[\\"Properties\\", \\"IamInstanceProfile\\"]", label=Ref, color=black];
60+
ElasticLoadBalancer -> MyEC2Instance [key=0, source_paths="[\\"Properties\\", \\"Instances\\", 0]", label=Ref, color=black];
6161
}
6262
""".split(
6363
"\n"

0 commit comments

Comments
 (0)