-
Couldn't load subscription status.
- Fork 727
478 identify go binaries and extract mod information #534
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
28 commits
Select commit
Hold shift + click to select a range
3572ee6
add query by MIME type to source.FileResolver
wagoodman 3e703aa
add small framework to ID go binary
spiffcs 3e8261c
import stereoscope lib changes to find mime type
spiffcs 66b40f3
update unit tests and add bin cataloger
spiffcs 70aa22b
update copied code to be closer to upstream
spiffcs 8b199ee
linter updates
spiffcs ca2103e
update no defer close go bin parse
spiffcs e910db6
typo and test updates
spiffcs 2113691
add small test base case and refactor
spiffcs 5fb24c8
unit test for buildGoPkgInfo
spiffcs 88115b2
update unit tests and add integration point
spiffcs 41423af
remove old integration test
spiffcs 7388da3
remove pinned versions breaking world
spiffcs dd370d4
add regression testing for go bin support
spiffcs d5c0d04
confirm no regression with mod directives
spiffcs 7390968
clean up from PR review
spiffcs 643bca0
remove containerd
spiffcs aef3ab5
pr comments
spiffcs d430c18
update with test for multiple case
spiffcs 1d4d783
update ex packages to be 4 now that we parse =>
spiffcs c885f3f
remove File cataloger from Image #465
spiffcs 1fefc3e
remove stub test and empty case branches
spiffcs 88a2005
integration tests
spiffcs 6bddbda
remove unused const
spiffcs ca81c39
code feedback
spiffcs fd5d244
update unit tests
spiffcs 2a87bd5
prune go mod from integration changes
spiffcs 3bd5eb8
update with clause to protect bad access path
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 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 |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /* | ||
| Package golang provides a concrete Cataloger implementation for go.mod files. | ||
| */ | ||
| package golang | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/anchore/syft/internal/log" | ||
| "github.com/anchore/syft/syft/pkg" | ||
| "github.com/anchore/syft/syft/source" | ||
| ) | ||
|
|
||
| const catalogerName = "go-module-binary-cataloger" | ||
|
|
||
| // current mime types to search by to discover go binaries | ||
| var mimeTypes = []string{ | ||
| "application/x-executable", | ||
| "application/x-mach-binary", | ||
| "application/x-elf", | ||
| "application/x-sharedlib", | ||
| "application/vnd.microsoft.portable-executable", | ||
| } | ||
|
|
||
| type Cataloger struct{} | ||
|
|
||
| // NewGoModuleBinaryCataloger returns a new Golang cataloger object. | ||
| func NewGoModuleBinaryCataloger() *Cataloger { | ||
| return &Cataloger{} | ||
| } | ||
|
|
||
| // Name returns a string that uniquely describes a cataloger | ||
| func (c *Cataloger) Name() string { | ||
| return catalogerName | ||
| } | ||
|
|
||
| // Catalog is given an object to resolve file references and content, this function returns any discovered Packages after analyzing rpm db installation. | ||
| func (c *Cataloger) Catalog(resolver source.FileResolver) ([]pkg.Package, error) { | ||
| pkgs := make([]pkg.Package, 0) | ||
| fileMatches, err := resolver.FilesByMIMEType(mimeTypes...) | ||
| if err != nil { | ||
| return pkgs, fmt.Errorf("failed to find bin by mime types: %w", err) | ||
| } | ||
|
|
||
| for _, location := range fileMatches { | ||
| r, err := resolver.FileContentsByLocation(location) | ||
spiffcs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if err != nil { | ||
| return pkgs, fmt.Errorf("failed to resolve file contents by location: %w", err) | ||
| } | ||
|
|
||
| goPkgs, err := parseGoBin(location.RealPath, r) | ||
| if err != nil { | ||
| log.Infof("could not parse go bin for: %w", err) | ||
| } | ||
|
|
||
| r.Close() | ||
| pkgs = append(pkgs, goPkgs...) | ||
| } | ||
|
|
||
| return pkgs, nil | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.