Skip to content

Commit

Permalink
Merge pull request #220 from Honny1/add-target-ips
Browse files Browse the repository at this point in the history
Add target addresses
  • Loading branch information
jan-cerny authored Jan 24, 2024
2 parents 1ff08b1 + 9d97241 commit 55298b4
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,20 @@ <h3>
</div>
</div>
</li>

{%- for type, addresses in report.scan_result.target_addresses.items() -%}
<li class="pf-c-data-list__item">
<div class="pf-c-data-list__item-row">
<div class="pf-c-data-list__item-content">
<div class="pf-c-data-list__cell"><b>Target {{ type }} addresses:</b></div>
<div class="pf-c-data-list__cell">
{{- ", ".join(addresses) -}}
</div>
</div>
</div>
</li>
{%- endfor -%}

</ul>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: LGPL-2.1-or-later

from dataclasses import asdict, dataclass, field
from typing import List
from typing import Dict, List

SCAN_JSON_KEYS = [
"title",
Expand All @@ -21,6 +21,7 @@
"score_system",
"score",
"score_max",
"target_addresses",
]

SCORE_COMPUTATION_EXPLANATIONS = {
Expand Down Expand Up @@ -68,6 +69,7 @@ class ResultOfScan: # pylint: disable=R0902
score_system: str = ""
score: float = 0.0
score_max: float = 0.0
target_addresses: Dict[str, list] = field(default_factory=dict)

def as_dict(self):
return asdict(self)
Expand Down
15 changes: 15 additions & 0 deletions openscap_report/scap_results_parser/parsers/scan_result_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ def _get_text_of_element(self, element_path):
return ""
return element.text

def _get_list_of_addresses(self, type_):
out = []
path = (
".//xccdf:target-facts/xccdf:fact"
f"[@name='urn:xccdf:fact:asset:identifier:{type_.lower()}']"
)
for address in self.test_results_el.findall(path, NAMESPACES):
out.append(address.text)
return out

def get_test_result(self):
score_el = self.test_results_el.find(".//xccdf:score", NAMESPACES)

Expand Down Expand Up @@ -50,4 +60,9 @@ def get_test_result(self):
if profile_name is not None:
scan_result_dict["profile_id"] = profile_name.get("idref")

target_addresses = {}
for type_ in ["MAC", "IPv4", "IPv6"]:
target_addresses[type_] = self._get_list_of_addresses(type_)

scan_result_dict["target_addresses"] = target_addresses
return ResultOfScan(**scan_result_dict)
29 changes: 27 additions & 2 deletions tests/json_schema_of_report.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,31 @@
"title": "Score Max",
"default": 0.0,
"type": "number"
}
},
"target_addresses": {
"title": "Target addresses",
"type": "object",
"properties": {
"IPv4": {
"type": "array",
"items": {
"type": "string"
}
},
"IPv6": {
"type": "array",
"items": {
"type": "string"
}
},
"MAC": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
},
"required": [
"title",
Expand All @@ -128,7 +152,8 @@
"end_time",
"test_system",
"score",
"score_max"
"score_max",
"target_addresses"
]
},
"rules": {
Expand Down

0 comments on commit 55298b4

Please sign in to comment.