From 3f16ac0882cbd4a2ef022df539d155ef9d6d711d Mon Sep 17 00:00:00 2001 From: George Jenkins Date: Wed, 23 Jul 2025 18:26:12 -0700 Subject: [PATCH] fix downloader command Signed-off-by: George Jenkins --- .../plugins/runtimes/subprocess/downloader.go | 6 +--- .../plugins/runtimes/subprocess/plugin.go | 32 +++++++++++++------ internal/plugins/schema/getter.go | 3 +- pkg/getter/plugingetter.go | 4 +-- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/internal/plugins/runtimes/subprocess/downloader.go b/internal/plugins/runtimes/subprocess/downloader.go index fbe621eac..99ed9b1b6 100644 --- a/internal/plugins/runtimes/subprocess/downloader.go +++ b/internal/plugins/runtimes/subprocess/downloader.go @@ -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 } diff --git a/internal/plugins/runtimes/subprocess/plugin.go b/internal/plugins/runtimes/subprocess/plugin.go index e7b8e6b50..70771f8fe 100644 --- a/internal/plugins/runtimes/subprocess/plugin.go +++ b/internal/plugins/runtimes/subprocess/plugin.go @@ -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) } diff --git a/internal/plugins/schema/getter.go b/internal/plugins/schema/getter.go index 8f59020dd..b9c8c2557 100644 --- a/internal/plugins/schema/getter.go +++ b/internal/plugins/schema/getter.go @@ -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"` } diff --git a/pkg/getter/plugingetter.go b/pkg/getter/plugingetter.go index 658553668..62af1d94e 100644 --- a/pkg/getter/plugingetter.go +++ b/pkg/getter/plugingetter.go @@ -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, }, }