mirror of
https://github.com/anchore/grype
synced 2024-11-14 00:07:08 +00:00
80f9e04289
Co-authored-by: Christopher Phillips <christopher.phillips@anchore.com>
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/anchore/grype/grype/db"
|
|
)
|
|
|
|
var dbCheckCmd = &cobra.Command{
|
|
Use: "check",
|
|
Short: "check to see if there is a database update available",
|
|
Args: cobra.ExactArgs(0),
|
|
RunE: runDBCheckCmd,
|
|
}
|
|
|
|
func init() {
|
|
dbCmd.AddCommand(dbCheckCmd)
|
|
}
|
|
|
|
func runDBCheckCmd(_ *cobra.Command, _ []string) error {
|
|
dbCurator, err := db.NewCurator(appConfig.DB.ToCuratorConfig())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
updateAvailable, currentDBMetadata, updateDBEntry, err := dbCurator.IsUpdateAvailable()
|
|
if err != nil {
|
|
return fmt.Errorf("unable to check for vulnerability database update: %+v", err)
|
|
}
|
|
|
|
if !updateAvailable {
|
|
return stderrPrintLnf("No update available")
|
|
}
|
|
|
|
fmt.Println("Update available!")
|
|
|
|
if currentDBMetadata != nil {
|
|
fmt.Printf("Current DB version %d was built on %s\n", currentDBMetadata.Version, currentDBMetadata.Built.String())
|
|
}
|
|
|
|
fmt.Printf("Updated DB version %d was built on %s\n", updateDBEntry.Version, updateDBEntry.Built.String())
|
|
fmt.Printf("Updated DB URL: %s\n", updateDBEntry.URL.String())
|
|
fmt.Println("You can run 'grype db update' to update to the latest db")
|
|
|
|
return nil
|
|
}
|