1
|
|
|
# Copyright 2022, Red Hat, Inc. |
2
|
|
|
# SPDX-License-Identifier: LGPL-2.1-or-later |
3
|
|
|
|
4
|
1 |
|
from lxml.builder import E |
5
|
|
|
|
6
|
1 |
|
from ..data_structures import OvalObject, OvalObjectMessage |
7
|
1 |
|
from ..namespaces import NAMESPACES |
8
|
1 |
|
from .oval_endpoint_information_parser import OVALEndpointInformation |
9
|
1 |
|
from .oval_items_parser import OVALItemsParser |
10
|
1 |
|
from .shared_static_methods_of_parser import SharedStaticMethodsOfParser |
11
|
|
|
|
12
|
|
|
|
13
|
1 |
|
class OVALObjectParser(OVALEndpointInformation): |
14
|
1 |
|
def __init__(self, objects, collected_objects, system_data): |
15
|
1 |
|
self.objects = objects |
16
|
1 |
|
self.collected_objects = collected_objects |
17
|
1 |
|
self.system_data = system_data |
18
|
1 |
|
self.item_parser = OVALItemsParser(collected_objects, system_data) |
19
|
|
|
|
20
|
1 |
|
def _get_oval_message(self, xml_collected_object): |
21
|
1 |
|
message = xml_collected_object.find( |
22
|
|
|
".//oval-characteristics:message", NAMESPACES |
23
|
|
|
) |
24
|
1 |
|
if message is not None: |
25
|
1 |
|
return OvalObjectMessage(message.get("level", ""), message.text) |
26
|
1 |
|
return None |
27
|
|
|
|
28
|
1 |
|
def _get_collected_object_xml(self, id_object): |
29
|
1 |
|
return self.collected_objects.get(id_object, E.xml("empty")) |
30
|
|
|
|
31
|
1 |
|
def get_object(self, id_object): |
32
|
1 |
|
xml_object = self.objects.get(id_object) |
33
|
1 |
|
object_dict = { |
34
|
|
|
"object_id": xml_object.get("id"), |
35
|
|
|
"comment": xml_object.get("comment", ""), |
36
|
|
|
"object_type": SharedStaticMethodsOfParser.get_key_of_xml_element(xml_object), |
37
|
|
|
"object_data": self._get_items(xml_object), |
38
|
|
|
"collected_items": self.item_parser.get_oval_items(id_object) |
39
|
|
|
} |
40
|
1 |
|
xml_collected_object = self._get_collected_object_xml(id_object) |
41
|
|
|
|
42
|
1 |
|
message = self._get_oval_message(xml_collected_object) |
43
|
1 |
|
if message is not None: |
44
|
1 |
|
object_dict["message"] = message |
45
|
1 |
|
object_dict["flag"] = xml_collected_object.get("flag", "") |
46
|
|
|
return OvalObject(**object_dict) |
47
|
|
|
|