From 08af535b75b678d1178c3917bb38268a5e1a74f7 Mon Sep 17 00:00:00 2001 From: pelegli Date: Mon, 19 Sep 2022 10:09:49 +0300 Subject: [PATCH 1/5] added base class K8SEdgeBuilder --- .../graph_components/K8SEdgeBuilder.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 checkov/kubernetes/graph_builder/graph_components/K8SEdgeBuilder.py diff --git a/checkov/kubernetes/graph_builder/graph_components/K8SEdgeBuilder.py b/checkov/kubernetes/graph_builder/graph_components/K8SEdgeBuilder.py new file mode 100644 index 00000000000..5b3fe89b568 --- /dev/null +++ b/checkov/kubernetes/graph_builder/graph_components/K8SEdgeBuilder.py @@ -0,0 +1,23 @@ +from __future__ import annotations +from abc import abstractmethod + +from checkov.kubernetes.graph_builder.graph_components.blocks import KubernetesBlock + +class K8SEdgeBuilder: + + @abstractmethod + def find_connection(self, vertex: KubernetesBlock, vertices: list[KubernetesBlock]) -> KubernetesBlock | None: + """ + implementation should search in each of the vertices for a possible connection + to the vertex param according to the concrete class's rule(s) + """ + raise NotImplementedError + + @abstractmethod + def should_search_for_edges(self, vertex: KubernetesBlock) -> bool: + """ + implementation should examine vertex's attributes and indicate if it's potentially + suitable for the concrete class's edge type. + e.g: search for a label attribute in LabelSelectorEdgeBuilder's implementation + """ + raise NotImplementedError From 6e8e97dc84914f41c525c3299f88a7787ca79ddb Mon Sep 17 00:00:00 2001 From: pelegli Date: Mon, 19 Sep 2022 10:15:54 +0300 Subject: [PATCH 2/5] added example in find_connection description --- .../graph_components/K8SEdgeBuilder.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/checkov/kubernetes/graph_builder/graph_components/K8SEdgeBuilder.py b/checkov/kubernetes/graph_builder/graph_components/K8SEdgeBuilder.py index 5b3fe89b568..80b6397139d 100644 --- a/checkov/kubernetes/graph_builder/graph_components/K8SEdgeBuilder.py +++ b/checkov/kubernetes/graph_builder/graph_components/K8SEdgeBuilder.py @@ -6,18 +6,19 @@ class K8SEdgeBuilder: @abstractmethod - def find_connection(self, vertex: KubernetesBlock, vertices: list[KubernetesBlock]) -> KubernetesBlock | None: + def should_search_for_edges(self, vertex: KubernetesBlock) -> bool: """ - implementation should search in each of the vertices for a possible connection - to the vertex param according to the concrete class's rule(s) + implementation should examine vertex's attributes and indicate if it's potentially + suitable for the concrete class's edge type. + e.g: search for a label attribute in LabelSelectorEdgeBuilder's implementation """ raise NotImplementedError @abstractmethod - def should_search_for_edges(self, vertex: KubernetesBlock) -> bool: + def find_connection(self, vertex: KubernetesBlock, vertices: list[KubernetesBlock]) -> KubernetesBlock | None: """ - implementation should examine vertex's attributes and indicate if it's potentially - suitable for the concrete class's edge type. - e.g: search for a label attribute in LabelSelectorEdgeBuilder's implementation + implementation should search in each of the vertices for a possible connection + to the vertex param according to the concrete class's rule(s). + e.g: find vertices with a label attribute that match current vertex's selector attribute """ raise NotImplementedError From a323d3286a699b20e13a7e84cf2cbe8f40b4c178 Mon Sep 17 00:00:00 2001 From: pelegli Date: Mon, 19 Sep 2022 11:01:57 +0300 Subject: [PATCH 3/5] change method signature to return a list --- .../kubernetes/graph_builder/graph_components/K8SEdgeBuilder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checkov/kubernetes/graph_builder/graph_components/K8SEdgeBuilder.py b/checkov/kubernetes/graph_builder/graph_components/K8SEdgeBuilder.py index 80b6397139d..785b6ca6336 100644 --- a/checkov/kubernetes/graph_builder/graph_components/K8SEdgeBuilder.py +++ b/checkov/kubernetes/graph_builder/graph_components/K8SEdgeBuilder.py @@ -15,7 +15,7 @@ def should_search_for_edges(self, vertex: KubernetesBlock) -> bool: raise NotImplementedError @abstractmethod - def find_connection(self, vertex: KubernetesBlock, vertices: list[KubernetesBlock]) -> KubernetesBlock | None: + def find_connection(self, vertex: KubernetesBlock, vertices: list[KubernetesBlock]) -> list[KubernetesBlock] | None: """ implementation should search in each of the vertices for a possible connection to the vertex param according to the concrete class's rule(s). From f7ac86efdd8a98a4a5731d601227bbec9896958e Mon Sep 17 00:00:00 2001 From: pelegli Date: Mon, 19 Sep 2022 11:19:39 +0300 Subject: [PATCH 4/5] remove type from method signature --- .../kubernetes/graph_builder/graph_components/K8SEdgeBuilder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checkov/kubernetes/graph_builder/graph_components/K8SEdgeBuilder.py b/checkov/kubernetes/graph_builder/graph_components/K8SEdgeBuilder.py index 785b6ca6336..a70c5a5e7fa 100644 --- a/checkov/kubernetes/graph_builder/graph_components/K8SEdgeBuilder.py +++ b/checkov/kubernetes/graph_builder/graph_components/K8SEdgeBuilder.py @@ -15,7 +15,7 @@ def should_search_for_edges(self, vertex: KubernetesBlock) -> bool: raise NotImplementedError @abstractmethod - def find_connection(self, vertex: KubernetesBlock, vertices: list[KubernetesBlock]) -> list[KubernetesBlock] | None: + def find_connection(self, vertex: KubernetesBlock, vertices: list[KubernetesBlock]) -> list[KubernetesBlock]: """ implementation should search in each of the vertices for a possible connection to the vertex param according to the concrete class's rule(s). From 0fa58f5e41f5043e2f40a5f2949bb9ee8159e92a Mon Sep 17 00:00:00 2001 From: pelegli Date: Mon, 19 Sep 2022 14:02:35 +0300 Subject: [PATCH 5/5] added line space for linter --- .../kubernetes/graph_builder/graph_components/K8SEdgeBuilder.py | 1 + 1 file changed, 1 insertion(+) diff --git a/checkov/kubernetes/graph_builder/graph_components/K8SEdgeBuilder.py b/checkov/kubernetes/graph_builder/graph_components/K8SEdgeBuilder.py index a70c5a5e7fa..db1a89d1e38 100644 --- a/checkov/kubernetes/graph_builder/graph_components/K8SEdgeBuilder.py +++ b/checkov/kubernetes/graph_builder/graph_components/K8SEdgeBuilder.py @@ -3,6 +3,7 @@ from checkov.kubernetes.graph_builder.graph_components.blocks import KubernetesBlock + class K8SEdgeBuilder: @abstractmethod