mirror of
https://github.com/aquasecurity/trivy.git
synced 2026-02-10 18:53:16 +08:00
refactor: better integration of the parser into Trivy (#6183)
Signed-off-by: knqyf263 <knqyf263@gmail.com>
This commit is contained in:
@@ -9,9 +9,9 @@ import (
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
dio "github.com/aquasecurity/trivy/pkg/dependency/parser/io"
|
||||
"github.com/aquasecurity/trivy/pkg/dependency/parser/log"
|
||||
"github.com/aquasecurity/trivy/pkg/dependency/parser/types"
|
||||
"github.com/aquasecurity/trivy/pkg/log"
|
||||
xio "github.com/aquasecurity/trivy/pkg/x/io"
|
||||
)
|
||||
|
||||
type Parser struct{}
|
||||
@@ -22,7 +22,7 @@ func NewParser() types.Parser {
|
||||
|
||||
// Parse parses egg and wheel metadata.
|
||||
// e.g. .egg-info/PKG-INFO and dist-info/METADATA
|
||||
func (*Parser) Parse(r dio.ReadSeekerAt) ([]types.Library, []types.Dependency, error) {
|
||||
func (*Parser) Parse(r xio.ReadSeekerAt) ([]types.Library, []types.Dependency, error) {
|
||||
rd := textproto.NewReader(bufio.NewReader(r))
|
||||
h, err := rd.ReadMIMEHeader()
|
||||
if e := textproto.ProtocolError(""); errors.As(err, &e) {
|
||||
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
"golang.org/x/text/transform"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
dio "github.com/aquasecurity/trivy/pkg/dependency/parser/io"
|
||||
"github.com/aquasecurity/trivy/pkg/dependency/parser/types"
|
||||
xio "github.com/aquasecurity/trivy/pkg/x/io"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -28,7 +28,7 @@ func NewParser() types.Parser {
|
||||
return &Parser{}
|
||||
}
|
||||
|
||||
func (p *Parser) Parse(r dio.ReadSeekerAt) ([]types.Library, []types.Dependency, error) {
|
||||
func (p *Parser) Parse(r xio.ReadSeekerAt) ([]types.Library, []types.Dependency, error) {
|
||||
// `requirements.txt` can use byte order marks (BOM)
|
||||
// e.g. on Windows `requirements.txt` can use UTF-16LE with BOM
|
||||
// We need to override them to avoid the file being read incorrectly
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"github.com/liamg/jfather"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
dio "github.com/aquasecurity/trivy/pkg/dependency/parser/io"
|
||||
"github.com/aquasecurity/trivy/pkg/dependency/parser/types"
|
||||
xio "github.com/aquasecurity/trivy/pkg/x/io"
|
||||
)
|
||||
|
||||
type lockFile struct {
|
||||
@@ -26,7 +26,7 @@ func NewParser() types.Parser {
|
||||
return &Parser{}
|
||||
}
|
||||
|
||||
func (p *Parser) Parse(r dio.ReadSeekerAt) ([]types.Library, []types.Dependency, error) {
|
||||
func (p *Parser) Parse(r xio.ReadSeekerAt) ([]types.Library, []types.Dependency, error) {
|
||||
var lockFile lockFile
|
||||
input, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
|
||||
@@ -8,10 +8,10 @@ import (
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
version "github.com/aquasecurity/go-pep440-version"
|
||||
dio "github.com/aquasecurity/trivy/pkg/dependency/parser/io"
|
||||
"github.com/aquasecurity/trivy/pkg/dependency/parser/log"
|
||||
"github.com/aquasecurity/trivy/pkg/dependency/parser/types"
|
||||
"github.com/aquasecurity/trivy/pkg/dependency/parser/utils"
|
||||
"github.com/aquasecurity/trivy/pkg/log"
|
||||
xio "github.com/aquasecurity/trivy/pkg/x/io"
|
||||
)
|
||||
|
||||
type Lockfile struct {
|
||||
@@ -34,7 +34,7 @@ func NewParser() types.Parser {
|
||||
return &Parser{}
|
||||
}
|
||||
|
||||
func (p *Parser) Parse(r dio.ReadSeekerAt) ([]types.Library, []types.Dependency, error) {
|
||||
func (p *Parser) Parse(r xio.ReadSeekerAt) ([]types.Library, []types.Dependency, error) {
|
||||
var lockfile Lockfile
|
||||
if _, err := toml.NewDecoder(r).Decode(&lockfile); err != nil {
|
||||
return nil, nil, xerrors.Errorf("failed to decode poetry.lock: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user