feat: Asset subtype population for container remedies from Trivy - #21
Conversation
a60fa82
into
ASPMAIN-5492_fix-versions-added-to-remedies-from-imports
There was a problem hiding this comment.
Code Review
This pull request introduces support for an optional asset_sub_type parameter during asset imports, passing it through the batching process and including it in the final API payload. Additionally, it adds a helper method to automatically set the subtype to "CONTAINER_IMAGE" when using the TrivyTranslator. The review feedback correctly points out that unconditionally applying this subtype for all Trivy scans is problematic, as Trivy can scan non-container assets. It is recommended to update the helper method to only apply the "CONTAINER_IMAGE" subtype when container assets are actually present in the parsed list.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| @staticmethod | ||
| def _trivy_asset_sub_type(translator) -> Optional[str]: | ||
| """Trivy container imports require assessment.assetSubType=CONTAINER_IMAGE.""" | ||
| if translator and translator.__class__.__name__ == "TrivyTranslator": | ||
| return "CONTAINER_IMAGE" | ||
| return None |
There was a problem hiding this comment.
Unconditionally returning "CONTAINER_IMAGE" for any scan processed by TrivyTranslator is problematic. Trivy is a multi-purpose scanner that can also scan filesystems, git repositories, virtual machines, and cloud accounts (which map to REPOSITORY, BUILD, INFRA, or CLOUD asset types). Setting the assessment's assetSubType to "CONTAINER_IMAGE" for these non-container scans will result in mismatched metadata or API validation failures in the Phoenix backend.
We should restrict this subtype population to only when the parsed assets are actually of type CONTAINER.
| @staticmethod | |
| def _trivy_asset_sub_type(translator) -> Optional[str]: | |
| """Trivy container imports require assessment.assetSubType=CONTAINER_IMAGE.""" | |
| if translator and translator.__class__.__name__ == "TrivyTranslator": | |
| return "CONTAINER_IMAGE" | |
| return None | |
| @staticmethod | |
| def _trivy_asset_sub_type(translator, assets: list) -> Optional[str]: | |
| """Trivy container imports require assessment.assetSubType=CONTAINER_IMAGE.""" | |
| if translator and translator.__class__.__name__ == "TrivyTranslator": | |
| if assets and any(getattr(asset, "asset_type", None) == "CONTAINER" for asset in assets): | |
| return "CONTAINER_IMAGE" | |
| return None |
| assessment_name = self._generate_assessment_name(file_path, detected_scanner) | ||
|
|
||
| # Step 6: Import with or without batching | ||
| asset_sub_type = self._trivy_asset_sub_type(translator) |
There was a problem hiding this comment.
* fix: fixVersions included in import assets HTTP call * feat: Asset subtype population for container remedies from Trivy (#21)
No description provided.