Skip to content

Commit

Permalink
fix(scanner): pass docker options as an argument (aquasecurity#408)
Browse files Browse the repository at this point in the history
  • Loading branch information
knqyf263 authored Feb 18, 2020
1 parent db2136b commit 7726963
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
10 changes: 8 additions & 2 deletions internal/client/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,21 @@ func run(c config.Config) (err error) {

scanOptions := types.ScanOptions{
VulnType: c.VulnType,
Timeout: c.Timeout,
RemoteURL: c.RemoteAddr,
}
log.Logger.Debugf("Vulnerability type: %s", scanOptions.VulnType)

dockerOption, err := types.GetDockerOption()
if err != nil {
return xerrors.Errorf("failed to get docker option: %w", err)
}
dockerOption.Timeout = c.Timeout

scanner := initializeScanner(cacheClient,
ospkg.CustomHeaders(c.CustomHeaders), library.CustomHeaders(c.CustomHeaders),
ospkg.RemoteURL(c.RemoteAddr), library.RemoteURL(c.RemoteAddr))
results, err := scanner.ScanImage(c.ImageName, c.Input, scanOptions)

results, err := scanner.ScanImage(c.ImageName, c.Input, scanOptions, dockerOption)
if err != nil {
return xerrors.Errorf("error in image scan: %w", err)
}
Expand Down
9 changes: 7 additions & 2 deletions internal/standalone/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,17 @@ func run(c config.Config) (err error) {

scanOptions := types.ScanOptions{
VulnType: c.VulnType,
Timeout: c.Timeout,
}
log.Logger.Debugf("Vulnerability type: %s", scanOptions.VulnType)

dockerOption, err := types.GetDockerOption()
if err != nil {
return xerrors.Errorf("failed to get docker option: %w", err)
}
dockerOption.Timeout = c.Timeout

scanner := initializeScanner(cacheClient)
results, err := scanner.ScanImage(c.ImageName, c.Input, scanOptions)
results, err := scanner.ScanImage(c.ImageName, c.Input, scanOptions, dockerOption)
if err != nil {
return xerrors.Errorf("error in image scan: %w", err)
}
Expand Down
10 changes: 2 additions & 8 deletions pkg/scanner/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/aquasecurity/fanal/cache"
"github.com/aquasecurity/fanal/extractor"
"github.com/aquasecurity/fanal/extractor/docker"
ftypes "github.com/aquasecurity/fanal/types"
libDetector "github.com/aquasecurity/trivy/pkg/detector/library"
ospkgDetector "github.com/aquasecurity/trivy/pkg/detector/ospkg"
"github.com/aquasecurity/trivy/pkg/report"
Expand Down Expand Up @@ -56,21 +57,14 @@ func NewScanner(cacheClient cache.Cache, ospkgScanner ospkg.Scanner, libScanner
return Scanner{cacheClient: cacheClient, ospkgScanner: ospkgScanner, libScanner: libScanner}
}

func (s Scanner) ScanImage(imageName, filePath string, scanOptions types.ScanOptions) (report.Results, error) {
func (s Scanner) ScanImage(imageName, filePath string, scanOptions types.ScanOptions, dockerOption ftypes.DockerOption) (report.Results, error) {
results := report.Results{}
ctx := context.Background()

var target string
var files extractor.FileMap
var ac analyzer.Config
dockerOption, err := types.GetDockerOption()
if err != nil {
return nil, xerrors.Errorf("failed to get docker option: %w", err)
}

if imageName != "" {
dockerOption.Timeout = scanOptions.Timeout
}
ext, err := docker.NewDockerExtractor(dockerOption, s.cacheClient)
if err != nil {
return nil, err
Expand Down
3 changes: 0 additions & 3 deletions pkg/types/scanoptions.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package types

import "time"

type ScanOptions struct {
VulnType []string
Timeout time.Duration

// for client/server
RemoteURL string
Expand Down

0 comments on commit 7726963

Please sign in to comment.