Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pkg/commands/artifact/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const (
TargetRepository TargetKind = "repo"
TargetSBOM TargetKind = "sbom"
TargetVM TargetKind = "vm"
TargetK8s TargetKind = "k8s"
)

var (
Expand Down Expand Up @@ -113,7 +114,7 @@ func WithInitializeService(f InitializeScanService) RunnerOption {

// NewRunner initializes Runner that provides scanning functionalities.
// It is possible to return SkipScan and it must be handled by caller.
func NewRunner(ctx context.Context, cliOptions flag.Options, opts ...RunnerOption) (Runner, error) {
func NewRunner(ctx context.Context, cliOptions flag.Options, targetKind TargetKind, opts ...RunnerOption) (Runner, error) {
r := &runner{}
for _, opt := range opts {
opt(r)
Expand All @@ -125,9 +126,8 @@ func NewRunner(ctx context.Context, cliOptions flag.Options, opts ...RunnerOptio
Timeout: cliOptions.Timeout,
TraceHTTP: cliOptions.TraceHTTP,
}))
// get the sub command that is being used or fallback to "trivy"
commandName := lo.NthOr(os.Args, 1, "trivy")
r.versionChecker = notification.NewVersionChecker(commandName, &cliOptions)

r.versionChecker = notification.NewVersionChecker(string(targetKind), &cliOptions)

// Update the vulnerability database if needed.
if err := r.initDB(ctx, cliOptions); err != nil {
Expand Down Expand Up @@ -421,7 +421,7 @@ func Run(ctx context.Context, opts flag.Options, targetKind TargetKind) (err err
}

func run(ctx context.Context, opts flag.Options, targetKind TargetKind) (types.Report, error) {
r, err := NewRunner(ctx, opts)
r, err := NewRunner(ctx, opts, targetKind)
if err != nil {
if errors.Is(err, SkipScan) {
return types.Report{}, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/k8s/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func newRunner(flagOpts flag.Options, cluster string) *runner {
}

func (r *runner) run(ctx context.Context, artifacts []*k8sArtifacts.Artifact) error {
runner, err := cmd.NewRunner(ctx, r.flagOpts)
runner, err := cmd.NewRunner(ctx, r.flagOpts, cmd.TargetK8s)
if err != nil {
if errors.Is(err, cmd.SkipScan) {
return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/k8s/scanner/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func TestScanner_Scan(t *testing.T) {
ctx := t.Context()
uuid.SetFakeUUID(t, "3ff14136-e09f-4df9-80ea-%012d")

runner, err := cmd.NewRunner(ctx, flagOpts)
runner, err := cmd.NewRunner(ctx, flagOpts, cmd.TargetK8s)
require.NoError(t, err)

scanner := NewScanner(tt.clusterName, runner, flagOpts)
Expand Down
Loading