Refacotring
This commit is contained in:
@@ -21,13 +21,14 @@ func NewDebian() Debian {
|
||||
}
|
||||
|
||||
// FillCveInfoFromOvalDB returns scan result after updating CVE info by OVAL
|
||||
func (o Debian) FillCveInfoFromOvalDB(r *models.ScanResult) (*models.ScanResult, error) {
|
||||
util.Log.Debugf("open oval-dictionary db (%s)", config.Conf.OvalDBType)
|
||||
func (o Debian) FillCveInfoFromOvalDB(r *models.ScanResult) error {
|
||||
ovalconf.Conf.DBType = config.Conf.OvalDBType
|
||||
ovalconf.Conf.DBPath = config.Conf.OvalDBPath
|
||||
util.Log.Infof("open oval-dictionary db (%s): %s",
|
||||
config.Conf.OvalDBType, config.Conf.OvalDBPath)
|
||||
|
||||
if err := db.OpenDB(); err != nil {
|
||||
return nil, fmt.Errorf("Failed to open OVAL DB. err: %s", err)
|
||||
return fmt.Errorf("Failed to open OVAL DB. err: %s", err)
|
||||
}
|
||||
|
||||
var d db.OvalDB
|
||||
@@ -40,27 +41,27 @@ func (o Debian) FillCveInfoFromOvalDB(r *models.ScanResult) (*models.ScanResult,
|
||||
for _, pack := range r.Packages {
|
||||
definitions, err := d.GetByPackName(r.Release, pack.Name)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to get Debian OVAL info by package name: %v", err)
|
||||
return fmt.Errorf("Failed to get Debian OVAL info by package name: %v", err)
|
||||
}
|
||||
for _, definition := range definitions {
|
||||
for _, def := range definitions {
|
||||
current, _ := ver.NewVersion(pack.Version)
|
||||
for _, p := range definition.AffectedPacks {
|
||||
for _, p := range def.AffectedPacks {
|
||||
if pack.Name != p.Name {
|
||||
continue
|
||||
}
|
||||
affected, _ := ver.NewVersion(p.Version)
|
||||
if current.LessThan(affected) {
|
||||
r = o.fillOvalInfo(r, &definition)
|
||||
o.fillOvalInfo(r, &def)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return r, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o Debian) fillOvalInfo(r *models.ScanResult, definition *ovalmodels.Definition) *models.ScanResult {
|
||||
func (o Debian) fillOvalInfo(r *models.ScanResult, definition *ovalmodels.Definition) {
|
||||
ovalContent := *o.convertToModel(definition)
|
||||
ovalContent.Type = models.CveContentType(r.Family)
|
||||
ovalContent.Type = models.NewCveContentType(r.Family)
|
||||
vinfo, ok := r.ScannedCves.Get(definition.Debian.CveID)
|
||||
if !ok {
|
||||
util.Log.Infof("%s is newly detected by OVAL",
|
||||
@@ -72,7 +73,7 @@ func (o Debian) fillOvalInfo(r *models.ScanResult, definition *ovalmodels.Defini
|
||||
CveContents: []models.CveContent{ovalContent},
|
||||
}
|
||||
} else {
|
||||
if _, ok := vinfo.CveContents.Get(models.CveContentType(r.Family)); !ok {
|
||||
if _, ok := vinfo.CveContents.Get(models.NewCveContentType(r.Family)); !ok {
|
||||
util.Log.Infof("%s is also detected by OVAL", definition.Debian.CveID)
|
||||
} else {
|
||||
util.Log.Infof("%s will be updated by OVAL", definition.Debian.CveID)
|
||||
@@ -83,7 +84,6 @@ func (o Debian) fillOvalInfo(r *models.ScanResult, definition *ovalmodels.Defini
|
||||
vinfo.CveContents.Upsert(ovalContent)
|
||||
}
|
||||
r.ScannedCves.Upsert(vinfo)
|
||||
return r
|
||||
}
|
||||
|
||||
func (o Debian) convertToModel(def *ovalmodels.Definition) *models.CveContent {
|
||||
|
||||
Reference in New Issue
Block a user