Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
YaaraVerner committed Sep 26, 2023
1 parent 3f8fb7e commit 818559e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
12 changes: 5 additions & 7 deletions checkov/common/runners/runner_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from checkov.common.output.spdx import SPDX
from checkov.common.parallelizer.parallel_runner import parallel_runner
from checkov.common.resource_code_logger_filter import add_resource_code_filter_to_logger
from checkov.common.typing import _ExitCodeThresholds, _BaseRunner, _ScaExitCodeThresholds
from checkov.common.typing import _ExitCodeThresholds, _BaseRunner, _ScaExitCodeThresholds, LibraryGraph
from checkov.common.util import data_structures_utils
from checkov.common.util.banner import tool as tool_name
from checkov.common.util.data_structures_utils import pickle_deepcopy
Expand All @@ -53,8 +53,6 @@
from checkov.common.output.baseline import Baseline
from checkov.common.runners.base_runner import BaseRunner # noqa
from checkov.runner_filter import RunnerFilter
from igraph import Graph
from networkx import DiGraph

CONSOLE_OUTPUT = "console"
CHECK_BLOCK_TYPES = frozenset(["resource", "data", "provider", "module"])
Expand Down Expand Up @@ -97,7 +95,7 @@ def __init__(
self._check_type_to_report_map: dict[str, Report] = {} # used for finding reports with the same check type
self.licensing_integration = licensing_integration # can be maniuplated by unit tests
self.secrets_omitter_class = secrets_omitter_class
self.check_type_to_graph: dict[str, list[Tuple[Graph | DiGraph], Optional[str]]] = {}
self.check_type_to_graph: dict[str, list[Tuple[LibraryGraph, Optional[str]]]] = {}
for runner in runners:
if isinstance(runner, image_runner):
runner.image_referencers = self.image_referencing_runners
Expand Down Expand Up @@ -126,7 +124,7 @@ def run(
# This is the only runner, so raise a clear indication of failure
raise ModuleNotEnabledError(f'The framework "{runner_check_type}" is part of the "{self.licensing_integration.get_subscription_for_runner(runner_check_type).name}" module, which is not enabled in the platform')
else:
def _parallel_run(runner: _BaseRunner) -> tuple[Report | list[Report], str | None, Optional[list[Tuple[DiGraph | Graph, Optional[str]]]]]:
def _parallel_run(runner: _BaseRunner) -> tuple[Report | list[Report], str | None, Optional[list[Tuple[LibraryGraph, Optional[str]]]]]:
report = runner.run(
root_folder=root_folder,
external_checks_dir=external_checks_dir,
Expand Down Expand Up @@ -752,11 +750,11 @@ def extract_git_info_from_account_id(account_id: str) -> tuple[str, str]:
return git_org, git_repository

@staticmethod
def extract_graphs_from_runner(runner: BaseRunner) -> List[Tuple[Graph | DiGraph, Optional[str]]]:
def extract_graphs_from_runner(runner: _BaseRunner) -> List[Tuple[LibraryGraph, Optional[str]]]:
# exist only for terraform
all_graphs = getattr(runner, 'all_graphs', None)
if all_graphs:
return all_graphs
return all_graphs # type:ignore[no-any-return]
elif runner.graph_manager:
return [(runner.graph_manager.get_reader_endpoint(), None)]
return []
5 changes: 2 additions & 3 deletions checkov/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from checkov.common.bridgecrew.check_type import checkov_runners, CheckType
from checkov.common.resource_code_logger_filter import add_resource_code_filter_to_logger
from checkov.common.runners.runner_registry import RunnerRegistry
from checkov.common.typing import LibraryGraph
from checkov.common.util import prompt
from checkov.common.util.banner import banner as checkov_banner, tool as checkov_tool
from checkov.common.util.config_utils import get_default_config_paths
Expand Down Expand Up @@ -83,8 +84,6 @@
from checkov.common.output.report import Report
from configargparse import Namespace
from typing_extensions import Literal
from igraph import Graph
from networkx import DiGraph

signal.signal(signal.SIGINT, lambda x, y: sys.exit(''))

Expand Down Expand Up @@ -131,7 +130,7 @@ def __init__(self, argv: list[str] = sys.argv[1:]) -> None:
self.runners = DEFAULT_RUNNERS
self.scan_reports: "list[Report]" = []
self.run_metadata: dict[str, str | list[str]] = {}
self.graphs: dict[str, list[Tuple[DiGraph | Graph, Optional[str]]]] = {}
self.graphs: dict[str, list[Tuple[LibraryGraph, Optional[str]]]] = {}
self.url: str | None = None

self.parse_config(argv=argv)
Expand Down
18 changes: 9 additions & 9 deletions checkov/terraform/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ class Runner(BaseTerraformRunner[_TerraformDefinitions, _TerraformContext, TFDef
check_type = CheckType.TERRAFORM # noqa: CCE003 # a static attribute

def __init__(
self,
parser: TFParser | None = None,
db_connector: LibraryGraphConnector | None = None,
external_registries: list[BaseRegistry] | None = None,
source: str = GraphSource.TERRAFORM,
graph_class: type[TerraformLocalGraph] = TerraformLocalGraph,
graph_manager: TerraformGraphManager | None = None,
self,
parser: TFParser | None = None,
db_connector: LibraryGraphConnector | None = None,
external_registries: list[BaseRegistry] | None = None,
source: str = GraphSource.TERRAFORM,
graph_class: type[TerraformLocalGraph] = TerraformLocalGraph,
graph_manager: TerraformGraphManager | None = None,
) -> None:
super().__init__(parser, db_connector, external_registries, source, graph_class, graph_manager)
self.all_graphs: list[tuple[LibraryGraph, str]] = []
Expand Down Expand Up @@ -116,7 +116,7 @@ def run(

if CHECKOV_CREATE_GRAPH:
if tf_split_graph:
local_graphs = self.graph_manager.build_multi_graph_from_definitions( # type:ignore[assignment] # will be fixed after removing 'CHECKOV_CREATE_GRAPH'
local_graphs = self.graph_manager.build_multi_graph_from_definitions( # will be fixed after removing 'CHECKOV_CREATE_GRAPH'
self.definitions
)
else:
Expand All @@ -126,7 +126,7 @@ def run(
raise Exception("Root directory was not specified, files were not specified")

if CHECKOV_CREATE_GRAPH and local_graphs:
self._update_definitions_and_breadcrumbs(local_graphs, report, root_folder) # type:ignore[arg-type] # will be fixed after removing 'CHECKOV_CREATE_GRAPH'
self._update_definitions_and_breadcrumbs(local_graphs, report, root_folder) # will be fixed after removing 'CHECKOV_CREATE_GRAPH'
else:
logging.info("Scanning root folder using existing tf_definitions")
if root_folder is None:
Expand Down

0 comments on commit 818559e

Please sign in to comment.