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" package subprocess // import "helm.sh/helm/v4/internal/plugins/runtimes/subprocess"
func IsDownloader(p *Plugin) bool { func IsDownloader(p *Plugin) bool {
if p.Metadata == nil { return p.Metadata != nil && len(p.Metadata.Downloaders) > 0
return false
}
return len(p.Metadata.Downloaders) > 0
} }

@ -24,6 +24,7 @@ import (
"path/filepath" "path/filepath"
"regexp" "regexp"
"runtime" "runtime"
"slices"
"strings" "strings"
"unicode" "unicode"
@ -382,7 +383,8 @@ type pluginExec struct {
env []string 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)) tmpDir, err := os.MkdirTemp(os.TempDir(), fmt.Sprintf("helm-plugin-%s-", p.Metadata.Name))
if err != nil { if err != nil {
return pluginExec{}, fmt.Errorf("failed to create temporary directory: %w", err) 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 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( argv := append(
argvBase, commands[1:],
certFile, certFile,
keyFile, keyFile,
caFile, caFile,
msg.URL) msg.Href)
env := append( env := append(
os.Environ(), 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)) fmt.Sprintf("HELM_PLUGIN_PASS_CREDENTIALS_ALL=%t", msg.Options.PassCredentialsAll))
return pluginExec{ return pluginExec{
command: command, command: commands[0],
argv: argv, argv: argv,
env: env, env: env,
}, nil }, nil
} }
func convertInput(p *Plugin, input *plugins.Input) (pluginExec, error) { 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) { switch inputMsg := input.Message.(type) {
case schema.GetterInputV1: case schema.GetterInputV1:
return convertInputGetterInputV1( return convertInputGetterInputV1(
p, p,
command,
argv,
inputMsg) inputMsg)
} }

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

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

Loading…
Cancel
Save