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

Rework of cpe_generate.py #11644

Merged
merged 12 commits into from
Mar 7, 2024
Merged

Conversation

Honny1
Copy link
Collaborator

@Honny1 Honny1 commented Mar 1, 2024

Description:

This PR reworks the cpe_generate.py script. It simplifies the code for future enhancements such as reducing CPE AL in the data stream. The script uses the OVAL object model to process OVAL. And it separates the process of creating the CPE dictionary and the CPE OVAL.

Review Hints:

These changes shouldn't change the functionality of the script.

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Used by openshift-ci bot. label Mar 1, 2024
Copy link

openshift-ci bot commented Mar 1, 2024

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

Copy link

github-actions bot commented Mar 1, 2024

Start a new ephemeral environment with changes proposed in this pull request:

Fedora Environment
Open in Gitpod

Oracle Linux 8 Environment
Open in Gitpod

Copy link

github-actions bot commented Mar 1, 2024

🤖 A k8s content image for this PR is available at:
ghcr.io/complianceascode/k8scontent:11644
This image was built from commit: dbf1e69

Click here to see how to deploy it

If you alread have Compliance Operator deployed:
utils/build_ds_container.py -i ghcr.io/complianceascode/k8scontent:11644

Otherwise deploy the content and operator together by checking out ComplianceAsCode/compliance-operator and:
CONTENT_IMAGE=ghcr.io/complianceascode/k8scontent:11644 make deploy-local

@Honny1 Honny1 marked this pull request as ready for review March 4, 2024 14:01
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Used by openshift-ci bot. label Mar 4, 2024
@Honny1 Honny1 added enhancement General enhancements to the project. Infrastructure Our content build system labels Mar 5, 2024
@jan-cerny jan-cerny self-assigned this Mar 6, 2024
Comment on lines 130 to 131
# Lets scrape the shorthand for the list of platforms referenced
benchmark_cpe_names = get_benchmark_cpe_names(args.shorthandfile)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This file actually isn't in shorthand format. It's build/${product}/ssg-${product}-xccdf.xml which is a normal XCCDF document. This comment is outdated. We should change the comment and rename all variables accordingly. Also, we need to rename the argument shorthandfile.

Comment on lines 89 to 84
# skip CPE AL platforms (they are handled later)
# this is temporary solution until we get rid of old type of platforms in the benchmark
if cpe_name.startswith("#"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you check if what the comment says is still the case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I think it's still relevant because, for example, OS platforms use CPE identifiers and CPE dictionaries.


# parse oval file
ovaltree = ssg.xml.parse_file(args.ovalfile)
def load_oval(args):
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's better to not pass args down here. Instead, this function should have 2 specific arguments.


# parse oval file
ovaltree = ssg.xml.parse_file(args.ovalfile)
def load_oval(args):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the name of this function is misleading, it's load_oval but it actually does many more actions that just loading. Please rename it.

Comment on lines 77 to 72
# turn IDs into meaningless numbers
translator = ssg.id_translate.IDTranslator(args.idname)
ovaltree = translator.translate(ovaltree)
oval_document = translator.translate_oval_document(oval_document, store_defname=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The IDs aren't turned into "meaningless numbers", they're added prefix, suffix and number, which makes them unique, but not meaningless.


def load_cpe_dictionary(benchmark_cpe_names, product_yaml, args):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't like that the args is passed down in here. I think that the function should have 2 specific arguments instead of the args argument.

Comment on lines 40 to 43
p.add_argument(
"idname",
help="Identifier prefix"
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

When we are here can we actually make this a constant please? I think that it's unlikely to ever be anything different than ssg.

@jan-cerny
Copy link
Collaborator

Also, I have noticed that there are frequent typos in your commit messages. I think I pointed out this before in one of your previous PRs. Please employ a spell checker.

Copy link

codeclimate bot commented Mar 7, 2024

Code Climate has analyzed commit dbf1e69 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 50.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 59.8% (0.0% change).

View more on Code Climate.

Copy link
Collaborator

@jan-cerny jan-cerny left a comment

Choose a reason for hiding this comment

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

I have reviewed the code and I have reviewed the generated output from the RHEL 8 product, focusing on the CPE OVAL and CPE dictionary.

@jan-cerny jan-cerny merged commit f0474eb into ComplianceAsCode:master Mar 7, 2024
44 checks passed
@jan-cerny jan-cerny added this to the 0.1.73 milestone Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement General enhancements to the project. Infrastructure Our content build system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants