|
6 | 6 | from json import dumps |
7 | 7 | from typing import Any, Optional |
8 | 8 |
|
9 | | -from trycast import trycast |
10 | | - |
11 | 9 | from application.core.models import Observation |
12 | 10 | from application.core.types import Severity |
13 | 11 | from application.import_observations.parsers.base_parser import ( |
@@ -496,16 +494,14 @@ def _add_evidences( |
496 | 494 | evidence.append(dumps(translated_component_dependencies)) |
497 | 495 | observation.unsaved_evidences.append(evidence) |
498 | 496 |
|
499 | | - def _get_component_location(self, component_json: dict[str, str]) -> str: |
500 | | - properties_as_list = trycast( |
501 | | - list[dict[str, str]], component_json.get("properties", "") |
502 | | - ) |
503 | | - if properties_as_list is not None: |
504 | | - for prop in properties_as_list: |
| 497 | + def _get_component_location(self, component_json: dict[str, Any]) -> str: |
| 498 | + properties = component_json.get("properties", []) |
| 499 | + if isinstance(properties, list) and all(isinstance(prop, dict) for prop in properties): |
| 500 | + for prop in properties: |
505 | 501 | if prop.get("name") == "syft:location:0:path": |
506 | | - return prop.get("value") |
| 502 | + return prop.get("value", "") |
507 | 503 | if prop.get("name") == "aquasecurity:trivy:FilePath": |
508 | | - return prop.get("value") |
| 504 | + return prop.get("value", "") |
509 | 505 | return "" |
510 | 506 |
|
511 | 507 | def _get_patched_versions(self, component: Component, recommendation: str) -> str: |
|
0 commit comments