aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2022-03-20 20:41:57 -0400
committerPaul Duncan <pabs@pablotron.org>2022-03-20 20:41:57 -0400
commit173b126c5672f87145d658ca051357c925a168c2 (patch)
tree1cf66775e89bf26c34d0bcc3f8502dc4ad391c43
parentac564c53e8f31bc2d410e9941435cc68e9be1ac0 (diff)
downloadcvez-173b126c5672f87145d658ca051357c925a168c2.tar.bz2
cvez-173b126c5672f87145d658ca051357c925a168c2.zip
cmd/update.go: use DbStore.Update()
-rw-r--r--cmd/update.go50
1 files changed, 1 insertions, 49 deletions
diff --git a/cmd/update.go b/cmd/update.go
index 8615057..1c1866a 100644
--- a/cmd/update.go
+++ b/cmd/update.go
@@ -3,12 +3,9 @@ package cmd
import (
// "encoding/json"
"context"
- "github.com/pablotron/cvez/cisa"
"github.com/pablotron/cvez/nvdmirror"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
- "os"
- "path/filepath"
)
var updateCmd = &cobra.Command{
@@ -35,53 +32,8 @@ var updateCmd = &cobra.Command{
log.Info().Msg("sync mirror")
updates := nvdmirror.Sync(config, &cache, cacheDir)
if len(updates) > 0 {
- // connect to db
ctx := context.Background()
- db := getDb()
-
- // load feeds
- log.Info().Msg("load feeds")
- if feeds := getFeeds(cacheDir, updates); len(feeds) > 0 {
- log.Info().Msg("AddCveFeeds")
- if _, err := db.AddCveFeeds(ctx, feeds); err != nil {
- // FIXME: failing like this leaves an invalid cache
- log.Error().Err(err).Msg("AddCveFeeds")
- os.Exit(-1)
- }
- }
-
- // process cpe dictionary before cpe matches to prevent FK
- // constraint violations
- for _, row := range(updates) {
- if row.Type == nvdmirror.UpdateCpeDict {
- log.Info().Msg("AddCpeDictionary")
- dict := getCpeDict(filepath.Join(cacheDir, row.Path))
- if err := db.AddCpeDictionary(ctx, dict); err != nil {
- log.Error().Err(err).Msg("AddCpeDictionary")
- os.Exit(-1)
- }
- }
- }
-
- for _, row := range(updates) {
- switch row.Type {
- case nvdmirror.UpdateCpeMatch:
- log.Info().Msg("AddCpeMatches")
- matches := getCpeMatches(filepath.Join(cacheDir, row.Path))
- if err := db.AddCpeMatches(ctx, matches); err != nil {
- log.Error().Err(err).Msg("AddCpeMatches")
- os.Exit(-1)
- }
- case nvdmirror.UpdateCisaKevc:
- log.Info().Msg("AddCisaCatalogs")
- cat := getCisaCatalog(filepath.Join(cacheDir, row.Path))
- if _, err := db.AddCisaCatalogs(ctx, []cisa.Catalog { cat }); err != nil {
- log.Error().Err(err).Msg("AddCisaCatalogs")
- os.Exit(-1)
- }
- }
- }
-
+ getDb().Update(ctx, cacheDir, updates)
log.Info().Msg("done")
}
},