mirror of
https://github.com/goharbor/harbor.git
synced 2025-01-20 06:31:55 +01:00
Merge pull request #8571 from ywk253100/190806_retention_time
Populate pull/push time properties to the returning data when listing tags
This commit is contained in:
commit
6c0c75743e
@ -88,6 +88,21 @@ func ListArtifacts(query *models.ArtifactQuery) ([]*models.Artifact, error) {
|
|||||||
return afs, err
|
return afs, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetArtifact by repository and tag
|
||||||
|
func GetArtifact(repo, tag string) (*models.Artifact, error) {
|
||||||
|
artifact := &models.Artifact{}
|
||||||
|
err := GetOrmer().QueryTable(&models.Artifact{}).
|
||||||
|
Filter("Repo", repo).
|
||||||
|
Filter("Tag", tag).One(artifact)
|
||||||
|
if err != nil {
|
||||||
|
if err == orm.ErrNoRows {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return artifact, nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetTotalOfArtifacts returns total of artifacts
|
// GetTotalOfArtifacts returns total of artifacts
|
||||||
func GetTotalOfArtifacts(query ...*models.ArtifactQuery) (int64, error) {
|
func GetTotalOfArtifacts(query ...*models.ArtifactQuery) (int64, error) {
|
||||||
var qs orm.QuerySeter
|
var qs orm.QuerySeter
|
||||||
|
@ -40,6 +40,16 @@ func TestAddArtifact(t *testing.T) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetArtifact(t *testing.T) {
|
||||||
|
repo := "hello-world"
|
||||||
|
tag := "latest"
|
||||||
|
artifact, err := GetArtifact(repo, tag)
|
||||||
|
require.Nil(t, err)
|
||||||
|
require.NotNil(t, artifact)
|
||||||
|
assert.Equal(t, repo, artifact.Repo)
|
||||||
|
assert.Equal(t, tag, artifact.Tag)
|
||||||
|
}
|
||||||
|
|
||||||
func TestUpdateArtifactDigest(t *testing.T) {
|
func TestUpdateArtifactDigest(t *testing.T) {
|
||||||
af := &models.Artifact{
|
af := &models.Artifact{
|
||||||
PID: 1,
|
PID: 1,
|
||||||
|
@ -57,6 +57,8 @@ type TagResp struct {
|
|||||||
Signature *model.Target `json:"signature"`
|
Signature *model.Target `json:"signature"`
|
||||||
ScanOverview *ImgScanOverview `json:"scan_overview,omitempty"`
|
ScanOverview *ImgScanOverview `json:"scan_overview,omitempty"`
|
||||||
Labels []*Label `json:"labels"`
|
Labels []*Label `json:"labels"`
|
||||||
|
PushTime time.Time `json:"push_time"`
|
||||||
|
PullTime time.Time `json:"pull_time"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TagDetail ...
|
// TagDetail ...
|
||||||
|
@ -649,6 +649,20 @@ func assembleTag(c chan *models.TagResp, client *registry.Repository,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pull/push time
|
||||||
|
artifact, err := dao.GetArtifact(repository, tag)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("failed to get artifact %s:%s: %v", repository, tag, err)
|
||||||
|
} else {
|
||||||
|
if artifact == nil {
|
||||||
|
log.Warningf("artifact %s:%s not found", repository, tag)
|
||||||
|
} else {
|
||||||
|
item.PullTime = artifact.PullTime
|
||||||
|
item.PushTime = artifact.PushTime
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
c <- item
|
c <- item
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,9 +17,7 @@ package dep
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/common/http/modifier/auth"
|
"github.com/goharbor/harbor/src/common/http/modifier/auth"
|
||||||
"github.com/goharbor/harbor/src/jobservice/config"
|
"github.com/goharbor/harbor/src/jobservice/config"
|
||||||
@ -113,8 +111,8 @@ func (bc *basicClient) GetCandidates(repository *res.Repository) ([]*res.Candida
|
|||||||
Tag: image.Name,
|
Tag: image.Name,
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
CreationTime: image.Created.Unix(),
|
CreationTime: image.Created.Unix(),
|
||||||
PulledTime: time.Now().Unix() - (int64)(rand.Int31n(4)*3600),
|
PulledTime: image.PullTime.Unix(),
|
||||||
PushedTime: time.Now().Unix() - (int64)((rand.Int31n(5)+5)*3600),
|
PushedTime: image.PushTime.Unix(),
|
||||||
}
|
}
|
||||||
candidates = append(candidates, candidate)
|
candidates = append(candidates, candidate)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user