mirror of
https://github.com/goharbor/harbor.git
synced 2025-01-17 05:01:22 +01:00
Merge pull request #3790 from ywk253100/171214_author
Read image author from label 'maintainer' if author is null
This commit is contained in:
commit
c0c262cb53
@ -20,6 +20,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/distribution/manifest/schema1"
|
"github.com/docker/distribution/manifest/schema1"
|
||||||
@ -63,6 +64,11 @@ type tagDetail struct {
|
|||||||
DockerVersion string `json:"docker_version"`
|
DockerVersion string `json:"docker_version"`
|
||||||
Author string `json:"author"`
|
Author string `json:"author"`
|
||||||
Created time.Time `json:"created"`
|
Created time.Time `json:"created"`
|
||||||
|
Config *cfg `json:"config"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type cfg struct {
|
||||||
|
Labels map[string]string `json:"labels"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type tagResp struct {
|
type tagResp struct {
|
||||||
@ -460,9 +466,28 @@ func getTagDetail(client *registry.Repository, tag string) (*tagDetail, error) {
|
|||||||
return detail, err
|
return detail, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
populateAuthor(detail)
|
||||||
|
|
||||||
return detail, nil
|
return detail, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func populateAuthor(detail *tagDetail) {
|
||||||
|
// has author info already
|
||||||
|
if len(detail.Author) > 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// try to set author with the value of label "maintainer"
|
||||||
|
if detail.Config != nil {
|
||||||
|
for k, v := range detail.Config.Labels {
|
||||||
|
if strings.ToLower(k) == "maintainer" {
|
||||||
|
detail.Author = v
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// GetManifests returns the manifest of a tag
|
// GetManifests returns the manifest of a tag
|
||||||
func (ra *RepositoryAPI) GetManifests() {
|
func (ra *RepositoryAPI) GetManifests() {
|
||||||
repoName := ra.GetString(":splat")
|
repoName := ra.GetString(":splat")
|
||||||
|
@ -199,3 +199,27 @@ func TestGetReposTop(t *testing.T) {
|
|||||||
|
|
||||||
fmt.Printf("\n")
|
fmt.Printf("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPopulateAuthor(t *testing.T) {
|
||||||
|
author := "author"
|
||||||
|
detail := &tagDetail{
|
||||||
|
Author: author,
|
||||||
|
}
|
||||||
|
populateAuthor(detail)
|
||||||
|
assert.Equal(t, author, detail.Author)
|
||||||
|
|
||||||
|
detail = &tagDetail{}
|
||||||
|
populateAuthor(detail)
|
||||||
|
assert.Equal(t, "", detail.Author)
|
||||||
|
|
||||||
|
maintainer := "maintainer"
|
||||||
|
detail = &tagDetail{
|
||||||
|
Config: &cfg{
|
||||||
|
Labels: map[string]string{
|
||||||
|
"Maintainer": maintainer,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
populateAuthor(detail)
|
||||||
|
assert.Equal(t, maintainer, detail.Author)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user