openscap_report.scap_results_parser.parsers.oval_variable_parser   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 34
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A OVALVariableParser.__init__() 0 4 1
A OVALVariableParser.get_variable() 0 19 2
1
# Copyright 2022, Red Hat, Inc.
2
# SPDX-License-Identifier: LGPL-2.1-or-later
3
4 1
from ..data_structures import OvalVariable
5 1
from .oval_endpoint_information_parser import OVALEndpointInformation
6 1
from .shared_static_methods_of_parser import SharedStaticMethodsOfParser
7
8
9 1
class OVALVariableParser(OVALEndpointInformation):
10 1
    def __init__(self, variables, oval_var_id_to_value_id, ref_values):
11 1
        self.oval_var_id_to_value_id = oval_var_id_to_value_id
12 1
        self.ref_values = ref_values
13 1
        self.variables = variables
14
15 1
    def get_variable(self, variable_id):
16 1
        xml_variable = self.variables[variable_id]
17 1
        variable_dict = {
18
            "variable_id": xml_variable.attrib.get("id"),
19
            "comment": xml_variable.attrib.get("comment", ""),
20
            "variable_type": SharedStaticMethodsOfParser.get_key_of_xml_element(xml_variable),
21
            "variable_data": self._get_items(xml_variable),
22
        }
23
24 1
        if variable_dict["variable_type"] == "external_variable":
25 1
            variable_dict["variable_data"] = {
26
                "external_variable": {
27
                    "value": self.ref_values.get(
28
                        self.oval_var_id_to_value_id.get(variable_id, ""),
29
                        "not found"
30
                    )
31
                }
32
            }
33
        return OvalVariable(**variable_dict)
34