adding validations for the twistcli_scan_result and informative errors in case the format isn't as expected
+import logging
import os
from pathlib import Path
from typing import Dict, Any
+import logging
from checkov.common.bridgecrew.platform_integration import bc_integration
from checkov.common.bridgecrew.vulnerability_scanning.integrations.twistcli import TwistcliIntegration
@@ -30,7 +32,7 @@ class DockerImageScanningIntegration(TwistcliIntegration):
file_content: str,
docker_image_name: str,
) -> Dict[str, Any]:
- results_dict = twistcli_scan_result["results"][0]
+ results_dict = self._get_results_dict(twistcli_scan_result)
payload = {
"dockerImageName": docker_image_name,
"dockerFilePath": removeprefix(str(file_path), os.getenv("BC_ROOT_DIR", "")),
@@ -46,5 +48,16 @@ class DockerImageScanningIntegration(TwistcliIntegration):
payload["cicd_details"] = bc_integration.cicd_details
return payload
+ @staticmethod
+ def _get_results_dict(twistcli_scan_result: Dict[str, Any]) -> Dict[str, Any]:
+ try:
+ results = twistcli_scan_result["results"]
+ # we expect that there is exactly 1 scanned dokcer-image.
+ if len(results) != 1:
+ raise Exception(f'expected length of \"results\": 1. found: {len(results)}', results)
+ except KeyError:
+ raise Exception("the key \"results\" expected to be existing in:", twistcli_scan_result)
+ return results[0]
+
docker_image_scanning_integration = DockerImageScanningIntegration()
