@@ -28,14 +28,20 @@ import (
2828 output "github.com/ComplianceAsCode/cvetool/output"
2929)
3030
31- var defaultDBPath = filepath .Join (os .TempDir (), "matcher.db" )
32-
3331type EnumValue struct {
3432 Enum []string
3533 Default string
3634 selected string
3735}
3836
37+ func getDefaultDBPath () (string , error ) {
38+ homeFolder , err := os .UserHomeDir ()
39+ if err != nil || homeFolder == "" {
40+ return "" , fmt .Errorf ("home folder not set, DB path must be specified" )
41+ }
42+ return filepath .Join (homeFolder , ".local" , "share" , "cvetool" , "matcher.db" ), nil
43+ }
44+
3945func (e * EnumValue ) Set (value string ) error {
4046 if slices .Contains (e .Enum , value ) {
4147 e .selected = value
@@ -59,15 +65,15 @@ const (
5965 plainFmt = "plain"
6066)
6167
62- var reportCmd = & cli.Command {
63- Name : "report " ,
64- Aliases : []string {"r " },
65- Usage : "report on a manifest " ,
66- Action : report ,
68+ var scanCmd = & cli.Command {
69+ Name : "scan " ,
70+ Aliases : []string {"s " },
71+ Usage : "scan a system " ,
72+ Action : scan ,
6773 Flags : []cli.Flag {
6874 & cli.PathFlag {
6975 Name : "root-path" ,
70- Value : "" ,
76+ Value : "/ " ,
7177 Usage : "where to look for the local filesystem root" ,
7278 EnvVars : []string {"ROOT_PATH" },
7379 },
@@ -83,18 +89,6 @@ var reportCmd = &cli.Command{
8389 Usage : "where to look for the matcher DB" ,
8490 EnvVars : []string {"DB_PATH" },
8591 },
86- & cli.StringFlag {
87- Name : "image-ref" ,
88- Value : "" ,
89- Usage : "the remote location of the image" ,
90- EnvVars : []string {"IMAGE_REF" },
91- },
92- & cli.StringFlag {
93- Name : "db-url" ,
94- Value : "" ,
95- Usage : "the remote location of the sqlite zstd DB" ,
96- EnvVars : []string {"DB_URL" },
97- },
9892 & cli.GenericFlag {
9993 Name : "format" ,
10094 Aliases : []string {"f" },
@@ -112,16 +106,10 @@ var reportCmd = &cli.Command{
112106 Usage : "what status code to return when vulnerabilites are found" ,
113107 EnvVars : []string {"RETURN_CODE" },
114108 },
115- & cli.StringFlag {
116- Name : "docker-config-dir" ,
117- Value : "" ,
118- Usage : "Docker config dir for the image registry where --image-ref is stored" ,
119- EnvVars : []string {"DOCKER_CONFIG_DIR" },
120- },
121109 },
122110}
123111
124- func report (c * cli.Context ) error {
112+ func scan (c * cli.Context ) error {
125113 ctx := c .Context
126114
127115 var (
@@ -170,14 +158,21 @@ func report(c *cli.Context) error {
170158 switch {
171159 case dbPath != "" :
172160 case dbURL != "" :
173- dbPath = defaultDBPath
174161 var err error
175- err = datastore .DownloadDB (ctx , dbURL , defaultDBPath )
162+ err = datastore .DownloadDB (ctx , dbURL , "" )
176163 if err != nil {
177164 return fmt .Errorf ("could not download database: %v" , err )
178165 }
179166 default :
180- return fmt .Errorf ("no $DB_PATH / --db-path or $DB_URL / --db-url set" )
167+ var err error
168+ dbPath , err = getDefaultDBPath ()
169+ if err != nil {
170+ return err
171+ }
172+ }
173+
174+ if _ , err := os .Stat (dbPath ); err != nil {
175+ return fmt .Errorf ("unable to get database path" )
181176 }
182177
183178 matcherStore , err := datastore .NewSQLiteMatcherStore (dbPath , true )
0 commit comments