aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-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")
}
},