From 5d45e2c3f288b4636340cd14f325fe3908e4c8e2 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Tue, 20 Jul 2021 15:57:16 -0700 Subject: [PATCH] Properly detect valid components before registering plugins --- internal/runner/operation.go | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/internal/runner/operation.go b/internal/runner/operation.go index 8608df932..c5b70b1a7 100644 --- a/internal/runner/operation.go +++ b/internal/runner/operation.go @@ -5,12 +5,14 @@ import ( "fmt" "path/filepath" + "github.com/hashicorp/go-argmapper" "github.com/hashicorp/go-hclog" "github.com/hashicorp/go-multierror" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "github.com/hashicorp/vagrant-plugin-sdk/component" + "github.com/hashicorp/vagrant-plugin-sdk/internal-shared/dynamic" "github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk" "github.com/hashicorp/vagrant-plugin-sdk/terminal" configpkg "github.com/hashicorp/vagrant/internal/config" @@ -32,13 +34,26 @@ func (r *Runner) LoadPlugins(cfg *configpkg.Config) error { cfg.TrackRubyPlugin(p.Name, []interface{}{p.Type}) } - components := []interface{}{} - for typ, _ := range plugin.BaseFactories { - components = append(components, typ) - } // Now lets load builtin plugins for name, options := range plugin.Builtins { r.logger.Info("loading builtin plugin " + name) + f := plugin.BuiltinFactory(name, component.PluginInfoType) + bp, err := dynamic.CallFunc(f, (**plugin.Instance)(nil), []*argmapper.Func{}, + argmapper.Typed(r.logger)) + if err != nil { + panic(err) + } + defer bp.(*plugin.Instance).Close() + p, ok := bp.(*plugin.Instance).Component.(component.PluginInfo) + if !ok { + panic("failed to convert instance to plugin info component") + } + typs := p.ComponentTypes() + r.logger.Info("valid component types for builtin plugin", "name", name, "types", typs) + cmps := []interface{}{} + for _, t := range typs { + cmps = append(cmps, t) + } if plugin.IN_PROCESS_PLUGINS { if err := r.builtinPlugins.Add(name, options...); err != nil { @@ -46,9 +61,14 @@ func (r *Runner) LoadPlugins(cfg *configpkg.Config) error { } } - cfg.TrackBuiltinPlugin(name, components) + cfg.TrackBuiltinPlugin(name, cmps) } + // TODO(spox): fix this loading + // if err == nil { + // cfg.TrackPlugin("custom-host", []interface{}{component.HostType}) + // } + return nil }