MCPcopy Create free account
hub / github.com/XmirrorSecurity/OpenSCA-cli / RunTask

Function RunTask

opensca/run.go:53–145  ·  view source on GitHub ↗

RunTask 运行检测任务 arg: 任务参数

(ctx context.Context, arg *TaskArg)

Source from the content-addressed store, hash-verified

51// RunTask 运行检测任务
52// arg: 任务参数
53func RunTask(ctx context.Context, arg *TaskArg) (result TaskResult) {
54
55 result.Start = time.Now()
56 defer func() {
57 result.End = time.Now()
58 result.Arg = arg
59 }()
60
61 if arg == nil {
62 arg = &TaskArg{DataOrigin: "./"}
63 }
64
65 if arg.ExtractFileFilter == nil {
66 arg.ExtractFileFilter = filter.CompressFile
67 }
68
69 if arg.Name == "" {
70 arg.Name = filepath.Base(arg.DataOrigin)
71 }
72
73 if arg.Timeout > 0 {
74 var cancel context.CancelFunc
75 ctx, cancel = context.WithTimeout(ctx, time.Duration(arg.Timeout)*time.Second)
76 if cancel != nil {
77 defer cancel()
78 }
79 }
80
81 if len(arg.Sca) == 0 {
82 arg.Sca = sca.AllSca
83 }
84
85 result.Size, result.Error = walk.Walk(ctx, arg.Name, arg.DataOrigin, func(relpath string) bool {
86
87 if arg.ExtractFileFilter != nil && arg.ExtractFileFilter(relpath) {
88 return true
89 }
90
91 for _, sca := range arg.Sca {
92 if sca.Filter(relpath) {
93 return true
94 }
95 }
96
97 return false
98
99 }, arg.IgnoreFileFilter, func(parent *model.File, files []*model.File) {
100
101 for _, sca := range arg.Sca {
102
103 fs := []*model.File{}
104 for _, f := range files {
105 if sca.Filter(f.Relpath()) {
106 fs = append(fs, f)
107 }
108 }
109
110 if len(fs) == 0 {

Callers 2

mainFunction · 0.92
RunTaskCaseFunction · 0.92

Calls 11

WalkFunction · 0.92
DebugfFunction · 0.92
ErrorfFunction · 0.92
ScaInterface · 0.92
InfofFunction · 0.92
RelpathMethod · 0.80
ForEachNodeMethod · 0.80
BuildMethod · 0.80
FilterMethod · 0.65
LanguageMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected