Remove CRUD funcs of CveContents

This commit is contained in:
Kota Kanbe
2017-05-10 11:43:10 +09:00
committed by kota kanbe
parent dd5a7920e5
commit b285cb0e57
5 changed files with 12 additions and 47 deletions

View File

@@ -513,7 +513,7 @@ func fillCveDetail(r *models.ScanResult) error {
}
for _, con := range []models.CveContent{*nvd, *jvn} {
if !con.Empty() {
vinfo.CveContents.Upsert(con)
vinfo.CveContents[con.Type] = con
}
}
r.ScannedCves[cveID] = vinfo

View File

@@ -239,7 +239,7 @@ func isCveInfoUpdated(cveID string, previous, current models.ScanResult) bool {
for _, c := range previous.ScannedCves {
if cveID == c.CveID {
for _, cType := range cTypes {
content, _ := c.CveContents.Get(cType)
content, _ := c.CveContents[cType]
prevLastModified[cType] = content.LastModified
}
break
@@ -250,7 +250,7 @@ func isCveInfoUpdated(cveID string, previous, current models.ScanResult) bool {
for _, c := range current.ScannedCves {
if cveID == c.CveID {
for _, cType := range cTypes {
content, _ := c.CveContents.Get(cType)
content, _ := c.CveContents[cType]
curLastModified[cType] = content.LastModified
}
break

View File

@@ -412,50 +412,14 @@ func NewCveContents(conts ...CveContent) CveContents {
return m
}
// Get CveContent by cveID
// TODO Pointer
func (v CveContents) Get(typestr CveContentType) (CveContent, bool) {
if vv, ok := v[typestr]; ok {
return vv, true
}
return CveContent{}, false
}
// Delete by cveID
func (v CveContents) Delete(typestr CveContentType) {
delete(v, typestr)
}
// Insert CveContent
func (v CveContents) Insert(cont CveContent) {
v[cont.Type] = cont
}
// Update VulnInfo
func (v CveContents) Update(cont CveContent) (ok bool) {
if _, ok := v[cont.Type]; ok {
v[cont.Type] = cont
return true
}
return false
}
// Upsert CveContent
func (v CveContents) Upsert(cont CveContent) {
ok := v.Update(cont)
if !ok {
v.Insert(cont)
}
}
// CvssV2Score returns CVSS V2 Score
func (v CveContents) CvssV2Score() float64 {
//TODO
if cont, found := v.Get(NVD); found {
if cont, found := v[NVD]; found {
return cont.Cvss2Score
} else if cont, found := v.Get(JVN); found {
} else if cont, found := v[JVN]; found {
return cont.Cvss2Score
} else if cont, found := v.Get(RedHat); found {
} else if cont, found := v[RedHat]; found {
return cont.Cvss2Score
}
return -1.1
@@ -463,7 +427,7 @@ func (v CveContents) CvssV2Score() float64 {
// CvssV3Score returns CVSS V2 Score
func (v CveContents) CvssV3Score() float64 {
if cont, found := v.Get(RedHat); found {
if cont, found := v[RedHat]; found {
return cont.Cvss3Score
}
return -1.1

View File

@@ -73,7 +73,8 @@ func (o Debian) fillOvalInfo(r *models.ScanResult, definition *ovalmodels.Defini
}
} else {
cveContents := vinfo.CveContents
if _, ok := vinfo.CveContents.Get(models.NewCveContentType(r.Family)); ok {
ctype := models.NewCveContentType(r.Family)
if _, ok := vinfo.CveContents[ctype]; ok {
util.Log.Infof("%s will be updated by OVAL", definition.Debian.CveID)
} else {
util.Log.Infof("%s is also detected by OVAL", definition.Debian.CveID)
@@ -82,7 +83,7 @@ func (o Debian) fillOvalInfo(r *models.ScanResult, definition *ovalmodels.Defini
if vinfo.Confidence.Score < models.OvalMatch.Score {
vinfo.Confidence = models.OvalMatch
}
cveContents.Upsert(ovalContent)
cveContents[ctype] = ovalContent
vinfo.CveContents = cveContents
}
r.ScannedCves[definition.Debian.CveID] = vinfo

View File

@@ -70,7 +70,7 @@ func (o Redhat) fillOvalInfo(r *models.ScanResult, definition *ovalmodels.Defini
}
} else {
cveContents := vinfo.CveContents
if _, ok := vinfo.CveContents.Get(models.RedHat); ok {
if _, ok := vinfo.CveContents[models.RedHat]; ok {
util.Log.Infof("%s will be updated by OVAL", cve.CveID)
} else {
util.Log.Infof("%s is also detected by OVAL", cve.CveID)
@@ -80,7 +80,7 @@ func (o Redhat) fillOvalInfo(r *models.ScanResult, definition *ovalmodels.Defini
if vinfo.Confidence.Score < models.OvalMatch.Score {
vinfo.Confidence = models.OvalMatch
}
cveContents.Upsert(ovalContent)
cveContents[models.RedHat] = ovalContent
vinfo.CveContents = cveContents
}
r.ScannedCves[cve.CveID] = vinfo