Skip to content

Commit

Permalink
Update some graph quoting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong committed May 2, 2024
1 parent 257e565 commit 9abbb14
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
12 changes: 9 additions & 3 deletions src/cfnlint/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@ 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)

# have to add quotes when outputing to dot
for resource in resources:
node = graph.nodes[resource]
node["type"] = f'"{node["type"]}"'
view.add_node(resource, **node)

view.add_edges_from(
(n, nbr, key, d)
for n, nbrs in graph.adj.items()
Expand Down Expand Up @@ -251,7 +257,7 @@ def _add_node(self, node_id, label, settings):
label=label,
color=settings.color,
shape=settings.shape,
type=f'"{settings.node_type}"',
type=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 @@ -26,8 +26,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"
Expand Down
3 changes: 3 additions & 0 deletions src/cfnlint/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ def run(self) -> Iterator[Match]:
):
yield from iter(matches)
return

if self.cfn.template is not None:
if self.config.build_graph:
self.cfn.build_graph()
yield from self._dedup(
self.check_metadata_directives(
self.rules.run(
Expand Down
4 changes: 2 additions & 2 deletions src/cfnlint/template/transforms/_language_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ def __init__(self, obj: Any) -> None:

def values(
self, cfn: Any, collection_cache: MutableMapping[str, Any]
) -> Iterator[str]:
) -> Iterator[str | dict[Any, Any]]:
if self._collection:
for item in self._collection:
try:
Expand Down Expand Up @@ -558,6 +558,6 @@ def __init__(
self._collection = _ForEachCollection(value[1])
self._output = _ForEachOutput(value[2])

def items(self, cfn: Any) -> Iterator[str]:
def items(self, cfn: Any) -> Iterator[str | dict[str, str]]:
items = self._collection.values(cfn, self._collection_cache)
yield from iter(items)

0 comments on commit 9abbb14

Please sign in to comment.