Fix result paths for sca scans
@@ -11,6 +11,7 @@ import requests
from checkov.common.bridgecrew.platform_integration import bc_integration
from checkov.common.util.file_utils import compress_file_gzip_base64, decompress_file_gzip_base64
+from checkov.common.util.str_utils import removeprefix
SLEEP_DURATION = 2
MAX_SLEEP_DURATION = 60
@@ -63,15 +64,11 @@ class Scanner:
response_json = response.json()
if response_json["status"] == "already_exist":
- return json.loads(
- decompress_file_gzip_base64(
- response_json["outputData"]
- )
- )
+ return self.parse_api_result(input_path, response_json["outputData"])
- return self.run_scan_busy_wait(response_json['id'])
+ return self.run_scan_busy_wait(input_path, response_json['id'])
- def run_scan_busy_wait(self, scan_id: str) -> dict:
+ def run_scan_busy_wait(self, input_path: Path, scan_id: str) -> dict:
current_state = "Empty"
desired_state = "Result"
total_sleeping_time = 0
@@ -96,8 +93,9 @@ class Scanner:
time.sleep(SLEEP_DURATION)
total_sleeping_time += SLEEP_DURATION
- return json.loads(
- decompress_file_gzip_base64(
- response.json()["outputData"]
- )
- )
+ return self.parse_api_result(input_path, response.json()["outputData"])
+
+ def parse_api_result(self, origin_file_path: Path, response: str):
+ raw_result = json.loads(decompress_file_gzip_base64(response))
+ raw_result['repository'] = removeprefix(str(origin_file_path), os.getenv("BC_ROOT_DIR", ""))
+ return raw_result
