-
Notifications
You must be signed in to change notification settings - Fork 397
/
config.go
95 lines (79 loc) · 2.46 KB
/
config.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
85
86
87
88
89
90
91
92
93
94
95
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package trust
import (
"strings"
"time"
"github.com/zeebo/errs"
)
// Config is the trust configuration.
type Config struct {
Sources Sources `help:"list of trust sources" devDefault:"" releaseDefault:"https://tardigrade.io/trusted-satellites"`
Exclusions Exclusions `help:"list of trust exclusions" devDefault:"" releaseDefault:""`
RefreshInterval time.Duration `help:"how often the trust pool should be refreshed" default:"6h"`
CachePath string `help:"file path where trust lists should be cached" default:"${CONFDIR}/trust-cache.json"`
}
// Sources is a list of sources that implements pflag.Value.
type Sources []Source
// String returns the string representation of the config.
func (sources Sources) String() string {
s := make([]string, 0, len(sources))
for _, source := range sources {
s = append(s, source.String())
}
return strings.Join(s, ",")
}
// Set implements pflag.Value by parsing a comma separated list of sources.
func (sources *Sources) Set(value string) error {
var entries []string
if value != "" {
entries = strings.Split(value, ",")
}
var toSet []Source
for _, entry := range entries {
source, err := NewSource(entry)
if err != nil {
return Error.New("invalid source %q: %w", entry, errs.Unwrap(err))
}
toSet = append(toSet, source)
}
*sources = toSet
return nil
}
// Type returns the type of the pflag.Value.
func (sources Sources) Type() string {
return "trust-sources"
}
// Exclusions is a list of excluding rules that implements pflag.Value.
type Exclusions struct {
Rules Rules
}
// String returns the string representation of the config.
func (exclusions *Exclusions) String() string {
s := make([]string, 0, len(exclusions.Rules))
for _, rule := range exclusions.Rules {
s = append(s, rule.String())
}
return strings.Join(s, ",")
}
// Set implements pflag.Value by parsing a comma separated list of exclusions.
func (exclusions *Exclusions) Set(value string) error {
var entries []string
if value != "" {
entries = strings.Split(value, ",")
}
var rules Rules
for _, entry := range entries {
rule, err := NewExcluder(entry)
if err != nil {
return Error.New("invalid exclusion %q: %w", entry, errs.Unwrap(err))
}
rules = append(rules, rule)
}
exclusions.Rules = rules
return nil
}
// Type returns the type of the pflag.Value.
func (exclusions Exclusions) Type() string {
return "trust-exclusions"
}