mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-23 18:55:18 +01:00
Merge remote-tracking branch 'upstream/master' into new-ui-with-sync-image
Conflicts: utils/registry/registry.go
This commit is contained in:
commit
9e039c6a8e
@ -3,9 +3,7 @@
|
|||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
@ -18,10 +16,10 @@ package registry
|
|||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
|
||||||
registry_error "github.com/vmware/harbor/utils/registry/error"
|
registry_error "github.com/vmware/harbor/utils/registry/error"
|
||||||
"github.com/vmware/harbor/utils/registry/utils"
|
"github.com/vmware/harbor/utils/registry/utils"
|
||||||
@ -74,42 +72,52 @@ func NewRegistryWithModifiers(endpoint string, insecure bool, modifiers ...Modif
|
|||||||
// Catalog ...
|
// Catalog ...
|
||||||
func (r *Registry) Catalog() ([]string, error) {
|
func (r *Registry) Catalog() ([]string, error) {
|
||||||
repos := []string{}
|
repos := []string{}
|
||||||
|
suffix := "/v2/_catalog?n=1000"
|
||||||
|
var url string
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", buildCatalogURL(r.Endpoint.String()), nil)
|
for len(suffix) > 0 {
|
||||||
if err != nil {
|
url = r.Endpoint.String() + suffix
|
||||||
return repos, err
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := r.client.Do(req)
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return repos, parseError(err)
|
return repos, err
|
||||||
}
|
}
|
||||||
|
resp, err := r.client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
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 repos, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode == http.StatusOK {
|
|
||||||
catalogResp := struct {
|
|
||||||
Repositories []string `json:"repositories"`
|
|
||||||
}{}
|
|
||||||
|
|
||||||
if err := json.Unmarshal(b, &catalogResp); err != nil {
|
|
||||||
return repos, err
|
return repos, err
|
||||||
}
|
}
|
||||||
|
|
||||||
repos = catalogResp.Repositories
|
if resp.StatusCode == http.StatusOK {
|
||||||
|
catalogResp := struct {
|
||||||
|
Repositories []string `json:"repositories"`
|
||||||
|
}{}
|
||||||
|
|
||||||
return repos, nil
|
if err := json.Unmarshal(b, &catalogResp); err != nil {
|
||||||
}
|
return repos, err
|
||||||
|
}
|
||||||
|
|
||||||
return repos, ®istry_error.Error{
|
repos = append(repos, catalogResp.Repositories...)
|
||||||
StatusCode: resp.StatusCode,
|
//Link: </v2/_catalog?last=library%2Fhello-world-25&n=100>; rel="next"
|
||||||
Detail: string(b),
|
link := resp.Header.Get("Link")
|
||||||
|
if strings.HasSuffix(link, `rel="next"`) && strings.Index(link, "<") >= 0 && strings.Index(link, ">") >= 0 {
|
||||||
|
suffix = link[strings.Index(link, "<")+1 : strings.Index(link, ">")]
|
||||||
|
} else {
|
||||||
|
suffix = ""
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return repos, ®istry_error.Error{
|
||||||
|
StatusCode: resp.StatusCode,
|
||||||
|
Detail: string(b),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return repos, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ping ...
|
// Ping ...
|
||||||
@ -140,7 +148,3 @@ func (r *Registry) Ping() error {
|
|||||||
Detail: string(b),
|
Detail: string(b),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildCatalogURL(endpoint string) string {
|
|
||||||
return fmt.Sprintf("%s/v2/_catalog", endpoint)
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user