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

Present references in a table #217

Merged
merged 6 commits into from
Dec 7, 2023
Merged

Present references in a table #217

merged 6 commits into from
Dec 7, 2023

Conversation

jan-cerny
Copy link
Member

We will sort and show the references grouped by reference target. The well-known references will be labeled. This makes the "References" section of rule detail actually useful.

For example:

image

Fixes: #154

@pep8speaks
Copy link

pep8speaks commented Nov 3, 2023

Hello @jan-cerny! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2023-12-06 12:48:06 UTC

We will sort and show the references grouped by reference target.  The
well-known references will be labeled. This makes the "References"
section of rule detail actually useful.

Fixes: OpenSCAP#154
@evgenyz
Copy link
Contributor

evgenyz commented Nov 22, 2023

It really feels like the code (and developers' personal preferences) is asking for the line length limit to be 120 instead of 100.

@jan-cerny
Copy link
Member Author

Not really. All the lines that are flagged as too long are in the list of URLs (KNOWN_REFERENCES) because the URLs are long. I think we can waive this occurrence as a special case. I think it's more useful to keep the URLs as they are instead of splitting them by a backlash because if they are kept as they are they can be easily identified by grep when a need to update them arise.

Copy link
Member

@Honny1 Honny1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the new style of references, but I have some ideas for improvements.

from dataclasses import replace

from ..data_structures import Identifier, Reference, Rule, RuleWarning
from ..namespaces import NAMESPACES
from .full_text_parser import FullTextParser
from .remediation_parser import RemediationParser

KNOWN_REFERENCES = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add comments to the code to turn off long-line warnings for this constant.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have add the comments.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pylint is not happy. Please use # pylint: disable=line-too-long before the constant definition and # pylint: enable=line-too-long after the constant definition. You can check this with the tox -e code_style command.

references.append(Reference(referenc.get("href"), referenc.text))
return references
for url, ref_ids in url_to_ref_ids.items():
name = KNOWN_REFERENCES.get(url, url)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest creating a default value for the name if the href attribute is an empty string.
For example, reference SRG-OS-000003-VMM-000030 of the xccdf_org.ssgproject.content_rule_account_disable_post_pw_expiration rule.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! You're right, the href attribute of the reference element is optional.

I have add code that accounts for this situation.

However, this situation shouldn't happen in our content. The reference without href makes little sense. Do you have a specific SCAP content or its version where this happens?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the latest content and all the href attributes are not empty strings.

I found this in:
SSG: [0, 1, 63]
Rule: xccdf_org.ssgproject.content_rule_account_disable_post_pw_expiration
Reference: SRG-OS-000003-VMM-000030

<div class="pf-l-flex pf-m-column"><div class="pf-l-flex__item">
<p class="pf-c-table__text">
<div>
<table>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create a responsive table using CSS classes from Patternfly. Missing CCS classes cause a grey bar. See image.
image

I think that the rows of the internal table with references should span the full width of the table cell with the OVAL definition.
Screenshot from 2023-11-27 19-41-09

Example rule: xccdf_org.ssgproject.content_rule_account_unique_name

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have add some class name that I have seen around. I'm not sure if it's correct because I don't have any experience with that. Please check this and point me to some resources.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is Patternfly documentation. Looks good to me.

These lines are too long according to the PEP8. But, I think we can
waive this occurrence as a special case. I think it's more useful to
keep the URLs as they are instead of splitting them by a backlash
because if they are kept as they are they can be easily identified by
grep when a need to update them arise.
The `href` attribute of the `reference` element is optional according to
the XCCDF specification. This commit solves the situation when the
`href` attribute is not set. In this situation, the reference source is
unknown, we don't know where this reference points to so we will put in
in a new "unknown" reference category to be displayed in the HTML
report.
@Honny1 Honny1 self-requested a review November 28, 2023 15:18
from dataclasses import replace

from ..data_structures import Identifier, Reference, Rule, RuleWarning
from ..namespaces import NAMESPACES
from .full_text_parser import FullTextParser
from .remediation_parser import RemediationParser

KNOWN_REFERENCES = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pylint is not happy. Please use # pylint: disable=line-too-long before the constant definition and # pylint: enable=line-too-long after the constant definition. You can check this with the tox -e code_style command.

@jan-cerny
Copy link
Member Author

I have add comments for the pylint tool

url_to_ref_ids = collections.defaultdict(list)
for reference_el in rule.findall(".//xccdf:reference", NAMESPACES):
url = reference_el.get("href")
if url is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is a little catch. I found out that in the reference element is present the href attribute but with an empty string so it looks like this: <reference href="">Example</reference>. So in a variable url is a present empty string. Please add a check for the empty string to the if condition.

@jan-cerny
Copy link
Member Author

I have extend the condition to account empty strings in href.

Copy link
Member

@Honny1 Honny1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the new presentation style of references. I have generated a report and checked the new presentation of references. I haven't noticed any problem.

@Honny1 Honny1 merged commit dc74e88 into OpenSCAP:main Dec 7, 2023
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

References are useless
4 participants