diff --git a/cmd/checkdb/main.go b/cmd/checkdb/main.go index 2a194653..1a4fe5e4 100644 --- a/cmd/checkdb/main.go +++ b/cmd/checkdb/main.go @@ -7,13 +7,17 @@ package main import ( "flag" + "fmt" "log" db "golang.org/x/vulndb/internal/database" "golang.org/x/vulndb/internal/database/legacydb" ) -var legacy = flag.Bool("legacy", false, "if true, check with respect to legacy database schema") +var ( + v1 = flag.Bool("v1", true, "if true, check with respect to v1 database schema") + legacy = flag.Bool("legacy", false, "if true, check with respect to legacy database schema") +) func main() { flag.Parse() @@ -21,13 +25,24 @@ func main() { if path == "" { log.Fatal("path must be set\nusage: checkdb [path]") } - if *legacy { - if _, err := legacydb.Load(path); err != nil { + if !*v1 && !*legacy { + log.Fatal("no versions set (use flags -v1 and/or -legacy)") + } + if *v1 { + if _, err := db.Load(path); err != nil { log.Fatal(err) } + fmt.Printf("%s contains valid v1 database\n", path) } else { - if _, err := db.Load(path); err != nil { + fmt.Println("skipping v1 validity check (use flag -v1 to enable)") + } + + if *legacy { + if _, err := legacydb.Load(path); err != nil { log.Fatal(err) } + fmt.Printf("%s contains valid legacy database\n", path) + } else { + fmt.Println("skipping legacy validity check (use flag -legacy to enable)") } } diff --git a/cmd/checkdeploy/main.go b/cmd/checkdeploy/main.go index edbc3a77..f62f11e1 100644 --- a/cmd/checkdeploy/main.go +++ b/cmd/checkdeploy/main.go @@ -8,6 +8,7 @@ package main import ( "flag" + "fmt" "log" db "golang.org/x/vulndb/internal/database" @@ -28,9 +29,12 @@ func main() { if *existingPath == "" { log.Fatalf("flag -existing must be set") } + if err := db.ValidateDeploy(*newPath, *existingPath); err != nil { log.Fatal(err) } + fmt.Printf("ok to deploy v1 database %s on top of %s\n", *newPath, *existingPath) + if *newLegacyPath != "" { if err := legacydb.Validate(*newLegacyPath, *existingPath); err != nil { log.Fatal(err) @@ -38,5 +42,8 @@ func main() { if err := legacydb.Equivalent(*newPath, *newLegacyPath); err != nil { log.Fatal(err) } + fmt.Printf("ok to deploy legacy database %s on top of %s\n", *newLegacyPath, *existingPath) + } else { + fmt.Println("not checking legacy database deploy (use -legacy flag to set)") } } diff --git a/deploy/build.yaml b/deploy/build.yaml index 8bb87a5c..9f884e2e 100644 --- a/deploy/build.yaml +++ b/deploy/build.yaml @@ -68,4 +68,4 @@ steps: - id: PostValidate name: golang:1.19.2 entrypoint: bash - args: ["-ec", "go run ./cmd/checkdb /workspace/deployed/go-vulndb"] + args: ["-ec", "go run ./cmd/checkdb -v1 -legacy /workspace/deployed/go-vulndb"]