-
Couldn't load subscription status.
- Fork 37
feat(crafter): support multiple tools in chainloop metadata #2481
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3e4e4b6
support multiple tools for cdx
Piskoo e0a81b0
add support for spdx
Piskoo 483c2d3
missing test file
Piskoo ff320da
use array for versions
Piskoo 29aa93e
lint
Piskoo fe354c7
hide legacy tool annotations from output
Piskoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,9 +66,12 @@ func TestNewSPDXJSONCrafter(t *testing.T) { | |
|
|
||
| func TestSPDXJSONCraft(t *testing.T) { | ||
| testCases := []struct { | ||
| name string | ||
| filePath string | ||
| wantErr string | ||
| name string | ||
| filePath string | ||
| wantErr string | ||
| wantDigest string | ||
| wantFilename string | ||
| annotations map[string]string | ||
| }{ | ||
| { | ||
| name: "invalid sbom format", | ||
|
|
@@ -86,8 +89,26 @@ func TestSPDXJSONCraft(t *testing.T) { | |
| wantErr: "unexpected material type", | ||
| }, | ||
| { | ||
| name: "valid artifact type", | ||
| filePath: "./testdata/sbom-spdx.json", | ||
| name: "valid artifact type", | ||
| filePath: "./testdata/sbom-spdx.json", | ||
| wantDigest: "sha256:fe2636fb6c698a29a315278b762b2000efd5959afe776ee4f79f1ed523365a33", | ||
| wantFilename: "sbom-spdx.json", | ||
| annotations: map[string]string{ | ||
| "chainloop.material.tool.name": "syft", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, this one, thanks |
||
| "chainloop.material.tool.version": "0.73.0", | ||
| "chainloop.material.tools": `["syft@0.73.0"]`, | ||
| }, | ||
| }, | ||
| { | ||
| name: "multiple tools", | ||
| filePath: "./testdata/sbom-spdx-multiple-tools.json", | ||
| wantDigest: "sha256:c1a61566c7c0224ac02ad9cd21d90234e5a71de26971e33df2205c1a2eb319fc", | ||
| wantFilename: "sbom-spdx-multiple-tools.json", | ||
| annotations: map[string]string{ | ||
| "chainloop.material.tool.name": "spdxgen", | ||
| "chainloop.material.tool.version": "1.0.0", | ||
| "chainloop.material.tools": `["spdxgen@1.0.0","scanner@2.1.5"]`, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
|
|
@@ -123,10 +144,17 @@ func TestSPDXJSONCraft(t *testing.T) { | |
| assert.Equal(contractAPI.CraftingSchema_Material_SBOM_SPDX_JSON.String(), got.MaterialType.String()) | ||
| assert.True(got.UploadedToCas) | ||
|
|
||
| // // The result includes the digest reference | ||
| // The result includes the digest reference | ||
| assert.Equal(got.GetArtifact(), &attestationApi.Attestation_Material_Artifact{ | ||
| Id: "test", Digest: "sha256:fe2636fb6c698a29a315278b762b2000efd5959afe776ee4f79f1ed523365a33", Name: "sbom-spdx.json", | ||
| Id: "test", Digest: tc.wantDigest, Name: tc.wantFilename, | ||
| }) | ||
|
|
||
| // Validate annotations if specified | ||
| if tc.annotations != nil { | ||
| for k, v := range tc.annotations { | ||
| assert.Equal(v, got.Annotations[k]) | ||
| } | ||
| } | ||
| }) | ||
| } | ||
| } | ||
27 changes: 27 additions & 0 deletions
27
pkg/attestation/crafter/materials/testdata/sbom-spdx-multiple-tools.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| { | ||
| "spdxVersion": "SPDX-2.3", | ||
| "dataLicense": "CC0-1.0", | ||
| "SPDXID": "SPDXRef-DOCUMENT", | ||
| "name": "test-multiple-tools", | ||
| "documentNamespace": "https://example.com/test/multiple-tools", | ||
| "creationInfo": { | ||
| "licenseListVersion": "3.20", | ||
| "creators": [ | ||
| "Organization: Example Corp", | ||
| "Tool: spdxgen-1.0.0", | ||
| "Tool: scanner-2.1.5" | ||
| ], | ||
| "created": "2024-01-01T10:00:00Z" | ||
| }, | ||
| "packages": [ | ||
| { | ||
| "name": "example-package", | ||
| "SPDXID": "SPDXRef-Package-example", | ||
| "versionInfo": "1.0.0", | ||
| "downloadLocation": "NOASSERTION", | ||
| "licenseConcluded": "MIT", | ||
| "licenseDeclared": "MIT", | ||
| "copyrightText": "NOASSERTION" | ||
| } | ||
| ] | ||
| } |
41 changes: 41 additions & 0 deletions
41
pkg/attestation/crafter/materials/testdata/sbom.cyclonedx-1.5-multiple-tools.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| { | ||
| "$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json", | ||
| "bomFormat": "CycloneDX", | ||
| "specVersion": "1.5", | ||
| "serialNumber": "urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79", | ||
| "version": 1, | ||
| "metadata": { | ||
| "timestamp": "2025-09-28T07:00:46Z", | ||
| "tools": { | ||
| "components": [ | ||
| { | ||
| "type": "application", | ||
| "author": "Black Duck", | ||
| "name": "Hub", | ||
| "version": "2025.4.2" | ||
| }, | ||
| { | ||
| "type": "library", | ||
| "author": "CycloneDX", | ||
| "name": "cyclonedx-core-java", | ||
| "version": "5.0.5" | ||
| } | ||
| ] | ||
| }, | ||
| "component": { | ||
| "bom-ref": "test-component", | ||
| "type": "application", | ||
| "name": "test-app", | ||
| "version": "1.0.0" | ||
| } | ||
| }, | ||
| "components": [ | ||
| { | ||
| "bom-ref": "pkg:golang/example.com/test@v1.0.0", | ||
| "type": "library", | ||
| "name": "example.com/test", | ||
| "version": "v1.0.0", | ||
| "purl": "pkg:golang/example.com/test@v1.0.0" | ||
| } | ||
| ] | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
so even if we have one tool, it will use also the new annotation correct?
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.
Correct, example:
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.
should we hide the deprecated method from the output?
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.
Updated, hidden from
att addandatt status