diff options
author | Paul Duncan <pabs@pablotron.org> | 2022-02-22 19:59:38 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2022-02-22 19:59:38 -0500 |
commit | 8edac6d76d5359c06a86fd2f24a44956d6158c22 (patch) | |
tree | 2a370114ba775a78b0fac1801e3dccf32646a1fc /cmd | |
parent | a4b802d22fa0940fd1862f2176dfb41f4a1be973 (diff) | |
download | cvez-8edac6d76d5359c06a86fd2f24a44956d6158c22.tar.bz2 cvez-8edac6d76d5359c06a86fd2f24a44956d6158c22.zip |
cmd: add update cmd
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/update.go | 46 |
1 files changed, 46 insertions, 0 deletions
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) +} |