-
Notifications
You must be signed in to change notification settings - Fork 587
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
Refactor source API #1846
Refactor source API #1846
Conversation
Benchmark Test ResultsBenchmark results from the latest changes vs base branch
|
92b411b
to
869d879
Compare
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
869d879
to
f33166d
Compare
note from sync review: this is a good time to make all breaking changes now, can we finalize |
from sync review:
|
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.
Left some initial feedback, overall looking like a 👍 change
syft/source/directory_source.go
Outdated
// from the path provided with an attempt to prune a prefix if a base is given. Since the contents of the directory | ||
// are not considered, there is no semantic meaning to the artifact ID -- this is why the alias is preferred without | ||
// consideration for the path. | ||
func deriveIDFromDirectory(cwd string, cfg DirectoryConfig) artifact.ID { |
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.
why is CWD part of this?
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 looks like it was needed for the chroot object, but I'm not using it to determine the ID here. I've updated this to extract cwd entirely from this execution path.
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
…n-location-refactor Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
7880d62
to
15fc598
Compare
// scanning root changes (e.g. a user scans a directory, then moves it to a new location and scans again). | ||
info = fmt.Sprintf("%s@%s", cfg.Alias.Name, cfg.Alias.Version) | ||
} else { | ||
log.Warn("no explicit name and version provided for directory source, deriving artifact ID from the given path (which is not ideal)") |
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 wanted to call out this change explicitly -- I still haven't been able to reconcile what a "good" ID is for a directory (that isn't too expensive to figure). But I've added this warning to at least let folks know that if you're doing a directory scan an are not setting --source-name
or --source-version
explicitly then this is most likely wrong. I didn't call out the specific options since this is the lib path and not in the cmd pkg.
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 this be an Info or Debug message? This will show for every directory scan otherwise, I think
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 think that's the problem with the directory source ID -- it's really not adequate for any use case where you're trying to cross correlate SBOMs historically since it's brittle and may overlap with entirely unrelated scans. It feels like it should be a warning for that reason.
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 did find that this wasn't showing up though, and I discovered why: we can't assume that a pointer to alias means that the alias is optional, we still need to check individual fields. I've updated the API to not take alias pointers in config objects (any spot on the exported API where they were function args it is still a pointer though). This allows for the zero value to be used in configs (or for the caller to fully specify like with the cmd package) and we need to check the name and version explicitly, which was already being done in some circumstances.
"reflect" | ||
) | ||
|
||
func AllNames() []string { |
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.
question: I missed this in the sync review, but where the "incorrect" names being handled?
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 PR doesn't go all the way with the packagemetadata
, that's reserved for #1844 . In short, this isn't used yet (except for a test), only AllTypes() is used and is consistent with the sourcemetadata
package approach. The value add for adding this in this PR was to add the completion test around packagemetadata.AllNames()
to detect when there is drift with the ast analysis and the generated code... a test that will be extended to include the JSON name mapping in #1844 (as done in the sourcemetadata.AllNames()
completion test).
// scanning root changes (e.g. a user scans a directory, then moves it to a new location and scans again). | ||
info = fmt.Sprintf("%s@%s", cfg.Alias.Name, cfg.Alias.Version) | ||
} else { | ||
log.Warn("no explicit name and version provided for directory source, deriving artifact ID from the given path (which is not ideal)") |
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 this be an Info or Debug message? This will show for every directory scan otherwise, I think
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
* main: feat: CLI flag for directory base (#1867) Fix CPE gen for k8s python client (#1921) chore: update iterations to protect against race (#1927) chore(deps): update bootstrap tools to latest versions (#1922) fix: Don't use the actual redis or grpc CPEs for gems (#1926) fix(install): return with right error code (#1915) Remove erroneous Java CPEs from generation (#1918) chore(deps): bump golang.org/x/net from 0.11.0 to 0.12.0 (#1916) Switch UI to bubbletea (#1888) fix: use filepath.EvalSymlinks if os.Readlink fails to evaluate the link (#1884) add file source digest support (#1914) chore(deps): update bootstrap tools to latest versions (#1908) chore(deps): bump golang.org/x/mod from 0.11.0 to 0.12.0 (#1912) chore(deps): bump golang.org/x/term from 0.9.0 to 0.10.0 (#1913) doc(readme): add installation section with scoop (#1909) Refactor source API (#1846) chore(deps): update bootstrap tools to latest versions (#1905)
* refactor source API and syft json source block Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * update source detection and format test utils Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * generate list of all source metadata types Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * extract base and root normalization into helper functions Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * preserve syftjson model package name import ref Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * alias should not be a pointer Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> --------- Signed-off-by: Alex Goodman <alex.goodman@anchore.com> Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Refactors the single uber-object of
source.Source
into multiple single responsibility objects (e.g.source.DirectorySource
,source.StereoscopeImageSource
, etc) that all fall under the same (new)source.Source
abstraction:There are two ways to create a source object:
The first is new with this PR:
The second was a simplification of the existing approach:
Open questions:
source.target
section JSON output captured in the JSON schema -- should we start to do this?Breaking changes:
source.target
section in the JSON output (now calledsource.metadata
), however, we have never made guarantees about this section of the JSON document.source.Source
interface replaces the existing object, which breaks the existing API.Main changes:
FileSource
,DirectorySource
, andStereoscopeImageSource
concrete types that implement the newsource.Source
interfacesource.Input
and detection approach to asource.Detect()
call which you can create a source object from.source.Description
. To keep patterns in line with how packages are done, thetarget
field in the JSON output of the source block has been renamed tometadata
. This means a new JSON schema has been generated (v9).file.ChrootContext
for the root+cwd+base logic from the directory resolver (simplifies the dir resolver and allows for reuse of the chroot-like logic).FileSource
used to not respond to FilesByPath, however, now it does (the parent dir is indexed with all other files excluded now)Auxiliary changes:
internal.AllSourceMetadataReflectTypes
collection to aid in testing, ensuring completion testing forsource.*Metadata
typesDeferred work:
source.Detect
have been deferred until adding the new--from
option Allow source type input via CLI flag (not scheme) #1783Follow up PRs:
pkg
metadata type reflect type helpers and usepackagemetadata
helpers with what was introduced withsourcemetadata
. Related to Remove MetadataType from the core package struct #1735syftjson
packageJSON Schema Diff for reviewers:
Addresses #558 (comment)
Closes: #1866