mirror of
https://github.com/goharbor/harbor.git
synced 2025-01-31 03:51:23 +01:00
GET tags api includes scan overview
This commit is contained in:
parent
8590c8d6bb
commit
f016dd113c
@ -58,10 +58,10 @@ type ImgScanOverview struct {
|
|||||||
JobID int64 `orm:"column(scan_job_id)" json:"job_id"`
|
JobID int64 `orm:"column(scan_job_id)" json:"job_id"`
|
||||||
Sev int `orm:"column(severity)" json:"severity"`
|
Sev int `orm:"column(severity)" json:"severity"`
|
||||||
CompOverviewStr string `orm:"column(components_overview)" json:"-"`
|
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"`
|
DetailsKey string `orm:"column(details_key)" json:"details_key"`
|
||||||
CreationTime time.Time `orm:"column(creation_time);auto_now_add" json:"creation_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"`
|
UpdateTime time.Time `orm:"column(update_time);auto_now" json:"update_time,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//TableName ...
|
//TableName ...
|
||||||
|
@ -27,10 +27,10 @@ import (
|
|||||||
"github.com/vmware/harbor/src/common/dao"
|
"github.com/vmware/harbor/src/common/dao"
|
||||||
"github.com/vmware/harbor/src/common/models"
|
"github.com/vmware/harbor/src/common/models"
|
||||||
"github.com/vmware/harbor/src/common/utils"
|
"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/log"
|
||||||
"github.com/vmware/harbor/src/common/utils/notary"
|
"github.com/vmware/harbor/src/common/utils/notary"
|
||||||
"github.com/vmware/harbor/src/common/utils/registry"
|
"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"
|
"github.com/vmware/harbor/src/ui/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -65,6 +65,7 @@ type tag struct {
|
|||||||
type tagResp struct {
|
type tagResp struct {
|
||||||
tag
|
tag
|
||||||
Signature *notary.Target `json:"signature"`
|
Signature *notary.Target `json:"signature"`
|
||||||
|
ScanOverview *models.ImgScanOverview `json:"scan_overview,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type manifestResp struct {
|
type manifestResp struct {
|
||||||
@ -353,6 +354,8 @@ func (ra *RepositoryAPI) GetTags() {
|
|||||||
tagResp := &tagResp{
|
tagResp := &tagResp{
|
||||||
tag: *tag,
|
tag: *tag,
|
||||||
}
|
}
|
||||||
|
//TODO: only when deployed with Clair...
|
||||||
|
tagResp.ScanOverview = getScanOverview(tag.Digest, tag.Name)
|
||||||
|
|
||||||
// compare both digest and tag
|
// compare both digest and tag
|
||||||
if signature, ok := signatures[tag.Digest]; ok {
|
if signature, ok := signatures[tag.Digest]; ok {
|
||||||
@ -636,3 +639,27 @@ func getSignatures(repository, username string) (map[string]*notary.Target, erro
|
|||||||
|
|
||||||
return signatures, nil
|
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
|
||||||
|
}
|
||||||
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user