Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump trivy #17

Merged
merged 2 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions apk/apk.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ var requiredFiles = []string{"lib/apk/db/installed"}

type alpinePkgAnalyzer struct{}

func (a alpinePkgAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInput) (*analyzer.AnalysisResult, error) {
func (a alpinePkgAnalyzer) Analyze(ctx context.Context, input analyzer.AnalysisInput) (*analyzer.AnalysisResult, error) {
scanner := bufio.NewScanner(input.Content)
parsedPkgs, installedFiles := a.parseApkInfo(scanner)
parsedPkgs, installedFiles := a.parseApkInfo(ctx, scanner)

binariesMap := make(map[string][]string)

Expand Down Expand Up @@ -67,7 +67,7 @@ func (a alpinePkgAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInp
}, nil
}

func (a alpinePkgAnalyzer) parseApkInfo(scanner *bufio.Scanner) ([]types.Package, map[string][]string) {
func (a alpinePkgAnalyzer) parseApkInfo(ctx context.Context, scanner *bufio.Scanner) ([]types.Package, map[string][]string) {
var (
pkgs []types.Package
pkg types.Package
Expand Down Expand Up @@ -96,7 +96,7 @@ func (a alpinePkgAnalyzer) parseApkInfo(scanner *bufio.Scanner) ([]types.Package
case "V:":
version = line[2:]
if !apkVersion.Valid(version) {
log.Logger.Warnf("Invalid Version Found : OS %s, Package %s, Version %s", "alpine", pkg.Name, version)
log.WarnContext(ctx, "Invalid Version Found : OS %s, Package %s, Version %s", "alpine", pkg.Name, version)
continue
}
pkg.Version = version
Expand Down
3 changes: 2 additions & 1 deletion apk/apk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package apk

import (
"bufio"
"context"
"os"
"testing"

Expand Down Expand Up @@ -283,7 +284,7 @@ func TestParseApkInfo(t *testing.T) {
t.Errorf("%s : can't open file %s", testname, v.path)
}
scanner := bufio.NewScanner(read)
gotPkgs, gotFiles := a.parseApkInfo(scanner)
gotPkgs, gotFiles := a.parseApkInfo(context.Background(), scanner)

r := require.New(t)
r.Equal(v.wantPkgs, gotPkgs)
Expand Down
11 changes: 7 additions & 4 deletions artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,13 @@ func NewArtifact(img types.Image, log logrus.FieldLogger, c CacheClient, opt Art
}

return &Artifact{
log: log,
image: img,
cache: c,
walker: walker.NewLayerTar(opt.SkipFiles, opt.SkipDirs),
log: log,
image: img,
cache: c,
walker: walker.NewLayerTar(walker.Option{
SkipFiles: opt.WalkerOption.SkipFiles,
SkipDirs: opt.WalkerOption.SkipDirs,
}),
analyzer: a,
configAnalyzer: ca,
artifactOption: opt,
Expand Down
14 changes: 7 additions & 7 deletions dpkg/dpkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var (

type dpkgAnalyzer struct{}

func (a dpkgAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInput) (*analyzer.AnalysisResult, error) {
func (a dpkgAnalyzer) Analyze(ctx context.Context, input analyzer.AnalysisInput) (*analyzer.AnalysisResult, error) {
scanner := bufio.NewScanner(input.Content)
path, filename := filepath.Split(input.FilePath)
if a.isListFile(path, filename) {
Expand Down Expand Up @@ -70,7 +70,7 @@ func (a dpkgAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInput) (
return result, nil
}

return a.parseDpkgStatus(input.FilePath, scanner)
return a.parseDpkgStatus(ctx, input.FilePath, scanner)
}

func (a dpkgAnalyzer) parseDpkgInfoList(scanner *bufio.Scanner) ([]string, error) {
Expand Down Expand Up @@ -105,7 +105,7 @@ func (a dpkgAnalyzer) parseDpkgInfoList(scanner *bufio.Scanner) ([]string, error
}

// parseDpkgStatus parses /var/lib/dpkg/status or /var/lib/dpkg/status/*
func (a dpkgAnalyzer) parseDpkgStatus(filePath string, scanner *bufio.Scanner) (*analyzer.AnalysisResult, error) {
func (a dpkgAnalyzer) parseDpkgStatus(ctx context.Context, filePath string, scanner *bufio.Scanner) (*analyzer.AnalysisResult, error) {
var pkg *types.Package
pkgs := map[string]*types.Package{}
pkgIDs := map[string]string{}
Expand All @@ -116,7 +116,7 @@ func (a dpkgAnalyzer) parseDpkgStatus(filePath string, scanner *bufio.Scanner) (
continue
}

pkg = a.parseDpkgPkg(scanner)
pkg = a.parseDpkgPkg(ctx, scanner)
if pkg != nil {
pkgs[pkg.ID] = pkg
pkgIDs[pkg.Name] = pkg.ID
Expand All @@ -141,7 +141,7 @@ func (a dpkgAnalyzer) parseDpkgStatus(filePath string, scanner *bufio.Scanner) (
}, nil
}

func (a dpkgAnalyzer) parseDpkgPkg(scanner *bufio.Scanner) (pkg *types.Package) {
func (a dpkgAnalyzer) parseDpkgPkg(ctx context.Context, scanner *bufio.Scanner) (pkg *types.Package) {
var (
name string
version string
Expand Down Expand Up @@ -192,7 +192,7 @@ func (a dpkgAnalyzer) parseDpkgPkg(scanner *bufio.Scanner) (pkg *types.Package)
if name == "" || version == "" || !isInstalled {
return nil
} else if !debVersion.Valid(version) {
log.Logger.Warnf("Invalid Version Found : OS %s, Package %s, Version %s", "debian", name, version)
log.WarnContext(ctx, "Invalid Version Found : OS %s, Package %s, Version %s", "debian", name, version)
return nil
}
pkg = &types.Package{
Expand All @@ -218,7 +218,7 @@ func (a dpkgAnalyzer) parseDpkgPkg(scanner *bufio.Scanner) (pkg *types.Package)
}

if !debVersion.Valid(sourceVersion) {
log.Logger.Warnf("Invalid Version Found : OS %s, Package %s, Version %s", "debian", sourceName, sourceVersion)
log.WarnContext(ctx, "Invalid Version Found : OS %s, Package %s, Version %s", "debian", sourceName, sourceVersion)
return pkg
}
pkg.SrcName = sourceName
Expand Down
Loading
Loading