From 33e99b69091639dc501e68f7144963ce0d53e76b Mon Sep 17 00:00:00 2001 From: Kevin DeJong Date: Mon, 29 Apr 2024 13:41:04 -0700 Subject: [PATCH] Fix an issue with graphs and not quoting attrs --- src/cfnlint/graph.py | 4 +-- .../rules/resources/CircularDependency.py | 4 +-- test/unit/module/test_template.py | 26 +++++++++---------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/cfnlint/graph.py b/src/cfnlint/graph.py index 5403cd233a..6192221eeb 100644 --- a/src/cfnlint/graph.py +++ b/src/cfnlint/graph.py @@ -46,7 +46,7 @@ class GraphSettings: def subgraph_view(self, graph) -> networkx.MultiDiGraph: view = networkx.MultiDiGraph(name="template") resources: List[str] = [ - n for n, v in graph.nodes.items() if v["type"] in ["Resource"] + n for n, v in graph.nodes.items() if v["type"] in ['"Resource"'] ] view.add_nodes_from((n, graph.nodes[n]) for n in resources) view.add_edges_from( @@ -247,7 +247,7 @@ def _add_node(self, node_id, label, settings): label=label, color=settings.color, shape=settings.shape, - type=settings.node_type, + type=f'"{settings.node_type}"', ) def _add_edge(self, source_id, target_id, source_path, settings): diff --git a/src/cfnlint/rules/resources/CircularDependency.py b/src/cfnlint/rules/resources/CircularDependency.py index 2152292061..08fff129d6 100644 --- a/src/cfnlint/rules/resources/CircularDependency.py +++ b/src/cfnlint/rules/resources/CircularDependency.py @@ -23,8 +23,8 @@ def match(self, cfn): for cycle in cfn.graph.get_cycles(cfn): source, target = cycle[:2] if ( - cfn.graph.graph.nodes[source].get("type") == "Resource" - and cfn.graph.graph.nodes[target].get("type") == "Resource" + cfn.graph.graph.nodes[source].get("type") == '"Resource"' + and cfn.graph.graph.nodes[target].get("type") == '"Resource"' ): message = f"Circular Dependencies for resource {source}. Circular dependency with [{target}]" path = ["Resources", source] diff --git a/test/unit/module/test_template.py b/test/unit/module/test_template.py index ae3969c318..69460d608c 100644 --- a/test/unit/module/test_template.py +++ b/test/unit/module/test_template.py @@ -40,19 +40,19 @@ def test_build_graph(self): dot = "test/fixtures/templates/good/generic.yaml.dot" expected_content = """digraph "template" { -MyModule [color=black, label="MyModule\\n", shape=ellipse, type=Resource]; -RootRole [color=black, label="RootRole\\n", shape=ellipse, type=Resource]; -RolePolicies [color=black, label="RolePolicies\\n", shape=ellipse, type=Resource]; -RootInstanceProfile [color=black, label="RootInstanceProfile\\n", shape=ellipse, type=Resource]; -MyEC2Instance [color=black, label="MyEC2Instance\\n", shape=ellipse, type=Resource]; -mySnsTopic [color=black, label="mySnsTopic\\n", shape=ellipse, type=Resource]; -MyEC2Instance1 [color=black, label="MyEC2Instance1\\n", shape=ellipse, type=Resource]; -ElasticIP [color=black, label="ElasticIP\\n", shape=ellipse, type=Resource]; -ElasticLoadBalancer [color=black, label="ElasticLoadBalancer\\n", shape=ellipse, type=Resource]; -IamPipeline [color=black, label="IamPipeline\\n", shape=ellipse, type=Resource]; -CustomResource [color=black, label="CustomResource\\n", shape=ellipse, type=Resource]; -WaitCondition [color=black, label="WaitCondition\\n", shape=ellipse, type=Resource]; -LambdaFunction [color=black, label="LambdaFunction\\n", shape=ellipse, type=Resource]; +MyModule [color=black, label="MyModule\\n", shape=ellipse, type="Resource"]; +RootRole [color=black, label="RootRole\\n", shape=ellipse, type="Resource"]; +RolePolicies [color=black, label="RolePolicies\\n", shape=ellipse, type="Resource"]; +RootInstanceProfile [color=black, label="RootInstanceProfile\\n", shape=ellipse, type="Resource"]; +MyEC2Instance [color=black, label="MyEC2Instance\\n", shape=ellipse, type="Resource"]; +mySnsTopic [color=black, label="mySnsTopic\\n", shape=ellipse, type="Resource"]; +MyEC2Instance1 [color=black, label="MyEC2Instance1\\n", shape=ellipse, type="Resource"]; +ElasticIP [color=black, label="ElasticIP\\n", shape=ellipse, type="Resource"]; +ElasticLoadBalancer [color=black, label="ElasticLoadBalancer\\n", shape=ellipse, type="Resource"]; +IamPipeline [color=black, label="IamPipeline\\n", shape=ellipse, type="Resource"]; +CustomResource [color=black, label="CustomResource\\n", shape=ellipse, type="Resource"]; +WaitCondition [color=black, label="WaitCondition\\n", shape=ellipse, type="Resource"]; +LambdaFunction [color=black, label="LambdaFunction\\n", shape=ellipse, type="Resource"]; RolePolicies -> RootRole [color=black, key=0, label=Ref, source_paths="['Properties', 'Roles', 0]"]; RootInstanceProfile -> RootRole [color=black, key=0, label=Ref, source_paths="['Properties', 'Roles', 0]"]; MyEC2Instance -> RootInstanceProfile [color=black, key=0, label=Ref, source_paths="['Properties', 'IamInstanceProfile']"];