Skip to content

Commit

Permalink
fix(kustomize): Checked for existence of caller_file_path in definiti…
Browse files Browse the repository at this point in the history
…ons_raw (#5324)

Checked for existence of caller_file_path in definitions_raw
  • Loading branch information
bo156 committed Jul 12, 2023
1 parent 00422d0 commit c2c6821
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion checkov/kustomize/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,20 @@ def _get_caller_line_range(self, root_folder: str, k8_file: str, origin_relative
if caller_file_path not in self.definitions:
return None
caller_resource = self.definitions[caller_file_path][0]

if caller_file_path not in self.definitions_raw:
# As we cannot calculate better lines with the `calculate_code_lines` without the raw code,
# we can use the existing info in the resource
return caller_resource[START_LINE], caller_resource[END_LINE]

raw_caller_resource = self.definitions_raw[caller_file_path]

caller_raw_start_line = caller_resource[START_LINE]
caller_raw_end_line = min(caller_resource[END_LINE], len(raw_caller_resource))

_, caller_start_line, caller_end_line = calculate_code_lines(raw_caller_resource, caller_raw_start_line,
caller_raw_end_line)
return (caller_start_line, caller_end_line)
return caller_start_line, caller_end_line

def line_range(self, code_lines: list[tuple[int, str]]) -> list[int]:
num_of_lines = len(code_lines)
Expand Down

0 comments on commit c2c6821

Please sign in to comment.