-
Notifications
You must be signed in to change notification settings - Fork 590
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
feat: add cyclonedx schema version selection #2123
Merged
+274
−24
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b9988df
wip: add cyclonedx schema version selection
spiffcs eb009e8
fix: fix static analysis
spiffcs 12355d8
fix: update unit tests back to correct state
spiffcs beffca2
fix: update cli tests by pinning default cyclonedx to v1.4
spiffcs 1f62e19
fix: reorient FormatID and alias for cyclonedx-xml
spiffcs 9aec01d
fix: update TODO with comment on when 1.5 is stable
spiffcs 0e2ddc4
fix: keep aliases to the original format
spiffcs 8cffa74
fix: comment with more context
spiffcs 0f80acc
fix: more generic match for other alias
spiffcs 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 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 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 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 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 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 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,34 @@ | ||
package cyclonedxjson | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/CycloneDX/cyclonedx-go" | ||
) | ||
|
||
func TestFormatVersions(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
expectedVersion string | ||
}{ | ||
{ | ||
|
||
"cyclonedx-json should default to v1.4", | ||
cyclonedx.SpecVersion1_4.String(), | ||
}, | ||
} | ||
|
||
for _, c := range tests { | ||
c := c | ||
t.Run(c.name, func(t *testing.T) { | ||
sbomFormat := Format() | ||
if sbomFormat.ID() != ID { | ||
t.Errorf("expected ID %q, got %q", ID, sbomFormat.ID()) | ||
} | ||
|
||
if sbomFormat.Version() != c.expectedVersion { | ||
t.Errorf("expected version %q, got %q", c.expectedVersion, sbomFormat.Version()) | ||
} | ||
}) | ||
} | ||
} |
This file contains 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 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 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 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 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,33 @@ | ||
package syftjson | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/anchore/syft/internal" | ||
) | ||
|
||
func TestFormat(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
version string | ||
}{ | ||
{ | ||
name: "default version should use latest internal version", | ||
version: "", | ||
}, | ||
} | ||
|
||
for _, c := range tests { | ||
c := c | ||
t.Run(c.name, func(t *testing.T) { | ||
sbomFormat := Format() | ||
if sbomFormat.ID() != ID { | ||
t.Errorf("expected ID %q, got %q", ID, sbomFormat.ID()) | ||
} | ||
|
||
if sbomFormat.Version() != internal.JSONSchemaVersion { | ||
t.Errorf("expected version %q, got %q", c.version, sbomFormat.Version()) | ||
} | ||
}) | ||
} | ||
} |
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.
It might be nice to programmatically build these formats, something like this could live in the
common/cyclonedxhelpers
package:This way there only needs to be a single
encodeCycloneDX()
function and adding new versions is just updating the list, which would update both XML and JSON variants. E.g. the XML variant would have: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.
This is a good suggestion, but I think we wanted to save this kind of work for when we go back and take a look at Formats before syft v1.0. The purpose of this PR was to just keep this as close to the same pattern as we have with SPDX. Getting creative here and trying to build these programmatically (different from the current SPDX pattern) would eventually get swallowed by that new work.
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.
agreed to the both of you -- it's a good suggestion, but it would be better to be consistent with the current pattern first, then refactor to "the next" pattern.