Skip to content

support inspect-manifest for CycloneDx 1.4 - #592

Merged
tdruez merged 6 commits into
aboutcode-org:mainfrom
keshav-space:import_cyclonedx
Mar 3, 2023
Merged

support inspect-manifest for CycloneDx 1.4#592
tdruez merged 6 commits into
aboutcode-org:mainfrom
keshav-space:import_cyclonedx

Conversation

@keshav-space

Copy link
Copy Markdown
Member
  • A CycloneDx component can have a list of components, those are dumped to extra_data as nestedComponents. Furthermore, these lists of components are recursively parsed and treated as normal package.
  • The Component may have multiple URLs in externalReferences. The first URL of the reference is added to the applicable package_data URL, while the rest are dumped in extra_data as externalReferences.

fixes #583

Signed-off-by: Keshav Priyadarshi git@keshav.space

@keshav-space
keshav-space marked this pull request as draft January 27, 2023 15:55
@keshav-space
keshav-space marked this pull request as ready for review January 30, 2023 13:12
@keshav-space
keshav-space force-pushed the import_cyclonedx branch 2 times, most recently from 1caeffc to 3e37835 Compare January 30, 2023 15:35

@AyanSinhaMahapatra AyanSinhaMahapatra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! A few initial nits and comments for you.

