Skip to content

Commit

Permalink
Update graph labels
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong committed Oct 16, 2024
1 parent dfb4390 commit 9039466
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/cfnlint/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from __future__ import annotations

import json
import logging
import warnings
from typing import Any
Expand Down Expand Up @@ -53,6 +54,9 @@ def _pydot_string_convert(self, value: str | int) -> str | int:

return value

def _pydot_list_convert(self, value: list[str | int]) -> str:
return json.dumps(json.dumps(value))

def subgraph_view(self, graph) -> networkx.MultiDiGraph:
view = networkx.MultiDiGraph(name="template")
resources: list[str] = [
Expand All @@ -69,9 +73,9 @@ def subgraph_view(self, graph) -> networkx.MultiDiGraph:

for edge_1, edge_2, edge_data in graph.edges(data=True):
if edge_1 in resources and edge_2 in resources:
edge_data["source_paths"] = [
self._pydot_string_convert(p) for p in edge_data["source_paths"]
]
edge_data["source_paths"] = self._pydot_list_convert(
edge_data["source_paths"]
)
view.add_edge(
edge_1,
edge_2,
Expand Down
8 changes: 4 additions & 4 deletions test/unit/module/template/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ def test_build_graph(self):
CustomResource [label="CustomResource\\n<Custom::Function>", color=black, shape=ellipse, type=Resource];
WaitCondition [label="WaitCondition\\n<AWS::CloudFormation::WaitCondition>", color=black, shape=ellipse, type=Resource];
LambdaFunction [label="LambdaFunction\\n<AWS::Lambda::Function>", color=black, shape=ellipse, type=Resource];
RolePolicies -> RootRole [key=0, source_paths="['Properties', 'Roles', 0]", label=Ref, color=black];
RootInstanceProfile -> RootRole [key=0, source_paths="['Properties', 'Roles', 0]", label=Ref, color=black];
MyEC2Instance -> RootInstanceProfile [key=0, source_paths="['Properties', 'IamInstanceProfile']", label=Ref, color=black];
ElasticLoadBalancer -> MyEC2Instance [key=0, source_paths="['Properties', 'Instances', 0]", label=Ref, color=black];
RolePolicies -> RootRole [key=0, source_paths="[\\"Properties\\", \\"Roles\\", 0]", label=Ref, color=black];
RootInstanceProfile -> RootRole [key=0, source_paths="[\\"Properties\\", \\"Roles\\", 0]", label=Ref, color=black];
MyEC2Instance -> RootInstanceProfile [key=0, source_paths="[\\"Properties\\", \\"IamInstanceProfile\\"]", label=Ref, color=black];
ElasticLoadBalancer -> MyEC2Instance [key=0, source_paths="[\\"Properties\\", \\"Instances\\", 0]", label=Ref, color=black];
}
""".split(
"\n"
Expand Down

0 comments on commit 9039466

Please sign in to comment.