2020-07-16 18:59:35 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2020-07-24 01:29:05 +00:00
|
|
|
"github.com/anchore/grype/grype/db"
|
2020-07-16 18:59:35 +00:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2020-07-26 12:12:08 +00:00
|
|
|
var showSupportedDbSchema bool
|
|
|
|
|
2020-07-16 18:59:35 +00:00
|
|
|
var statusCmd = &cobra.Command{
|
|
|
|
Use: "status",
|
|
|
|
Short: "display database status",
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2020-07-30 01:11:05 +00:00
|
|
|
err := runDbStatusCmd(cmd, args)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf(err.Error())
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2020-07-16 18:59:35 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2020-07-26 12:12:08 +00:00
|
|
|
// Note: this option cannot change as it supports the nightly DB generation job
|
|
|
|
statusCmd.Flags().BoolVar(&showSupportedDbSchema, "schema", false, "show supported DB schema")
|
|
|
|
|
2020-07-16 18:59:35 +00:00
|
|
|
dbCmd.AddCommand(statusCmd)
|
|
|
|
}
|
|
|
|
|
2020-07-30 01:11:05 +00:00
|
|
|
func runDbStatusCmd(_ *cobra.Command, _ []string) error {
|
|
|
|
dbCurator := db.NewCurator(appConfig.Db.ToCuratorConfig())
|
2020-07-16 18:59:35 +00:00
|
|
|
status := dbCurator.Status()
|
2020-07-26 12:12:08 +00:00
|
|
|
|
|
|
|
if showSupportedDbSchema {
|
2020-07-30 01:11:05 +00:00
|
|
|
// note: the output for this option cannot change as it supports the nightly DB generation job
|
|
|
|
fmt.Println(status.RequiredSchemaVersion)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if status.Err != nil {
|
|
|
|
return status.Err
|
2020-07-26 12:12:08 +00:00
|
|
|
}
|
|
|
|
|
2020-07-16 18:59:35 +00:00
|
|
|
fmt.Println("Location: ", status.Location)
|
|
|
|
fmt.Println("Built: ", status.Age.String())
|
2020-07-25 23:03:33 +00:00
|
|
|
fmt.Println("Current DB Version: ", status.CurrentSchemaVersion)
|
2020-07-30 01:11:05 +00:00
|
|
|
fmt.Println("Require DB Version: ", status.RequiredSchemaVersion)
|
|
|
|
fmt.Println("Status: Valid")
|
2020-07-16 18:59:35 +00:00
|
|
|
|
2020-07-30 01:11:05 +00:00
|
|
|
return nil
|
2020-07-16 18:59:35 +00:00
|
|
|
}
|