Skip to content

Commit

Permalink
feat(models): add AffectedResolution
Browse files Browse the repository at this point in the history
  • Loading branch information
MaineK00n committed May 8, 2024
1 parent 0375f25 commit ee425bf
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
6 changes: 6 additions & 0 deletions db/rdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ func (r *RDBDriver) MigrateDB() error {
&models.Advisory{},
&models.Cve{},
&models.Bugzilla{},
&models.Resolution{},
&models.Component{},
&models.Cpe{},
&models.Debian{},
); err != nil {
Expand Down Expand Up @@ -194,6 +196,8 @@ func (r *RDBDriver) GetByPackName(family, osVer, packName, arch string) ([]model
Preload("Advisory").
Preload("Advisory.Cves").
Preload("Advisory.Bugzillas").
Preload("Advisory.AffectedResolution").
Preload("Advisory.AffectedResolution.Components").
Preload("Advisory.AffectedCPEList").
Preload("References")

Expand Down Expand Up @@ -251,6 +255,8 @@ func (r *RDBDriver) GetByCveID(family, osVer, cveID, arch string) ([]models.Defi
Preload("Advisory").
Preload("Advisory.Cves").
Preload("Advisory.Bugzillas").
Preload("Advisory.AffectedResolution").
Preload("Advisory.AffectedResolution.Components").
Preload("Advisory.AffectedCPEList").
Preload("References")

Expand Down
18 changes: 18 additions & 0 deletions models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type Advisory struct {
Severity string `gorm:"type:varchar(255)"`
Cves []Cve
Bugzillas []Bugzilla
AffectedResolution []Resolution
AffectedCPEList []Cpe
AffectedRepository string `gorm:"type:varchar(255)"` // Amazon Linux 2 Only
Issued time.Time
Expand Down Expand Up @@ -105,6 +106,23 @@ type Bugzilla struct {
Title string `gorm:"type:varchar(255)"`
}

// Resolution : >definitions>definition>metadata>advisory>affected>resolution
type Resolution struct {
ID uint `gorm:"primary_key" json:"-"`
AdvisoryID uint `gorm:"index:idx_resolution_advisory_id" json:"-" xml:"-"`

State string `gorm:"type:varchar(255)"`
Components []Component
}

// Component : >definitions>definition>metadata>advisory>affected>resolution>component
type Component struct {
ID uint `gorm:"primary_key" json:"-"`
ResolutionID uint `gorm:"index:idx_component_resolution_id" json:"-" xml:"-"`

Component string `gorm:"type:varchar(255)"`
}

// Cpe : >definitions>definition>metadata>advisory>affected_cpe_list
type Cpe struct {
ID uint `gorm:"primary_key" json:"-"`
Expand Down
29 changes: 23 additions & 6 deletions models/redhat/redhat.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ func ConvertToModel(v string, roots []Root) []models.Definition {
})
}

var ress = make([]models.Resolution, 0, len(d.Advisory.Affected.Resolution))
for _, r := range d.Advisory.Affected.Resolution {
ress = append(ress, models.Resolution{
State: r.State,
Components: func() []models.Component {
var comps = make([]models.Component, 0, len(r.Component))
for _, c := range r.Component {
comps = append(comps, models.Component{
Component: c,
})
}
return comps
}(),
})
}

issued := util.ParsedOrDefaultTime([]string{"2006-01-02"}, d.Advisory.Issued.Date)
updated := util.ParsedOrDefaultTime([]string{"2006-01-02"}, d.Advisory.Updated.Date)

Expand All @@ -68,12 +84,13 @@ func ConvertToModel(v string, roots []Root) []models.Definition {
Title: d.Title,
Description: d.Description,
Advisory: models.Advisory{
Severity: d.Advisory.Severity,
Cves: cves,
Bugzillas: bs,
AffectedCPEList: cpes,
Issued: issued,
Updated: updated,
Severity: d.Advisory.Severity,
Cves: cves,
Bugzillas: bs,
AffectedResolution: ress,
AffectedCPEList: cpes,
Issued: issued,
Updated: updated,
},
AffectedPacks: collectRedHatPacks(v, d.Criteria),
References: rs,
Expand Down
2 changes: 1 addition & 1 deletion models/redhat/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ type Bugzilla struct {

// AffectedPkgs : >definitions>definition>metadata>advisory>affected
type AffectedPkgs struct {
Resolution struct {
Resolution []struct {
State string `xml:"state,attr"`
Component []string `xml:"component"`
} `xml:"resolution"`
Expand Down

0 comments on commit ee425bf

Please sign in to comment.