forked from google/osv-scalibr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.go
More file actions
110 lines (95 loc) · 3.28 KB
/
list.go
File metadata and controls
110 lines (95 loc) · 3.28 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2026 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 list of annotation plugins.
package list
import (
"fmt"
"maps"
"slices"
"github.com/google/osv-scalibr/annotator"
"github.com/google/osv-scalibr/annotator/cachedir"
"github.com/google/osv-scalibr/annotator/ffa/unknownbinariesanno"
"github.com/google/osv-scalibr/annotator/misc/brewsource"
"github.com/google/osv-scalibr/annotator/misc/dpkgsource"
"github.com/google/osv-scalibr/annotator/misc/npmsource"
noexecutabledpkg "github.com/google/osv-scalibr/annotator/noexecutable/dpkg"
"github.com/google/osv-scalibr/annotator/osduplicate/apk"
"github.com/google/osv-scalibr/annotator/osduplicate/cos"
"github.com/google/osv-scalibr/annotator/osduplicate/dpkg"
"github.com/google/osv-scalibr/annotator/osduplicate/rpm"
cpb "github.com/google/osv-scalibr/binary/proto/config_go_proto"
)
// InitFn is the annotator initializer function.
type InitFn func(cfg *cpb.PluginConfig) (annotator.Annotator, error)
// InitMap is a map of annotator names to their initers.
type InitMap map[string][]InitFn
// VEX generation related annotators.
var VEX = InitMap{
apk.Name: {apk.New},
cachedir.Name: {cachedir.New},
cos.Name: {cos.New},
dpkg.Name: {dpkg.New},
rpm.Name: {rpm.New},
noexecutabledpkg.Name: {noexecutabledpkg.New},
}
// Misc annotators.
var Misc = InitMap{
npmsource.Name: {npmsource.New},
dpkgsource.Name: {dpkgsource.New},
brewsource.Name: {brewsource.New},
}
// FFA (Full Filesystem Accountability) related annotators.
var FFA = InitMap{unknownbinariesanno.Name: {unknownbinariesanno.New}}
// Default detectors that are recommended to be enabled.
var Default = InitMap{cachedir.Name: {cachedir.New}}
// All annotators.
var All = concat(
VEX,
Misc,
FFA,
)
var annotatorNames = concat(All, InitMap{
"vex": vals(VEX),
"misc": vals(Misc),
"ffa": vals(FFA),
"annotators/default": vals(Default),
"default": vals(Default),
"annotators/all": vals(All),
"all": vals(All),
})
func concat(initMaps ...InitMap) InitMap {
result := InitMap{}
for _, m := range initMaps {
maps.Copy(result, m)
}
return result
}
func vals(initMap InitMap) []InitFn {
return slices.Concat(slices.Collect(maps.Values(initMap))...)
}
// AnnotatorsFromName returns a list of annotators from a name.
func AnnotatorsFromName(name string, cfg *cpb.PluginConfig) ([]annotator.Annotator, error) {
if initers, ok := annotatorNames[name]; ok {
result := []annotator.Annotator{}
for _, initer := range initers {
p, err := initer(cfg)
if err != nil {
return nil, err
}
result = append(result, p)
}
return result, nil
}
return nil, fmt.Errorf("unknown annotator %q", name)
}