forked from facebookincubator/nvdtools
/
main.go
84 lines (72 loc) · 2.17 KB
/
main.go
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// nvdsync is a command line tool to synchronize NVD data feeds to local directory.
//
// Copyright (c) Facebook, Inc. and its affiliates.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"context"
"flag"
"fmt"
"os"
"time"
"github.com/facebookincubator/flog"
"github.com/Daviid-P/nvdtools/providers/nvd"
)
func init() {
flog.AddFlags(flag.CommandLine, nil)
flag.Set("logtostderr", "true")
}
func main() {
var (
cvefeed nvd.CVE
cpefeed nvd.CPE
timeout time.Duration
userAgent string
source = nvd.NewSourceConfig()
)
flag.Var(&cvefeed, "cve_feed", cvefeed.Help())
flag.Var(&cpefeed, "cpe_feed", cpefeed.Help())
flag.DurationVar(&timeout, "timeout", 5*time.Minute, "sync timeout")
flag.StringVar(&userAgent, "user_agent", nvd.UserAgent(), "HTTP request User-Agent header")
source.AddFlags(flag.CommandLine)
flag.Usage = func() {
fmt.Printf("nvdsync %s\n\n", nvd.Version)
fmt.Printf("use: %s [flags] dir\n", os.Args[0])
fmt.Printf("Synchronizes NVD data feeds to local directory.\n\n")
fmt.Printf("Flags:\n\n")
flag.PrintDefaults()
os.Exit(1)
}
flag.Parse()
localdir := flag.Arg(0)
if localdir == "" {
flag.Usage()
}
// determine User-Agent header
// check if it's only ascii characters
if err := nvd.SetUserAgent(userAgent); err != nil {
flog.Warningf("could not set User-Agent HTTP header, using default: %v", err)
}
flog.Infof("Using http User-Agent: %s", nvd.UserAgent())
dfs := nvd.Sync{
Feeds: []nvd.Syncer{cvefeed, cpefeed},
Source: source,
LocalDir: localdir,
}
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
if err := dfs.Do(ctx); err != nil {
flog.Fatal(err)
}
}