Skip to content

Commit

Permalink
deploy, cmd: add check for correct legacy db to deploy
Browse files Browse the repository at this point in the history
Adds a check that the deployed legacy DB is correct (in addition
to the existing check that the deployed v1 DB is correct).

Also adds more logging to the checkdb/checkdeploy commands so we
know what settings are turned on/off from the deploy logs.

Change-Id: Iffbae9536fc4caef40993987384e256c8d4237ae
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/541676
Reviewed-by: Damien Neil <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
tatianab committed Nov 14, 2023
1 parent 4786473 commit 03ef353
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
23 changes: 19 additions & 4 deletions cmd/checkdb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,42 @@ 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()
path := flag.Arg(0)
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)")
}
}
7 changes: 7 additions & 0 deletions cmd/checkdeploy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package main

import (
"flag"
"fmt"
"log"

db "golang.org/x/vulndb/internal/database"
Expand All @@ -28,15 +29,21 @@ 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)
}
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)")
}
}
2 changes: 1 addition & 1 deletion deploy/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

0 comments on commit 03ef353

Please sign in to comment.