Paul Hinze 8b5d4b8631
Update and address protobuf package deprecations
These changes address the following warning showing up on `go get`
operations:

    go: module github.com/golang/protobuf is deprecated: Use the
    "google.golang.org/protobuf" module instead.

All changes are made using the recommendations in the per-function
deprecation notices from the docs at
https://pkg.go.dev/github.com/golang/protobuf/ptypes
2022-06-08 11:51:19 -05:00

78 lines
2.2 KiB
Go

package serverclient
import (
"context"
"errors"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin"
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/emptypb"
"github.com/hashicorp/vagrant-plugin-sdk/internal-shared/pluginclient"
"github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk"
"github.com/hashicorp/vagrant/internal/server/proto/ruby_vagrant"
)
type RubyVagrant interface {
GetPlugins() ([]*ruby_vagrant.Plugin, error)
ParseVagrantfile(string) (*vagrant_plugin_sdk.Vagrantfile_Vagrantfile, error)
}
// This is the implementation of plugin.GRPCPlugin so we can serve/consume this.
type RubyVagrantPlugin struct {
plugin.NetRPCUnsupportedPlugin
Impl RubyVagrant
}
type RubyVagrantClient struct {
broker *plugin.GRPCBroker
client ruby_vagrant.RubyVagrantClient
ctx context.Context
}
func RubyVagrantPluginConfig(log hclog.Logger) *plugin.ClientConfig {
log = log.ResetNamed("vagrant.legacy")
config := pluginclient.ClientConfig(log)
config.Logger = log
config.VersionedPlugins[1]["vagrantrubyruntime"] = &RubyVagrantPlugin{}
return config
}
// No Go server implementation. Server is provided by the Vagrant Ruby runtime
func (p *RubyVagrantPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error {
return errors.New("vagrant ruby runtime server not implemented")
}
func (p *RubyVagrantPlugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) {
return RubyVagrantClient{
broker: broker,
client: ruby_vagrant.NewRubyVagrantClient(c),
ctx: ctx,
}, nil
}
func (r *RubyVagrantClient) GRPCBroker() *plugin.GRPCBroker {
return r.broker
}
func (r *RubyVagrantClient) GetPlugins() ([]*ruby_vagrant.Plugin, error) {
plugins, err := r.client.GetPlugins(context.Background(), &emptypb.Empty{})
if err != nil {
return nil, err
}
return plugins.Plugins, nil
}
func (r *RubyVagrantClient) ParseVagrantfile(path string) (*vagrant_plugin_sdk.Vagrantfile_Vagrantfile, error) {
vf, err := r.client.ParseVagrantfile(
context.Background(),
&ruby_vagrant.ParseVagrantfileRequest{Path: path},
)
if err != nil {
return nil, err
}
return vf.Vagrantfile, nil
}