Merge pull request #88 from NeilHanlon/apollo/87/advisories-fixes

Make GetAllAdvisories return fixes in the sql query
This commit is contained in:
resf-prow[bot] 2023-01-16 21:01:20 +00:00 committed by GitHub
commit 26777167c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -223,6 +223,10 @@ func (a *Access) GetAllAdvisories(filters *apollopb.AdvisoryFilters, page int32,
}
}
if advisory.Fixes != nil && len(advisory.Fixes) < 1 {
return false
}
return true
}), nil
}
@ -235,11 +239,18 @@ func (a *Access) GetAdvisoryByCodeAndYearAndNum(code string, year int, num int)
return false
})
if len(advisories) == 0 {
return nil, sql.ErrNoRows
}
return advisories[0], nil
advisory := advisories[0]
if advisory.Fixes != nil && len(advisory.Fixes) < 1 {
return nil, fmt.Errorf("Expected advisory fixes. Was empty.")
}
return advisory, nil
}
func (a *Access) CreateAdvisory(advisory *apollodb.Advisory) (*apollodb.Advisory, error) {

View File

@ -120,6 +120,7 @@ func (a *Access) GetAllAdvisories(filters *apollopb.AdvisoryFilters, page int32,
a.reboot_suggested,
a.published_at,
array_remove(array_agg(distinct p.name), NULL) as affected_products,
(select array_agg(distinct(f.ticket || ':::' || f.source_by || ':::' || f.source_link || ':::' || f.description)) from advisory_fixes adf inner join fixes f on f.id = adf.fix_id where adf.advisory_id = a.id) as fixes,
(select array_agg(distinct(
case when c.content is null then c.source_by || ':::' || c.source_link || ':::' || c.id || ':::::::::'
else c.source_by || ':::' || c.source_link || ':::' || c.id || ':::' || jsonb_extract_path_text(c.content, 'cvss3', 'cvss3_scoring_vector') || ':::' || jsonb_extract_path_text(c.content, 'cvss3', 'cvss3_base_score') || ':::' || jsonb_extract_path_text(c.content, 'cwe')