mirror of
https://github.com/anchore/syft.git
synced 2026-11-01 15:06:36 +01:00
* migrate pkg.ID and pkg.Relationship to artifact package Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * return relationships from tasks Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * fix more tests Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add artifact.Identifiable by Identity() method Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * fix linting Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * remove catalog ID assignment Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * adjust spdx helpers to use copy of packages Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * stabilize package ID relative to encode-decode format cycles Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * rename Identity() to ID() Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * use zero value for nils in ID generation Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * enable source.Location to be identifiable Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * hoist up package relationship discovery to analysis stage Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * update ownership-by-file-overlap relationship description Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add test reminders to put new relationships under test Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * adjust PHP composer.lock parser function to return relationships Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
62 lines
1.3 KiB
Go
62 lines
1.3 KiB
Go
package golang
|
|
|
|
import (
|
|
"bufio"
|
|
"io"
|
|
"strings"
|
|
|
|
"github.com/anchore/syft/syft/pkg"
|
|
"github.com/anchore/syft/syft/source"
|
|
)
|
|
|
|
const (
|
|
packageIdentifier = "dep"
|
|
replaceIdentifier = "=>"
|
|
)
|
|
|
|
func parseGoBin(location source.Location, reader io.ReadCloser) ([]pkg.Package, error) {
|
|
// Identify if bin was compiled by go
|
|
x, err := openExe(reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
goVersion, mod := findVers(x)
|
|
|
|
return buildGoPkgInfo(location, mod, goVersion), nil
|
|
}
|
|
|
|
func buildGoPkgInfo(location source.Location, mod, goVersion string) []pkg.Package {
|
|
pkgsSlice := make([]pkg.Package, 0)
|
|
scanner := bufio.NewScanner(strings.NewReader(mod))
|
|
|
|
// filter mod dependencies: [dep, name, version, sha]
|
|
for scanner.Scan() {
|
|
fields := strings.Fields(scanner.Text())
|
|
|
|
// must have dep, name, version, sha
|
|
if len(fields) < 4 {
|
|
continue
|
|
}
|
|
|
|
if fields[0] == packageIdentifier || fields[0] == replaceIdentifier {
|
|
pkgsSlice = append(pkgsSlice, pkg.Package{
|
|
Name: fields[1],
|
|
Version: fields[2],
|
|
Language: pkg.Go,
|
|
Type: pkg.GoModulePkg,
|
|
Locations: []source.Location{
|
|
location,
|
|
},
|
|
MetadataType: pkg.GolangBinMetadataType,
|
|
Metadata: pkg.GolangBinMetadata{
|
|
GoCompiledVersion: goVersion,
|
|
H1Digest: fields[3],
|
|
},
|
|
})
|
|
}
|
|
}
|
|
|
|
return pkgsSlice
|
|
}
|