From 85f7aa1586bcbf40240fe6e0da51d72bf65544a5 Mon Sep 17 00:00:00 2001 From: sophia Date: Tue, 2 Nov 2021 16:52:25 -0500 Subject: [PATCH] Make go communincator plugin work --- builtin/myplugin/communicator/communicator.go | 16 +++++++--- internal/core/target.go | 3 +- plugins/commands/serve/client/communicator.rb | 30 ++++++++++++++----- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/builtin/myplugin/communicator/communicator.go b/builtin/myplugin/communicator/communicator.go index 7d784cb9a..7bf937196 100644 --- a/builtin/myplugin/communicator/communicator.go +++ b/builtin/myplugin/communicator/communicator.go @@ -1,6 +1,8 @@ package communicator import ( + "github.com/hashicorp/go-argmapper" + "github.com/hashicorp/go-hclog" "github.com/hashicorp/vagrant-plugin-sdk/component" plugincore "github.com/hashicorp/vagrant-plugin-sdk/core" pb "github.com/hashicorp/vagrant/builtin/myplugin/proto" @@ -61,10 +63,16 @@ func (h *DummyCommunicator) UploadFunc() interface{} { return h.Upload } -func (h *DummyCommunicator) Upload( - machine plugincore.Machine, - source string, destination string, +func (h *DummyCommunicator) Upload(input struct { + argmapper.Struct + Machine plugincore.Machine `argmapper:",typeOnly"` + Logger hclog.Logger `argmapper:",typeOnly"` + Source string + Destination string +}, ) error { + input.Logger.Debug("got Source ", input.Source) + input.Logger.Debug("got Destination ", input.Destination) return nil } @@ -87,7 +95,7 @@ func (h *DummyCommunicator) PrivilegedExecuteFunc() interface{} { func (h *DummyCommunicator) PrivilegedExecute( machine plugincore.Machine, command []string, - options *pb.CommunicatorOptions, + // options *pb.CommunicatorOptions, ) (status int32, err error) { return 0, nil } diff --git a/internal/core/target.go b/internal/core/target.go index 2614557cc..53583bdb1 100644 --- a/internal/core/target.go +++ b/internal/core/target.go @@ -95,7 +95,8 @@ func (t *Target) Communicate() (c core.Communicator, err error) { } // TODO: get the communicator name from the Vagrantfile // eg. t.target.Configuration.ConfigVm.Communicator - communicatorName := "ssh" + // communicatorName := "ssh" + communicatorName := "myplugin" communicators, err := t.project.basis.typeComponents(t.ctx, component.CommunicatorType) if err != nil { return nil, err diff --git a/plugins/commands/serve/client/communicator.rb b/plugins/commands/serve/client/communicator.rb index 9fed3ef0c..0c3ea0d71 100644 --- a/plugins/commands/serve/client/communicator.rb +++ b/plugins/commands/serve/client/communicator.rb @@ -96,6 +96,10 @@ module VagrantPlugins # @param [String] local path # @param [String] remote path def upload(machine, from, to) + from_val = Google::Protobuf::Value.new + from_val.from_ruby(from) + to_val = Google::Protobuf::Value.new + to_val.from_ruby(to) req = SDK::FuncSpec::Args.new( args: [ SDK::FuncSpec::Value.new( @@ -104,15 +108,25 @@ module VagrantPlugins value: Google::Protobuf::Any.pack(machine.to_proto) ), SDK::FuncSpec::Value.new( - type: "hashicorp.vagrant.sdk.Args.NamedPaths", - value: Google::Protobuf::Any.pack( - SDK::Args::NamedPaths.new( - paths: [ - SDK::Args::NamedPath.new(path: from, name: "from"), - SDK::Args::NamedPath.new(path: to, name: "to"), - ]) - ), + name: "source", + type: "string", + value: Google::Protobuf::Any.pack(from_val) ), + SDK::FuncSpec::Value.new( + name: "destination", + type: "string", + value: Google::Protobuf::Any.pack(to_val) + ), + # SDK::FuncSpec::Value.new( + # type: "hashicorp.vagrant.sdk.Args.NamedPaths", + # value: Google::Protobuf::Any.pack( + # SDK::Args::NamedPaths.new( + # paths: [ + # SDK::Args::NamedPath.new(path: from, name: "from"), + # SDK::Args::NamedPath.new(path: to, name: "to"), + # ]) + # ), + # ), ] )