Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion api/internal/plugins/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"path/filepath"
"plugin"
"reflect"
"runtime"
"strings"

"github.com/pkg/errors"
Expand Down Expand Up @@ -177,7 +178,8 @@ func (l *Loader) loadPlugin(res *resource.Resource) (resmap.Configurable, error)

func (l *Loader) loadExecOrGoPlugin(resId resid.ResId) (resmap.Configurable, error) {
// First try to load the plugin as an executable.
p := execplugin.NewExecPlugin(l.absolutePluginPath(resId))
path, _ := lookForExecutable(l.absolutePluginPath(resId))
p := execplugin.NewExecPlugin(path)
err := p.ErrIfNotExecutable()
if err == nil {
return p, nil
Expand Down Expand Up @@ -244,3 +246,21 @@ func copyPlugin(c resmap.Configurable) resmap.Configurable {
newNamed := newIndirect.Interface()
return newNamed.(resmap.Configurable)
}

func lookForExecutable(partialPath string) (fullPath string, err error) {
if runtime.GOOS != "windows" {
return partialPath, nil
}

possibleWindowsSuffixes := []string{"exe", "bat", "ps1"}

for _, possibleWindowsSuffix := range possibleWindowsSuffixes {
fullPath := fmt.Sprintf("%s.%s", partialPath, possibleWindowsSuffix)
_, err := os.Stat(fullPath)
if err == nil {
return fullPath, nil
}
}

return "", fmt.Errorf("no possible excutable found, partial path: %v tried suffixes: %v", partialPath, possibleWindowsSuffixes)
}