Show vulnerabilities

This commit is contained in:
Stefan Majer 2017-04-06 13:33:06 +02:00
parent 5c7c3f1ed7
commit eae3f5ee67
2 changed files with 45 additions and 1 deletions

View file

@ -38,7 +38,9 @@
{{ $value.Created.Format "02 Jan, 2006 15:04:05 UTC" }}
</td>
<td >
<a href="/repo/{{ $value.Name | urlquery }}/{{ $value.Tag }}/vulns">
{{ $value.VulnerabilityReport.BadVulns }}
</a>
</td>
</tr>
{{ end }}

View file

@ -274,5 +274,47 @@ func (rc *registryController) vulnerabilities(c echo.Context) error {
if tag == "" {
return c.String(http.StatusNotFound, "No tag given")
}
return nil
m1, err := r.ManifestV1(repo, tag)
if err != nil {
log.WithFields(log.Fields{
"error": err,
"repo": repo,
"tag": tag,
}).Warn("getting v1 manifest failed")
}
for _, h := range m1.History {
var comp v1Compatibility
if err := json.Unmarshal([]byte(h.V1Compatibility), &comp); err != nil {
log.WithFields(log.Fields{
"error": err,
"repo": repo,
"tag": tag,
}).Warn("unmarshal v1compatibility failed")
return c.String(http.StatusInternalServerError, "unmarshal v1compatibility failed")
}
break
}
result := clair.VulnerabilityReport{}
if rc.cl != nil {
result, err = rc.cl.Vulnerabilities(rc.reg, repo, tag, m1)
if err != nil {
log.WithFields(log.Fields{
"error": err,
"repo": repo,
"tag": tag,
}).Error("error during vulnerability scanning.")
}
}
err = c.Render(http.StatusOK, "vulns", result)
if err != nil {
log.WithFields(log.Fields{
"error": err,
}).Error("error during template rendering")
}
return err
}