Make GetAllAdvisories return fixes in the sql query

This commit is contained in:
Neil Hanlon 2023-01-10 15:58:58 -05:00
parent 95d7351c22
commit a3d61251ba
Signed by: neil
GPG Key ID: 705BC21EC3C70F34
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')