-
Notifications
You must be signed in to change notification settings - Fork 20
/
checks.go
92 lines (76 loc) · 2.67 KB
/
checks.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
package config
import (
// Register the DIY check
_ "github.com/Shopify/voucher/checks/diy"
// Register the Nobody check
_ "github.com/Shopify/voucher/checks/nobody"
// Register the Provenance check
_ "github.com/Shopify/voucher/checks/provenance"
// Register the Snakeoil check
_ "github.com/Shopify/voucher/checks/snakeoil"
)
import (
"fmt"
"github.com/Shopify/voucher"
)
// EnabledChecks returns a slice of strings with the check names, based on a
// map[string]bool (with a check name in the key, and the value storing whether
// or not to run the check). The returned map contains enabled checks.
func EnabledChecks(checks map[string]bool) (enabledChecks []string) {
enabledChecks = make([]string, 0, len(checks))
for name, check := range checks {
if check {
enabledChecks = append(enabledChecks, name)
}
}
return
}
// setAuth sets the Auth for the passed Check, if that Check implements
// AuthorizedCheck.
func setCheckAuth(check voucher.Check, auth voucher.Auth) {
if authCheck, ok := check.(voucher.AuthorizedCheck); ok {
authCheck.SetAuth(auth)
}
}
// setCheckScanner sets the scanner on the passed Check, if that Check implements
// VulnerabilityCheck.
func setCheckScanner(check voucher.Check, scanner voucher.VulnerabilityScanner) {
if vulCheck, ok := check.(voucher.VulnerabilityCheck); ok {
vulCheck.SetScanner(scanner)
}
}
// setCheckMetadataClient sets the MetadataClient for the passed Check, if that Check implements
// MetadataCheck.
func setCheckMetadataClient(check voucher.Check, metadataClient voucher.MetadataClient) {
if metadataCheck, ok := check.(voucher.MetadataCheck); ok {
metadataCheck.SetMetadataClient(metadataClient)
}
}
// setCheckValidRepos sets the valid repos list for the passed Check, if
// that Check is a RepoValidatorCheck.
func setCheckValidRepos(check voucher.Check, validRepos []string) {
if validRepoCheck, ok := check.(voucher.RepoValidatorCheck); ok {
validRepoCheck.SetValidRepos(validRepos)
}
}
// NewCheckSuite creates a new checks.Suite with the requested
// Checks, passing any necessary configuration details to the
// checks.
func NewCheckSuite(metadataClient voucher.MetadataClient, names ...string) (*voucher.Suite, error) {
auth := newAuth()
repos := validRepos()
scanner := newScanner(metadataClient, auth)
checksuite := voucher.NewSuite()
checks, err := voucher.GetCheckFactories(names...)
if nil != err {
return checksuite, fmt.Errorf("can't create check suite: %s", err)
}
for name, check := range checks {
setCheckAuth(check, auth)
setCheckScanner(check, scanner)
setCheckMetadataClient(check, metadataClient)
setCheckValidRepos(check, repos)
checksuite.Add(name, check)
}
return checksuite, nil
}