Skip to content

Commit

Permalink
typing:
Browse files Browse the repository at this point in the history
  • Loading branch information
omriyoffe-panw committed Dec 17, 2024
1 parent 3181d26 commit 49f819e
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions checkov/serverless/graph_builder/definition_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from typing import cast, Any

from checkov.common.util.consts import LINE_FIELD_NAMES
from checkov.common.parsers.node import StrNode
from checkov.common.util.consts import START_LINE, END_LINE
from checkov.common.util.suppression import collect_suppressions_for_report
Expand Down Expand Up @@ -40,19 +39,27 @@ def add_resource_to_definitions_context(definitions_context: dict[str, dict[str,
if not isinstance(resource_attributes, dict) and not isinstance(resource_attributes, StrNode):
return

start_line = resource_attributes[
START_LINE] if START_LINE in resource_attributes else resource_attributes.start_mark.line
end_line = resource_attributes[END_LINE] if END_LINE in resource_attributes else resource_attributes.end_mark.line
start_line = None
end_line = None

if isinstance(resource_attributes, dict):
start_line = resource_attributes[START_LINE]
end_line = resource_attributes[END_LINE]

elif isinstance(resource_attributes, StrNode):
start_line = resource_attributes.start_mark.line
end_line = resource_attributes.end_mark.line

definition_resource = {}

if resource_key is None:
if resource_key is None and isinstance(resource_attributes, dict):
resource_key = f"{resource_attributes.get('type')}.{resource_attributes.get('name')}"
int_start_line = cast(int, start_line)
int_end_line = cast(int, end_line)
code_lines_for_suppressions_check = definitions_raw[file_path][int_start_line: int_end_line]
definition_resource['skipped_checks'] = collect_suppressions_for_report(
code_lines=code_lines_for_suppressions_check)
if 'type' in resource_attributes:
if isinstance(resource_attributes, dict) and 'type' in resource_attributes:
definition_resource["type"] = resource_attributes.get('type')

definition_resource["code_lines"] = definitions_raw[file_path][start_line: end_line + 1]
Expand Down

0 comments on commit 49f819e

Please sign in to comment.