mirror of
https://github.com/aquasecurity/trivy.git
synced 2026-02-05 00:03:51 +08:00
refactor: unify Library and Package structs (#6633)
Signed-off-by: knqyf263 <knqyf263@gmail.com> Co-authored-by: DmitriyLewen <91113035+DmitriyLewen@users.noreply.github.com> Co-authored-by: DmitriyLewen <dmitriy.lewen@smartforce.io>
This commit is contained in:
@@ -7,9 +7,10 @@ import (
|
||||
"net/textproto"
|
||||
"strings"
|
||||
|
||||
"github.com/samber/lo"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/dependency/types"
|
||||
ftypes "github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"github.com/aquasecurity/trivy/pkg/log"
|
||||
xio "github.com/aquasecurity/trivy/pkg/x/io"
|
||||
)
|
||||
@@ -18,7 +19,7 @@ type Parser struct {
|
||||
logger *log.Logger
|
||||
}
|
||||
|
||||
func NewParser() types.Parser {
|
||||
func NewParser() *Parser {
|
||||
return &Parser{
|
||||
logger: log.WithPrefix("python"),
|
||||
}
|
||||
@@ -26,7 +27,7 @@ func NewParser() types.Parser {
|
||||
|
||||
// Parse parses egg and wheel metadata.
|
||||
// e.g. .egg-info/PKG-INFO and dist-info/METADATA
|
||||
func (p *Parser) Parse(r xio.ReadSeekerAt) ([]types.Library, []types.Dependency, error) {
|
||||
func (p *Parser) Parse(r xio.ReadSeekerAt) ([]ftypes.Package, []ftypes.Dependency, error) {
|
||||
rd := textproto.NewReader(bufio.NewReader(r))
|
||||
h, err := rd.ReadMIMEHeader()
|
||||
if e := textproto.ProtocolError(""); errors.As(err, &e) {
|
||||
@@ -82,11 +83,11 @@ func (p *Parser) Parse(r xio.ReadSeekerAt) ([]types.Library, []types.Dependency,
|
||||
license = "file://" + h.Get("License-File")
|
||||
}
|
||||
|
||||
return []types.Library{
|
||||
return []ftypes.Package{
|
||||
{
|
||||
Name: name,
|
||||
Version: version,
|
||||
License: license,
|
||||
Name: name,
|
||||
Version: version,
|
||||
Licenses: lo.Ternary(license != "", []string{license}, nil),
|
||||
},
|
||||
}, nil, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user