Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(db/redis) craete advisory and cve index #404

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions db/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

c "github.com/vulsio/goval-dictionary/config"
"github.com/vulsio/goval-dictionary/models"
"github.com/vulsio/goval-dictionary/util"
)

/**
Expand Down Expand Up @@ -54,6 +55,8 @@ import (
│ 3 │ OVAL#FETCHMETA │ SchemaVersion │ uint │ GET Go-Oval-Dictionary Schema Version │
├───┼─────────────────────────────┼───────────────┼───────────┼───────────────────────────────────────────┤
│ 4 │ OVAL#FETCHMETA │ LastFetchedAt │ time.Time │ GET Go-Oval-Dictionary Last Fetched Time │
├───┼─────────────────────────────┼───────────────┼───────────┼───────────────────────────────────────────┤
│ 5 │ OVAL#ADVISORY#OSFAMILY │ $ADVISORYNAME │ []string │ TO GET Cve id │
└───┴─────────────────────────────┴───────────────┴───────────┴───────────────────────────────────────────┘

**/
Expand All @@ -65,6 +68,7 @@ const (
cveKeyFormat = "OVAL#%s#%s#CVE#%s"
pkgKeyFormat = "OVAL#%s#%s#PKG#%s"
depKeyFormat = "OVAL#%s#%s#DEP"
advisoryKeyFormat = "OVAL#ADVISORY#%s"
lastModifiedKeyFormat = "OVAL#%s#%s#LASTMODIFIED"
fetchMetaKey = "OVAL#FETCHMETA"
)
Expand Down Expand Up @@ -362,6 +366,25 @@ func (r *RedisDriver) InsertOval(root *models.Root) (err error) {
}
}

var advisoryName string
var cveIDs []string
for _, reference := range def.References {
switch reference.Source {
case "RHSA":
advisoryName = reference.RefID
case "CVE":
cveIDs = append(cveIDs, reference.RefID)
}
}

if len(advisoryName) > 0 {
var cj []byte
if cj, err = json.Marshal(util.Unique(cveIDs)); err != nil {
return xerrors.Errorf("Failed to marshal cveID json. err: %w", err)
}
_ = pipe.HSet(ctx, fmt.Sprintf(advisoryKeyFormat, family), advisoryName, string(cj))
}

for _, pack := range def.AffectedPacks {
_ = pipe.SAdd(ctx, fmt.Sprintf(pkgKeyFormat, family, osVer, pack.Name), def.DefinitionID)
newDeps[def.DefinitionID]["packages"][pack.Name] = struct{}{}
Expand Down
Loading