diff --git a/internal/client/basis.go b/internal/client/basis.go index b7df3720e91..38d86be178b 100644 --- a/internal/client/basis.go +++ b/internal/client/basis.go @@ -12,6 +12,7 @@ import ( "github.com/hashicorp/vagrant-plugin-sdk/config" "github.com/hashicorp/vagrant-plugin-sdk/helper/path" + "github.com/hashicorp/vagrant-plugin-sdk/helper/paths" "github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk" "github.com/hashicorp/vagrant-plugin-sdk/terminal" "github.com/hashicorp/vagrant/internal/server/proto/vagrant_server" @@ -44,9 +45,14 @@ func (b *Basis) DetectProject() (p *Project, err error) { if err != nil && status.Code(err) != codes.NotFound { return } + dataPath, err := paths.VagrantData() + if err != nil { + return + } if err == nil { p.vagrantfile = v + b.client.LoadLocalProjectPlugins(dataPath.Join(b.basis.Name, "project", p.project.Name).String()) return } @@ -64,7 +70,7 @@ func (b *Basis) DetectProject() (p *Project, err error) { return } - return &Project{ + projectClient := &Project{ basis: b, client: b.client, ctx: b.ctx, @@ -73,7 +79,10 @@ func (b *Basis) DetectProject() (p *Project, err error) { ui: b.ui, vagrant: b.vagrant, vagrantfile: v, - }, nil + } + b.client.LoadLocalProjectPlugins(dataPath.Join(b.basis.Name, "project", projectClient.project.Name).String()) + + return projectClient, nil } func (b *Basis) LoadProject(n string) (*Project, error) { diff --git a/internal/client/client.go b/internal/client/client.go index eed9f6d5c21..1f440855822 100644 --- a/internal/client/client.go +++ b/internal/client/client.go @@ -201,6 +201,10 @@ func (c *Client) UI() terminal.UI { return c.ui } +func (c *Client) LoadLocalProjectPlugins(path string) error { + return c.runner.LoadLocalProjectPlugins(path) +} + type clientConfig struct { connectOpts []serverclient.ConnectOption } diff --git a/internal/plugin/manager.go b/internal/plugin/manager.go index 36a10dda19b..f3f04457068 100644 --- a/internal/plugin/manager.go +++ b/internal/plugin/manager.go @@ -22,6 +22,7 @@ import ( "github.com/hashicorp/vagrant-plugin-sdk/internal-shared/cacher" "github.com/hashicorp/vagrant-plugin-sdk/internal-shared/cleanup" "github.com/hashicorp/vagrant-plugin-sdk/internal-shared/protomappers" + "github.com/hashicorp/vagrant/internal/server/proto/ruby_vagrant" "github.com/hashicorp/vagrant/internal/serverclient" ) @@ -137,7 +138,32 @@ func (m *Manager) LegacyEnabled() bool { // Load legacy Ruby based Vagrant plugins using a // running Vagrant runtime -func (m *Manager) LoadLegacyPlugins( +func (m *Manager) LoadLocalLegacyPlugins( + c *serverclient.RubyVagrantClient, // Client connection to the Legacy Ruby Vagrant server + r plugin.ClientProtocol, // go-plugin client connection to Ruby plugin server + path string, // project plugin path +) (err error) { + m.m.Lock() + defer m.m.Unlock() + + m.logger.Trace("loading ruby based legacy vagrant plugins") + + plugins, err := c.GetLocalPlugins(path) + if err != nil { + m.logger.Trace("failed to fetch ruby based legacy vagrant plugin information", + "error", err, + ) + + return + } + + err = m.RegisterLegacyPlugins(c, r, plugins) + return +} + +// Load legacy Ruby based Vagrant plugins using a +// running Vagrant runtime +func (m *Manager) LoadGlobalLegacyPlugins( c *serverclient.RubyVagrantClient, // Client connection to the Legacy Ruby Vagrant server r plugin.ClientProtocol, // go-plugin client connection to Ruby plugin server ) (err error) { @@ -151,7 +177,7 @@ func (m *Manager) LoadLegacyPlugins( m.logger.Trace("loading ruby based legacy vagrant plugins") - plugins, err := c.GetPlugins() + plugins, err := c.GetGlobalPlugins() if err != nil { m.logger.Trace("failed to fetch ruby based legacy vagrant plugin information", "error", err, @@ -159,7 +185,15 @@ func (m *Manager) LoadLegacyPlugins( return } + err = m.RegisterLegacyPlugins(c, r, plugins) + return +} +func (m *Manager) RegisterLegacyPlugins( + c *serverclient.RubyVagrantClient, + r plugin.ClientProtocol, + plugins []*ruby_vagrant.Plugin, +) (err error) { for _, p := range plugins { m.logger.Info("loading ruby based legacy vagrant plugin", "name", p.Name, diff --git a/internal/runner/runner.go b/internal/runner/runner.go index 85d4b8ee2a2..5fb001bb83d 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -125,7 +125,7 @@ func New(opts ...Option) (*Runner, error) { return nil, err } - if err := runner.plugins.LoadLegacyPlugins( + if err := runner.plugins.LoadGlobalLegacyPlugins( runner.vagrantRubyClient, runner.vagrantRubyRuntime); err != nil { return nil, err } @@ -156,6 +156,13 @@ func New(opts ...Option) (*Runner, error) { return runner, nil } +func (r *Runner) LoadLocalProjectPlugins(path string) error { + // TODO: should this check if the runner is local? + err := r.plugins.LoadLocalLegacyPlugins( + r.vagrantRubyClient, r.vagrantRubyRuntime, path) + return err +} + // Id returns the runner ID. func (r *Runner) Id() string { return r.id diff --git a/internal/server/proto/ruby_vagrant/ruby-server.pb.go b/internal/server/proto/ruby_vagrant/ruby-server.pb.go index 81254fe78b8..bf824ea707f 100644 --- a/internal/server/proto/ruby_vagrant/ruby-server.pb.go +++ b/internal/server/proto/ruby_vagrant/ruby-server.pb.go @@ -588,51 +588,56 @@ var file_proto_ruby_vagrant_ruby_server_proto_rawDesc = []byte{ 0x67, 0x2e, 0x52, 0x61, 0x77, 0x52, 0x75, 0x62, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x52, 0x05, 0x73, 0x75, 0x62, 0x76, 0x6d, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, - 0x72, 0x32, 0xf6, 0x04, 0x0a, 0x0b, 0x52, 0x75, 0x62, 0x79, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, - 0x74, 0x12, 0x59, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x73, 0x12, - 0x24, 0x2e, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, 0x67, 0x72, - 0x61, 0x6e, 0x74, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x73, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, - 0x70, 0x2e, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x6c, 0x75, - 0x67, 0x69, 0x6e, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x6b, 0x0a, 0x10, - 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, - 0x12, 0x2a, 0x2e, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, 0x67, - 0x72, 0x61, 0x6e, 0x74, 0x2e, 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, - 0x74, 0x66, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2b, 0x2e, 0x68, - 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, - 0x2e, 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, - 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x73, 0x0a, 0x14, 0x50, 0x61, 0x72, - 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x50, 0x72, 0x6f, - 0x63, 0x12, 0x2e, 0x2e, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, - 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2e, 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, - 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x50, 0x72, 0x6f, 0x63, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x1a, 0x2b, 0x2e, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, - 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2e, 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, - 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x75, - 0x0a, 0x15, 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, - 0x6c, 0x65, 0x53, 0x75, 0x62, 0x76, 0x6d, 0x12, 0x2f, 0x2e, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, - 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2e, 0x50, 0x61, 0x72, 0x73, - 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x53, 0x75, 0x62, 0x76, - 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2b, 0x2e, 0x68, 0x61, 0x73, 0x68, 0x69, + 0x72, 0x32, 0xce, 0x05, 0x0a, 0x0b, 0x52, 0x75, 0x62, 0x79, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, + 0x74, 0x12, 0x5e, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x50, 0x6c, 0x75, + 0x67, 0x69, 0x6e, 0x73, 0x12, 0x24, 0x2e, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, + 0x2e, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x6c, 0x75, 0x67, + 0x69, 0x6e, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x68, 0x61, 0x73, + 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2e, 0x47, + 0x65, 0x74, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x51, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x50, 0x6c, + 0x75, 0x67, 0x69, 0x6e, 0x73, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x25, 0x2e, + 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, + 0x74, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x73, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x6b, 0x0a, 0x10, 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, + 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x12, 0x2a, 0x2e, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2e, 0x50, 0x61, 0x72, - 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x7b, 0x0a, 0x18, 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, - 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, - 0x72, 0x12, 0x32, 0x2e, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, - 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2e, 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, - 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2b, 0x2e, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, - 0x70, 0x2e, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2e, 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, - 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x12, 0x36, 0x0a, 0x04, 0x53, 0x74, 0x6f, 0x70, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, + 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2b, 0x2e, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, + 0x2e, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2e, 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, + 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x73, 0x0a, 0x14, 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, + 0x74, 0x66, 0x69, 0x6c, 0x65, 0x50, 0x72, 0x6f, 0x63, 0x12, 0x2e, 0x2e, 0x68, 0x61, 0x73, 0x68, + 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2e, 0x50, 0x61, + 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x50, 0x72, + 0x6f, 0x63, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2b, 0x2e, 0x68, 0x61, 0x73, 0x68, + 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2e, 0x50, 0x61, + 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x75, 0x0a, 0x15, 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, + 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x53, 0x75, 0x62, 0x76, 0x6d, 0x12, + 0x2f, 0x2e, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, 0x67, 0x72, + 0x61, 0x6e, 0x74, 0x2e, 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, + 0x66, 0x69, 0x6c, 0x65, 0x53, 0x75, 0x62, 0x76, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x2b, 0x2e, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, 0x67, + 0x72, 0x61, 0x6e, 0x74, 0x2e, 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, + 0x74, 0x66, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x7b, 0x0a, + 0x18, 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, + 0x65, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x12, 0x32, 0x2e, 0x68, 0x61, 0x73, 0x68, + 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2e, 0x50, 0x61, + 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x50, 0x72, + 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2b, 0x2e, + 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, + 0x74, 0x2e, 0x50, 0x61, 0x72, 0x73, 0x65, 0x56, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x66, 0x69, + 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x36, 0x0a, 0x04, 0x53, 0x74, + 0x6f, 0x70, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, - 0x74, 0x79, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x42, 0x41, 0x5a, 0x3f, 0x67, 0x69, - 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, - 0x72, 0x70, 0x2f, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, - 0x6e, 0x61, 0x6c, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x2f, 0x72, 0x75, 0x62, 0x79, 0x5f, 0x76, 0x61, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x74, 0x79, 0x42, 0x41, 0x5a, 0x3f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, + 0x2f, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2f, 0x76, 0x61, 0x67, 0x72, 0x61, + 0x6e, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x73, 0x65, 0x72, 0x76, + 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x72, 0x75, 0x62, 0x79, 0x5f, 0x76, 0x61, + 0x67, 0x72, 0x61, 0x6e, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -673,20 +678,22 @@ var file_proto_ruby_vagrant_ruby_server_proto_depIdxs = []int32{ 11, // 4: hashicorp.vagrant.ParseVagrantfileResponse.data:type_name -> hashicorp.vagrant.sdk.Args.Hash 12, // 5: hashicorp.vagrant.ParseVagrantfileSubvmRequest.subvm:type_name -> hashicorp.vagrant.sdk.Config.RawRubyValue 12, // 6: hashicorp.vagrant.ParseVagrantfileProviderRequest.subvm:type_name -> hashicorp.vagrant.sdk.Config.RawRubyValue - 1, // 7: hashicorp.vagrant.RubyVagrant.GetPlugins:input_type -> hashicorp.vagrant.GetPluginsRequest - 4, // 8: hashicorp.vagrant.RubyVagrant.ParseVagrantfile:input_type -> hashicorp.vagrant.ParseVagrantfileRequest - 5, // 9: hashicorp.vagrant.RubyVagrant.ParseVagrantfileProc:input_type -> hashicorp.vagrant.ParseVagrantfileProcRequest - 7, // 10: hashicorp.vagrant.RubyVagrant.ParseVagrantfileSubvm:input_type -> hashicorp.vagrant.ParseVagrantfileSubvmRequest - 8, // 11: hashicorp.vagrant.RubyVagrant.ParseVagrantfileProvider:input_type -> hashicorp.vagrant.ParseVagrantfileProviderRequest - 13, // 12: hashicorp.vagrant.RubyVagrant.Stop:input_type -> google.protobuf.Empty - 2, // 13: hashicorp.vagrant.RubyVagrant.GetPlugins:output_type -> hashicorp.vagrant.GetPluginsResponse - 6, // 14: hashicorp.vagrant.RubyVagrant.ParseVagrantfile:output_type -> hashicorp.vagrant.ParseVagrantfileResponse - 6, // 15: hashicorp.vagrant.RubyVagrant.ParseVagrantfileProc:output_type -> hashicorp.vagrant.ParseVagrantfileResponse - 6, // 16: hashicorp.vagrant.RubyVagrant.ParseVagrantfileSubvm:output_type -> hashicorp.vagrant.ParseVagrantfileResponse - 6, // 17: hashicorp.vagrant.RubyVagrant.ParseVagrantfileProvider:output_type -> hashicorp.vagrant.ParseVagrantfileResponse - 13, // 18: hashicorp.vagrant.RubyVagrant.Stop:output_type -> google.protobuf.Empty - 13, // [13:19] is the sub-list for method output_type - 7, // [7:13] is the sub-list for method input_type + 1, // 7: hashicorp.vagrant.RubyVagrant.GetLocalPlugins:input_type -> hashicorp.vagrant.GetPluginsRequest + 13, // 8: hashicorp.vagrant.RubyVagrant.GetGlobalPlugins:input_type -> google.protobuf.Empty + 4, // 9: hashicorp.vagrant.RubyVagrant.ParseVagrantfile:input_type -> hashicorp.vagrant.ParseVagrantfileRequest + 5, // 10: hashicorp.vagrant.RubyVagrant.ParseVagrantfileProc:input_type -> hashicorp.vagrant.ParseVagrantfileProcRequest + 7, // 11: hashicorp.vagrant.RubyVagrant.ParseVagrantfileSubvm:input_type -> hashicorp.vagrant.ParseVagrantfileSubvmRequest + 8, // 12: hashicorp.vagrant.RubyVagrant.ParseVagrantfileProvider:input_type -> hashicorp.vagrant.ParseVagrantfileProviderRequest + 13, // 13: hashicorp.vagrant.RubyVagrant.Stop:input_type -> google.protobuf.Empty + 2, // 14: hashicorp.vagrant.RubyVagrant.GetLocalPlugins:output_type -> hashicorp.vagrant.GetPluginsResponse + 2, // 15: hashicorp.vagrant.RubyVagrant.GetGlobalPlugins:output_type -> hashicorp.vagrant.GetPluginsResponse + 6, // 16: hashicorp.vagrant.RubyVagrant.ParseVagrantfile:output_type -> hashicorp.vagrant.ParseVagrantfileResponse + 6, // 17: hashicorp.vagrant.RubyVagrant.ParseVagrantfileProc:output_type -> hashicorp.vagrant.ParseVagrantfileResponse + 6, // 18: hashicorp.vagrant.RubyVagrant.ParseVagrantfileSubvm:output_type -> hashicorp.vagrant.ParseVagrantfileResponse + 6, // 19: hashicorp.vagrant.RubyVagrant.ParseVagrantfileProvider:output_type -> hashicorp.vagrant.ParseVagrantfileResponse + 13, // 20: hashicorp.vagrant.RubyVagrant.Stop:output_type -> google.protobuf.Empty + 14, // [14:21] is the sub-list for method output_type + 7, // [7:14] is the sub-list for method input_type 7, // [7:7] is the sub-list for extension type_name 7, // [7:7] is the sub-list for extension extendee 0, // [0:7] is the sub-list for field type_name diff --git a/internal/server/proto/ruby_vagrant/ruby-server.proto b/internal/server/proto/ruby_vagrant/ruby-server.proto index d0f7a31610d..f34286f0625 100644 --- a/internal/server/proto/ruby_vagrant/ruby-server.proto +++ b/internal/server/proto/ruby_vagrant/ruby-server.proto @@ -13,7 +13,8 @@ import "plugin.proto"; // The service that is implemented for the server backend. service RubyVagrant { // Gets available ruby plugins - rpc GetPlugins(GetPluginsRequest) returns (GetPluginsResponse); + rpc GetLocalPlugins(GetPluginsRequest) returns (GetPluginsResponse); + rpc GetGlobalPlugins(google.protobuf.Empty) returns (GetPluginsResponse); rpc ParseVagrantfile(ParseVagrantfileRequest) returns (ParseVagrantfileResponse); rpc ParseVagrantfileProc(ParseVagrantfileProcRequest) returns (ParseVagrantfileResponse); rpc ParseVagrantfileSubvm(ParseVagrantfileSubvmRequest) returns (ParseVagrantfileResponse); diff --git a/internal/server/proto/ruby_vagrant/ruby-server_grpc.pb.go b/internal/server/proto/ruby_vagrant/ruby-server_grpc.pb.go index 8a1240925b3..ea63fe356ad 100644 --- a/internal/server/proto/ruby_vagrant/ruby-server_grpc.pb.go +++ b/internal/server/proto/ruby_vagrant/ruby-server_grpc.pb.go @@ -20,7 +20,8 @@ const _ = grpc.SupportPackageIsVersion7 // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. type RubyVagrantClient interface { // Gets available ruby plugins - GetPlugins(ctx context.Context, in *GetPluginsRequest, opts ...grpc.CallOption) (*GetPluginsResponse, error) + GetLocalPlugins(ctx context.Context, in *GetPluginsRequest, opts ...grpc.CallOption) (*GetPluginsResponse, error) + GetGlobalPlugins(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*GetPluginsResponse, error) ParseVagrantfile(ctx context.Context, in *ParseVagrantfileRequest, opts ...grpc.CallOption) (*ParseVagrantfileResponse, error) ParseVagrantfileProc(ctx context.Context, in *ParseVagrantfileProcRequest, opts ...grpc.CallOption) (*ParseVagrantfileResponse, error) ParseVagrantfileSubvm(ctx context.Context, in *ParseVagrantfileSubvmRequest, opts ...grpc.CallOption) (*ParseVagrantfileResponse, error) @@ -36,9 +37,18 @@ func NewRubyVagrantClient(cc grpc.ClientConnInterface) RubyVagrantClient { return &rubyVagrantClient{cc} } -func (c *rubyVagrantClient) GetPlugins(ctx context.Context, in *GetPluginsRequest, opts ...grpc.CallOption) (*GetPluginsResponse, error) { +func (c *rubyVagrantClient) GetLocalPlugins(ctx context.Context, in *GetPluginsRequest, opts ...grpc.CallOption) (*GetPluginsResponse, error) { out := new(GetPluginsResponse) - err := c.cc.Invoke(ctx, "/hashicorp.vagrant.RubyVagrant/GetPlugins", in, out, opts...) + err := c.cc.Invoke(ctx, "/hashicorp.vagrant.RubyVagrant/GetLocalPlugins", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *rubyVagrantClient) GetGlobalPlugins(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*GetPluginsResponse, error) { + out := new(GetPluginsResponse) + err := c.cc.Invoke(ctx, "/hashicorp.vagrant.RubyVagrant/GetGlobalPlugins", in, out, opts...) if err != nil { return nil, err } @@ -95,7 +105,8 @@ func (c *rubyVagrantClient) Stop(ctx context.Context, in *emptypb.Empty, opts .. // for forward compatibility type RubyVagrantServer interface { // Gets available ruby plugins - GetPlugins(context.Context, *GetPluginsRequest) (*GetPluginsResponse, error) + GetLocalPlugins(context.Context, *GetPluginsRequest) (*GetPluginsResponse, error) + GetGlobalPlugins(context.Context, *emptypb.Empty) (*GetPluginsResponse, error) ParseVagrantfile(context.Context, *ParseVagrantfileRequest) (*ParseVagrantfileResponse, error) ParseVagrantfileProc(context.Context, *ParseVagrantfileProcRequest) (*ParseVagrantfileResponse, error) ParseVagrantfileSubvm(context.Context, *ParseVagrantfileSubvmRequest) (*ParseVagrantfileResponse, error) @@ -108,8 +119,11 @@ type RubyVagrantServer interface { type UnimplementedRubyVagrantServer struct { } -func (UnimplementedRubyVagrantServer) GetPlugins(context.Context, *GetPluginsRequest) (*GetPluginsResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetPlugins not implemented") +func (UnimplementedRubyVagrantServer) GetLocalPlugins(context.Context, *GetPluginsRequest) (*GetPluginsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetLocalPlugins not implemented") +} +func (UnimplementedRubyVagrantServer) GetGlobalPlugins(context.Context, *emptypb.Empty) (*GetPluginsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetGlobalPlugins not implemented") } func (UnimplementedRubyVagrantServer) ParseVagrantfile(context.Context, *ParseVagrantfileRequest) (*ParseVagrantfileResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ParseVagrantfile not implemented") @@ -139,20 +153,38 @@ func RegisterRubyVagrantServer(s grpc.ServiceRegistrar, srv RubyVagrantServer) { s.RegisterService(&RubyVagrant_ServiceDesc, srv) } -func _RubyVagrant_GetPlugins_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _RubyVagrant_GetLocalPlugins_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(GetPluginsRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(RubyVagrantServer).GetPlugins(ctx, in) + return srv.(RubyVagrantServer).GetLocalPlugins(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/hashicorp.vagrant.RubyVagrant/GetLocalPlugins", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RubyVagrantServer).GetLocalPlugins(ctx, req.(*GetPluginsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _RubyVagrant_GetGlobalPlugins_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(emptypb.Empty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RubyVagrantServer).GetGlobalPlugins(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/hashicorp.vagrant.RubyVagrant/GetPlugins", + FullMethod: "/hashicorp.vagrant.RubyVagrant/GetGlobalPlugins", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(RubyVagrantServer).GetPlugins(ctx, req.(*GetPluginsRequest)) + return srv.(RubyVagrantServer).GetGlobalPlugins(ctx, req.(*emptypb.Empty)) } return interceptor(ctx, in, info, handler) } @@ -255,8 +287,12 @@ var RubyVagrant_ServiceDesc = grpc.ServiceDesc{ HandlerType: (*RubyVagrantServer)(nil), Methods: []grpc.MethodDesc{ { - MethodName: "GetPlugins", - Handler: _RubyVagrant_GetPlugins_Handler, + MethodName: "GetLocalPlugins", + Handler: _RubyVagrant_GetLocalPlugins_Handler, + }, + { + MethodName: "GetGlobalPlugins", + Handler: _RubyVagrant_GetGlobalPlugins_Handler, }, { MethodName: "ParseVagrantfile", diff --git a/internal/serverclient/ruby_client.go b/internal/serverclient/ruby_client.go index 07be66eed66..1fa7492b266 100644 --- a/internal/serverclient/ruby_client.go +++ b/internal/serverclient/ruby_client.go @@ -4,6 +4,7 @@ import ( "context" "errors" + "github.com/golang/protobuf/ptypes/empty" "github.com/hashicorp/go-hclog" "github.com/hashicorp/go-plugin" "google.golang.org/grpc" @@ -57,8 +58,16 @@ func (r *RubyVagrantClient) GRPCBroker() *plugin.GRPCBroker { return r.broker } -func (r *RubyVagrantClient) GetPlugins() ([]*ruby_vagrant.Plugin, error) { - plugins, err := r.client.GetPlugins(context.Background(), &ruby_vagrant.GetPluginsRequest{}) +func (r *RubyVagrantClient) GetGlobalPlugins() ([]*ruby_vagrant.Plugin, error) { + plugins, err := r.client.GetGlobalPlugins(context.Background(), &empty.Empty{}) + if err != nil { + return nil, err + } + return plugins.Plugins, nil +} + +func (r *RubyVagrantClient) GetLocalPlugins(path string) ([]*ruby_vagrant.Plugin, error) { + plugins, err := r.client.GetLocalPlugins(context.Background(), &ruby_vagrant.GetPluginsRequest{ProjectPath: path}) if err != nil { return nil, err } diff --git a/lib/vagrant/plugin/v2/manager.rb b/lib/vagrant/plugin/v2/manager.rb index 0927958ada9..9e4fb65e6f3 100644 --- a/lib/vagrant/plugin/v2/manager.rb +++ b/lib/vagrant/plugin/v2/manager.rb @@ -14,6 +14,11 @@ def initialize @registered = [] end + def initialize_clone(org) + super + @registered = org.registered.dup + end + # This returns all the action hooks. # # @return [Array] diff --git a/lib/vagrant/protobufs/proto/ruby_vagrant/ruby-server_services_pb.rb b/lib/vagrant/protobufs/proto/ruby_vagrant/ruby-server_services_pb.rb index 0bbb5d557f1..b4011bf76f8 100644 --- a/lib/vagrant/protobufs/proto/ruby_vagrant/ruby-server_services_pb.rb +++ b/lib/vagrant/protobufs/proto/ruby_vagrant/ruby-server_services_pb.rb @@ -17,7 +17,8 @@ class Service self.service_name = 'hashicorp.vagrant.RubyVagrant' # Gets available ruby plugins - rpc :GetPlugins, ::Hashicorp::Vagrant::GetPluginsRequest, ::Hashicorp::Vagrant::GetPluginsResponse + rpc :GetLocalPlugins, ::Hashicorp::Vagrant::GetPluginsRequest, ::Hashicorp::Vagrant::GetPluginsResponse + rpc :GetGlobalPlugins, ::Google::Protobuf::Empty, ::Hashicorp::Vagrant::GetPluginsResponse rpc :ParseVagrantfile, ::Hashicorp::Vagrant::ParseVagrantfileRequest, ::Hashicorp::Vagrant::ParseVagrantfileResponse rpc :ParseVagrantfileProc, ::Hashicorp::Vagrant::ParseVagrantfileProcRequest, ::Hashicorp::Vagrant::ParseVagrantfileResponse rpc :ParseVagrantfileSubvm, ::Hashicorp::Vagrant::ParseVagrantfileSubvmRequest, ::Hashicorp::Vagrant::ParseVagrantfileResponse diff --git a/plugins/commands/serve/service/internal_service.rb b/plugins/commands/serve/service/internal_service.rb index 4b32ddad7fd..da24d30f758 100644 --- a/plugins/commands/serve/service/internal_service.rb +++ b/plugins/commands/serve/service/internal_service.rb @@ -11,36 +11,66 @@ module CommandServe module Service class InternalService < ProtoService(Hashicorp::Vagrant::RubyVagrant::Service) - def get_plugins(req, _) - plugins = [] + def vagrant_env(project_path, opts={}) + klass = Class.new do + attr_reader :local_data_path + def initialize(pp) + @local_data_path = Pathname.new(pp) + end + end + klass.new(project_path) + end + + def extract_plugin_protos(plugin_manager) + plugins = [[:commands, :COMMAND], + [:communicators, :COMMUNICATOR], + [:config, :CONFIG], + [:guests, :GUEST], + [:hosts, :HOST], + [:provider_configs, :CONFIG], + [:providers, :PROVIDER], + [:provisioner_configs, :CONFIG], + [:provisioners, :PROVISIONER], + [:push_configs, :CONFIG], + [:pushes, :PUSH], + [:synced_folders, :SYNCEDFOLDER]].map do |method, const| + plugin_manager.send(method).map do |k, v| + Hashicorp::Vagrant::Plugin.new( + name: k, + type: Hashicorp::Vagrant::Plugin::Type.const_get(const), + options: Google::Protobuf::Any.pack( + _convert_options_to_proto(const, v) + ) + ) + end + end.flatten + Hashicorp::Vagrant::GetPluginsResponse.new( + plugins: plugins + ) + end + + def get_global_plugins(req, _) plugin_manager = Vagrant::Plugin::V2::Plugin.local_manager globalized_plugins = Vagrant::Plugin::Manager.instance.globalize! Vagrant::Plugin::Manager.instance.load_plugins(globalized_plugins) - plugins = [[:commands, :COMMAND], - [:communicators, :COMMUNICATOR], - [:config, :CONFIG], - [:guests, :GUEST], - [:hosts, :HOST], - [:provider_configs, :CONFIG], - [:providers, :PROVIDER], - [:provisioner_configs, :CONFIG], - [:provisioners, :PROVISIONER], - [:push_configs, :CONFIG], - [:pushes, :PUSH], - [:synced_folders, :SYNCEDFOLDER]].map do |method, const| - plugin_manager.send(method).map do |k, v| - Hashicorp::Vagrant::Plugin.new( - name: k, - type: Hashicorp::Vagrant::Plugin::Type.const_get(const), - options: Google::Protobuf::Any.pack( - _convert_options_to_proto(const, v) - ) - ) - end - end.flatten - Hashicorp::Vagrant::GetPluginsResponse.new( - plugins: plugins - ) + extract_plugin_protos(plugin_manager) + end + + def get_local_plugins(req, _) + env = vagrant_env(req.project_path) + # Keep track of global plugins that should be removed + to_remove = Vagrant::Plugin::V2::Plugin.local_manager.registered.dup + + localized_plugins = Vagrant::Plugin::Manager.instance.localize!(env) + Vagrant::Plugin::Manager.instance.load_plugins(localized_plugins) + plugin_manager = Vagrant::Plugin::V2::Plugin.local_manager.clone + + # Remove global plugins + to_remove.each do |p| + plugin_manager.unregister(p) + end + + extract_plugin_protos(plugin_manager) end def stop(_, _)