Skip to content

Commit

Permalink
Ent - CertifyVuln: fixed noVuln management (#1240)
Browse files Browse the repository at this point in the history
Signed-off-by: mrizzi <mrizzi@redhat.com>
  • Loading branch information
mrizzi committed Sep 8, 2023
1 parent c0efbbf commit 4f2c49e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 29 deletions.
20 changes: 5 additions & 15 deletions pkg/assembler/backends/ent/backend/certifyVuln.go
Expand Up @@ -48,21 +48,12 @@ func (b *EntBackend) IngestCertifyVuln(ctx context.Context, pkg model.PkgInputSp
certifyvuln.FieldDbVersion,
}

var conflictPredicate *sql.Predicate

if spec.Type == NoVuln {
// No vulnerability found, so we don't have a vulnerability ID to set
conflictPredicate = sql.And(sql.IsNull(certifyvuln.FieldVulnerabilityID))
} else {
vuln, err := getVulnerabilityFromInput(ctx, client.Client(), spec)
if err != nil {
return nil, err
}

insert.SetVulnerability(vuln)
columns = append(columns, certifyvuln.FieldVulnerabilityID)
conflictPredicate = sql.And(sql.NotNull(certifyvuln.FieldVulnerabilityID))
vuln, err := getVulnerabilityFromInput(ctx, client.Client(), spec)
if err != nil {
return nil, err
}
insert.SetVulnerability(vuln)
columns = append(columns, certifyvuln.FieldVulnerabilityID)

pv, err := getPkgVersion(ctx, client.Client(), pkg)
if err != nil {
Expand All @@ -82,7 +73,6 @@ func (b *EntBackend) IngestCertifyVuln(ctx context.Context, pkg model.PkgInputSp
id, err := insert.
OnConflict(
sql.ConflictColumns(columns...),
sql.ConflictWhere(conflictPredicate),
).
Ignore().
ID(ctx)
Expand Down
11 changes: 0 additions & 11 deletions pkg/assembler/backends/ent/migrate/schema.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions pkg/assembler/backends/ent/schema/certifyvuln.go
Expand Up @@ -17,7 +17,6 @@ package schema

import (
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
Expand Down Expand Up @@ -54,7 +53,6 @@ func (CertifyVuln) Edges() []ent.Edge {
// Indexes of the Vulnerability.
func (CertifyVuln) Indexes() []ent.Index {
return []ent.Index{
index.Fields("db_uri", "db_version", "scanner_uri", "scanner_version", "origin", "collector").Edges("vulnerability", "package").Unique().Annotations(entsql.IndexWhere("vulnerability_id IS NOT NULL")),
index.Fields("db_uri", "db_version", "scanner_uri", "scanner_version", "origin", "collector").Edges("package").Unique().Annotations(entsql.IndexWhere("vulnerability_id IS NULL")),
index.Fields("db_uri", "db_version", "scanner_uri", "scanner_version", "origin", "collector").Edges("vulnerability", "package").Unique(),
}
}

0 comments on commit 4f2c49e

Please sign in to comment.