mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-20 07:37:38 +01:00
Merge pull request #10083 from MrMEEE/fix-listings-squashed
Squashed version of PR-9943
This commit is contained in:
commit
a1712e5332
@ -80,13 +80,10 @@ func NewRegistry(endpoint string, client *http.Client) (*Registry, error) {
|
|||||||
// Catalog ...
|
// Catalog ...
|
||||||
func (r *Registry) Catalog() ([]string, error) {
|
func (r *Registry) Catalog() ([]string, error) {
|
||||||
repos := []string{}
|
repos := []string{}
|
||||||
suffix := "/v2/_catalog?n=1000"
|
aurl := r.Endpoint.String() + "/v2/_catalog?n=1000"
|
||||||
var url string
|
|
||||||
|
|
||||||
for len(suffix) > 0 {
|
for len(aurl) > 0 {
|
||||||
url = r.Endpoint.String() + suffix
|
req, err := http.NewRequest("GET", aurl, nil)
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return repos, err
|
return repos, err
|
||||||
}
|
}
|
||||||
@ -112,11 +109,15 @@ func (r *Registry) Catalog() ([]string, error) {
|
|||||||
|
|
||||||
repos = append(repos, catalogResp.Repositories...)
|
repos = append(repos, catalogResp.Repositories...)
|
||||||
// Link: </v2/_catalog?last=library%2Fhello-world-25&n=100>; rel="next"
|
// Link: </v2/_catalog?last=library%2Fhello-world-25&n=100>; rel="next"
|
||||||
|
// Link: <http://domain.com/v2/_catalog?last=library%2Fhello-world-25&n=100>; rel="next"
|
||||||
link := resp.Header.Get("Link")
|
link := resp.Header.Get("Link")
|
||||||
if strings.HasSuffix(link, `rel="next"`) && strings.Index(link, "<") >= 0 && strings.Index(link, ">") >= 0 {
|
if strings.HasSuffix(link, `rel="next"`) && strings.Index(link, "<") >= 0 && strings.Index(link, ">") >= 0 {
|
||||||
suffix = link[strings.Index(link, "<")+1 : strings.Index(link, ">")]
|
aurl = link[strings.Index(link, "<")+1 : strings.Index(link, ">")]
|
||||||
|
if strings.Index(aurl, ":") < 0 {
|
||||||
|
aurl = r.Endpoint.String() + aurl
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
suffix = ""
|
aurl = ""
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return repos, &commonhttp.Error{
|
return repos, &commonhttp.Error{
|
||||||
|
@ -69,18 +69,19 @@ func parseError(err error) error {
|
|||||||
// ListTag ...
|
// ListTag ...
|
||||||
func (r *Repository) ListTag() ([]string, error) {
|
func (r *Repository) ListTag() ([]string, error) {
|
||||||
tags := []string{}
|
tags := []string{}
|
||||||
req, err := http.NewRequest("GET", buildTagListURL(r.Endpoint.String(), r.Name), nil)
|
aurl := buildTagListURL(r.Endpoint.String(), r.Name)
|
||||||
|
|
||||||
|
for len(aurl) > 0 {
|
||||||
|
req, err := http.NewRequest("GET", aurl, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return tags, err
|
return tags, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := r.client.Do(req)
|
resp, err := r.client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return tags, parseError(err)
|
return nil, parseError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
b, err := ioutil.ReadAll(resp.Body)
|
b, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return tags, err
|
return tags, err
|
||||||
@ -94,10 +95,19 @@ func (r *Repository) ListTag() ([]string, error) {
|
|||||||
if err := json.Unmarshal(b, &tagsResp); err != nil {
|
if err := json.Unmarshal(b, &tagsResp); err != nil {
|
||||||
return tags, err
|
return tags, err
|
||||||
}
|
}
|
||||||
sort.Strings(tags)
|
|
||||||
tags = tagsResp.Tags
|
|
||||||
|
|
||||||
return tags, nil
|
tags = append(tags, tagsResp.Tags...)
|
||||||
|
// Link: </v2/library/hello-world/tags/list?last=......>; rel="next"
|
||||||
|
// Link: <http://domain.com/v2/library/hello-world/tags/list?last=......>; rel="next"
|
||||||
|
link := resp.Header.Get("Link")
|
||||||
|
if strings.HasSuffix(link, `rel="next"`) && strings.Index(link, "<") >= 0 && strings.Index(link, ">") >= 0 {
|
||||||
|
aurl = link[strings.Index(link, "<")+1 : strings.Index(link, ">")]
|
||||||
|
if strings.Index(aurl, ":") < 0 {
|
||||||
|
aurl = r.Endpoint.String() + aurl
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
aurl = ""
|
||||||
|
}
|
||||||
} else if resp.StatusCode == http.StatusNotFound {
|
} else if resp.StatusCode == http.StatusNotFound {
|
||||||
|
|
||||||
// TODO remove the logic if the bug of registry is fixed
|
// TODO remove the logic if the bug of registry is fixed
|
||||||
@ -105,13 +115,15 @@ func (r *Repository) ListTag() ([]string, error) {
|
|||||||
// a repository which is being pushed, a "NAME_UNKNOWN" error will
|
// a repository which is being pushed, a "NAME_UNKNOWN" error will
|
||||||
// been returned, while the catalog API can list this repository.
|
// been returned, while the catalog API can list this repository.
|
||||||
return tags, nil
|
return tags, nil
|
||||||
}
|
} else {
|
||||||
|
|
||||||
return tags, &commonhttp.Error{
|
return tags, &commonhttp.Error{
|
||||||
Code: resp.StatusCode,
|
Code: resp.StatusCode,
|
||||||
Message: string(b),
|
Message: string(b),
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sort.Strings(tags)
|
||||||
|
return tags, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ManifestExist ...
|
// ManifestExist ...
|
||||||
|
@ -314,7 +314,7 @@ func Test_native_FetchImages(t *testing.T) {
|
|||||||
for i, resource := range resources {
|
for i, resource := range resources {
|
||||||
require.NotNil(t, resource.Metadata)
|
require.NotNil(t, resource.Metadata)
|
||||||
assert.Equal(t, tt.want[i].Metadata.Repository, resource.Metadata.Repository)
|
assert.Equal(t, tt.want[i].Metadata.Repository, resource.Metadata.Repository)
|
||||||
assert.Equal(t, tt.want[i].Metadata.Vtags, resource.Metadata.Vtags)
|
assert.ElementsMatch(t, tt.want[i].Metadata.Vtags, resource.Metadata.Vtags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user