grype/cmd/db_update.go

44 lines
839 B
Go
Raw Normal View History

2020-05-26 17:31:50 +00:00
package cmd
import (
2020-06-19 14:12:29 +00:00
"fmt"
2020-05-26 17:31:50 +00:00
"os"
2020-07-24 01:29:05 +00:00
"github.com/anchore/grype/grype/db"
2020-05-26 17:31:50 +00:00
"github.com/spf13/cobra"
)
var dbUpdateCmd = &cobra.Command{
Use: "update",
Short: "download the latest vulnerability database",
Run: func(cmd *cobra.Command, args []string) {
2020-06-19 14:12:29 +00:00
ret := runDbUpdateCmd(cmd, args)
if ret != 0 {
fmt.Println("Unable to update vulnerability database")
}
os.Exit(ret)
2020-05-26 17:31:50 +00:00
},
}
func init() {
dbCmd.AddCommand(dbUpdateCmd)
}
2020-06-19 14:12:29 +00:00
func runDbUpdateCmd(_ *cobra.Command, _ []string) int {
dbCurator := db.NewCurator(appConfig.Db.ToCuratorConfig())
2020-06-19 14:12:29 +00:00
2020-08-01 15:58:10 +00:00
updated, err := dbCurator.Update()
2020-06-19 14:12:29 +00:00
if err != nil {
2020-08-01 15:58:10 +00:00
log.Errorf("unable to update vulnerability database: %+v", err)
2020-06-19 14:12:29 +00:00
return 1
}
2020-08-01 15:58:10 +00:00
if updated {
fmt.Println("Vulnerability database updated!")
2020-06-19 14:12:29 +00:00
return 0
}
2020-08-01 15:58:10 +00:00
fmt.Println("No vulnerability database update available")
2020-05-26 17:31:50 +00:00
return 0
}