Skip to content

Commit 7e427bb

Browse files
committed
feat: new subcommand image scan
1 parent 818eec7 commit 7e427bb

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

cmd/murphy/internal/binscan/cmd.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
var cliIOTScan bool
2222
var projectNameCli string
2323
var projectTagNames []string
24+
var imageScan bool
2425

2526
func Cmd() *cobra.Command {
2627
var c cobra.Command
@@ -34,6 +35,20 @@ func Cmd() *cobra.Command {
3435
return &c
3536
}
3637

38+
func ImageScanCmd() *cobra.Command {
39+
var c cobra.Command
40+
c.Use = "imagescan <DIR>"
41+
c.Args = cobra.ExactArgs(1)
42+
c.Run = func(cmd *cobra.Command, args []string) {
43+
imageScan = true
44+
binScanRun(cmd, args)
45+
}
46+
c.Short = "Detects open source vulnerabilities by scanning docker image files"
47+
c.Flags().StringVar(&projectNameCli, "project-name", "", "specify project name")
48+
c.Flags().StringArrayVar(&projectTagNames, "project-tag", make([]string, 0), "specify the tag of the project")
49+
return &c
50+
}
51+
3752
func binScanRun(cmd *cobra.Command, args []string) {
3853
var (
3954
// workaround
@@ -92,6 +107,9 @@ func binScan(ctx context.Context, scanPath string) error {
92107
if cliIOTScan {
93108
mode = model.ScanModeIot
94109
}
110+
if imageScan {
111+
mode = model.ScanModeImage
112+
}
95113
taskResp, e := api.CreateSubTask(api.DefaultClient(), &api.CreateSubTaskRequest{
96114
AccessType: model.AccessTypeCli,
97115
ScanMode: mode,

cmd/murphy/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func rootCmd() *cobra.Command {
6666
c.AddCommand(scan.SbomScan())
6767
c.AddCommand(scan.EnvCmd())
6868
c.AddCommand(binscan.Cmd())
69+
c.AddCommand(binscan.ImageScanCmd())
6970
c.AddCommand(internalcmd.Cmd())
7071
c.AddCommand(internalcmd.MachineIdCmd())
7172
return c

model/scan_mode.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ const (
99
ScanModeIot ScanMode = "iot"
1010
ScanModeStandard ScanMode = "standard"
1111
ScanModeComp ScanMode = "comp"
12+
ScanModeImage ScanMode = "docker"
1213
)

0 commit comments

Comments
 (0)