Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

refactor(scanner): propagate context to scanners/analyzers #1741

Merged
merged 10 commits into from
Jun 11, 2024
2 changes: 1 addition & 1 deletion cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ require (
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/Microsoft/hcsshim v0.12.3 // indirect
github.com/OneOfOne/xxhash v1.2.8 // indirect
github.com/Portshift/dockle v0.3.2-0.20240508131533-4f3b165086b7 // indirect
github.com/Portshift/dockle v0.3.2-0.20240611055957-53ff8586f9c7 // indirect
github.com/ProtonMail/go-crypto v1.1.0-alpha.2 // indirect
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acobaugh/osrelease v0.1.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions cli/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ github.com/Microsoft/hcsshim v0.12.3/go.mod h1:Iyl1WVpZzr+UkzjekHZbV8o5Z9ZkxNGx6
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/OneOfOne/xxhash v1.2.8 h1:31czK/TI9sNkxIKfaUfGlU47BAxQ0ztGgd9vPyqimf8=
github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q=
github.com/Portshift/dockle v0.3.2-0.20240508131533-4f3b165086b7 h1:d8TjnmUvMG8up/q+oVxanmAMqj+stbZEChx8FHXA9R8=
github.com/Portshift/dockle v0.3.2-0.20240508131533-4f3b165086b7/go.mod h1:FUpB0D5B7AaKtY3Xt1kvO5QlJV2OifG3NNmvisDMla8=
github.com/Portshift/dockle v0.3.2-0.20240611055957-53ff8586f9c7 h1:VbPjdBPXkQAW5gMmBPrslfmmppc7nrsq5hnoBo+fUuE=
github.com/Portshift/dockle v0.3.2-0.20240611055957-53ff8586f9c7/go.mod h1:FUpB0D5B7AaKtY3Xt1kvO5QlJV2OifG3NNmvisDMla8=
github.com/ProtonMail/go-crypto v1.1.0-alpha.2 h1:bkyFVUP+ROOARdgCiJzNQo2V2kiB97LyUpzH9P6Hrlg=
github.com/ProtonMail/go-crypto v1.1.0-alpha.2/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE=
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
Expand Down
2 changes: 1 addition & 1 deletion e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ require (
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/Microsoft/hcsshim v0.12.3 // indirect
github.com/OneOfOne/xxhash v1.2.8 // indirect
github.com/Portshift/dockle v0.3.2-0.20240508131533-4f3b165086b7 // indirect
github.com/Portshift/dockle v0.3.2-0.20240611055957-53ff8586f9c7 // indirect
github.com/ProtonMail/go-crypto v1.1.0-alpha.2 // indirect
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
Expand Down
4 changes: 2 additions & 2 deletions e2e/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDe
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/OneOfOne/xxhash v1.2.8 h1:31czK/TI9sNkxIKfaUfGlU47BAxQ0ztGgd9vPyqimf8=
github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q=
github.com/Portshift/dockle v0.3.2-0.20240508131533-4f3b165086b7 h1:d8TjnmUvMG8up/q+oVxanmAMqj+stbZEChx8FHXA9R8=
github.com/Portshift/dockle v0.3.2-0.20240508131533-4f3b165086b7/go.mod h1:FUpB0D5B7AaKtY3Xt1kvO5QlJV2OifG3NNmvisDMla8=
github.com/Portshift/dockle v0.3.2-0.20240611055957-53ff8586f9c7 h1:VbPjdBPXkQAW5gMmBPrslfmmppc7nrsq5hnoBo+fUuE=
github.com/Portshift/dockle v0.3.2-0.20240611055957-53ff8586f9c7/go.mod h1:FUpB0D5B7AaKtY3Xt1kvO5QlJV2OifG3NNmvisDMla8=
github.com/ProtonMail/go-crypto v1.1.0-alpha.2 h1:bkyFVUP+ROOARdgCiJzNQo2V2kiB97LyUpzH9P6Hrlg=
github.com/ProtonMail/go-crypto v1.1.0-alpha.2/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE=
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
Expand Down
2 changes: 1 addition & 1 deletion orchestrator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ require (
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/Microsoft/hcsshim v0.12.3 // indirect
github.com/OneOfOne/xxhash v1.2.8 // indirect
github.com/Portshift/dockle v0.3.2-0.20240508131533-4f3b165086b7 // indirect
github.com/Portshift/dockle v0.3.2-0.20240611055957-53ff8586f9c7 // indirect
github.com/ProtonMail/go-crypto v1.1.0-alpha.2 // indirect
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acobaugh/osrelease v0.1.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions orchestrator/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb0
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/OneOfOne/xxhash v1.2.8 h1:31czK/TI9sNkxIKfaUfGlU47BAxQ0ztGgd9vPyqimf8=
github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q=
github.com/Portshift/dockle v0.3.2-0.20240508131533-4f3b165086b7 h1:d8TjnmUvMG8up/q+oVxanmAMqj+stbZEChx8FHXA9R8=
github.com/Portshift/dockle v0.3.2-0.20240508131533-4f3b165086b7/go.mod h1:FUpB0D5B7AaKtY3Xt1kvO5QlJV2OifG3NNmvisDMla8=
github.com/Portshift/dockle v0.3.2-0.20240611055957-53ff8586f9c7 h1:VbPjdBPXkQAW5gMmBPrslfmmppc7nrsq5hnoBo+fUuE=
github.com/Portshift/dockle v0.3.2-0.20240611055957-53ff8586f9c7/go.mod h1:FUpB0D5B7AaKtY3Xt1kvO5QlJV2OifG3NNmvisDMla8=
github.com/Portshift/go-utils v0.0.0-20220421083203-89265d8a6487 h1:CD9mOTUMX6f33pRJoYUDyI+IDnCWWhwBBoXqxGMrAaQ=
github.com/Portshift/go-utils v0.0.0-20220421083203-89265d8a6487/go.mod h1:w2CFHePN1v+p2v/NSpe7aK+cFu0E2+9MrQ3CgB6vydk=
github.com/ProtonMail/go-crypto v1.1.0-alpha.2 h1:bkyFVUP+ROOARdgCiJzNQo2V2kiB97LyUpzH9P6Hrlg=
Expand Down
2 changes: 1 addition & 1 deletion plugins/runner/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func main() {
// Create plugin runner
fmt.Printf("Starting plugin runner\n")
config := LoadConfig()
runner, err := runner.New(config)
runner, err := runner.New(ctx, config)
if err != nil {
fmt.Println(err)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type containerManager struct {
runningErr atomic.Pointer[error]
}

func New(config types.PluginConfig) (containermanager.PluginContainerManager, error) {
func New(ctx context.Context, config types.PluginConfig) (containermanager.PluginContainerManager, error) {
// Load docker client
client, err := newDockerClient()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions plugins/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ type pluginRunner struct {
client runnerclient.ClientWithResponsesInterface
}

func New(config types.PluginConfig) (types.PluginRunner, error) {
func New(ctx context.Context, config types.PluginConfig) (types.PluginRunner, error) {
// Create docker container
// TODO: switch to factory once the support for more container engines is added
manager, err := docker.New(config)
manager, err := docker.New(ctx, config)
if err != nil {
return nil, fmt.Errorf("failed to create plugin manager: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion provider/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ require (
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/Microsoft/hcsshim v0.12.3 // indirect
github.com/OneOfOne/xxhash v1.2.8 // indirect
github.com/Portshift/dockle v0.3.2-0.20240508131533-4f3b165086b7 // indirect
github.com/Portshift/dockle v0.3.2-0.20240611055957-53ff8586f9c7 // indirect
github.com/ProtonMail/go-crypto v1.1.0-alpha.2 // indirect
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acobaugh/osrelease v0.1.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions provider/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ github.com/Microsoft/hcsshim v0.12.3/go.mod h1:Iyl1WVpZzr+UkzjekHZbV8o5Z9ZkxNGx6
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/OneOfOne/xxhash v1.2.8 h1:31czK/TI9sNkxIKfaUfGlU47BAxQ0ztGgd9vPyqimf8=
github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q=
github.com/Portshift/dockle v0.3.2-0.20240508131533-4f3b165086b7 h1:d8TjnmUvMG8up/q+oVxanmAMqj+stbZEChx8FHXA9R8=
github.com/Portshift/dockle v0.3.2-0.20240508131533-4f3b165086b7/go.mod h1:FUpB0D5B7AaKtY3Xt1kvO5QlJV2OifG3NNmvisDMla8=
github.com/Portshift/dockle v0.3.2-0.20240611055957-53ff8586f9c7 h1:VbPjdBPXkQAW5gMmBPrslfmmppc7nrsq5hnoBo+fUuE=
github.com/Portshift/dockle v0.3.2-0.20240611055957-53ff8586f9c7/go.mod h1:FUpB0D5B7AaKtY3Xt1kvO5QlJV2OifG3NNmvisDMla8=
github.com/ProtonMail/go-crypto v1.1.0-alpha.2 h1:bkyFVUP+ROOARdgCiJzNQo2V2kiB97LyUpzH9P6Hrlg=
github.com/ProtonMail/go-crypto v1.1.0-alpha.2/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE=
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
Expand Down
10 changes: 5 additions & 5 deletions scanner/analyzer/syft/syft.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,28 @@ func New(_ string, c job_manager.IsConfig, logger *log.Entry, resultChan chan jo
}
}

func (a *Analyzer) Run(sourceType utils.SourceType, userInput string) error {
func (a *Analyzer) Run(ctx context.Context, sourceType utils.SourceType, userInput string) error {
src := utils.CreateSource(sourceType, a.localImage)

a.logger.Infof("Called %s analyzer on source %s", a.name, src)
// TODO platform can be defined
// https://github.com/anchore/syft/blob/b20310eaf847c259beb4fe5128c842bd8aa4d4fc/cmd/syft/cli/options/packages.go#L48
source, err := syft.GetSource(
context.Background(),
ctx,
userInput,
syft.DefaultGetSourceConfig().WithSources(src).WithRegistryOptions(a.config.RegistryOptions),
)
if err != nil {
return fmt.Errorf("failed to create source analyzer=%s: %w", a.name, err)
}

go func() {
go func(ctx context.Context) {
res := &analyzer.Results{}

sbomConfig := syft.DefaultCreateSBOMConfig().
WithSearchConfig(cataloging.DefaultSearchConfig().WithScope(a.config.Scope))

sbom, err := syft.CreateSBOM(context.TODO(), source, sbomConfig)
sbom, err := syft.CreateSBOM(ctx, source, sbomConfig)
if err != nil {
a.setError(res, fmt.Errorf("failed to write results: %w", err))
return
Expand Down Expand Up @@ -110,7 +110,7 @@ func (a *Analyzer) Run(sourceType utils.SourceType, userInput string) error {

a.logger.Infof("Sending successful results")
a.resultChan <- res
}()
}(ctx)

return nil
}
Expand Down
8 changes: 4 additions & 4 deletions scanner/analyzer/trivy/trivy.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func New(_ string, c job_manager.IsConfig, logger *log.Entry, resultChan chan jo
}

// nolint:cyclop
func (a *Analyzer) Run(sourceType utils.SourceType, userInput string) error {
func (a *Analyzer) Run(ctx context.Context, sourceType utils.SourceType, userInput string) error {
a.logger.Infof("Called %s analyzer on source %v %v", a.name, sourceType, userInput)

tempFile, err := os.CreateTemp(a.config.TempDir, "trivy.sbom.*.json")
Expand All @@ -75,7 +75,7 @@ func (a *Analyzer) Run(sourceType utils.SourceType, userInput string) error {
return fmt.Errorf("unable to get db options: %w", err)
}

go func() {
go func(ctx context.Context) {
defer os.Remove(tempFile.Name())

res := &analyzer.Results{}
Expand Down Expand Up @@ -139,7 +139,7 @@ func (a *Analyzer) Run(sourceType utils.SourceType, userInput string) error {
// Ensure we're configured for private registry if required
trivyOptions = trivy.SetTrivyRegistryConfigs(a.config.Registry, trivyOptions)

err = artifact.Run(context.TODO(), trivyOptions, trivySourceType)
err = artifact.Run(ctx, trivyOptions, trivySourceType)
if err != nil {
a.setError(res, fmt.Errorf("failed to generate SBOM: %w", err))
return
Expand Down Expand Up @@ -182,7 +182,7 @@ func (a *Analyzer) Run(sourceType utils.SourceType, userInput string) error {

a.logger.Infof("Sending successful results")
a.resultChan <- res
}()
}(ctx)

return nil
}
Expand Down
3 changes: 2 additions & 1 deletion scanner/analyzer/windows/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package windows

import (
"context"
"fmt"

log "github.com/sirupsen/logrus"
Expand All @@ -42,7 +43,7 @@ func New(_ string, _ job_manager.IsConfig, logger *log.Entry, resultChan chan jo
}

// nolint:cyclop
func (a *Analyzer) Run(sourceType utils.SourceType, userInput string) error {
func (a *Analyzer) Run(ctx context.Context, sourceType utils.SourceType, userInput string) error {
a.logger.Infof("Called %s analyzer on source %v %v", a.name, sourceType, userInput)

go func() {
Expand Down
9 changes: 5 additions & 4 deletions scanner/families/exploits/exploitdb/exploitdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package exploitdb

import (
"context"
"fmt"

log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -45,8 +46,8 @@ func New(_ string, c job_manager.IsConfig, logger *log.Entry, resultChan chan jo
}
}

func (a *Scanner) Run(sourceType utils.SourceType, userInput string) error {
go func() {
func (a *Scanner) Run(ctx context.Context, sourceType utils.SourceType, userInput string) error {
go func(ctx context.Context) {
retResults := common.Results{
ScannedInput: userInput,
ScannerName: ScannerName,
Expand All @@ -63,15 +64,15 @@ func (a *Scanner) Run(sourceType utils.SourceType, userInput string) error {
}

// get exploits (get request to exploit db)
exploits, err := a.getExploitsFromCVEIDs(cveIDs)
exploits, err := a.getExploitsFromCVEIDs(ctx, cveIDs)
if err != nil {
a.sendResults(retResults, fmt.Errorf("failed to get exploits from cve ids: %w", err))
return
}
retResults.Exploits = exploits

a.sendResults(retResults, nil)
}()
}(ctx)

return nil
}
Expand Down
12 changes: 6 additions & 6 deletions scanner/families/exploits/exploitdb/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ func stringToArray(str string) []string {
return cveIDs
}

func (a *Scanner) getExploitsFromCVEIDs(cveIDs []string) ([]common.Exploit, error) {
func (a *Scanner) getExploitsFromCVEIDs(ctx context.Context, cveIDs []string) ([]common.Exploit, error) {
var ret []common.Exploit
prefix, err := url.JoinPath(a.config.BaseURL, "cves")
if err != nil {
return nil, fmt.Errorf("failed to join URLPath: %w", err)
}
responses, err := getExploitsViaHTTP(cveIDs, prefix)
responses, err := getExploitsViaHTTP(ctx, cveIDs, prefix)
if err != nil {
return nil, fmt.Errorf("failed to get exploits via HTTP: %w", err)
}
Expand Down Expand Up @@ -102,7 +102,7 @@ const (
taskTimeoutSec = 30
)

func getExploitsViaHTTP(cveIDs []string, urlPrefix string) ([]exploitResponse, error) {
func getExploitsViaHTTP(ctx context.Context, cveIDs []string, urlPrefix string) ([]exploitResponse, error) {
var responses []exploitResponse

numCVEs := len(cveIDs)
Expand All @@ -127,7 +127,7 @@ func getExploitsViaHTTP(cveIDs []string, urlPrefix string) ([]exploitResponse, e
return
}
log.Debugf("HTTP Request to %s", URL)
httpGetExploit(URL, req, resChan, errChan)
httpGetExploit(ctx, URL, req, resChan, errChan)
}
}

Expand All @@ -150,13 +150,13 @@ func getExploitsViaHTTP(cveIDs []string, urlPrefix string) ([]exploitResponse, e
return responses, nil
}

func httpGetExploit(url string, req exploitRequest, resChan chan<- exploitResponse, errChan chan<- error) {
func httpGetExploit(ctx context.Context, url string, req exploitRequest, resChan chan<- exploitResponse, errChan chan<- error) {
var body string
var resp *http.Response
var maxRetries uint64 = 3

requestFn := func() error {
ctx, cancel := context.WithTimeout(context.Background(), taskTimeoutSec*time.Second)
ctx, cancel := context.WithTimeout(ctx, taskTimeoutSec*time.Second)
defer cancel()

r, err := http.NewRequest(http.MethodGet, url, nil)
Expand Down
2 changes: 1 addition & 1 deletion scanner/families/exploits/family.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (e Exploits) Run(ctx context.Context, res *results.Results) (interfaces.IsR
var exploitsResults Results
for _, input := range e.conf.Inputs {
startTime := time.Now()
managerResults, err := manager.Run(utils.SourceType(input.InputType), input.Input)
managerResults, err := manager.Run(ctx, utils.SourceType(input.InputType), input.Input)
if err != nil {
return nil, fmt.Errorf("failed to scan input %q for exploits: %w", input.Input, err)
}
Expand Down
2 changes: 1 addition & 1 deletion scanner/families/infofinder/family.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (i InfoFinder) Run(ctx context.Context, _ *results.Results) (interfaces.IsR
manager := job_manager.New(i.conf.ScannersList, i.conf.ScannersConfig, logger, job.Factory)
for _, input := range i.conf.Inputs {
startTime := time.Now()
managerResults, err := manager.Run(utils.SourceType(input.InputType), input.Input)
managerResults, err := manager.Run(ctx, utils.SourceType(input.InputType), input.Input)
if err != nil {
return nil, fmt.Errorf("failed to scan input %q for info: %w", input.Input, err)
}
Expand Down
8 changes: 4 additions & 4 deletions scanner/families/infofinder/sshtopology/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func New(_ string, c job_manager.IsConfig, logger *log.Entry, resultChan chan jo
}

// nolint:cyclop,gocognit
func (s *Scanner) Run(sourceType utils.SourceType, userInput string) error {
go func() {
func (s *Scanner) Run(ctx context.Context, sourceType utils.SourceType, userInput string) error {
go func(ctx context.Context) {
s.logger.Debugf("Running with input=%v and source type=%v", userInput, sourceType)
retResults := types.ScannerResult{
ScannerName: ScannerName,
Expand All @@ -69,7 +69,7 @@ func (s *Scanner) Run(sourceType utils.SourceType, userInput string) error {
return
}

fsPath, cleanup, err := familiesutils.ConvertInputToFilesystem(context.TODO(), sourceType, userInput)
fsPath, cleanup, err := familiesutils.ConvertInputToFilesystem(ctx, sourceType, userInput)
if err != nil {
s.sendResults(retResults, fmt.Errorf("failed to convert input to filesystem: %w", err))
return
Expand Down Expand Up @@ -163,7 +163,7 @@ func (s *Scanner) Run(sourceType utils.SourceType, userInput string) error {
}

s.sendResults(retResults, nil)
}()
}(ctx)

return nil
}
Expand Down
8 changes: 4 additions & 4 deletions scanner/families/malware/clam/clam.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ type Scanner struct {
}

// nolint: cyclop
func (s *Scanner) Run(sourceType utils.SourceType, userInput string) error {
go func() {
func (s *Scanner) Run(ctx context.Context, sourceType utils.SourceType, userInput string) error {
go func(ctx context.Context) {
retResults := common.Results{
Source: userInput,
ScannerName: ScannerName,
Expand Down Expand Up @@ -107,7 +107,7 @@ func (s *Scanner) Run(sourceType utils.SourceType, userInput string) error {
}
s.logger.Infof("freshclam has finished running: %s", string(freshclamOut))

fsPath, cleanup, err := familiesutils.ConvertInputToFilesystem(context.TODO(), sourceType, userInput)
fsPath, cleanup, err := familiesutils.ConvertInputToFilesystem(ctx, sourceType, userInput)
if err != nil {
s.sendResults(retResults, fmt.Errorf("failed to convert input to filesystem: %w", err))
return
Expand Down Expand Up @@ -157,7 +157,7 @@ func (s *Scanner) Run(sourceType utils.SourceType, userInput string) error {
retResults.Summary = summary

s.sendResults(retResults, nil)
}()
}(ctx)

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion scanner/families/malware/family.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (m Malware) Run(ctx context.Context, _ *results.Results) (interfaces.IsResu

for _, input := range m.conf.Inputs {
startTime := time.Now()
resultArr, err := manager.Run(utils.SourceType(input.InputType), input.Input)
resultArr, err := manager.Run(ctx, utils.SourceType(input.InputType), input.Input)
if err != nil {
return nil, fmt.Errorf("failed to scan input %q for malware: %w", input.Input, err)
}
Expand Down
Loading
Loading