mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-22 07:10:41 -08:00
refactor: move from urfave/cli to spf13/cobra (#2458)
Co-authored-by: afdesk <work@afdesk.com> Co-authored-by: DmitriyLewen <91113035+DmitriyLewen@users.noreply.github.com>
This commit is contained in:
@@ -1,47 +1,48 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/aquasecurity/trivy/pkg/flag"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/aquasecurity/trivy-kubernetes/pkg/artifacts"
|
||||
"github.com/aquasecurity/trivy-kubernetes/pkg/k8s"
|
||||
"github.com/aquasecurity/trivy-kubernetes/pkg/trivyk8s"
|
||||
cmd "github.com/aquasecurity/trivy/pkg/commands/artifact"
|
||||
"github.com/aquasecurity/trivy/pkg/log"
|
||||
)
|
||||
|
||||
// resourceRun runs scan on kubernetes cluster
|
||||
func resourceRun(cliCtx *cli.Context, opt cmd.Option, cluster k8s.Cluster) error {
|
||||
kind, name, err := extractKindAndName(cliCtx.Args().Slice())
|
||||
func resourceRun(ctx context.Context, args []string, opts flag.Options, cluster k8s.Cluster) error {
|
||||
kind, name, err := extractKindAndName(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
trivyk8s := trivyk8s.New(cluster, log.Logger).Namespace(getNamespace(opt, cluster.GetCurrentNamespace()))
|
||||
trivyk8s := trivyk8s.New(cluster, log.Logger).Namespace(getNamespace(opts, cluster.GetCurrentNamespace()))
|
||||
|
||||
if len(name) == 0 { // pods or configmaps etc
|
||||
if err := validateReportArguments(cliCtx); err != nil {
|
||||
if err = validateReportArguments(opts); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
targets, err := trivyk8s.Resources(kind).ListArtifacts(cliCtx.Context)
|
||||
targets, err := trivyk8s.Resources(kind).ListArtifacts(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return run(cliCtx.Context, opt, cluster.GetCurrentContext(), targets)
|
||||
return run(ctx, opts, cluster.GetCurrentContext(), targets)
|
||||
}
|
||||
|
||||
// pod/NAME or pod NAME etc
|
||||
artifact, err := trivyk8s.GetArtifact(cliCtx.Context, kind, name)
|
||||
artifact, err := trivyk8s.GetArtifact(ctx, kind, name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return run(cliCtx.Context, opt, cluster.GetCurrentContext(), []*artifacts.Artifact{artifact})
|
||||
return run(ctx, opts, cluster.GetCurrentContext(), []*artifacts.Artifact{artifact})
|
||||
}
|
||||
|
||||
func extractKindAndName(args []string) (string, string, error) {
|
||||
|
||||
Reference in New Issue
Block a user