Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search rules by references #224

Merged
merged 3 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions openscap_report/report_generators/html_templates/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@ footer {
border-radius: 0px !important;
}

.tooltip-box-bottom-side {
visibility: hidden;
position: absolute;
top: 120%;
left: 15%;
}

.tooltip-wrapper:hover .tooltip-box-bottom-side {
visibility: visible;
z-index: calc(var(--pf-c-tree-view--m-guides__list-item--ZIndex) + 1);
}

.tooltip-box-right-side {
visibility: hidden;
position: absolute;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ function search_rule(self) { // eslint-disable-line no-unused-vars
rules.forEach(function (rule) {
const is_matched_title = rule.getAttribute("rule-title").toLowerCase().includes(value);
const is_matched_rule_id = rule.getAttribute("rule-id").toLowerCase().includes(value);
const is_matched_rule_reference = rule.getAttribute("rule-references").toLowerCase().includes(value);
const result_of_rule = rule.getAttribute("result").asId('result-');
const severity_of_rule = rule.getAttribute("severity").asId('severity-');
const advance_option = (FILTER_TABLE[result_of_rule]) && (FILTER_TABLE[severity_of_rule]);
if ((is_matched_title || is_matched_rule_id) && advance_option) {
if ((is_matched_title || is_matched_rule_id || is_matched_rule_reference) && advance_option) {
rule.style.display = "";
rule.classList.remove("hidden")
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
{% if loop.index > 50 %}
{%- set rule_hidden = "hidden" -%}
{% endif %}
<tbody class="pf-m-expanded {{ rule_hidden }}" role="rowgroup" rule-title="{{ rule_title }}" rule-id="{{ rule.rule_id }}" result="{{ rule.result }}" severity="{{ rule.severity }}">
<tbody class="pf-m-expanded {{ rule_hidden }}" role="rowgroup" rule-title="{{ rule_title }}" rule-id="{{ rule.rule_id }}" result="{{ rule.result }}" severity="{{ rule.severity }}" rule-references="{{ rule.get_reference_search_string() }}">
<tr role="row">
<td class="pf-c-table__toggle" role="cell">
<button
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{# Copyright 2022, Red Hat, Inc. #}
{# SPDX-License-Identifier: LGPL-2.1-or-later #}
<div class="pf-c-accordion pf-m-display-lg">
<div class="pf-c-input-group">
<div class="pf-c-input-group tooltip-wrapper" style="position: relative;">
<input class="pf-c-form-control pf-m-search" oninput="search_rule(this)" type="search"
placeholder="Search rule" id="input-search-rule" />
<button class="pf-c-button pf-m-control" type="button" aria-label="Clear" onclick="clear_input(this)">
Expand All @@ -11,6 +11,14 @@
onclick="show_advanced_options(this);">
<i class="fas fa-caret-right" aria-hidden="true"></i>
</button>
<div class="pf-c-tooltip pf-m-bottom tooltip-box-bottom-side" role="tooltip">
<div class="pf-c-tooltip__arrow"></div>
<div class="pf-c-tooltip__content tooltip__content-width">
You can search for rules by ID, name, references, or policy name.
To specify policy and reference, you can enter a search bar in the format: <i>POLICY_NAME: REFERENCE</i><br>
To filter rules by result or severity, you can use advanced filtering by clicking the arrow on the right side of the search bar.
</div>
</div>
</div>
<div class="pf-c-accordion__expanded-content" style="display: none;">
<div class="pf-c-accordion__expanded-content-body">
Expand Down
7 changes: 7 additions & 0 deletions openscap_report/scap_results_parser/data_structures/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,10 @@ class Rule: # pylint: disable=R0902

def as_dict(self):
return asdict(self)

def get_reference_search_string(self):
out = []
for ref in self.references:
prefix = f"{ref.name.lower().replace(' ', '')}: "
out.extend([prefix + ref_ for ref_ in ref.ref_ids])
return " ".join(out)
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

from ..namespaces import NAMESPACES

# pylint: disable=line-too-long
Expand Down Expand Up @@ -32,6 +34,10 @@

def update_references(root):
references_elements = root.findall(".//xccdf:Benchmark/xccdf:reference", NAMESPACES)
if len(references_elements) == 0:
logging.warning(
"Mapping of references was not found. So search by references is disabled."
)
for ref_el in references_elements:
href = ref_el.get("href")
if href is not None:
Expand Down
Loading