Coverage for muuntaa/dialect.py: 100.00%
22 statements
« prev ^ index » next coverage.py v7.6.0, created at 2024-07-21 12:16:47 +00:00
« prev ^ index » next coverage.py v7.6.0, created at 2024-07-21 12:16:47 +00:00
1"""Translate between topic values in CVRF and CSAF dialects."""
3from dataclasses import dataclass
4from typing import Union
6BRANCH_TYPE = {
7 'Architecture': 'architecture',
8 'Host Name': 'host_name',
9 'Language': 'language',
10 'Legacy': 'legacy',
11 'Patch Level': 'patch_level',
12 'Product Family': 'product_family',
13 'Product Name': 'product_name',
14 'Product Version': 'product_version',
15 'Realm': 'product_name', # Does not exist in CSAF, closest match is product_name
16 'Resource': 'product_name', # Does not exist in CSAF, closest match is product_name
17 'Service Pack': 'service_pack',
18 'Specification': 'specification',
19 'Vendor': 'vendor',
20}
22PUBLISHER_TYPE_CATEGORY = {
23 'Coordinator': 'coordinator',
24 'Discoverer': 'discoverer',
25 'Other': 'other',
26 'User': 'user',
27 'Vendor': 'vendor',
28}
30RELATION_TYPE = {
31 'Default Component Of': 'default_component_of',
32 'Optional Component Of': 'optional_component_of',
33 'External Component Of': 'external_component_of',
34 'Installed On': 'installed_on',
35 'Installed With': 'installed_with',
36}
38REMEDIATION_CATEGORY = {
39 'Mitigation': 'mitigation',
40 'None Available': 'none_available',
41 'Vendor Fix': 'vendor_fix',
42 'Will Not Fix': 'no_fix_planned',
43 'Workaround': 'workaround',
44}
46SCORE_CVSS_V2 = {
47 'BaseScoreV2': 'baseScore',
48 'EnvironmentalScoreV2': 'environmentalScore',
49 'TemporalScoreV2': 'temporalScore',
50 'VectorV2': 'vectorString',
51}
53SCORE_CVSS_V3 = {
54 'BaseScoreV3': 'baseScore',
55 'EnvironmentalScoreV3': 'environmentalScore',
56 'TemporalScoreV3': 'temporalScore',
57 'VectorV3': 'vectorString',
58}
60TRACKING_STATUS = {
61 'Draft': 'draft',
62 'Final': 'final',
63 'Interim': 'interim',
64}
67@dataclass
68class TopicalTrans:
69 """Class for translating using a topic dialect map."""
71 pairs: dict[str, str]
72 not_found: Union[str, None] = None
74 def late(self, term: str) -> str:
75 """Play safe, when you trans.late(a_term)."""
76 return self.pairs.get(term, self.not_found) # type: ignore
79branch_trans = TopicalTrans(BRANCH_TYPE)
80publisher_type_category_trans = TopicalTrans(PUBLISHER_TYPE_CATEGORY)
81relation_trans = TopicalTrans(RELATION_TYPE)
82remediation_trans = TopicalTrans(REMEDIATION_CATEGORY)
83score_cvss_v2_trans = TopicalTrans(SCORE_CVSS_V2)
84score_cvss_v3_trans = TopicalTrans(SCORE_CVSS_V3)
85tracking_status_trans = TopicalTrans(TRACKING_STATUS)