From 82384a8d271918d22eba4a9f139641589b01b5d3 Mon Sep 17 00:00:00 2001 From: gruebel Date: Sun, 24 Sep 2023 15:03:48 +0200 Subject: [PATCH] fix linting and tests --- checkov/cloudformation/runner.py | 9 +++++---- .../checks_infra/extensions/iam_action_expansion.py | 6 ++++-- checkov/common/checks_infra/extensions_registry.py | 7 ++++--- .../graph/checks_infra/extensions/base_extension.py | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/checkov/cloudformation/runner.py b/checkov/cloudformation/runner.py index 957c935105f..113a62be4d3 100644 --- a/checkov/cloudformation/runner.py +++ b/checkov/cloudformation/runner.py @@ -221,9 +221,10 @@ def get_graph_checks_report(self, root_folder: str | None, runner_filter: Runner entity_file_abs_path = entity[CustomAttributes.FILE_PATH] entity_file_path = f"/{os.path.relpath(entity_file_abs_path, root_folder)}" entity_name = entity[CustomAttributes.BLOCK_NAME].split(".")[-1] - entity_context = self.context[entity_file_abs_path][TemplateSections.RESOURCES][ - entity_name - ] + if entity_file_abs_path in self.context: + entity_context = self.context[entity_file_abs_path][TemplateSections.RESOURCES][entity_name] + else: + entity_context = {} skipped_check = next( ( @@ -243,7 +244,7 @@ def get_graph_checks_report(self, root_folder: str | None, runner_filter: Runner check_result=check_result, code_block=entity_context.get("code_lines"), file_path=entity_file_path, - file_line_range=[entity_context.get("start_line"), entity_context.get("end_line")], + file_line_range=[entity_context.get("start_line", 1), entity_context.get("end_line", 1)], resource=entity[CustomAttributes.ID], evaluations={}, check_class=check.__class__.__module__, diff --git a/checkov/common/checks_infra/extensions/iam_action_expansion.py b/checkov/common/checks_infra/extensions/iam_action_expansion.py index a2fdbb61dfa..3b6983fecae 100644 --- a/checkov/common/checks_infra/extensions/iam_action_expansion.py +++ b/checkov/common/checks_infra/extensions/iam_action_expansion.py @@ -1,9 +1,8 @@ from __future__ import annotations -from typing import Any +from typing import Any, TYPE_CHECKING from policy_sentry.analysis.expand import expand # type:ignore[import] # will be fixed with the next version -from typing_extensions import Self from checkov.common.graph.checks_infra.extensions.base_extension import BaseGraphCheckExtension from checkov.common.graph.graph_builder.graph_components.attribute_names import CustomAttributes @@ -11,6 +10,9 @@ from checkov.common.util.data_structures_utils import pickle_deepcopy from checkov.common.util.type_forcers import force_list +if TYPE_CHECKING: + from typing_extensions import Self + SUPPORTED_IAM_BLOCKS = { "aws_iam_group_policy", "aws_iam_policy", diff --git a/checkov/common/checks_infra/extensions_registry.py b/checkov/common/checks_infra/extensions_registry.py index 5beb72bac03..ba9bbd1887c 100644 --- a/checkov/common/checks_infra/extensions_registry.py +++ b/checkov/common/checks_infra/extensions_registry.py @@ -1,13 +1,14 @@ from __future__ import annotations import logging -from typing import Any - -from typing_extensions import Self +from typing import Any, TYPE_CHECKING from checkov.common.checks_infra.extensions.iam_action_expansion import IamActionExpansion from checkov.common.models.enums import GraphCheckExtension +if TYPE_CHECKING: + from typing_extensions import Self + logger = logging.getLogger(__name__) diff --git a/checkov/common/graph/checks_infra/extensions/base_extension.py b/checkov/common/graph/checks_infra/extensions/base_extension.py index 62e37bab42e..a2563fcfbc5 100644 --- a/checkov/common/graph/checks_infra/extensions/base_extension.py +++ b/checkov/common/graph/checks_infra/extensions/base_extension.py @@ -7,7 +7,7 @@ class BaseGraphCheckExtension(ABC): - name: GraphCheckExtension + name: GraphCheckExtension # noqa: CCE003 # a static attribute @abstractmethod def extend(self, vertex_data: dict[str, Any]) -> dict[str, Any]: