| Total Complexity | 9 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Coverage | 81.48% |
| Changes | 0 | ||
| 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 |