-
Notifications
You must be signed in to change notification settings - Fork 80
/
opts.go
79 lines (71 loc) · 1.96 KB
/
opts.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
package libvuln
import (
"fmt"
"time"
"github.com/quay/claircore/alpine"
"github.com/quay/claircore/aws"
"github.com/quay/claircore/debian"
"github.com/quay/claircore/libvuln/driver"
"github.com/quay/claircore/ubuntu"
)
const (
DefaultUpdateInterval = 30 * time.Minute
DefaultUpdaterInitConcurrency = 10
DefaultMaxConnPool = 100
)
type Opts struct {
// the maximum size of the connection pool used by the database
MaxConnPool int32
// the connectiong string to the above data store implementation
ConnString string
// the interval in minutes which updaters will update the vulnstore
UpdateInterval time.Duration
// number of updaters ran in parallel while libvuln initializes. use this to tune io/cpu on library start when using many updaters
UpdaterInitConcurrency int
// returns the matchers to be used during libvuln runtime
Matchers []driver.Matcher
// returns the updaters to run on an interval
Updaters []driver.Updater
// a regex string to filter running updaters by
Run string
}
func (o *Opts) Parse() error {
// required
if o.ConnString == "" {
return fmt.Errorf("no connection string provided")
}
// optional
if o.UpdateInterval == 0 || o.UpdateInterval < time.Minute {
o.UpdateInterval = DefaultUpdateInterval
}
if o.UpdaterInitConcurrency == 0 {
o.UpdaterInitConcurrency = DefaultUpdaterInitConcurrency
}
if o.MaxConnPool == 0 {
o.MaxConnPool = DefaultMaxConnPool
}
if len(o.Matchers) == 0 {
o.Matchers = []driver.Matcher{
&debian.Matcher{},
&ubuntu.Matcher{},
&alpine.Matcher{},
&aws.Matcher{},
}
}
if len(o.Updaters) == 0 {
var err error
o.Updaters, err = updaters()
if err != nil {
return fmt.Errorf("failed to create default set of updaters: %w", err)
}
}
// filter out updaters if regex was passed
if o.Run != "" {
var err error
o.Updaters, err = regexFilter(o.Run, o.Updaters)
if err != nil {
return fmt.Errorf("regex filtering of updaters failed: %w", err)
}
}
return nil
}