-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnotes.py
59 lines (46 loc) · 1.78 KB
/
notes.py
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
""" Module containing Notes class """
import logging
from ..common.common import SectionHandler
# pylint: disable=too-few-public-methods
class Notes(SectionHandler):
""" Responsible for converting the Notes sections:
- /cvrf:cvrfdoc/cvrf:DocumentNotes
- /cvrf:cvrfdoc/vuln:Vulnerability[i+1]/vuln:Notes
"""
def __init__(self):
super().__init__()
self.enum_categories = {
'description',
'details',
'faq',
'general',
'legal_disclaimer',
'other',
'summary'
}
def _process_mandatory_and_optional(self, root_element):
notes = []
for elem_note in root_element.Note:
# mandatory
new_note = {
"text": elem_note.text,
"category": elem_note.get('Type').lower().replace(' ', '_'),
}
if new_note['category'] not in self.enum_categories:
log_msg = f'Invalid document notes category {new_note["category"]}. Should be' \
f' one of: {",".join(str(x) for x in sorted(self.enum_categories))}!'
logging.error(log_msg)
SectionHandler.error_occurred = True
# optional
if elem_note.get('Audience'):
new_note['audience'] = elem_note.get('Audience')
if elem_note.get('Title'):
new_note['title'] = elem_note.get('Title')
notes.append(new_note)
if notes and len(notes) > 0:
self.csaf = notes
def _process_mandatory_elements(self, root_element):
return self._process_mandatory_and_optional(root_element=root_element)
def _process_optional_elements(self, root_element):
# No optional elements
pass