Convert null to empty in JSON
This commit is contained in:
@@ -162,22 +162,29 @@ func (v VulnInfo) VendorLinks(family string) map[string]string {
|
||||
return links
|
||||
}
|
||||
|
||||
// TODO
|
||||
// NilToEmpty set nil slice or map fields to empty to avoid null in JSON
|
||||
// func (v *VulnInfo) NilToEmpty() {
|
||||
// if v.CpeNames == nil {
|
||||
// v.CpeNames = []string{}
|
||||
// }
|
||||
// if v.DistroAdvisories == nil {
|
||||
// v.DistroAdvisories = []DistroAdvisory{}
|
||||
// }
|
||||
// if v.PackageNames == nil {
|
||||
// v.PackageNames = []string{}
|
||||
// }
|
||||
// if v.CveContents == nil {
|
||||
// v.CveContents = NewCveContents()
|
||||
// }
|
||||
// }
|
||||
func (v *VulnInfo) NilToEmpty() *VulnInfo {
|
||||
if v.CpeNames == nil {
|
||||
v.CpeNames = []string{}
|
||||
}
|
||||
if v.DistroAdvisories == nil {
|
||||
v.DistroAdvisories = []DistroAdvisory{}
|
||||
}
|
||||
if v.PackageNames == nil {
|
||||
v.PackageNames = []string{}
|
||||
}
|
||||
if v.CveContents == nil {
|
||||
v.CveContents = NewCveContents()
|
||||
}
|
||||
for key := range v.CveContents {
|
||||
if v.CveContents[key].Cpes == nil {
|
||||
cont := v.CveContents[key]
|
||||
cont.Cpes = []Cpe{}
|
||||
v.CveContents[key] = cont
|
||||
}
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// DistroAdvisory has Amazon Linux, RHEL, FreeBSD Security Advisory information.
|
||||
type DistroAdvisory struct {
|
||||
|
||||
@@ -104,6 +104,11 @@ func fillCveInfo(r *models.ScanResult) error {
|
||||
if err := fillCveInfoFromCveDB(r); err != nil {
|
||||
return fmt.Errorf("Failed to fill CVE information: %s", err)
|
||||
}
|
||||
|
||||
for cveID := range r.ScannedCves {
|
||||
vinfo := r.ScannedCves[cveID]
|
||||
r.ScannedCves[cveID] = *vinfo.NilToEmpty()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -192,8 +197,6 @@ func fillVulnByCpeNames(cpeNames []string, scannedVulns models.VulnInfos) error
|
||||
CpeNames: []string{name},
|
||||
Confidence: models.CpeNameMatch,
|
||||
}
|
||||
//TODO
|
||||
// v.NilToEmpty()
|
||||
scannedVulns[detail.CveID] = v
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user