fix downloader command

Signed-off-by: George Jenkins <gvjenkins@gmail.com>
pull/31080/head
George Jenkins 2 months ago
parent ac0fcef641
commit 3f16ac0882

@ -16,9 +16,5 @@ limitations under the License.
package subprocess // import "helm.sh/helm/v4/internal/plugins/runtimes/subprocess"
func IsDownloader(p *Plugin) bool {
if p.Metadata == nil {
return false
}
return len(p.Metadata.Downloaders) > 0
return p.Metadata != nil && len(p.Metadata.Downloaders) > 0
}

@ -24,6 +24,7 @@ import (
"path/filepath"
"regexp"
"runtime"
"slices"
"strings"
"unicode"
@ -382,7 +383,8 @@ type pluginExec struct {
env []string
}
func convertInputGetterInputV1(p *Plugin, command string, argvBase []string, msg schema.GetterInputV1) (pluginExec, error) {
func convertInputGetterInputV1(p *Plugin, msg schema.GetterInputV1) (pluginExec, error) {
tmpDir, err := os.MkdirTemp(os.TempDir(), fmt.Sprintf("helm-plugin-%s-", p.Metadata.Name))
if err != nil {
return pluginExec{}, fmt.Errorf("failed to create temporary directory: %w", err)
@ -417,12 +419,28 @@ func convertInputGetterInputV1(p *Plugin, command string, argvBase []string, msg
return pluginExec{}, err
}
getDownloaderCommand := func(p *Plugin, protocol string) *Downloaders {
for _, d := range p.Metadata.Downloaders {
if slices.Contains(d.Protocols, protocol) {
return &d
}
}
return nil
}
d := getDownloaderCommand(p, msg.Scheme)
if d == nil {
return pluginExec{}, fmt.Errorf("unable to match downloader scheme: %q", msg.Scheme)
}
commands := strings.Split(d.Command, " ")
argv := append(
argvBase,
commands[1:],
certFile,
keyFile,
caFile,
msg.URL)
msg.Href)
env := append(
os.Environ(),
@ -431,24 +449,18 @@ func convertInputGetterInputV1(p *Plugin, command string, argvBase []string, msg
fmt.Sprintf("HELM_PLUGIN_PASS_CREDENTIALS_ALL=%t", msg.Options.PassCredentialsAll))
return pluginExec{
command: command,
command: commands[0],
argv: argv,
env: env,
}, nil
}
func convertInput(p *Plugin, input *plugins.Input) (pluginExec, error) {
command, argv, err := p.PrepareCommand([]string{})
if err != nil {
return pluginExec{}, fmt.Errorf("failed to prepare command for plugin %q: %w", p.Dir, err)
}
switch inputMsg := input.Message.(type) {
case schema.GetterInputV1:
return convertInputGetterInputV1(
p,
command,
argv,
inputMsg)
}

@ -40,7 +40,8 @@ type GetterOptionsV1 struct {
}
type GetterInputV1 struct {
URL string `json:"url"`
Href string `json:"href"`
Scheme string `json:"scheme"`
Options GetterOptionsV1 `json:"options"`
}

@ -125,7 +125,7 @@ type getterPlugin struct {
plg plugins.Plugin
}
func (g *getterPlugin) Get(url string, options ...Option) (*bytes.Buffer, error) {
func (g *getterPlugin) Get(href string, options ...Option) (*bytes.Buffer, error) {
opts, err := convertOptions(g.options, options)
if err != nil {
@ -134,7 +134,7 @@ func (g *getterPlugin) Get(url string, options ...Option) (*bytes.Buffer, error)
input := &plugins.Input{
Message: schema.GetterInputV1{
URL: url,
Href: href,
Options: opts,
},
}

Loading…
Cancel
Save