mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-23 17:17:46 +01:00
Merge pull request #8594 from ywk253100/190731_replicate_chart
Fix bug in Helm Hub and Harbor adapter for replicating chart
This commit is contained in:
commit
34f845b804
@ -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