-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add options to merge command for controlling creation of system entry and type of relationships #201
base: main
Are you sure you want to change the base?
Conversation
@click.command("merge") | ||
def merge_command(input_sboms, sbom_outfile, config_file, output_format, input_format): | ||
def merge_command( |
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.
If you want to clean this up a bit, you could use **kwargs. But it isn't neccessary
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.
I've been thinking about how to handle this pattern in click that seems to result in function definitions with a lot of arguments -- ideally I'd like to have a function that makes the feature usable when using Surfactant as a library, which will probably need at least one function with many args.
**kwargs could be a nice solution to avoid having two functions with duplicate function signatures that have many args and need to be kept in sync. I'll look into this some more and probably convert the generate subcommand at the same time.
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.
Ah I see, I think you can achieve this by creating a custom decorator that adds options or args in the way you want. Similar to what you see in this stack overflow post: https://stackoverflow.com/questions/50061342/is-it-possible-to-reuse-python-click-option-decorators-for-multiple-commands
@nightlark I'm a bit concerned with the functionality of creating a contains relationship with a randomly generated uuid if no system uuid is present and the user specifies they don't want one added. This would create a relationship to a uuid that has no information attached to it, so a user looking at it wouldn't know if it was a system uuid, software uuid, or what. I think it would be better to require the user to provide a uuid to link to if no system uuid is present and a system object is not to be added. This would prevent floating UUIDs with no meaning attached to them. Thoughts? |
@nightlark Also I typically use Includes for merges, what was the reason for changing the default to Contains? |
If possible I would also add a few unit tests! |
Mostly consistency -- I was talking with Aaron about what relationships other labs were using in their SBOMs for tying software entries to the system object, and it seems everyone else is using "Contains".
Oof... that would be fun to figure out why an SBOM fails validation when uploading to the repository. I'll add a command line option for providing a system_uuid, and checks to make sure a relationship to a random UUID is only added if the system was also added. I'll also make so that command line options take precedence over the config file like I'd originally planned. |
Ah got it, maybe I'm using them wrong then :D |
babdba3
to
7439af4
Compare
@nightlark The fix for the random uuid looks good! The logic if random system uuid is used, you must add the system object to the sbom makes sense to me and will prevent any floating uuids from getting generated. |
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.
Copilot reviewed 1 out of 1 changed files in this pull request and generated no suggestions.
Comments skipped due to low confidence (3)
surfactant/cmd/merge.py:205
- The docstring of the create_system_object function should be updated to reflect the new return type (System, bool).
def create_system_object(sbom: SBOM, config=None, system_uuid=None) -> Tuple[System, bool]:
surfactant/cmd/merge.py:121
- Ensure consistent use of system.UUID instead of system["UUID"].
Relationship(xUUID=system.UUID, yUUID=r, relationship=system_relationship)
surfactant/cmd/merge.py:47
- [nitpick] Improve the error message to provide more context, e.g., 'UUID xUUID or yUUID does not exist in the graph.'
logger.error("====ERROR xUUID or yUUID doesn't exist====")
…t and controlling the type of relationship created
for more information, see https://pre-commit.ci
…ndomly generated UUIDs without a system object
for more information, see https://pre-commit.ci
5bc1e12
to
4d7e0dc
Compare
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
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.
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 suggestion.
Adds several options to the merge subcommand for controlling if a system entry should be created, and what type should be used for the relationships created.
This enables workflow where relationships to a UUID should be created, but the system UUID was added to e.g. an SBOM repository as part of a separate file.
The more "standard"
Contains
relationship is used instead of theIncludes
relationship that apparently was unique to Surfactant merged SBOMs.Changes
["UUID"]
) instead of as a member variable (.UUID
)Resolves #115
Resolves #116