feat(materials): extract main component info from SPDX files#2984
feat(materials): extract main component info from SPDX files#2984waveywaves wants to merge 3 commits intochainloop-dev:mainfrom
Conversation
143b790 to
76e2477
Compare
Follow the CycloneDX pattern to extract and populate MainComponent in SBOMArtifact for SPDX JSON materials. Uses spdxlib.GetDescribedPackageIDs to find the described package, then extracts name, version, and kind (PrimaryPackagePurpose). Container names are standardized via go-containerregistry. Gracefully skips when no described package is found. Fixes chainloop-dev#2580 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com>
The Id field is deprecated in crafting_state.proto (kept only for server-side compatibility). Remove the test assertion to fix the SA1019 staticcheck lint failure. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com>
76e2477 to
9e0f4dc
Compare
jiparis
left a comment
There was a problem hiding this comment.
Thanks @waveywaves. Please check my comments.
| // since we cannot determine the component kind. | ||
| kind := strings.ToLower(describedPkg.PrimaryPackagePurpose) | ||
| if kind == "" { | ||
| return fmt.Errorf("described package %q has no PrimaryPackagePurpose set", describedPkg.PackageName) |
There was a problem hiding this comment.
In this case, as a best effort, it could just return name and version. Not sure if Kind is expected in other parts of the code.
There was a problem hiding this comment.
Good point — now returns name and version as best effort when PrimaryPackagePurpose is absent. Kind will be empty string.
| // For container packages, standardize the name via go-containerregistry | ||
| // to get the full repository name and strip any tag (matching CycloneDX behavior) | ||
| if kind == containerComponentKind { | ||
| ref, err := remotename.ParseReference(name) |
There was a problem hiding this comment.
Here it's likely that chainloop doesn't have the credentials for this query in most cases. Instead of returning, I'd just continue and return the existing values.
There was a problem hiding this comment.
Makes sense — chainloop likely won't have registry credentials in most cases. Now logs at debug level and continues with the original name instead of returning an error.
Address review feedback: - Return name and version even when PrimaryPackagePurpose is absent (kind will be empty string instead of erroring out) - When OCI image reference parsing fails (e.g. missing registry credentials), log at debug level and continue with the original name instead of returning an error Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com>
Summary
spdxlib.GetDescribedPackageIDsto identify the described package, then populateSBOMArtifact.MainComponentwith the package's name, version, and lowercasedPrimaryPackagePurposego-containerregistry(same as CycloneDX) and gracefully skip when no described package is foundFixes #2580
Test plan
go vetpasses cleanly🤖 Generated with Claude Code