Skip to content

Commit 19b3227

Browse files
authored
CM-31412 - Fix severity sorting for unknown severity (#197)
* CM-31412 [cli] - SCA- fix advisory severity is missing throw exception in sorted detections
1 parent 7978be2 commit 19b3227

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

cycode/cli/models.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from enum import Enum
33
from typing import Dict, List, NamedTuple, Optional, Type
44

5+
from cycode.cyclient import logger
56
from cycode.cyclient.models import Detection
67

78

@@ -42,6 +43,14 @@ def try_get_value(name: str) -> any:
4243

4344
return Severity[name].value
4445

46+
@staticmethod
47+
def get_member_weight(name: str) -> any:
48+
weight = Severity.try_get_value(name)
49+
if weight is None:
50+
logger.debug(f'missing severity in enum: {name}')
51+
return -2
52+
return weight
53+
4554

4655
class CliError(NamedTuple):
4756
code: str

cycode/cli/printers/tables/sca_table_printer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def __group_by(detections: List[Detection], details_field_name: str) -> Dict[str
7474
@staticmethod
7575
def __severity_sort_key(detection: Detection) -> int:
7676
severity = detection.detection_details.get('advisory_severity')
77-
return Severity.try_get_value(severity)
77+
return Severity.get_member_weight(severity)
7878

7979
def _sort_detections_by_severity(self, detections: List[Detection]) -> List[Detection]:
8080
return sorted(detections, key=self.__severity_sort_key, reverse=True)

0 commit comments

Comments
 (0)