-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathcli_types.py
More file actions
93 lines (70 loc) · 2.37 KB
/
cli_types.py
File metadata and controls
93 lines (70 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from enum import Enum
from cycode.cli import consts
class OutputTypeOption(str, Enum):
RICH = 'rich'
TEXT = 'text'
JSON = 'json'
TABLE = 'table'
class ScanTypeOption(str, Enum):
SECRET = consts.SECRET_SCAN_TYPE
SCA = consts.SCA_SCAN_TYPE
IAC = consts.IAC_SCAN_TYPE
SAST = consts.SAST_SCAN_TYPE
class ScaScanTypeOption(str, Enum):
PACKAGE_VULNERABILITIES = 'package-vulnerabilities'
LICENSE_COMPLIANCE = 'license-compliance'
class SbomFormatOption(str, Enum):
SPDX_2_2 = 'spdx-2.2'
SPDX_2_3 = 'spdx-2.3'
CYCLONEDX_1_4 = 'cyclonedx-1.4'
class SbomOutputFormatOption(str, Enum):
JSON = 'json'
class SeverityOption(str, Enum):
INFO = 'info'
LOW = 'low'
MEDIUM = 'medium'
HIGH = 'high'
CRITICAL = 'critical'
@classmethod
def _missing_(cls, value: str) -> str:
value = value.lower()
for member in cls:
if member.lower() == value:
return member
return cls.INFO # fallback to INFO if no match is found
@staticmethod
def get_member_weight(name: str) -> int:
return _SEVERITY_WEIGHTS.get(name.lower(), _SEVERITY_DEFAULT_WEIGHT)
@staticmethod
def get_member_color(name: str) -> str:
return _SEVERITY_COLORS.get(name.lower(), _SEVERITY_DEFAULT_COLOR)
@staticmethod
def get_member_emoji(name: str) -> str:
return _SEVERITY_EMOJIS.get(name.lower(), _SEVERITY_DEFAULT_EMOJI)
def __rich__(self) -> str:
color = self.get_member_color(self.value)
return f'[{color}]{self.value.upper()}[/]'
_SEVERITY_DEFAULT_WEIGHT = -1
_SEVERITY_WEIGHTS = {
SeverityOption.INFO.value: 0,
SeverityOption.LOW.value: 1,
SeverityOption.MEDIUM.value: 2,
SeverityOption.HIGH.value: 3,
SeverityOption.CRITICAL.value: 4,
}
_SEVERITY_DEFAULT_COLOR = 'white'
_SEVERITY_COLORS = {
SeverityOption.INFO.value: 'deep_sky_blue1',
SeverityOption.LOW.value: 'gold1',
SeverityOption.MEDIUM.value: 'dark_orange',
SeverityOption.HIGH.value: 'red1',
SeverityOption.CRITICAL.value: 'red3',
}
_SEVERITY_DEFAULT_EMOJI = ':white_circle:'
_SEVERITY_EMOJIS = {
SeverityOption.INFO.value: ':blue_circle:',
SeverityOption.LOW.value: ':yellow_circle:',
SeverityOption.MEDIUM.value: ':orange_circle:',
SeverityOption.HIGH.value: ':heavy_large_circle:',
SeverityOption.CRITICAL.value: ':red_circle:',
}