Skip to content

Commit

Permalink
Merge pull request #251 from jan-cerny/issue250
Browse files Browse the repository at this point in the history
Fix colors in CPE AL details
  • Loading branch information
Mab879 authored Sep 10, 2024
2 parents ce3f578 + fb03120 commit 3ad6439
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function generate_oval_tree(self, div_id_with_oval_graph_data) { // eslint-disab
}

function get_CPE_AL_tree_node(root) {
if (root.node_type == 'frac-ref') {
if (root.node_type == 'fact-ref') {
return undefined;
}

Expand All @@ -178,8 +178,8 @@ function get_CPE_AL_tree_node(root) {
ul.setAttribute('role', "group");
const fragment = document.createDocumentFragment();
for (const child of root.children) {
if (child.node_type == "frac-ref") {
fragment.appendChild(render_CPE_frac_ref(child));
if (child.node_type == "fact-ref") {
fragment.appendChild(render_CPE_fact_ref(child));
} else {
fragment.appendChild(get_CPE_AL_tree_node(child));
}
Expand All @@ -201,24 +201,15 @@ function get_colors_and_icons(node_data) {
color = 'pf-m-red';
icon = 'fa-times';
}

let negate_color = '';
let negate_icon = icon;
if (node_data.negation) {
negate_color = COLOR_TRANSLATION[NEGATION_COLOR[color]];
negate_icon = NEGATION_ICON[icon];
} else {
negate_color = COLOR_TRANSLATION[color];
}
return { color, icon, negate_color, negate_icon };
return { color, icon };
}


function base_operator_node(node_data, node_text) {
const { color, icon, negate_color, negate_icon } = get_colors_and_icons(node_data);
const node = get_node(negate_color);
const { color, icon } = get_colors_and_icons(node_data);
const node = get_node(COLOR_TRANSLATION[color]);
node_text.appendChild(node);
const html_icon = get_icon_as_html(negate_icon);
const html_icon = get_icon_as_html(icon);
node.appendChild(html_icon);
if (node_data.negation) {
node.appendChild(get_operator_label_with_tooltip("NOT", OVAL_OPERATOR_EXPLANATION));
Expand All @@ -241,12 +232,12 @@ function get_CPE_AL_operator_node(node_data) {
}


function render_CPE_frac_ref(node_data) {
function render_CPE_fact_ref(node_data) {
const { operator_node, node_text } = get_operator_node();
const { node, color, icon } = base_operator_node(node_data.oval_tree, node_text);

node.appendChild(get_bold_text(` Reference to OVAL definition `));
node_text.appendChild(get_label(color, "frac-ref", undefined, "cpe-label"," cpe-label__content"));
node_text.appendChild(get_label(color, "fact-ref", undefined, "cpe-label"," cpe-label__content"));
const span_space = SPAN.cloneNode();
span_space.innerText = "\u00A0";
node_text.appendChild(span_space);
Expand Down Expand Up @@ -321,11 +312,11 @@ function get_test_node() {

function render_OVAL_test(node_data) {
const { test_node, node_content, node_text } = get_test_node();
const { color, icon, negate_color, negate_icon } = get_colors_and_icons(node_data);
const { color, icon } = get_colors_and_icons(node_data);

const node = get_node(negate_color);
const node = get_node(COLOR_TRANSLATION[color]);
node_text.appendChild(node);
const html_icon = get_icon_as_html(negate_icon);
const html_icon = get_icon_as_html(icon);
node.appendChild(html_icon);
if (node_data.negation) {
node.appendChild(get_operator_label_with_tooltip("NOT", OVAL_OPERATOR_EXPLANATION));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ def _get_result_counts(self):
result = Counter(EMPTY_RESULT)
for child in self.children:
value = None
if child.node_type == "frac-ref":
if child.node_type == "fact-ref":
value = str(child.oval_tree.evaluate_tree())
else:
value = str(child.evaluate_tree())

node_result = OVAL_RESULT_TO_CPE_RESULT.get(value, "error")
if child.negation:
node_result = NEGATE_VALUE[value]
result[f"number_of_{node_result}"] += 1
return result

Expand All @@ -48,8 +46,6 @@ def _eval_operator(self, cpe_result):
out_result = cpe_result.eval_operator_or()
elif self.node_type.lower() == "and":
out_result = cpe_result.eval_operator_and()
if out_result is not None:
self.value = out_result
return out_result

def evaluate_tree(self):
Expand All @@ -58,4 +54,5 @@ def evaluate_tree(self):
out_result = self._eval_operator(cpe_result)
if self.negation:
out_result = NEGATE_VALUE[out_result]
self.value = out_result
return out_result
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def _load_cpe_platforms(self):
logical_test=LogicalTest(
node_type="AND",
children=[LogicalTest(
node_type="frac-ref",
node_type="fact-ref",
value=oval_definition.definition_id,
oval_tree=oval_definition.oval_tree
)],
Expand Down
3 changes: 1 addition & 2 deletions openscap_report/scap_results_parser/parsers/cpe_al_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ def get_logical_test(self, logical_test_el):
check_id_ref = child_logical_test_el.get("id-ref")
logical_test.children.append(
LogicalTest(
node_type="frac-ref",
value=platform_name if platform_name is not None else check_id_ref,
node_type="fact-ref",
oval_tree=self._get_oval_cpe_tree(platform_name, check_id_ref))
)
if child_logical_test_el.get('operator') is not None:
Expand Down

0 comments on commit 3ad6439

Please sign in to comment.