remove restriction on unversioned plugins

Discover unversioned plugins regarless of location.
This commit is contained in:
James Bardin 2017-06-16 15:28:48 -04:00
parent 270eedd4b8
commit 6faace287d
2 changed files with 11 additions and 25 deletions

View File

@ -4,15 +4,9 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"path/filepath" "path/filepath"
"regexp"
"runtime"
"strings" "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 // FindPlugins looks in the given directories for files whose filenames
// suggest that they are plugins of the given kind (e.g. "provider") and // suggest that they are plugins of the given kind (e.g. "provider") and
// returns a PluginMetaSet representing the discovered potential-plugins. // 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 { func findPluginPaths(kind string, dirs []string) []string {
hasMachineSuffix := regexp.MustCompile(machineName + "/?").MatchString
prefix := "terraform-" + kind + "-" prefix := "terraform-" + kind + "-"
ret := make([]string, 0, len(dirs)) 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) log.Printf("[DEBUG] checking for plugins in %q", dir)
isMachineDir := hasMachineSuffix(dir)
for _, item := range items { for _, item := range items {
fullName := item.Name() fullName := item.Name()
@ -86,18 +76,16 @@ func findPluginPaths(kind string, dirs []string) []string {
continue continue
} }
if !isMachineDir { // Legacy style with files directly in the base directory
// Legacy style with files directly in the base directory absPath, err := filepath.Abs(filepath.Join(dir, fullName))
absPath, err := filepath.Abs(filepath.Join(dir, fullName)) if err != nil {
if err != nil { log.Printf("[ERROR] plugin filepath error: %s", err)
log.Printf("[ERROR] plugin filepath error: %s", err) continue
continue
}
log.Printf("[DEBUG] found legacy plugin %q", fullName)
ret = append(ret, filepath.Clean(absPath))
} }
log.Printf("[WARNING] found legacy plugin %q", fullName)
ret = append(ret, filepath.Clean(absPath))
} }
} }

View File

@ -7,10 +7,6 @@ import (
"testing" "testing"
) )
func init() {
machineName = "mockos_mockarch"
}
func TestFindPluginPaths(t *testing.T) { func TestFindPluginPaths(t *testing.T) {
got := findPluginPaths( got := findPluginPaths(
"foo", "foo",
@ -24,6 +20,8 @@ func TestFindPluginPaths(t *testing.T) {
want := []string{ 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_v0.0.1"),
filepath.Join("test-fixtures", "current-style-plugins", "mockos_mockarch", "terraform-foo-bar_v1.0.0"), 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-bar"),
filepath.Join("test-fixtures", "legacy-style-plugins", "terraform-foo-baz"), filepath.Join("test-fixtures", "legacy-style-plugins", "terraform-foo-baz"),
} }