From b0971519476b96cef2eec598c248286d484be44d Mon Sep 17 00:00:00 2001 From: xh4n3 Date: Mon, 12 Aug 2019 13:49:06 +0800 Subject: [PATCH] pass username and password to pluginGetter Signed-off-by: xh4n3 --- pkg/getter/plugingetter.go | 19 +++++++++++++++---- pkg/repo/chartrepo.go | 3 +++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/pkg/getter/plugingetter.go b/pkg/getter/plugingetter.go index c918aa744..bcb259a1d 100644 --- a/pkg/getter/plugingetter.go +++ b/pkg/getter/plugingetter.go @@ -51,22 +51,33 @@ func collectPlugins(settings environment.EnvSettings) (Providers, error) { return result, nil } -// pluginGetter is a generic type to invoke custom downloaders, +// PluginGetter is a generic type to invoke custom downloaders, // implemented in plugins. -type pluginGetter struct { +type PluginGetter struct { command string + username, password string certFile, keyFile, cAFile string settings environment.EnvSettings name string base string } +//SetCredentials sets the credentials for the getter +func (p *PluginGetter) SetCredentials(username, password string) { + p.username = username + p.password = password +} + // Get runs downloader plugin command -func (p *pluginGetter) Get(href string) (*bytes.Buffer, error) { +func (p *PluginGetter) Get(href string) (*bytes.Buffer, error) { commands := strings.Split(p.command, " ") argv := append(commands[1:], p.certFile, p.keyFile, p.cAFile, href) prog := exec.Command(filepath.Join(p.base, commands[0]), argv...) plugin.SetupPluginEnv(p.settings, p.name, p.base) + if p.username != "" && p.password != "" { + os.Setenv("HELM_REPO_USERNAME", p.username) + os.Setenv("HELM_REPO_PASSWORD", p.password) + } prog.Env = os.Environ() buf := bytes.NewBuffer(nil) prog.Stdout = buf @@ -85,7 +96,7 @@ func (p *pluginGetter) Get(href string) (*bytes.Buffer, error) { // newPluginGetter constructs a valid plugin getter func newPluginGetter(command string, settings environment.EnvSettings, name, base string) Constructor { return func(URL, CertFile, KeyFile, CAFile string) (Getter, error) { - result := &pluginGetter{ + result := &PluginGetter{ command: command, certFile: CertFile, keyFile: KeyFile, diff --git a/pkg/repo/chartrepo.go b/pkg/repo/chartrepo.go index c512c5b7e..e5123fa74 100644 --- a/pkg/repo/chartrepo.go +++ b/pkg/repo/chartrepo.go @@ -154,6 +154,9 @@ func (r *ChartRepository) setCredentials() { if t, ok := r.Client.(*getter.HttpGetter); ok { t.SetCredentials(r.Config.Username, r.Config.Password) } + if t, ok := r.Client.(*getter.PluginGetter); ok { + t.SetCredentials(r.Config.Username, r.Config.Password) + } } // Index generates an index for the chart repository and writes an index.yaml file.