pull/31092/merge
Douglas Camata 1 week ago committed by GitHub
commit 891930f715
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -796,8 +796,8 @@ func (c *ChartPathOptions) LocateChart(name string, settings *cli.EnvSettings) (
dl.Verify = downloader.VerifyAlways
}
if c.RepoURL != "" {
chartURL, err := repo.FindChartInAuthAndTLSAndPassRepoURL(c.RepoURL, c.Username, c.Password, name, version,
c.CertFile, c.KeyFile, c.CaFile, c.InsecureSkipTLSverify, c.PassCredentialsAll, getter.All(settings))
chartURL, err := repo.FindChartInAuthAndTLSAndPassAndCacheRepoURL(c.RepoURL, c.Username, c.Password, name, version,
c.CertFile, c.KeyFile, c.CaFile, c.InsecureSkipTLSverify, c.PassCredentialsAll, getter.All(settings), settings.RepositoryCache)
if err != nil {
return "", err
}

@ -122,7 +122,7 @@ func (p *Pull) Run(chartRef string) (string, error) {
}
if p.RepoURL != "" {
chartURL, err := repo.FindChartInAuthAndTLSAndPassRepoURL(p.RepoURL, p.Username, p.Password, chartRef, p.Version, p.CertFile, p.KeyFile, p.CaFile, p.InsecureSkipTLSverify, p.PassCredentialsAll, getter.All(p.Settings))
chartURL, err := repo.FindChartInAuthAndTLSAndPassAndCacheRepoURL(p.RepoURL, p.Username, p.Password, chartRef, p.Version, p.CertFile, p.KeyFile, p.CaFile, p.InsecureSkipTLSverify, p.PassCredentialsAll, getter.All(p.Settings), p.Settings.RepositoryCache)
if err != nil {
return out.String(), err
}

@ -742,7 +742,7 @@ func (m *Manager) findChartURL(name, version, repoURL string, repos map[string]*
return
}
}
url, err = repo.FindChartInRepoURL(repoURL, name, version, certFile, keyFile, caFile, m.Getters)
url, err = repo.FindChartInAuthAndTLSAndPassAndCacheRepoURL(repoURL, "", "", name, version, certFile, keyFile, caFile, false, false, m.Getters, m.RepositoryCache)
if err == nil {
return url, username, password, false, false, "", "", "", err
}

@ -223,7 +223,14 @@ func FindChartInAuthAndTLSRepoURL(repoURL, username, password, chartName, chartV
// be passed on to other domains.
// TODO Helm 4, FindChartInAuthAndTLSAndPassRepoURL should be integrated into FindChartInAuthRepoURL.
func FindChartInAuthAndTLSAndPassRepoURL(repoURL, username, password, chartName, chartVersion, certFile, keyFile, caFile string, insecureSkipTLSverify, passCredentialsAll bool, getters getter.Providers) (string, error) {
return FindChartInAuthAndTLSAndPassAndCacheRepoURL(repoURL, username, password, chartName, chartVersion, certFile, keyFile, caFile, insecureSkipTLSverify, passCredentialsAll, getters, "")
}
// FindChartInAuthAndTLSAndPassAndCacheRepoURL finds chart in chart repository pointed by repoURL
// without adding repo to repositories, like FindChartInRepoURL,
// but it also receives credentials, TLS verify flag, if credentials should
// be passed on to other domains, and a custom cache path.
func FindChartInAuthAndTLSAndPassAndCacheRepoURL(repoURL, username, password, chartName, chartVersion, certFile, keyFile, caFile string, insecureSkipTLSverify, passCredentialsAll bool, getters getter.Providers, cachePath string) (string, error) {
// Download and write the index file to a temporary location
buf := make([]byte, 20)
rand.Read(buf)
@ -244,6 +251,9 @@ func FindChartInAuthAndTLSAndPassRepoURL(repoURL, username, password, chartName,
if err != nil {
return "", err
}
if cachePath != "" {
r.CachePath = cachePath
}
idx, err := r.DownloadIndexFile()
if err != nil {
return "", errors.Wrapf(err, "looks like %q is not a valid chart repository or cannot be reached", repoURL)

@ -33,6 +33,7 @@ import (
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/cli"
"helm.sh/helm/v3/pkg/getter"
"helm.sh/helm/v3/pkg/helmpath"
)
const (
@ -73,6 +74,41 @@ func TestLoadChartRepository(t *testing.T) {
}
}
func TestNewChartRepositoryWithCachePath(t *testing.T) {
srv, err := startLocalServerForTests(nil)
if err != nil {
t.Fatal(err)
}
defer srv.Close()
cacheDir := t.TempDir()
r, err := NewChartRepository(&Entry{
Name: testRepository,
URL: srv.URL,
}, getter.All(&cli.EnvSettings{}))
if err != nil {
t.Errorf("Problem creating chart repository from %s: %v", testRepository, err)
}
r.CachePath = cacheDir
if err := r.Load(); err != nil {
t.Errorf("Problem loading chart repository from %s: %v", testRepository, err)
}
_, err = r.DownloadIndexFile()
if err != nil {
t.Errorf("Problem downloading index file from %s: %v", testRepository, err)
}
if _, err := os.Stat(filepath.Join(cacheDir, helmpath.CacheIndexFile(r.Config.Name))); err != nil {
t.Errorf("Expected index.yaml to be created in %s, but got an error: %v", cacheDir, err)
}
if _, err := os.Stat(filepath.Join(cacheDir, helmpath.CacheChartsFile(r.Config.Name))); err != nil {
t.Errorf("Expected charts to be created in %s, but got an error: %v", cacheDir, err)
}
}
func TestIndex(t *testing.T) {
r, err := NewChartRepository(&Entry{
Name: testRepository,
@ -344,13 +380,25 @@ func TestFindChartInRepoURL(t *testing.T) {
}
}
func TestErrorFindChartInRepoURL(t *testing.T) {
func TestFindChartInAuthAndTLSAndPassAndCacheRepoURL(t *testing.T) {
srv, err := startLocalServerForTests(nil)
if err != nil {
t.Fatal(err)
}
defer srv.Close()
g := getter.All(&cli.EnvSettings{
RepositoryCache: t.TempDir(),
})
cacheDir := t.TempDir()
chartURL, err := FindChartInAuthAndTLSAndPassAndCacheRepoURL(srv.URL, "", "", "nginx", "", "", "", "", false, false, getter.All(&cli.EnvSettings{}), cacheDir)
if err != nil {
t.Fatalf("%v", err)
}
if chartURL != "https://charts.helm.sh/stable/nginx-0.2.0.tgz" {
t.Errorf("%s is not the valid URL", chartURL)
}
}
if _, err := FindChartInRepoURL("http://someserver/something", "nginx", "", "", "", "", g); err == nil {
func TestErrorFindChartInRepoURL(t *testing.T) {
if _, err := FindChartInRepoURL("http://someserver/something", "nginx", "", "", "", "", getter.All(&cli.EnvSettings{})); err == nil {
t.Errorf("Expected error for bad chart URL, but did not get any errors")
} else if !strings.Contains(err.Error(), `looks like "http://someserver/something" is not a valid chart repository or cannot be reached`) {
t.Errorf("Expected error for bad chart URL, but got a different error (%v)", err)
@ -362,19 +410,19 @@ func TestErrorFindChartInRepoURL(t *testing.T) {
}
defer srv.Close()
if _, err = FindChartInRepoURL(srv.URL, "nginx1", "", "", "", "", g); err == nil {
if _, err = FindChartInRepoURL(srv.URL, "nginx1", "", "", "", "", getter.All(&cli.EnvSettings{})); err == nil {
t.Errorf("Expected error for chart not found, but did not get any errors")
} else if err.Error() != `chart "nginx1" not found in `+srv.URL+` repository` {
t.Errorf("Expected error for chart not found, but got a different error (%v)", err)
}
if _, err = FindChartInRepoURL(srv.URL, "nginx1", "0.1.0", "", "", "", g); err == nil {
if _, err = FindChartInRepoURL(srv.URL, "nginx1", "0.1.0", "", "", "", getter.All(&cli.EnvSettings{})); err == nil {
t.Errorf("Expected error for chart not found, but did not get any errors")
} else if err.Error() != `chart "nginx1" version "0.1.0" not found in `+srv.URL+` repository` {
t.Errorf("Expected error for chart not found, but got a different error (%v)", err)
}
if _, err = FindChartInRepoURL(srv.URL, "chartWithNoURL", "", "", "", "", g); err == nil {
if _, err = FindChartInRepoURL(srv.URL, "chartWithNoURL", "", "", "", "", getter.All(&cli.EnvSettings{})); err == nil {
t.Errorf("Expected error for no chart URLs available, but did not get any errors")
} else if err.Error() != `chart "chartWithNoURL" has no downloadable URLs` {
t.Errorf("Expected error for chart not found, but got a different error (%v)", err)

Loading…
Cancel
Save