pass username and password to pluginGetter

Signed-off-by: xh4n3 <xyn1016@gmail.com>
pull/6110/head
xh4n3 6 years ago
parent 2f16e0ed26
commit b097151947

@ -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,

@ -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.

Loading…
Cancel
Save