-
Notifications
You must be signed in to change notification settings - Fork 528
/
package.go
69 lines (61 loc) · 1.89 KB
/
package.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package models
import (
"github.com/anchore/grype/grype/pkg"
"github.com/anchore/syft/syft/file"
syftPkg "github.com/anchore/syft/syft/pkg"
)
// Package is meant to be only the fields that are needed when displaying a single pkg.Package object for the JSON presenter.
type Package struct {
ID string `json:"id"`
Name string `json:"name"`
Version string `json:"version"`
Type syftPkg.Type `json:"type"`
Locations []file.Coordinates `json:"locations"`
Language syftPkg.Language `json:"language"`
Licenses []string `json:"licenses"`
CPEs []string `json:"cpes"`
PURL string `json:"purl"`
Upstreams []UpstreamPackage `json:"upstreams"`
MetadataType pkg.MetadataType `json:"metadataType,omitempty"`
Metadata interface{} `json:"metadata,omitempty"`
}
type UpstreamPackage struct {
Name string `json:"name"`
Version string `json:"version,omitempty"`
}
func newPackage(p pkg.Package) Package {
var cpes = make([]string, 0)
for _, c := range p.CPEs {
cpes = append(cpes, c.BindToFmtString())
}
licenses := p.Licenses
if licenses == nil {
licenses = make([]string, 0)
}
var coordinates = make([]file.Coordinates, 0)
locations := p.Locations.ToSlice()
for _, l := range locations {
coordinates = append(coordinates, l.Coordinates)
}
var upstreams = make([]UpstreamPackage, 0)
for _, u := range p.Upstreams {
upstreams = append(upstreams, UpstreamPackage{
Name: u.Name,
Version: u.Version,
})
}
return Package{
ID: string(p.ID),
Name: p.Name,
Version: p.Version,
Locations: coordinates,
Licenses: licenses,
Language: p.Language,
Type: p.Type,
CPEs: cpes,
PURL: p.PURL,
Upstreams: upstreams,
MetadataType: p.MetadataType,
Metadata: p.Metadata,
}
}