From 8edac6d76d5359c06a86fd2f24a44956d6158c22 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Tue, 22 Feb 2022 19:59:38 -0500 Subject: cmd: add update cmd --- cmd/update.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 cmd/update.go diff --git a/cmd/update.go b/cmd/update.go new file mode 100644 index 0000000..fe234ed --- /dev/null +++ b/cmd/update.go @@ -0,0 +1,46 @@ +package cmd + +import ( + // "encoding/json" + "github.com/pablotron/cvez/nvdmirror" + "github.com/spf13/cobra" + "github.com/rs/zerolog" + "github.com/rs/zerolog/log" + "os" + "time" +) + +var updateCmd = &cobra.Command{ + Use: "update", + Aliases: []string { "up" }, + Short: "Update mirror.", + Long: `Update local NVD mirror.`, + + Run: func(cmd *cobra.Command, args []string) { + // set global logging options + zerolog.TimeFieldFormat = time.RFC3339 + zerolog.SetGlobalLevel(zerolog.InfoLevel) + + // create cache + cache, err := nvdmirror.NewJsonCache("stuff/cache.json.gz") + if err != nil { + log.Error().Err(err).Msg("NewJsonCache") + } + defer cache.Close() + + // custom sync config + urls := nvdmirror.Urls { + Cve11Base: "https://pmdn.org/nvdmirror", + } + + // sync data + if err := nvdmirror.Sync(urls, &cache, "stuff"); err != nil { + log.Error().Err(err).Msg("Sync") + os.Exit(-1) + } + }, +} + +func init() { + rootCmd.AddCommand(updateCmd) +} -- cgit v1.2.3