From cd83e4fb45fb19ba776fd5e70419e9a77bfd2947 Mon Sep 17 00:00:00 2001 From: Michal Cwienczek Date: Tue, 3 Oct 2017 19:58:45 +0200 Subject: [PATCH] Fixed base URL appending when chart address is not absolute --- pkg/downloader/chart_downloader.go | 53 ++++++------------------------ 1 file changed, 10 insertions(+), 43 deletions(-) diff --git a/pkg/downloader/chart_downloader.go b/pkg/downloader/chart_downloader.go index 659a655e1..98283efed 100644 --- a/pkg/downloader/chart_downloader.go +++ b/pkg/downloader/chart_downloader.go @@ -82,25 +82,14 @@ type ChartDownloader struct { // (if provenance was verified), or an error if something bad happened. func (c *ChartDownloader) DownloadTo(ref, version, dest string) (string, *provenance.Verification, error) { u, g, err := c.ResolveChartVersion(ref, version) + if err != nil { return "", nil, err } - chartURL := u.String() - - data, err := g.Get(chartURL) + data, err := g.Get(u.String()) if err != nil { - originalError := err - - chartURL, err = fixupURL(chartURL) - if err != nil { - return "", nil, originalError - } - fmt.Println(chartURL) - data, err = g.Get(chartURL) - if err != nil { - return "", nil, originalError - } + return "", nil, err } name := filepath.Base(u.Path) @@ -137,34 +126,6 @@ func (c *ChartDownloader) DownloadTo(ref, version, dest string) (string, *proven return destfile, ver, nil } -// https://github.com/kubernetes/helm/issues/2937 -// tries to fix URL because of BUG #2937 -// transforms URL from -// https://url.to.repo/path?key=value/chart-0.1.0.tgz -// into -// https://url.to.repo/path/chart-0-1-0.tgz?key=value -func fixupURL(chartURL string) (string, error) { - queryStringStartIndex := strings.Index(chartURL, "?") - - if queryStringStartIndex == -1 { - return "", errors.New("Could not fixup URL") - } - var appendedURLIndex int - for i := queryStringStartIndex + 1; i < len(chartURL); i++ { - if chartURL[i] == '/' { - appendedURLIndex = i - break - } - } - - appendedURL := chartURL[appendedURLIndex:] - restURL := chartURL[0:appendedURLIndex] - - uu, _ := url.Parse(restURL) - uu.Path = strings.TrimSuffix(uu.Path, "/") + appendedURL - return uu.String(), nil -} - // ResolveChartVersion resolves a chart reference to a URL. // // It returns the URL as well as a preconfigured repo.Getter that can fetch @@ -251,13 +212,19 @@ func (c *ChartDownloader) ResolveChartVersion(ref, version string) (*url.URL, ge // TODO: Seems that picking first URL is not fully correct u, err = url.Parse(cv.URLs[0]) + if err != nil { return u, r.Client, fmt.Errorf("invalid chart URL format: %s", ref) } // If the URL is relative (no scheme), prepend the chart repo's base URL if !u.IsAbs() { - u, err = url.Parse(rc.URL + "/" + u.Path) + path := u.Path + u, err = url.Parse(rc.URL) + if err != nil { + return nil, r.Client, err + } + u.Path = u.Path + path return u, r.Client, err }