-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_cfg.go
62 lines (57 loc) · 1.57 KB
/
client_cfg.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
package sbom
import (
cond "github.com/vela-ssoc/vela-cond"
"github.com/vela-ssoc/vela-kit/auxlib"
"github.com/vela-ssoc/vela-kit/lua"
"github.com/vela-ssoc/vela-kit/pipe"
vswitch "github.com/vela-ssoc/vela-switch"
"go.uber.org/ratelimit"
)
const MinFileSize = 1024 * 1024 * 5
type config struct {
name string
limit ratelimit.Limiter
remote bool
report bool
cache bool
bucket []string //扫描记录
storage []string //延时扫描存储
timeout int
ignore *cond.Ignore
filter *cond.Combine
filterCatalog *cond.Combine
vsh *vswitch.Switch
pipe *pipe.Chains
co *lua.LState
}
func newConfig(L *lua.LState) *config {
tab := L.CheckTable(1)
cfg := &config{
co: xEnv.Clone(L),
vsh: vswitch.NewL(L),
ignore: cond.NewIgnore(),
filter: cond.NewCombine(),
filterCatalog: cond.NewCombine(),
pipe: pipe.New(pipe.Env(xEnv)),
bucket: []string{"vela", "sbom", "catalog"},
storage: []string{"vela", "sbom_file", "storage"},
}
tab.Range(func(key string, val lua.LValue) { cfg.NewIndex(L, key, val) })
return cfg
}
func (cfg *config) NewIndex(L *lua.LState, key string, val lua.LValue) {
switch key {
case "name":
cfg.name = auxlib.CheckProcName(val, L)
case "remote":
cfg.remote = lua.IsTrue(val)
case "report":
cfg.report = lua.IsTrue(val)
case "cache":
cfg.cache = lua.IsTrue(val)
case "timeout":
cfg.timeout = lua.IsInt(val)
case "bucket":
cfg.bucket = []string{auxlib.CheckProcName(val, L)}
}
}