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

Function SearchDetail

cmd/detail/detail.go:227–311  ·  view source on GitHub ↗

SearchDetail 查找组件详情:漏洞/许可证

(detailRoot *DepDetailGraph)

Source from the content-addressed store, hash-verified

225
226// SearchDetail 查找组件详情:漏洞/许可证
227func SearchDetail(detailRoot *DepDetailGraph) (err error) {
228
229 var details []*DepDetailGraph
230 var ds []Dep
231
232 detailRoot.ForEach(func(n *DepDetailGraph) bool {
233 details = append(details, n)
234 ds = append(ds, n.Dep)
235 return true
236 })
237
238 serverVulns := [][]*Vuln{}
239 localVulns := GetOrigin().SearchVuln(ds)
240
241 c := config.Conf().Origin
242 if c.Url != "" && c.Token != "" {
243 // vulnerability
244 logs.Info("get server vuln")
245 serverVulns, err = GetServerVuln(ds)
246 // license
247 logs.Info("get server license")
248 serverLicenses, _ := GetServerLicense(ds)
249 for i, lics := range serverLicenses {
250 if len(lics) > 0 {
251 details[i].Licenses = lics
252 }
253 }
254 } else if len(localVulns) == 0 {
255 err = errors.New("not config vuln database origin")
256 }
257
258 // 合并本地和云端库搜索的漏洞
259 for i, detail := range details {
260 exist := map[string]struct{}{}
261 if len(localVulns) != 0 {
262 for _, vuln := range localVulns[i] {
263 if vuln.Id == "" {
264 continue
265 }
266 if _, ok := exist[vuln.Id]; !ok {
267 exist[vuln.Id] = struct{}{}
268 detail.Vulnerabilities = append(detail.Vulnerabilities, vuln)
269 }
270 }
271 }
272 if len(serverVulns) != 0 {
273 for _, vuln := range serverVulns[i] {
274 if vuln.Id == "" {
275 continue
276 }
277 if _, ok := exist[vuln.Id]; !ok {
278 exist[vuln.Id] = struct{}{}
279 detail.Vulnerabilities = append(detail.Vulnerabilities, vuln)
280 }
281 }
282 }
283 }
284

Callers 1

taskReportFunction · 0.92

Calls 7

ConfFunction · 0.92
InfoFunction · 0.92
GetOriginFunction · 0.85
GetServerVulnFunction · 0.85
GetServerLicenseFunction · 0.85
SearchVulnMethod · 0.80
ForEachMethod · 0.45

Tested by

no test coverage detected