aboutsummaryrefslogtreecommitdiff
path: root/cmd/update.go
blob: fe234ed44189375410508bf836bc19f9643324ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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)
}