func Convert()

in pkg/vul/convert/trivy/trivy.go [28:62]


func Convert(s *utils.Source) (types.NoteOccurrencesMap, error) {
	if s == nil || s.Data == nil {
		return nil, types.ErrInvalidSource
	}

	if !s.Data.Search("Results").Exists() {
		return nil, errors.New("unable to find Results in source data")
	}

	list := make(types.NoteOccurrencesMap, 0)

	for _, r := range s.Data.Search("Results").Children() {
		for _, v := range r.Search("Vulnerabilities").Children() {
			// create note
			n := convertNote(s, v)

			// don't add notes with no CVSS score
			if n == nil || n.GetVulnerability().CvssScore == 0 {
				continue
			}
			noteID := utils.GetPrefixNoteName(n.GetShortDescription())

			// If cve is not found, add to map
			if _, ok := list[noteID]; !ok {
				list[noteID] = types.NoteOccurrences{Note: n}
			}
			nocc := list[noteID]
			occ := convertOccurrence(s, v, noteID, getPackageType(r))
			nocc.Occurrences = append(nocc.Occurrences, occ)
			list[noteID] = nocc
		}
	}

	return list, nil
}