Skip to content

Commit

Permalink
move resource_subgraph_map to the base_runner
Browse files Browse the repository at this point in the history
  • Loading branch information
YaaraVerner committed Oct 3, 2023
1 parent 825b3d4 commit f79afc5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 14 deletions.
3 changes: 2 additions & 1 deletion checkov/common/bridgecrew/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ def _upload_resource_subgraph_map(check_type: str, resource_subgraph_map: dict[s
except Exception:
logging.error(f'failed to upload resource_subgraph_map from framework {check_type} to platform', exc_info=True)

# removing '/src' with [:-4]
graphs_repo_object_key = full_repo_object_key.replace('checkov', 'graphs')[:-4]
with futures.ThreadPoolExecutor() as executor:
futures.wait(
Expand All @@ -214,4 +215,4 @@ def _upload_resource_subgraph_map(check_type: str, resource_subgraph_map: dict[s
return_when=futures.FIRST_EXCEPTION,
timeout=timeout
)
logging.info(f"Done persisting {len(resource_subgraph_maps)} resource_subgraph_maps")
logging.info(f"Done persisting resource_subgraph_maps for frameworks - {', '.join(resource_subgraph_maps.keys())}")
3 changes: 2 additions & 1 deletion checkov/common/runners/base_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import re
from abc import ABC, abstractmethod
from collections.abc import Iterable
from typing import List, Any, TYPE_CHECKING, TypeVar, Generic, Dict
from typing import List, Any, TYPE_CHECKING, TypeVar, Generic, Dict, Optional

from checkov.common.graph.db_connectors.igraph.igraph_db_connector import IgraphConnector
from checkov.common.graph.graph_builder import CustomAttributes
Expand Down Expand Up @@ -62,6 +62,7 @@ class BaseRunner(ABC, Generic[_Definitions, _Context, _GraphManager]):
graph_manager: _GraphManager | None = None
graph_registry: Registry | None = None
db_connector: LibraryGraphConnector
resource_subgraph_map: Optional[dict[str, str]] = None

def __init__(self, file_extensions: Iterable[str] | None = None, file_names: Iterable[str] | None = None):
self.file_extensions = file_extensions or []
Expand Down
14 changes: 3 additions & 11 deletions checkov/common/runners/runner_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def _parallel_run(runner: _BaseRunner) -> tuple[Report | list[Report], str | Non

if runner.graph_manager:
return report, runner.check_type, self.extract_graphs_from_runner(runner), \
self.extract_resource_subgraph_map_from_runner(runner)
runner.resource_subgraph_map
return report, None, None, None

valid_runners = []
Expand Down Expand Up @@ -200,11 +200,8 @@ def _parallel_run(runner: _BaseRunner) -> tuple[Report | list[Report], str | Non
self.check_type_to_graph = {runner.check_type: self.extract_graphs_from_runner(runner) for runner
in self.runners if runner.graph_manager}
if not self.check_type_to_resource_subgraph_map:
self.check_type_to_resource_subgraph_map = {}
for runner in self.runners:
resource_subgraph_map = self.extract_resource_subgraph_map_from_runner(runner)
if resource_subgraph_map is not None:
self.check_type_to_resource_subgraph_map[runner.check_type] = resource_subgraph_map
self.check_type_to_resource_subgraph_map = {runner.check_type: runner.resource_subgraph_map for runner in
self.runners if runner.resource_subgraph_map is not None}
return self.scan_reports

def _merge_reports(self, reports: Iterable[Report | list[Report]]) -> list[Report]:
Expand Down Expand Up @@ -771,8 +768,3 @@ def extract_graphs_from_runner(runner: _BaseRunner) -> list[tuple[LibraryGraph,
elif runner.graph_manager:
return [(runner.graph_manager.get_reader_endpoint(), None)]
return []

@staticmethod
def extract_resource_subgraph_map_from_runner(runner: _BaseRunner) -> Optional[dict[str, str]]:
# exist only for terraform
return getattr(runner, 'resource_subgraph_map', None)
1 change: 0 additions & 1 deletion checkov/terraform/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def __init__(
) -> None:
super().__init__(parser, db_connector, external_registries, source, graph_class, graph_manager)
self.all_graphs: list[tuple[LibraryGraph, Optional[str]]] = []
self.resource_subgraph_map: Optional[dict[str, str]] = None

def run(
self,
Expand Down

0 comments on commit f79afc5

Please sign in to comment.