From 6faace287db4bcd74c3a3b52e4bf4f8668f08c01 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Fri, 16 Jun 2017 15:28:48 -0400 Subject: [PATCH] remove restriction on unversioned plugins Discover unversioned plugins regarless of location. --- plugin/discovery/find.go | 28 ++++++++-------------------- plugin/discovery/find_test.go | 6 ++---- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/plugin/discovery/find.go b/plugin/discovery/find.go index e42bb49f68..71db22a4f1 100644 --- a/plugin/discovery/find.go +++ b/plugin/discovery/find.go @@ -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 - } + // 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) + log.Printf("[WARNING] found legacy plugin %q", fullName) - ret = append(ret, filepath.Clean(absPath)) - } + ret = append(ret, filepath.Clean(absPath)) } } diff --git a/plugin/discovery/find_test.go b/plugin/discovery/find_test.go index 58e2946d18..7115e28722 100644 --- a/plugin/discovery/find_test.go +++ b/plugin/discovery/find_test.go @@ -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"), }