Comment thread scanpipe/cyclonedx/__init__.py Outdated
Comment thread scanpipe/cyclonedx/__init__.py Outdated
Requires the `jsonschema` library.
"""
try:
import jsonschema

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Isn't jsonschema in install_requires? Will this ever fail?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Isn't jsonschema in install_requires?

I was just being consistent with spdx.validate_document 😅
https://github.com/nexB/scancode.io/blob/0b4053ebe8c229c18308c0e96af8346842b75a7b/scanpipe/spdx/__init__.py#L648-L659

Will this ever fail?

Let me confirm if it!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Will this ever fail?

I checked, it will never fail. Will get this removed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe we can remove this in spdx too (?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Maybe we can remove this in spdx too (?)

I will enter an issue for that and if there is no objection then we can go ahead and remove it.

Sounds good?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is just a tiny nit, too small for a separate issue, just keep this conversation open for others to comment.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ack

Comment thread scanpipe/cyclonedx/__init__.py Outdated
Comment thread scanpipe/pipes/resolve.py Outdated
@AyanSinhaMahapatra

Copy link
Copy Markdown
Member

@kpriyadarshi I ran a inspect_manifest pipeline from your branch and it worked great!

INFO "GET /project/add/ HTTP/1.1" 200 35090
INFO Fetching "https://raw.githubusercontent.com/keshav-space/scancode.io/import_cyclonedx/scanpipe/tests/data/cyclonedx/asgiref-3.3.0.bom.json" using fetch_http
INFO Run[e650ea41-ba7a-4e61-85a5-5abfd6f316a7] Enter `execute_pipeline_task` Run.pk/Task.id=e650ea41-ba7a-4e61-85a5-5abfd6f316a7
INFO Run[e650ea41-ba7a-4e61-85a5-5abfd6f316a7] Run pipeline: "inspect_manifest" on project: "cyclonedx-test-asgiref-3.3.0"
INFO 2023-02-01 16:39:52.46 Pipeline [inspect_manifest] starting
INFO 2023-02-01 16:39:52.46 Step [get_manifest_inputs] starting
INFO 2023-02-01 16:39:52.46 Step [get_manifest_inputs] completed in 0.00 seconds
INFO 2023-02-01 16:39:52.46 Step [create_packages_from_manifest] starting
INFO 2023-02-01 16:39:52.46 `cyclonedx` input detected for /home/ayansinha/nexB/main_repos/gh-cli-repos/scancode.io/var/projects/cyclonedx-test-asgiref-330-9e28864f/input/asgiref-3.3.0.bom.json
INFO 2023-02-01 16:39:52.52 Step [create_packages_from_manifest] completed in 0.05 seconds
INFO 2023-02-01 16:39:52.52 Pipeline completed
INFO Run[e650ea41-ba7a-4e61-85a5-5abfd6f316a7] Update Run instance with exitcode, output, and end_date
INFO "POST /project/add/ HTTP/1.1" 302 0
INFO "GET /project/9e28864f-d580-4e10-8ec0-bb515c5d66d5/ HTTP/1.1" 200 19754
INFO "GET /project/9e28864f-d580-4e10-8ec0-bb515c5d66d5/charts/ HTTP/1.1" 200 4491
INFO "GET /project/9e28864f-d580-4e10-8ec0-bb515c5d66d5/packages/ HTTP/1.1" 200 8867
INFO "GET /project/9e28864f-d580-4e10-8ec0-bb515c5d66d5/packages/30/ HTTP/1.1" 200 22602
INFO "GET /project/add/ HTTP/1.1" 200 35090

The license_expression also seems to work fine:

License expression

    bsd-new AND bsd-new

Declared license

    BSD-3-Clause AND BSD-3-Clause

I'll check with some more complicated cyclonedx boms, and let you know!

@tdruez tdruez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@keshav-space great start, here's some suggestions to improve the code:

  • We do not use typing in ScanCode.io at the moment, you want to be consistent with the existing codebase convention.
  • Do not use the or [] syntax.
  • Do not use obj nor iterableas variable names but try to name things what they are.
  • Some docstring are not ending with a .
  • The integraiton test is great, but we are missing a unit test for each functions of the cyclonedx module.

Comment thread Makefile
Comment thread scanpipe/cyclonedx/__init__.py Outdated
Comment thread scanpipe/cyclonedx/__init__.py Outdated
Comment thread scanpipe/cyclonedx/jsf-0.82.schema.json
Comment thread scanpipe/cyclonedx/spdx.schema.json
Comment thread scanpipe/pipes/resolve.py Outdated
Comment thread scanpipe/pipes/resolve.py Outdated
@keshav-space
keshav-space force-pushed the import_cyclonedx branch 2 times, most recently from 5ae8195 to 75ecd2a Compare February 20, 2023 16:17
@keshav-space
keshav-space requested a review from tdruez February 20, 2023 16:54

@tdruez tdruez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@keshav-space see my various comments for refinements, also:

  • You have "CycloneDx" and "CYCLONEDX" occurrences that need to be replaced by the proper syntax: "CycloneDX".
  • I gave you "write" access on the repo so in the future you can create branches directly on the repo.

Comment thread scanpipe/cyclonedx/__init__.py Outdated
Comment thread scanpipe/cyclonedx/__init__.py
Comment thread scanpipe/cyclonedx/__init__.py Outdated
Comment thread scanpipe/cyclonedx/__init__.py Outdated
Comment thread scanpipe/cyclonedx/__init__.py Outdated
Comment thread scanpipe/cyclonedx/__init__.py Outdated
Comment thread scanpipe/cyclonedx/__init__.py Outdated
Comment thread scanpipe/cyclonedx/__init__.py Outdated
Comment on lines +175 to +166
resolver = jsonschema.RefResolver(
base_uri="file://" + str(pathlib.Path(__file__).parent), referrer=schema
)

validator = jsonschema.Draft7Validator(schema=schema, resolver=resolver)

validator.validate(instance=document)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this complexity needed?
The basic jsonschema.validate(instance=document, schema=schema) is not enough in the CycloneDX case?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

jsonschema.validate(instance=document, schema=schema) will work, but if BOM contains an invalid SPDX license expression, then hoppr-cyclonedx-models won't be able to parse it. The same thing goes for JSF.

Comment thread setup.cfg Outdated
- CycloneDx `component` can have a `list of components`, those are dumped to extra_data as `nestedComponents`. Furthermore, these lists of components are recursively parsed and treated as normal package.
- The Component may have multiple URLs in externalReferences. The first URL of the reference is added to the applicable package_data URL, while the rest are dumped in extra_data as externalReferences.

Fixes aboutcode-org#583

Signed-off-by: Keshav Priyadarshi <git@keshav.space>
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
@keshav-space
keshav-space requested review from tdruez March 2, 2023 19:00
@tdruez
tdruez merged commit ae4860c into aboutcode-org:main Mar 3, 2023
@keshav-space
keshav-space deleted the import_cyclonedx branch June 8, 2023 11:02
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.

Add support for CycloneDX 1.4 to the "inspect-manifest" pipeline to import the SBOM into a Project

3 participants