Merge pull request #3790 from ywk253100/171214_author

Read image author from label 'maintainer' if author is null
This commit is contained in:
Daniel Jiang 2017-12-19 18:40:25 +08:00 committed by GitHub
commit c0c262cb53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 0 deletions

View File

@ -20,6 +20,7 @@ import (
"io/ioutil"
"net/http"
"strconv"
"strings"
"time"
"github.com/docker/distribution/manifest/schema1"
@ -63,6 +64,11 @@ type tagDetail struct {
DockerVersion string `json:"docker_version"`
Author string `json:"author"`
Created time.Time `json:"created"`
Config *cfg `json:"config"`
}
type cfg struct {
Labels map[string]string `json:"labels"`
}
type tagResp struct {
@ -460,9 +466,28 @@ func getTagDetail(client *registry.Repository, tag string) (*tagDetail, error) {
return detail, err
}
populateAuthor(detail)
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
func (ra *RepositoryAPI) GetManifests() {
repoName := ra.GetString(":splat")

View File

@ -199,3 +199,27 @@ func TestGetReposTop(t *testing.T) {
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)
}