From e3d3a1864abf5f5f8474776419645bc69af271d3 Mon Sep 17 00:00:00 2001 From: Luke Reed Date: Tue, 23 Nov 2021 12:43:12 -0500 Subject: [PATCH] revert changes to DownloadTo function and implement using the ChartDownloader object instead Signed-off-by: Luke Reed --- cmd/helm/upgrade.go | 2 +- pkg/action/install.go | 4 ++-- pkg/action/pull.go | 2 +- pkg/downloader/chart_downloader.go | 24 ++++++++++++------------ pkg/downloader/chart_downloader_test.go | 6 +++--- pkg/downloader/manager.go | 2 +- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/cmd/helm/upgrade.go b/cmd/helm/upgrade.go index 2e9a496f4..4c7fe9c37 100644 --- a/cmd/helm/upgrade.go +++ b/cmd/helm/upgrade.go @@ -152,7 +152,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { if err != nil { return err } - if client.ChartPathOptions.RepoURL != "" && ch.Metadata.RepoURL == "" { + if client.ChartPathOptions.RepoURL != "" { ch.Metadata.RepoURL = client.ChartPathOptions.RepoURL } if req := ch.Metadata.Dependencies; req != nil { diff --git a/pkg/action/install.go b/pkg/action/install.go index 215b43f10..811543dbd 100644 --- a/pkg/action/install.go +++ b/pkg/action/install.go @@ -750,8 +750,8 @@ func (c *ChartPathOptions) LocateChart(name string, settings *cli.EnvSettings) ( return "", err } - filename, rURL, _, err := dl.DownloadTo(name, version, settings.RepositoryCache) - c.RepoURL = rURL + filename, _, err := dl.DownloadTo(name, version, settings.RepositoryCache) + c.RepoURL = dl.RepositoryURL if err == nil { lname, err := filepath.Abs(filename) if err != nil { diff --git a/pkg/action/pull.go b/pkg/action/pull.go index ee7f756b4..2f5127ea9 100644 --- a/pkg/action/pull.go +++ b/pkg/action/pull.go @@ -127,7 +127,7 @@ func (p *Pull) Run(chartRef string) (string, error) { chartRef = chartURL } - saved, _, v, err := c.DownloadTo(chartRef, p.Version, dest) + saved, v, err := c.DownloadTo(chartRef, p.Version, dest) if err != nil { return out.String(), err } diff --git a/pkg/downloader/chart_downloader.go b/pkg/downloader/chart_downloader.go index 6efb627dc..b94f1396e 100644 --- a/pkg/downloader/chart_downloader.go +++ b/pkg/downloader/chart_downloader.go @@ -84,22 +84,22 @@ type ChartDownloader struct { // // For VerifyNever and VerifyIfPossible, the Verification may be empty. // -// Returns two strings, the first of which is a path to the location where the file was downloaded, the second being the repository URL. -// Also returned is a verification (if provenance was verified), or an error if something bad happened. -func (c *ChartDownloader) DownloadTo(ref, version, dest string) (string, string, *provenance.Verification, error) { +// Returns a string path to the location where the file was downloaded and a verification +// (if provenance was verified), or an error if something bad happened. +func (c *ChartDownloader) DownloadTo(ref, version, dest string) (string, *provenance.Verification, error) { u, err := c.ResolveChartVersion(ref, version) if err != nil { - return "", "", nil, err + return "", nil, err } g, err := c.Getters.ByScheme(u.Scheme) if err != nil { - return "", "", nil, err + return "", nil, err } data, err := g.Get(u.String(), c.Options...) if err != nil { - return "", "", nil, err + return "", nil, err } name := filepath.Base(u.Path) @@ -109,7 +109,7 @@ func (c *ChartDownloader) DownloadTo(ref, version, dest string) (string, string, destfile := filepath.Join(dest, name) if err := fileutil.AtomicWriteFile(destfile, data, 0644); err != nil { - return destfile, c.RepositoryURL, nil, err + return destfile, nil, err } // If provenance is requested, verify it. @@ -118,14 +118,14 @@ func (c *ChartDownloader) DownloadTo(ref, version, dest string) (string, string, body, err := g.Get(u.String() + ".prov") if err != nil { if c.Verify == VerifyAlways { - return destfile, c.RepositoryURL, ver, errors.Errorf("failed to fetch provenance %q", u.String()+".prov") + return destfile, ver, errors.Errorf("failed to fetch provenance %q", u.String()+".prov") } fmt.Fprintf(c.Out, "WARNING: Verification not found for %s: %s\n", ref, err) - return destfile, c.RepositoryURL, ver, nil + return destfile, ver, nil } provfile := destfile + ".prov" if err := fileutil.AtomicWriteFile(provfile, body, 0644); err != nil { - return destfile, c.RepositoryURL, nil, err + return destfile, nil, err } if c.Verify != VerifyLater { @@ -133,11 +133,11 @@ func (c *ChartDownloader) DownloadTo(ref, version, dest string) (string, string, if err != nil { // Fail always in this case, since it means the verification step // failed. - return destfile, c.RepositoryURL, ver, err + return destfile, ver, err } } } - return destfile, c.RepositoryURL, ver, nil + return destfile, ver, nil } // ResolveChartVersion resolves a chart reference to a URL. diff --git a/pkg/downloader/chart_downloader_test.go b/pkg/downloader/chart_downloader_test.go index fe8a64e6b..f70a56422 100644 --- a/pkg/downloader/chart_downloader_test.go +++ b/pkg/downloader/chart_downloader_test.go @@ -197,7 +197,7 @@ func TestDownloadTo(t *testing.T) { } cname := "/signtest-0.1.0.tgz" dest := srv.Root() - where, _, v, err := c.DownloadTo(srv.URL()+cname, "", dest) + where, v, err := c.DownloadTo(srv.URL()+cname, "", dest) if err != nil { t.Fatal(err) } @@ -248,7 +248,7 @@ func TestDownloadTo_TLS(t *testing.T) { } cname := "test/signtest" dest := srv.Root() - where, _, v, err := c.DownloadTo(cname, "", dest) + where, v, err := c.DownloadTo(cname, "", dest) if err != nil { t.Fatal(err) } @@ -294,7 +294,7 @@ func TestDownloadTo_VerifyLater(t *testing.T) { }), } cname := "/signtest-0.1.0.tgz" - where, _, _, err := c.DownloadTo(srv.URL()+cname, "", dest) + where, _, err := c.DownloadTo(srv.URL()+cname, "", dest) if err != nil { t.Fatal(err) } diff --git a/pkg/downloader/manager.go b/pkg/downloader/manager.go index 4a59889b8..52f1a1312 100644 --- a/pkg/downloader/manager.go +++ b/pkg/downloader/manager.go @@ -357,7 +357,7 @@ func (m *Manager) downloadAll(deps []*chart.Dependency) error { getter.WithTagName(version)) } - if _, _, _, err = dl.DownloadTo(churl, version, tmpPath); err != nil { + if _, _, err = dl.DownloadTo(churl, version, tmpPath); err != nil { saveError = errors.Wrapf(err, "could not download %s", churl) break }