-
Notifications
You must be signed in to change notification settings - Fork 364
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
sbom tool cycloneDX #3959
base: develop2
Are you sure you want to change the base?
sbom tool cycloneDX #3959
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is looking good, a couple of small additions:
- Adding the
conanfile.subgraph
docs somewhere, as experimental too - Adding a small example with a hook using the
.subgraph.serialize()
to serialize the conan graph.json. It can be done also to put it inside the binary package metadata folder in the same way as the cyclonedx. It can be a parallel section to theCycloneDX
one, calledConan
- Remind somewhere that the contents of the files are also subject to modifications and evolution, they might change in future version
json.dump(sbom_cyclonedx_1_4, f, indent=4) | ||
ConanOutput().success(f"CYCLONEDX CREATED - {conanfile.generators_folder}") | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets add a small reference
section for the cyclonedx_1_4()
function.
Let's look at two examples: | ||
|
||
In the first one, we have the case where we want to generate the SBOM at the moment we create our app, after the | ||
package method. This is very useful for keeping track of the components and dependencies of our software. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
package method. This is very useful for keeping track of the components and dependencies of our software. | |
package method. This is very useful for keeping track of the components and dependencies of that went into building our software. |
import os | ||
from conan.api.output import ConanOutput | ||
from conan.tools.sbom.cyclonedx import cyclonedx_1_4 | ||
def post_package(conanfile): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def post_package(conanfile): | |
def post_package(conanfile, **kwargs): |
Most hook examples should have this so that in the future we can more easily update their signature if it's ever needed
import os | ||
from conan.api.output import ConanOutput | ||
from conan.tools.sbom.cyclonedx import cyclonedx_1_4 | ||
def post_generate(conanfile): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def post_generate(conanfile): | |
def post_generate(conanfile, **kwargs): |
os.mkdir(os.path.join(generators_folder, "sbom")) | ||
with open(os.path.join(generators_folder, "sbom", file_name), 'w') as f: | ||
json.dump(sbom_cyclonedx_1_4, f, indent=4) | ||
ConanOutput().success(f"CYCLONEDX CREATED - {conanfile.generators_folder}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a comment that both hooks are outputting their sbom in different places?
import json | ||
import os | ||
from conan.api.output import ConanOutput | ||
def post_package(conanfile): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def post_package(conanfile): | |
def post_package(conanfile, **kwargs): |
|
||
Instead of using a standard, we can take a Conan-based approach. Thanks to the ``conanfile.subgraph.serialize()`` | ||
function, we can directly obtain information about the dependencies of our program. | ||
In the following example, we can see a hook that generates this simplified SBOM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the following example, we can see a hook that generates this simplified SBOM. | |
In the following example, we can see a hook that generates a simplified SBOM | |
consisting of the serialization of the subgraph, which includes all data Conan has | |
about the specific dependencies. |
or something like this, as I don't think either method is too documented right now
conan-io/conan#17559