mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-19 08:45:27 +01:00
replication helm hub adapter bug fix
Signed-off-by: Wenkai Yin <yinw@vmware.com>
This commit is contained in:
parent
f3ba25f656
commit
b7b8332626
@ -164,6 +164,13 @@ func (a *adapter) DownloadChart(name, version string) (io.ReadCloser, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, fmt.Errorf("failed to download the chart %s: %d %s", req.URL.String(), resp.StatusCode, string(body))
|
||||
}
|
||||
return resp.Body, nil
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,7 @@ func TestDownloadChart(t *testing.T) {
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Pattern: "/api/chartrepo/library/charts/harbor-1.0.tgz",
|
||||
Pattern: "/chartrepo/library/charts/harbor-1.0.tgz",
|
||||
Handler: func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
},
|
||||
|
@ -17,6 +17,7 @@ package helmhub
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
@ -123,7 +124,7 @@ func (a *adapter) download(version *chartVersion) (io.ReadCloser, error) {
|
||||
|
||||
url := strings.ToLower(version.Attributes.URLs[0])
|
||||
if !(strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "https://")) {
|
||||
url = fmt.Sprintf("%s/charts/%s", version.Relationships.Chart.Data.Repo.URL, url)
|
||||
url = fmt.Sprintf("%s/%s", version.Relationships.Chart.Data.Repo.URL, url)
|
||||
}
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||
@ -134,6 +135,13 @@ func (a *adapter) download(version *chartVersion) (io.ReadCloser, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, fmt.Errorf("failed to download the chart %s: %d %s", req.URL.String(), resp.StatusCode, string(body))
|
||||
}
|
||||
return resp.Body, nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user