Merge pull request #2525 from reasonerjt/clair-integration

GET tags api includes scan overview
This commit is contained in:
Daniel Jiang 2017-06-15 15:34:05 +08:00 committed by GitHub
commit 6a85012dbd
2 changed files with 35 additions and 5 deletions

View File

@ -58,10 +58,10 @@ type ImgScanOverview struct {
JobID int64 `orm:"column(scan_job_id)" json:"job_id"`
Sev int `orm:"column(severity)" json:"severity"`
CompOverviewStr string `orm:"column(components_overview)" json:"-"`
CompOverview *ComponentsOverview `orm:"-" json:"components"`
CompOverview *ComponentsOverview `orm:"-" json:"components,omitempty"`
DetailsKey string `orm:"column(details_key)" json:"details_key"`
CreationTime time.Time `orm:"column(creation_time);auto_now_add" json:"creation_time"`
UpdateTime time.Time `orm:"column(update_time);auto_now" json:"update_time"`
CreationTime time.Time `orm:"column(creation_time);auto_now_add" json:"creation_time,omitempty"`
UpdateTime time.Time `orm:"column(update_time);auto_now" json:"update_time,omitempty"`
}
//TableName ...

View File

@ -27,10 +27,10 @@ import (
"github.com/vmware/harbor/src/common/dao"
"github.com/vmware/harbor/src/common/models"
"github.com/vmware/harbor/src/common/utils"
registry_error "github.com/vmware/harbor/src/common/utils/error"
"github.com/vmware/harbor/src/common/utils/log"
"github.com/vmware/harbor/src/common/utils/notary"
"github.com/vmware/harbor/src/common/utils/registry"
registry_error "github.com/vmware/harbor/src/common/utils/error"
"github.com/vmware/harbor/src/ui/config"
)
@ -64,7 +64,8 @@ type tag struct {
type tagResp struct {
tag
Signature *notary.Target `json:"signature"`
Signature *notary.Target `json:"signature"`
ScanOverview *models.ImgScanOverview `json:"scan_overview,omitempty"`
}
type manifestResp struct {
@ -353,6 +354,8 @@ func (ra *RepositoryAPI) GetTags() {
tagResp := &tagResp{
tag: *tag,
}
//TODO: only when deployed with Clair...
tagResp.ScanOverview = getScanOverview(tag.Digest, tag.Name)
// compare both digest and tag
if signature, ok := signatures[tag.Digest]; ok {
@ -636,3 +639,30 @@ func getSignatures(repository, username string) (map[string]*notary.Target, erro
return signatures, nil
}
//will return nil when it failed to get data. The parm "tag" is for logging only.
func getScanOverview(digest string, tag string) *models.ImgScanOverview {
data, err := dao.GetImgScanOverview(digest)
if err != nil {
log.Errorf("Failed to get scan result for tag:%s, digest: %s, error: %v", tag, digest, err)
}
if data == nil {
return nil
}
job, err := dao.GetScanJob(data.JobID)
if err != nil {
log.Errorf("Failed to get scan job for id:%d, error: %v", data.JobID, err)
return nil
} else if job == nil { //job does not exist
log.Errorf("The scan job with id: %d does not exist, returning nil", data.JobID)
return nil
}
data.Status = job.Status
if data.Status != models.JobFinished {
log.Debugf("Unsetting vulnerable related historical values, job status: %s", data.Status)
data.Sev = 0
data.CompOverview = nil
data.DetailsKey = ""
}
return data
}