mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 18:01:01 -06:00
remove restriction on unversioned plugins
Discover unversioned plugins regarless of location.
This commit is contained in:
parent
270eedd4b8
commit
6faace287d
@ -4,15 +4,9 @@ import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Store the machine name for excluding legacy plugins in new-style directories.
|
||||
// This is a var to override in testing
|
||||
var machineName = runtime.GOOS + "_" + runtime.GOARCH
|
||||
|
||||
// FindPlugins looks in the given directories for files whose filenames
|
||||
// suggest that they are plugins of the given kind (e.g. "provider") and
|
||||
// returns a PluginMetaSet representing the discovered potential-plugins.
|
||||
@ -48,8 +42,6 @@ func FindPluginPaths(kind string, dirs []string) []string {
|
||||
}
|
||||
|
||||
func findPluginPaths(kind string, dirs []string) []string {
|
||||
hasMachineSuffix := regexp.MustCompile(machineName + "/?").MatchString
|
||||
|
||||
prefix := "terraform-" + kind + "-"
|
||||
|
||||
ret := make([]string, 0, len(dirs))
|
||||
@ -63,8 +55,6 @@ func findPluginPaths(kind string, dirs []string) []string {
|
||||
|
||||
log.Printf("[DEBUG] checking for plugins in %q", dir)
|
||||
|
||||
isMachineDir := hasMachineSuffix(dir)
|
||||
|
||||
for _, item := range items {
|
||||
fullName := item.Name()
|
||||
|
||||
@ -86,18 +76,16 @@ func findPluginPaths(kind string, dirs []string) []string {
|
||||
continue
|
||||
}
|
||||
|
||||
if !isMachineDir {
|
||||
// Legacy style with files directly in the base directory
|
||||
absPath, err := filepath.Abs(filepath.Join(dir, fullName))
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] plugin filepath error: %s", err)
|
||||
continue
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] found legacy plugin %q", fullName)
|
||||
|
||||
ret = append(ret, filepath.Clean(absPath))
|
||||
// Legacy style with files directly in the base directory
|
||||
absPath, err := filepath.Abs(filepath.Join(dir, fullName))
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] plugin filepath error: %s", err)
|
||||
continue
|
||||
}
|
||||
|
||||
log.Printf("[WARNING] found legacy plugin %q", fullName)
|
||||
|
||||
ret = append(ret, filepath.Clean(absPath))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,10 +7,6 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func init() {
|
||||
machineName = "mockos_mockarch"
|
||||
}
|
||||
|
||||
func TestFindPluginPaths(t *testing.T) {
|
||||
got := findPluginPaths(
|
||||
"foo",
|
||||
@ -24,6 +20,8 @@ func TestFindPluginPaths(t *testing.T) {
|
||||
want := []string{
|
||||
filepath.Join("test-fixtures", "current-style-plugins", "mockos_mockarch", "terraform-foo-bar_v0.0.1"),
|
||||
filepath.Join("test-fixtures", "current-style-plugins", "mockos_mockarch", "terraform-foo-bar_v1.0.0"),
|
||||
// un-versioned plugins are still picked up, even in current-style paths
|
||||
filepath.Join("test-fixtures", "current-style-plugins", "mockos_mockarch", "terraform-foo-missing-version"),
|
||||
filepath.Join("test-fixtures", "legacy-style-plugins", "terraform-foo-bar"),
|
||||
filepath.Join("test-fixtures", "legacy-style-plugins", "terraform-foo-baz"),
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user