more options

Signed-off-by: George Jenkins <gvjenkins@gmail.com>
pull/13579/head
George Jenkins 8 months ago
parent 7ea1d1df66
commit 0ce267d907

@ -792,11 +792,9 @@ func (c *ChartPathOptions) LocateChart(name string, settings *cli.EnvSettings) (
chartURL, err := repo.FindChartInRepoURL( chartURL, err := repo.FindChartInRepoURL(
c.RepoURL, c.RepoURL,
name, name,
version,
c.CertFile,
c.KeyFile,
c.CaFile,
getter.All(settings), getter.All(settings),
repo.WithChartVersion(version),
repo.WithClientTLS(c.CertFile, c.KeyFile, c.CaFile),
repo.WithUsernamePassword(c.Username, c.Password), repo.WithUsernamePassword(c.Username, c.Password),
repo.WithInsecureSkipTLSverify(c.InsecureSkipTLSverify), repo.WithInsecureSkipTLSverify(c.InsecureSkipTLSverify),
repo.WithPassCredentialsAll(c.PassCredentialsAll), repo.WithPassCredentialsAll(c.PassCredentialsAll),

@ -120,11 +120,9 @@ func (p *Pull) Run(chartRef string) (string, error) {
chartURL, err := repo.FindChartInRepoURL( chartURL, err := repo.FindChartInRepoURL(
p.RepoURL, p.RepoURL,
chartRef, chartRef,
p.Version,
p.CertFile,
p.KeyFile,
p.CaFile,
getter.All(p.Settings), getter.All(p.Settings),
repo.WithChartVersion(p.Version),
repo.WithClientTLS(p.CertFile, p.KeyFile, p.CaFile),
repo.WithUsernamePassword(p.Username, p.Password), repo.WithUsernamePassword(p.Username, p.Password),
repo.WithInsecureSkipTLSverify(p.InsecureSkipTLSverify), repo.WithInsecureSkipTLSverify(p.InsecureSkipTLSverify),
repo.WithPassCredentialsAll(p.PassCredentialsAll), repo.WithPassCredentialsAll(p.PassCredentialsAll),

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

@ -201,10 +201,21 @@ type findChartInRepoURLOptions struct {
Password string Password string
PassCredentialsAll bool PassCredentialsAll bool
InsecureSkipTLSverify bool InsecureSkipTLSverify bool
CertFile string
KeyFile string
CAFile string
ChartVersion string
} }
type FindChartInRepoURLOption func(*findChartInRepoURLOptions) type FindChartInRepoURLOption func(*findChartInRepoURLOptions)
// WithChartVersion specifies the chart version to find
func WithChartVersion(chartVersion string) FindChartInRepoURLOption {
return func(options *findChartInRepoURLOptions) {
options.ChartVersion = chartVersion
}
}
// WithUsernamePassword specifies the username/password credntials for the repository // WithUsernamePassword specifies the username/password credntials for the repository
func WithUsernamePassword(username, password string) FindChartInRepoURLOption { func WithUsernamePassword(username, password string) FindChartInRepoURLOption {
return func(options *findChartInRepoURLOptions) { return func(options *findChartInRepoURLOptions) {
@ -220,6 +231,15 @@ func WithPassCredentialsAll(passCredentialsAll bool) FindChartInRepoURLOption {
} }
} }
// WithClientTLS species the cert, key, and CA files for client mTLS
func WithClientTLS(certFile, keyFile, caFile string) FindChartInRepoURLOption {
return func(options *findChartInRepoURLOptions) {
options.CertFile = certFile
options.KeyFile = keyFile
options.CAFile = caFile
}
}
// WithInsecureSkipTLSverify skips TLS verification for repostory communication // WithInsecureSkipTLSverify skips TLS verification for repostory communication
func WithInsecureSkipTLSverify(insecureSkipTLSverify bool) FindChartInRepoURLOption { func WithInsecureSkipTLSverify(insecureSkipTLSverify bool) FindChartInRepoURLOption {
return func(options *findChartInRepoURLOptions) { return func(options *findChartInRepoURLOptions) {
@ -229,7 +249,7 @@ func WithInsecureSkipTLSverify(insecureSkipTLSverify bool) FindChartInRepoURLOpt
// FindChartInRepoURL finds chart in chart repository pointed by repoURL // FindChartInRepoURL finds chart in chart repository pointed by repoURL
// without adding repo to repositories // without adding repo to repositories
func FindChartInRepoURL(repoURL, chartName, chartVersion, certFile, keyFile, caFile string, getters getter.Providers, options ...FindChartInRepoURLOption) (string, error) { func FindChartInRepoURL(repoURL string, chartName string, getters getter.Providers, options ...FindChartInRepoURLOption) (string, error) {
opts := findChartInRepoURLOptions{} opts := findChartInRepoURLOptions{}
for _, option := range options { for _, option := range options {
@ -246,9 +266,9 @@ func FindChartInRepoURL(repoURL, chartName, chartVersion, certFile, keyFile, caF
Username: opts.Username, Username: opts.Username,
Password: opts.Password, Password: opts.Password,
PassCredentialsAll: opts.PassCredentialsAll, PassCredentialsAll: opts.PassCredentialsAll,
CertFile: certFile, CertFile: opts.CertFile,
KeyFile: keyFile, KeyFile: opts.KeyFile,
CAFile: caFile, CAFile: opts.CAFile,
Name: name, Name: name,
InsecureSkipTLSverify: opts.InsecureSkipTLSverify, InsecureSkipTLSverify: opts.InsecureSkipTLSverify,
} }
@ -272,10 +292,10 @@ func FindChartInRepoURL(repoURL, chartName, chartVersion, certFile, keyFile, caF
} }
errMsg := fmt.Sprintf("chart %q", chartName) errMsg := fmt.Sprintf("chart %q", chartName)
if chartVersion != "" { if opts.ChartVersion != "" {
errMsg = fmt.Sprintf("%s version %q", errMsg, chartVersion) errMsg = fmt.Sprintf("%s version %q", errMsg, opts.ChartVersion)
} }
cv, err := repoIndex.Get(chartName, chartVersion) cv, err := repoIndex.Get(chartName, opts.ChartVersion)
if err != nil { if err != nil {
return "", errors.Errorf("%s not found in %s repository", errMsg, repoURL) return "", errors.Errorf("%s not found in %s repository", errMsg, repoURL)
} }

@ -300,10 +300,6 @@ func TestFindChartInAuthAndTLSAndPassRepoURL(t *testing.T) {
chartURL, err := FindChartInRepoURL( chartURL, err := FindChartInRepoURL(
srv.URL, srv.URL,
"nginx", "nginx",
"",
"",
"",
"",
getter.All(&cli.EnvSettings{}), getter.All(&cli.EnvSettings{}),
WithInsecureSkipTLSverify(true), WithInsecureSkipTLSverify(true),
) )
@ -315,7 +311,7 @@ func TestFindChartInAuthAndTLSAndPassRepoURL(t *testing.T) {
} }
// If the insecureSkipTLSVerify is false, it will return an error that contains "x509: certificate signed by unknown authority". // If the insecureSkipTLSVerify is false, it will return an error that contains "x509: certificate signed by unknown authority".
_, err = FindChartInRepoURL(srv.URL, "nginx", "0.1.0", "", "", "", getter.All(&cli.EnvSettings{})) _, err = FindChartInRepoURL(srv.URL, "nginx", getter.All(&cli.EnvSettings{}), WithChartVersion("0.1.0"))
// Go communicates with the platform and different platforms return different messages. Go itself tests darwin // Go communicates with the platform and different platforms return different messages. Go itself tests darwin
// differently for its message. On newer versions of Darwin the message includes the "Acme Co" portion while older // differently for its message. On newer versions of Darwin the message includes the "Acme Co" portion while older
// versions of Darwin do not. As there are people developing Helm using both old and new versions of Darwin we test // versions of Darwin do not. As there are people developing Helm using both old and new versions of Darwin we test
@ -336,7 +332,7 @@ func TestFindChartInRepoURL(t *testing.T) {
} }
defer srv.Close() defer srv.Close()
chartURL, err := FindChartInRepoURL(srv.URL, "nginx", "", "", "", "", getter.All(&cli.EnvSettings{})) chartURL, err := FindChartInRepoURL(srv.URL, "nginx", getter.All(&cli.EnvSettings{}))
if err != nil { if err != nil {
t.Fatalf("%v", err) t.Fatalf("%v", err)
} }
@ -344,7 +340,7 @@ func TestFindChartInRepoURL(t *testing.T) {
t.Errorf("%s is not the valid URL", chartURL) t.Errorf("%s is not the valid URL", chartURL)
} }
chartURL, err = FindChartInRepoURL(srv.URL, "nginx", "0.1.0", "", "", "", getter.All(&cli.EnvSettings{})) chartURL, err = FindChartInRepoURL(srv.URL, "nginx", getter.All(&cli.EnvSettings{}), WithChartVersion("0.1.0"))
if err != nil { if err != nil {
t.Errorf("%s", err) t.Errorf("%s", err)
} }
@ -359,7 +355,7 @@ func TestErrorFindChartInRepoURL(t *testing.T) {
RepositoryCache: t.TempDir(), RepositoryCache: t.TempDir(),
}) })
if _, err := FindChartInRepoURL("http://someserver/something", "nginx", "", "", "", "", g); err == nil { if _, err := FindChartInRepoURL("http://someserver/something", "nginx", g); err == nil {
t.Errorf("Expected error for bad chart URL, but did not get any errors") 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`) { } 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) t.Errorf("Expected error for bad chart URL, but got a different error (%v)", err)
@ -371,19 +367,19 @@ func TestErrorFindChartInRepoURL(t *testing.T) {
} }
defer srv.Close() defer srv.Close()
if _, err = FindChartInRepoURL(srv.URL, "nginx1", "", "", "", "", g); err == nil { if _, err = FindChartInRepoURL(srv.URL, "nginx1", g); err == nil {
t.Errorf("Expected error for chart not found, but did not get any errors") 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` { } 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) 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", g, WithChartVersion("0.1.0")); err == nil {
t.Errorf("Expected error for chart not found, but did not get any errors") 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` { } 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) 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", g); err == nil {
t.Errorf("Expected error for no chart URLs available, but did not get any errors") 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` { } 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) t.Errorf("Expected error for chart not found, but got a different error (%v)", err)

Loading…
Cancel
Save