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

Update graph labels #3752

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