Skip to content

Commit

Permalink
Fix an issue with graphs and not quoting attrs (#3177)
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong authored Apr 29, 2024
1 parent 5c4f1b1 commit 6918363
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/cfnlint/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions src/cfnlint/rules/resources/CircularDependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
26 changes: 13 additions & 13 deletions test/unit/module/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<My::Organization::Custom::MODULE>", shape=ellipse, type=Resource];
RootRole [color=black, label="RootRole\\n<AWS::IAM::Role>", shape=ellipse, type=Resource];
RolePolicies [color=black, label="RolePolicies\\n<AWS::IAM::Policy>", shape=ellipse, type=Resource];
RootInstanceProfile [color=black, label="RootInstanceProfile\\n<AWS::IAM::InstanceProfile>", shape=ellipse, type=Resource];
MyEC2Instance [color=black, label="MyEC2Instance\\n<AWS::EC2::Instance>", shape=ellipse, type=Resource];
mySnsTopic [color=black, label="mySnsTopic\\n<AWS::SNS::Topic>", shape=ellipse, type=Resource];
MyEC2Instance1 [color=black, label="MyEC2Instance1\\n<AWS::EC2::Instance>", shape=ellipse, type=Resource];
ElasticIP [color=black, label="ElasticIP\\n<AWS::EC2::EIP>", shape=ellipse, type=Resource];
ElasticLoadBalancer [color=black, label="ElasticLoadBalancer\\n<AWS::ElasticLoadBalancing::LoadBalancer>", shape=ellipse, type=Resource];
IamPipeline [color=black, label="IamPipeline\\n<AWS::CloudFormation::Stack>", shape=ellipse, type=Resource];
CustomResource [color=black, label="CustomResource\\n<Custom::Function>", shape=ellipse, type=Resource];
WaitCondition [color=black, label="WaitCondition\\n<AWS::CloudFormation::WaitCondition>", shape=ellipse, type=Resource];
LambdaFunction [color=black, label="LambdaFunction\\n<AWS::Lambda::Function>", shape=ellipse, type=Resource];
MyModule [color=black, label="MyModule\\n<My::Organization::Custom::MODULE>", shape=ellipse, type="Resource"];
RootRole [color=black, label="RootRole\\n<AWS::IAM::Role>", shape=ellipse, type="Resource"];
RolePolicies [color=black, label="RolePolicies\\n<AWS::IAM::Policy>", shape=ellipse, type="Resource"];
RootInstanceProfile [color=black, label="RootInstanceProfile\\n<AWS::IAM::InstanceProfile>", shape=ellipse, type="Resource"];
MyEC2Instance [color=black, label="MyEC2Instance\\n<AWS::EC2::Instance>", shape=ellipse, type="Resource"];
mySnsTopic [color=black, label="mySnsTopic\\n<AWS::SNS::Topic>", shape=ellipse, type="Resource"];
MyEC2Instance1 [color=black, label="MyEC2Instance1\\n<AWS::EC2::Instance>", shape=ellipse, type="Resource"];
ElasticIP [color=black, label="ElasticIP\\n<AWS::EC2::EIP>", shape=ellipse, type="Resource"];
ElasticLoadBalancer [color=black, label="ElasticLoadBalancer\\n<AWS::ElasticLoadBalancing::LoadBalancer>", shape=ellipse, type="Resource"];
IamPipeline [color=black, label="IamPipeline\\n<AWS::CloudFormation::Stack>", shape=ellipse, type="Resource"];
CustomResource [color=black, label="CustomResource\\n<Custom::Function>", shape=ellipse, type="Resource"];
WaitCondition [color=black, label="WaitCondition\\n<AWS::CloudFormation::WaitCondition>", shape=ellipse, type="Resource"];
LambdaFunction [color=black, label="LambdaFunction\\n<AWS::Lambda::Function>", 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']"];
Expand Down

0 comments on commit 6918363

Please sign in to comment.