From 5d2e8754df5cdea6c3b6a50776765155c6f77820 Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Fri, 5 Mar 2021 09:41:04 +0100 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20use=20context=20for=20scan=20su?= =?UTF-8?q?ggest=20message,=20use=20cliconfig.Dir()=20as=20in=20scan=20plu?= =?UTF-8?q?gin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Guillaume Tardif --- local/compose/build.go | 4 ++-- local/compose/scan_suggest.go | 12 +++++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/local/compose/build.go b/local/compose/build.go index 5a6f1f9f8..0430d927b 100644 --- a/local/compose/build.go +++ b/local/compose/build.go @@ -50,7 +50,7 @@ func (s *composeService) Build(ctx context.Context, project *types.Project, opti err := s.build(ctx, project, opts, options.Progress) if err == nil { - displayScanSuggestMsg(ctx, imagesToBuild) + displayScanSuggestMsg(imagesToBuild) } return err @@ -100,7 +100,7 @@ func (s *composeService) ensureImagesExists(ctx context.Context, project *types. err := s.build(ctx, project, opts, "auto") if err == nil { - displayScanSuggestMsg(ctx, imagesToBuild) + displayScanSuggestMsg(imagesToBuild) } return err } diff --git a/local/compose/scan_suggest.go b/local/compose/scan_suggest.go index 2d5ab0fea..3a7eb82bf 100644 --- a/local/compose/scan_suggest.go +++ b/local/compose/scan_suggest.go @@ -17,7 +17,6 @@ package compose import ( - "context" "encoding/json" "fmt" "io/ioutil" @@ -26,25 +25,24 @@ import ( pluginmanager "github.com/docker/cli/cli-plugins/manager" "github.com/docker/cli/cli/command" - "github.com/docker/compose-cli/api/config" + cliConfig "github.com/docker/cli/cli/config" ) -func displayScanSuggestMsg(ctx context.Context, builtImages []string) { +func displayScanSuggestMsg(builtImages []string) { if len(builtImages) <= 0 { return } if os.Getenv("DOCKER_SCAN_SUGGEST") == "false" { return } - if !scanAvailable() || scanAlreadyInvoked(ctx) { + if !scanAvailable() || scanAlreadyInvoked() { return } fmt.Println("Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them") } -func scanAlreadyInvoked(ctx context.Context) bool { - configDir := config.Dir(ctx) - filename := filepath.Join(configDir, "scan", "config.json") +func scanAlreadyInvoked() bool { + filename := filepath.Join(cliConfig.Dir(), "scan", "config.json") f, err := os.Stat(filename) if os.IsNotExist(err) { return false