openscap_report.scap_results_parser.data_structures.profile_info   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 81.48%

Importance

Changes 0
Metric Value
wmc 9
eloc 34
dl 0
loc 48
ccs 22
cts 27
cp 0.8148
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A ProfileInfo.select_rules() 0 3 2
A ProfileInfo.get_cpe_platforms_that_satisfy_evaluation_target() 0 2 1
A ProfileInfo.get_list_of_cpe_platforms_that_satisfy_evaluation_target() 0 3 1
A ProfileInfo.deselect_rules() 0 4 3
A ProfileInfo.as_dict() 0 2 1
A ProfileInfo.get_applicable_cpe_platforms_for_profile() 0 2 1
1
# Copyright 2022, Red Hat, Inc.
2
# SPDX-License-Identifier: LGPL-2.1-or-later
3
4 1
from typing import Dict, List
5
6 1
from openscap_report.dataclasses import asdict, dataclass, field
7
8 1
PROFILE_JSON_KEYS = [
9
    "profile_id",
10
    "description",
11
    "title",
12
    "extends",
13
]
14
15
16 1
@dataclass
17 1
class ProfileInfo:
18 1
    profile_id: str
19 1
    description: str
20 1
    title: str
21 1
    extends: str = None
22 1
    cpe_platforms_for_profile: Dict[str, bool] = field(default_factory=dict)
23 1
    selected_rules_ids: List[str] = field(default_factory=list)
24 1
    selected_groups_ids: List[str] = field(default_factory=list)
25
26 1
    def as_dict(self):
27
        return asdict(self)
28
29 1
    def get_applicable_cpe_platforms_for_profile(self):
30
        return ", ".join(self.cpe_platforms_for_profile.keys())
31
32 1
    def get_cpe_platforms_that_satisfy_evaluation_target(self):
33
        return ", ".join(self.get_list_of_cpe_platforms_that_satisfy_evaluation_target())
34
35 1
    def get_list_of_cpe_platforms_that_satisfy_evaluation_target(self):
36 1
        return [
37
            cpe_id for cpe_id, is_satisfy in self.cpe_platforms_for_profile.items() if is_satisfy
38
        ]
39
40 1
    def deselect_rules(self, rule_ids):
41 1
        for rule_id in rule_ids:
42
            if rule_id in self.selected_rules_ids:
43
                self.selected_rules_ids.remove(rule_id)
44
45 1
    def select_rules(self, rule_ids):
46 1
        if len(self.selected_rules_ids) > 0:
47
            self.selected_rules_ids.extend(rule_ids)
48