Skip to content

Commit

Permalink
fix novuln check for ent query (#1939)
Browse files Browse the repository at this point in the history
Signed-off-by: pxp928 <parth.psu@gmail.com>
  • Loading branch information
pxp928 committed May 31, 2024
1 parent c8b8ff3 commit 1253f28
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/guacingest/cmd/ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func ingest(cmd *cobra.Command, args []string) {
if errors.As(err, &urlErr) {
return fmt.Errorf("unable to ingest document due to connection error with graphQL %q : %w", d.SourceInformation.Source, urlErr)
}
logger.Errorf("unable to ingest document %q : %v", d.SourceInformation.Source, err)
d.ChildLogger.Errorf("unable to ingest document %q : %v", d.SourceInformation.Source, err)
}
return nil
}
Expand Down
13 changes: 12 additions & 1 deletion pkg/assembler/backends/ent/backend/vulnerability.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,21 @@ func vulnerabilityQueryPredicates(filter model.VulnerabilitySpec) []predicate.Vu
var where = []predicate.VulnerabilityID{
optionalPredicate(filter.ID, IDEQ),
}

// setting noVuln to true return all packages that have no vulnerabilities
if filter.NoVuln != nil && *filter.NoVuln {
filter.Type = ptrfrom.String(NoVuln)
filter.VulnerabilityID = ptrfrom.String("")
}

// setting noVuln to false return all packages with vulnerabilities. This adds a
// check to make sure type is not equal to `novuln`
if filter.NoVuln != nil && !*filter.NoVuln {
where = append(where,
optionalPredicate(ptrfrom.String(NoVuln), vulnerabilityid.TypeEQ),
optionalPredicate(ptrfrom.String(strings.ToLower(NoVuln)), vulnerabilityid.TypeNEQ),
)
}

if filter.Type != nil {
where = append(where,
optionalPredicate(ptrfrom.String(strings.ToLower(*filter.Type)), vulnerabilityid.TypeEQ),
Expand All @@ -174,6 +184,7 @@ func vulnerabilityQueryPredicates(filter model.VulnerabilitySpec) []predicate.Vu
)
}
}

return where
}

Expand Down

0 comments on commit 1253f28

Please sign in to comment.