forked from google/osv-scalibr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.go
98 lines (84 loc) · 2.82 KB
/
list.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
96
97
98
// Copyright 2024 Google LLC
//
// 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 list provides a public list of SCALIBR-internal detection plugins.
package list
import (
"fmt"
"os"
"slices"
"strings"
"github.com/google/osv-scalibr/detector/cis/generic_linux/etcpasswdpermissions"
"github.com/google/osv-scalibr/detector/cve/cve202338408"
"github.com/google/osv-scalibr/detector"
"github.com/google/osv-scalibr/detector/govulncheck/binary"
"github.com/google/osv-scalibr/detector/weakcredentials/etcshadow"
"github.com/google/osv-scalibr/log"
)
// CIS scanning related detectors.
var CIS []detector.Detector = []detector.Detector{&etcpasswdpermissions.Detector{}}
// CVE scanning related detectors.
var CVE []detector.Detector = []detector.Detector{&cve202338408.Detector{}}
// Govulncheck detectors.
var Govulncheck []detector.Detector = []detector.Detector{&binary.Detector{}}
// Weakcreds detectors for weak credentials.
var Weakcreds []detector.Detector = []detector.Detector{&etcshadow.Detector{}}
// Default detectors that are recommended to be enabled.
var Default []detector.Detector = []detector.Detector{}
// All detectors internal to SCALIBR.
var All []detector.Detector = slices.Concat(
CIS,
CVE,
Govulncheck,
Weakcreds,
)
var detectorNames = map[string][]detector.Detector{
"cis": CIS,
"cve": CVE,
"govulncheck": Govulncheck,
"weakcreds": Weakcreds,
"default": Default,
"all": All,
}
func init() {
for _, d := range All {
register(d)
}
}
func register(d detector.Detector) {
if _, ok := detectorNames[strings.ToLower(d.Name())]; ok {
log.Errorf("There are 2 detectors with the name: %q", d.Name())
os.Exit(1)
}
detectorNames[strings.ToLower(d.Name())] = []detector.Detector{d}
}
// DetectorsFromNames returns a deduplicated list of detectors from a list of names.
func DetectorsFromNames(names []string) ([]detector.Detector, error) {
resultMap := make(map[string]detector.Detector)
for _, n := range names {
if ds, ok := detectorNames[strings.ToLower(n)]; ok {
for _, d := range ds {
if _, ok := resultMap[d.Name()]; !ok {
resultMap[d.Name()] = d
}
}
} else {
return nil, fmt.Errorf("unknown detector %s", n)
}
}
result := make([]detector.Detector, 0, len(resultMap))
for _, d := range resultMap {
result = append(result, d)
}
return result, nil
}