make image path rootless instead of abs
@@ -132,6 +132,8 @@ class Runner(PackageRunner):
if not runner_filter.show_progress_bar:
self.pbar.turn_off_progress_bar()
+ self._code_repo_path = Path(root_folder) if root_folder else None
+
report = Report(self.check_type)
if "dockerfile_path" in kwargs and "image_id" in kwargs:
@@ -150,7 +152,6 @@ class Runner(PackageRunner):
self.pbar.update()
self.pbar.close()
-
if root_folder:
for root, d_names, f_names in os.walk(root_folder):
filter_ignored_paths(root, d_names, runner_filter.excluded_paths, included_paths=self.included_paths())
@@ -200,11 +201,19 @@ class Runner(PackageRunner):
vulnerabilities = result.get("vulnerabilities") or []
image_id = self.extract_image_short_id(result)
image_details = self.get_image_details_from_twistcli_result(scan_result=result, image_id=image_id)
+ dockerfile_path = Path(dockerfile_path)
+ if self._code_repo_path:
+ try:
+ dockerfile_path = dockerfile_path.relative_to(self._code_repo_path)
+ except ValueError:
+ # Path.is_relative_to() was implemented in Python 3.9
+ pass
+ rootless_file_path = str(dockerfile_path).replace(Path(dockerfile_path).anchor, "", 1)
self.parse_vulns_to_records(
report=report,
scanned_file_path=os.path.abspath(dockerfile_path),
- rootless_file_path=f"{dockerfile_path} ({image.name} lines:{image.start_line}-{image.end_line} ({image_id}))",
+ rootless_file_path=f"{rootless_file_path} ({image.name} lines:{image.start_line}-{image.end_line} ({image_id}))",
runner_filter=runner_filter,
vulnerabilities=vulnerabilities,
packages=[],
@@ -274,7 +283,6 @@ class Runner(PackageRunner):
return image_id[:17]
return image_id[:10]
-
def get_image_details_from_twistcli_result(self, scan_result: dict[str, Any], image_id: str) -> ImageDetails:
image_packages = scan_result.get('packages', [])
image_package_types = {
