Skip to content

Commit

Permalink
affected manifests: Add missing properties into affected manifest query
Browse files Browse the repository at this point in the history
These properties were missing in queries that search for affected
manifest which caused incorrect API response.

Signed-off-by: Ales Raszka <[email protected]>
  • Loading branch information
Allda authored and ldelossa committed Oct 1, 2020
1 parent c6b1bc9 commit aebd3a8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
14 changes: 13 additions & 1 deletion internal/indexer/postgres/affectedmanifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var (
func affectedManifests(ctx context.Context, pool *pgxpool.Pool, v claircore.Vulnerability) ([]claircore.Digest, error) {
const (
selectPackages = `
SELECT id, name, version, kind
SELECT id, name, version, kind, norm_kind, norm_version, module, arch
FROM package
WHERE name = $1;
`
Expand Down Expand Up @@ -93,17 +93,29 @@ func affectedManifests(ctx context.Context, pool *pgxpool.Pool, v claircore.Vuln
for rows.Next() {
var pkg claircore.Package
var id int64
var nKind *string
var nVer pgtype.Int4Array
err := rows.Scan(
&id,
&pkg.Name,
&pkg.Version,
&pkg.Kind,
&nKind,
&nVer,
&pkg.Module,
&pkg.Arch,
)
if err != nil {
return nil, fmt.Errorf("failed to scan package: %v", err)
}
idStr := strconv.FormatInt(id, 10)
pkg.ID = idStr
if nKind != nil {
pkg.NormalizedVersion.Kind = *nKind
for i, n := range nVer.Elements {
pkg.NormalizedVersion.V[i] = n.Int
}
}
pkgsToFilter = append(pkgsToFilter, pkg)
}
log.Debug().Int("count", len(pkgsToFilter)).Msg("packages to filter")
Expand Down
3 changes: 2 additions & 1 deletion internal/vulnstore/postgres/getupdateoperationdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func getUpdateDiff(ctx context.Context, pool *pgxpool.Pool, prev, cur uuid.UUID)
arch_operation,
repo_name,
repo_key,
repo_uri
repo_uri,
fixed_in_version
FROM vuln
WHERE
vuln.id IN (
Expand Down
1 change: 1 addition & 0 deletions internal/vulnstore/postgres/scan_vulnerability.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func scanVulnerability(v *claircore.Vulnerability, row scanner) error {
&v.Repo.Name,
&v.Repo.Key,
&v.Repo.URI,
&v.FixedInVersion,
); err != nil {
return err
}
Expand Down

0 comments on commit aebd3a8

Please sign in to comment.