From c953b47bef38baee4ac1bb29188b7264896b620d Mon Sep 17 00:00:00 2001 From: knqyf263 Date: Thu, 16 Nov 2023 15:19:26 +0900 Subject: [PATCH 1/2] chore: add prefix to image errors Signed-off-by: knqyf263 --- pkg/fanal/image/image.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/fanal/image/image.go b/pkg/fanal/image/image.go index 0194dff6b217..fc8e14ab37e1 100644 --- a/pkg/fanal/image/image.go +++ b/pkg/fanal/image/image.go @@ -2,6 +2,7 @@ package image import ( "context" + "fmt" "strings" "github.com/google/go-containerregistry/pkg/name" @@ -50,6 +51,7 @@ func NewContainerImage(ctx context.Context, imageName string, opt types.ImageOpt // Return v1.Image if the image is found return img, cleanup, nil } + err = multierror.Prefix(err, fmt.Sprintf("%s error:", src)) errs = multierror.Append(errs, err) } From 2e6b7bfeca00ec9a7c4ae1c7ef5fcdc56ded86e6 Mon Sep 17 00:00:00 2001 From: knqyf263 Date: Mon, 20 Nov 2023 16:45:12 +0900 Subject: [PATCH 2/2] refactor: rename docker scanner with image scanner Signed-off-by: knqyf263 --- pkg/commands/artifact/inject.go | 8 ++++---- pkg/commands/artifact/scanner.go | 8 ++++---- pkg/commands/artifact/wire_gen.go | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/commands/artifact/inject.go b/pkg/commands/artifact/inject.go index c6bf6f4594a6..19d6e8565f02 100644 --- a/pkg/commands/artifact/inject.go +++ b/pkg/commands/artifact/inject.go @@ -20,9 +20,9 @@ import ( // Standalone ////////////// -// initializeDockerScanner is for container image scanning in standalone mode +// initializeImageScanner is for container image scanning in standalone mode // e.g. dockerd, container registry, podman, etc. -func initializeDockerScanner(ctx context.Context, imageName string, artifactCache cache.ArtifactCache, +func initializeImageScanner(ctx context.Context, imageName string, artifactCache cache.ArtifactCache, localArtifactCache cache.LocalArtifactCache, imageOpt types.ImageOptions, artifactOption artifact.Option) ( scanner.Scanner, func(), error) { wire.Build(scanner.StandaloneDockerSet) @@ -67,9 +67,9 @@ func initializeVMScanner(ctx context.Context, filePath string, artifactCache cac // Client/Server ///////////////// -// initializeRemoteDockerScanner is for container image scanning in client/server mode +// initializeRemoteImageScanner is for container image scanning in client/server mode // e.g. dockerd, container registry, podman, etc. -func initializeRemoteDockerScanner(ctx context.Context, imageName string, artifactCache cache.ArtifactCache, +func initializeRemoteImageScanner(ctx context.Context, imageName string, artifactCache cache.ArtifactCache, remoteScanOptions client.ScannerOption, imageOpt types.ImageOptions, artifactOption artifact.Option) ( scanner.Scanner, func(), error) { wire.Build(scanner.RemoteDockerSet) diff --git a/pkg/commands/artifact/scanner.go b/pkg/commands/artifact/scanner.go index e5946193b789..5685572a10c4 100644 --- a/pkg/commands/artifact/scanner.go +++ b/pkg/commands/artifact/scanner.go @@ -12,10 +12,10 @@ import ( // imageStandaloneScanner initializes a container image scanner in standalone mode // $ trivy image alpine:3.15 func imageStandaloneScanner(ctx context.Context, conf ScannerConfig) (scanner.Scanner, func(), error) { - s, cleanup, err := initializeDockerScanner(ctx, conf.Target, conf.ArtifactCache, conf.LocalArtifactCache, + s, cleanup, err := initializeImageScanner(ctx, conf.Target, conf.ArtifactCache, conf.LocalArtifactCache, conf.ArtifactOption.ImageOption, conf.ArtifactOption) if err != nil { - return scanner.Scanner{}, func() {}, xerrors.Errorf("unable to initialize a docker scanner: %w", err) + return scanner.Scanner{}, func() {}, xerrors.Errorf("unable to initialize an image scanner: %w", err) } return s, cleanup, nil } @@ -34,10 +34,10 @@ func archiveStandaloneScanner(ctx context.Context, conf ScannerConfig) (scanner. // $ trivy image --server localhost:4954 alpine:3.15 func imageRemoteScanner(ctx context.Context, conf ScannerConfig) ( scanner.Scanner, func(), error) { - s, cleanup, err := initializeRemoteDockerScanner(ctx, conf.Target, conf.ArtifactCache, conf.ServerOption, + s, cleanup, err := initializeRemoteImageScanner(ctx, conf.Target, conf.ArtifactCache, conf.ServerOption, conf.ArtifactOption.ImageOption, conf.ArtifactOption) if err != nil { - return scanner.Scanner{}, nil, xerrors.Errorf("unable to initialize the remote docker scanner: %w", err) + return scanner.Scanner{}, nil, xerrors.Errorf("unable to initialize a remote image scanner: %w", err) } return s, cleanup, nil } diff --git a/pkg/commands/artifact/wire_gen.go b/pkg/commands/artifact/wire_gen.go index 2c8cb311d431..e91ae3d5e8c8 100644 --- a/pkg/commands/artifact/wire_gen.go +++ b/pkg/commands/artifact/wire_gen.go @@ -29,9 +29,9 @@ import ( // Injectors from inject.go: -// initializeDockerScanner is for container image scanning in standalone mode +// initializeImageScanner is for container image scanning in standalone mode // e.g. dockerd, container registry, podman, etc. -func initializeDockerScanner(ctx context.Context, imageName string, artifactCache cache.ArtifactCache, localArtifactCache cache.LocalArtifactCache, imageOpt types.ImageOptions, artifactOption artifact.Option) (scanner.Scanner, func(), error) { +func initializeImageScanner(ctx context.Context, imageName string, artifactCache cache.ArtifactCache, localArtifactCache cache.LocalArtifactCache, imageOpt types.ImageOptions, artifactOption artifact.Option) (scanner.Scanner, func(), error) { applierApplier := applier.NewApplier(localArtifactCache) ospkgScanner := ospkg.NewScanner() langpkgScanner := langpkg.NewScanner() @@ -140,9 +140,9 @@ func initializeVMScanner(ctx context.Context, filePath string, artifactCache cac }, nil } -// initializeRemoteDockerScanner is for container image scanning in client/server mode +// initializeRemoteImageScanner is for container image scanning in client/server mode // e.g. dockerd, container registry, podman, etc. -func initializeRemoteDockerScanner(ctx context.Context, imageName string, artifactCache cache.ArtifactCache, remoteScanOptions client.ScannerOption, imageOpt types.ImageOptions, artifactOption artifact.Option) (scanner.Scanner, func(), error) { +func initializeRemoteImageScanner(ctx context.Context, imageName string, artifactCache cache.ArtifactCache, remoteScanOptions client.ScannerOption, imageOpt types.ImageOptions, artifactOption artifact.Option) (scanner.Scanner, func(), error) { v := _wireValue clientScanner := client.NewScanner(remoteScanOptions, v...) typesImage, cleanup, err := image.NewContainerImage(ctx, imageName, imageOpt)