mirror of
https://github.com/anchore/syft.git
synced 2026-11-05 08:56:41 +01:00
translate maps to sequences in pkg metadata (#2553)
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/anchore/syft/syft/pkg"
|
||||
)
|
||||
|
||||
func (c *goBinaryCataloger) newGoBinaryPackage(resolver file.Resolver, dep *debug.Module, mainModule, goVersion, architecture string, buildSettings map[string]string, cryptoSettings []string, locations ...file.Location) pkg.Package {
|
||||
func (c *goBinaryCataloger) newGoBinaryPackage(resolver file.Resolver, dep *debug.Module, mainModule, goVersion, architecture string, buildSettings pkg.KeyValues, cryptoSettings []string, locations ...file.Location) pkg.Package {
|
||||
if dep.Replace != nil {
|
||||
dep = dep.Replace
|
||||
}
|
||||
|
||||
@@ -84,8 +84,8 @@ func (c *goBinaryCataloger) makeGoMainPackage(resolver file.Resolver, mod *exten
|
||||
return main
|
||||
}
|
||||
|
||||
version, hasVersion := gbs["vcs.revision"]
|
||||
timestamp, hasTimestamp := gbs["vcs.time"]
|
||||
version, hasVersion := gbs.Get("vcs.revision")
|
||||
timestamp, hasTimestamp := gbs.Get("vcs.time")
|
||||
|
||||
var ldflags string
|
||||
if metadata, ok := main.Metadata.(pkg.GolangBinaryBuildinfoEntry); ok {
|
||||
@@ -95,7 +95,7 @@ func (c *goBinaryCataloger) makeGoMainPackage(resolver file.Resolver, mod *exten
|
||||
// there is a matching vcs tag to match that could be referenced. This assumption could
|
||||
// be incorrect in terms of the go.mod contents, but is not incorrect in terms of the logical
|
||||
// version of the package.
|
||||
ldflags = metadata.BuildSettings["-ldflags"]
|
||||
ldflags, _ = metadata.BuildSettings.Get("-ldflags")
|
||||
}
|
||||
|
||||
majorVersion, fullVersion := extractVersionFromLDFlags(ldflags)
|
||||
@@ -207,10 +207,13 @@ func getGOARCHFromBin(r io.ReaderAt) (string, error) {
|
||||
return arch, nil
|
||||
}
|
||||
|
||||
func getBuildSettings(settings []debug.BuildSetting) map[string]string {
|
||||
m := make(map[string]string)
|
||||
func getBuildSettings(settings []debug.BuildSetting) pkg.KeyValues {
|
||||
m := make(pkg.KeyValues, 0)
|
||||
for _, s := range settings {
|
||||
m[s.Key] = s.Value
|
||||
m = append(m, pkg.KeyValue{
|
||||
Key: s.Key,
|
||||
Value: s.Value,
|
||||
})
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
@@ -124,10 +124,20 @@ func TestBuildGoPkgInfo(t *testing.T) {
|
||||
goCompiledVersion = "1.18"
|
||||
archDetails = "amd64"
|
||||
)
|
||||
defaultBuildSettings := map[string]string{
|
||||
"GOARCH": "amd64",
|
||||
"GOOS": "darwin",
|
||||
"GOAMD64": "v1",
|
||||
|
||||
defaultBuildSettings := []pkg.KeyValue{
|
||||
{
|
||||
Key: "GOARCH",
|
||||
Value: "amd64",
|
||||
},
|
||||
{
|
||||
Key: "GOOS",
|
||||
Value: "darwin",
|
||||
},
|
||||
{
|
||||
Key: "GOAMD64",
|
||||
Value: "v1",
|
||||
},
|
||||
}
|
||||
|
||||
unmodifiedMain := pkg.Package{
|
||||
@@ -275,10 +285,19 @@ func TestBuildGoPkgInfo(t *testing.T) {
|
||||
GoCompiledVersion: goCompiledVersion,
|
||||
Architecture: archDetails,
|
||||
H1Digest: "",
|
||||
BuildSettings: map[string]string{
|
||||
"GOAMD64": "v1",
|
||||
"GOARCH": "amd64",
|
||||
"GOOS": "darwin",
|
||||
BuildSettings: []pkg.KeyValue{
|
||||
{
|
||||
Key: "GOARCH",
|
||||
Value: archDetails,
|
||||
},
|
||||
{
|
||||
Key: "GOOS",
|
||||
Value: "darwin",
|
||||
},
|
||||
{
|
||||
Key: "GOAMD64",
|
||||
Value: "v1",
|
||||
},
|
||||
},
|
||||
MainModule: "github.com/a/b/c",
|
||||
GoCryptoSettings: []string{"boringcrypto + fips"},
|
||||
@@ -339,13 +358,31 @@ func TestBuildGoPkgInfo(t *testing.T) {
|
||||
Metadata: pkg.GolangBinaryBuildinfoEntry{
|
||||
GoCompiledVersion: goCompiledVersion,
|
||||
Architecture: archDetails,
|
||||
BuildSettings: map[string]string{
|
||||
"GOARCH": archDetails,
|
||||
"GOOS": "darwin",
|
||||
"GOAMD64": "v1",
|
||||
"vcs.revision": "41bc6bb410352845f22766e27dd48ba93aa825a4",
|
||||
"vcs.time": "2022-10-14T19:54:57Z",
|
||||
"-ldflags": `build -ldflags="-w -s -extldflags '-static' -X blah=foobar`,
|
||||
BuildSettings: []pkg.KeyValue{
|
||||
{
|
||||
Key: "GOARCH",
|
||||
Value: archDetails,
|
||||
},
|
||||
{
|
||||
Key: "GOOS",
|
||||
Value: "darwin",
|
||||
},
|
||||
{
|
||||
Key: "GOAMD64",
|
||||
Value: "v1",
|
||||
},
|
||||
{
|
||||
Key: "vcs.revision",
|
||||
Value: "41bc6bb410352845f22766e27dd48ba93aa825a4",
|
||||
},
|
||||
{
|
||||
Key: "vcs.time",
|
||||
Value: "2022-10-14T19:54:57Z",
|
||||
},
|
||||
{
|
||||
Key: "-ldflags",
|
||||
Value: `build -ldflags="-w -s -extldflags '-static' -X blah=foobar`,
|
||||
},
|
||||
},
|
||||
MainModule: "github.com/anchore/syft",
|
||||
},
|
||||
@@ -388,13 +425,31 @@ func TestBuildGoPkgInfo(t *testing.T) {
|
||||
Metadata: pkg.GolangBinaryBuildinfoEntry{
|
||||
GoCompiledVersion: goCompiledVersion,
|
||||
Architecture: archDetails,
|
||||
BuildSettings: map[string]string{
|
||||
"GOARCH": archDetails,
|
||||
"GOOS": "darwin",
|
||||
"GOAMD64": "v1",
|
||||
"vcs.revision": "41bc6bb410352845f22766e27dd48ba93aa825a4",
|
||||
"vcs.time": "2022-10-14T19:54:57Z",
|
||||
"-ldflags": `build -ldflags="-w -s -extldflags '-static' -X github.com/anchore/syft/internal/version.version=0.79.0`,
|
||||
BuildSettings: []pkg.KeyValue{
|
||||
{
|
||||
Key: "GOARCH",
|
||||
Value: archDetails,
|
||||
},
|
||||
{
|
||||
Key: "GOOS",
|
||||
Value: "darwin",
|
||||
},
|
||||
{
|
||||
Key: "GOAMD64",
|
||||
Value: "v1",
|
||||
},
|
||||
{
|
||||
Key: "vcs.revision",
|
||||
Value: "41bc6bb410352845f22766e27dd48ba93aa825a4",
|
||||
},
|
||||
{
|
||||
Key: "vcs.time",
|
||||
Value: "2022-10-14T19:54:57Z",
|
||||
},
|
||||
{
|
||||
Key: "-ldflags",
|
||||
Value: `build -ldflags="-w -s -extldflags '-static' -X github.com/anchore/syft/internal/version.version=0.79.0`,
|
||||
},
|
||||
},
|
||||
MainModule: "github.com/anchore/syft",
|
||||
},
|
||||
@@ -435,11 +490,23 @@ func TestBuildGoPkgInfo(t *testing.T) {
|
||||
Metadata: pkg.GolangBinaryBuildinfoEntry{
|
||||
GoCompiledVersion: goCompiledVersion,
|
||||
Architecture: archDetails,
|
||||
BuildSettings: map[string]string{
|
||||
"GOARCH": archDetails,
|
||||
"GOOS": "darwin",
|
||||
"GOAMD64": "v1",
|
||||
"-ldflags": `build -ldflags="-w -s -extldflags '-static' -X github.com/anchore/syft/internal/version.version=0.79.0`,
|
||||
BuildSettings: []pkg.KeyValue{
|
||||
{
|
||||
Key: "GOARCH",
|
||||
Value: archDetails,
|
||||
},
|
||||
{
|
||||
Key: "GOOS",
|
||||
Value: "darwin",
|
||||
},
|
||||
{
|
||||
Key: "GOAMD64",
|
||||
Value: "v1",
|
||||
},
|
||||
{
|
||||
Key: "-ldflags",
|
||||
Value: `build -ldflags="-w -s -extldflags '-static' -X github.com/anchore/syft/internal/version.version=0.79.0`,
|
||||
},
|
||||
},
|
||||
MainModule: "github.com/anchore/syft",
|
||||
},
|
||||
@@ -480,11 +547,23 @@ func TestBuildGoPkgInfo(t *testing.T) {
|
||||
Metadata: pkg.GolangBinaryBuildinfoEntry{
|
||||
GoCompiledVersion: goCompiledVersion,
|
||||
Architecture: archDetails,
|
||||
BuildSettings: map[string]string{
|
||||
"GOARCH": archDetails,
|
||||
"GOOS": "darwin",
|
||||
"GOAMD64": "v1",
|
||||
"-ldflags": `build -ldflags="-w -s -extldflags '-static' -X main.version=0.79.0`,
|
||||
BuildSettings: []pkg.KeyValue{
|
||||
{
|
||||
Key: "GOARCH",
|
||||
Value: archDetails,
|
||||
},
|
||||
{
|
||||
Key: "GOOS",
|
||||
Value: "darwin",
|
||||
},
|
||||
{
|
||||
Key: "GOAMD64",
|
||||
Value: "v1",
|
||||
},
|
||||
{
|
||||
Key: "-ldflags",
|
||||
Value: `build -ldflags="-w -s -extldflags '-static' -X main.version=0.79.0`,
|
||||
},
|
||||
},
|
||||
MainModule: "github.com/anchore/syft",
|
||||
},
|
||||
@@ -525,11 +604,23 @@ func TestBuildGoPkgInfo(t *testing.T) {
|
||||
Metadata: pkg.GolangBinaryBuildinfoEntry{
|
||||
GoCompiledVersion: goCompiledVersion,
|
||||
Architecture: archDetails,
|
||||
BuildSettings: map[string]string{
|
||||
"GOARCH": archDetails,
|
||||
"GOOS": "darwin",
|
||||
"GOAMD64": "v1",
|
||||
"-ldflags": `build -ldflags="-w -s -extldflags '-static' -X main.Version=0.79.0`,
|
||||
BuildSettings: []pkg.KeyValue{
|
||||
{
|
||||
Key: "GOARCH",
|
||||
Value: archDetails,
|
||||
},
|
||||
{
|
||||
Key: "GOOS",
|
||||
Value: "darwin",
|
||||
},
|
||||
{
|
||||
Key: "GOAMD64",
|
||||
Value: "v1",
|
||||
},
|
||||
{
|
||||
Key: "-ldflags",
|
||||
Value: `build -ldflags="-w -s -extldflags '-static' -X main.Version=0.79.0`,
|
||||
},
|
||||
},
|
||||
MainModule: "github.com/anchore/syft",
|
||||
},
|
||||
@@ -571,12 +662,27 @@ func TestBuildGoPkgInfo(t *testing.T) {
|
||||
Metadata: pkg.GolangBinaryBuildinfoEntry{
|
||||
GoCompiledVersion: goCompiledVersion,
|
||||
Architecture: archDetails,
|
||||
BuildSettings: map[string]string{
|
||||
"GOARCH": archDetails,
|
||||
"GOOS": "darwin",
|
||||
"GOAMD64": "v1",
|
||||
"vcs.revision": "41bc6bb410352845f22766e27dd48ba93aa825a4",
|
||||
"vcs.time": "2022-10-14T19:54:57Z",
|
||||
BuildSettings: []pkg.KeyValue{
|
||||
{
|
||||
Key: "GOARCH",
|
||||
Value: archDetails,
|
||||
},
|
||||
{
|
||||
Key: "GOOS",
|
||||
Value: "darwin",
|
||||
},
|
||||
{
|
||||
Key: "GOAMD64",
|
||||
Value: "v1",
|
||||
},
|
||||
{
|
||||
Key: "vcs.revision",
|
||||
Value: "41bc6bb410352845f22766e27dd48ba93aa825a4",
|
||||
},
|
||||
{
|
||||
Key: "vcs.time",
|
||||
Value: "2022-10-14T19:54:57Z",
|
||||
},
|
||||
},
|
||||
MainModule: "github.com/anchore/syft",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user