mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-12 07:40:48 -08:00
* Fix subcommands help * refactor: call ShowAppHelpAndExit * refactor: remove an unused error * test: remove exit cases Co-authored-by: knqyf263 <knqyf263@gmail.com>
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package artifact
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
"golang.org/x/xerrors"
|
|
|
|
"github.com/aquasecurity/fanal/cache"
|
|
"github.com/aquasecurity/trivy/internal/artifact/config"
|
|
"github.com/aquasecurity/trivy/pkg/scanner"
|
|
)
|
|
|
|
func archiveScanner(ctx context.Context, input string, ac cache.ArtifactCache, lac cache.LocalArtifactCache, timeout time.Duration) (
|
|
scanner.Scanner, func(), error) {
|
|
s, err := initializeArchiveScanner(ctx, input, ac, lac, timeout)
|
|
if err != nil {
|
|
return scanner.Scanner{}, func() {}, xerrors.Errorf("unable to initialize the archive scanner: %w", err)
|
|
}
|
|
return s, func() {}, nil
|
|
}
|
|
|
|
func dockerScanner(ctx context.Context, imageName string, ac cache.ArtifactCache, lac cache.LocalArtifactCache, timeout time.Duration) (
|
|
scanner.Scanner, func(), error) {
|
|
s, cleanup, err := initializeDockerScanner(ctx, imageName, ac, lac, timeout)
|
|
if err != nil {
|
|
return scanner.Scanner{}, func() {}, xerrors.Errorf("unable to initialize a docker scanner: %w", err)
|
|
}
|
|
return s, cleanup, nil
|
|
}
|
|
|
|
func ImageRun(cliCtx *cli.Context) error {
|
|
c, err := config.New(cliCtx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// initialize config
|
|
if err := c.Init(true); err != nil {
|
|
return xerrors.Errorf("failed to initialize options: %w", err)
|
|
}
|
|
|
|
if c.Input != "" {
|
|
// scan tar file
|
|
return run(c, archiveScanner)
|
|
}
|
|
|
|
return run(c, dockerScanner)
|
|
}
|