From bb084e42e41cb9f0c3e395570873562fe5b554e1 Mon Sep 17 00:00:00 2001 From: sophia Date: Wed, 3 Nov 2021 16:15:09 -0500 Subject: [PATCH] Apply changes to download funciton --- builtin/myplugin/communicator/communicator.go | 14 +++++--- plugins/commands/serve/client/communicator.rb | 18 +++++----- .../serve/service/communicator_service.rb | 34 ++++++++++--------- 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/builtin/myplugin/communicator/communicator.go b/builtin/myplugin/communicator/communicator.go index 7bf937196..231fa36dd 100644 --- a/builtin/myplugin/communicator/communicator.go +++ b/builtin/myplugin/communicator/communicator.go @@ -52,10 +52,16 @@ func (h *DummyCommunicator) DownloadFunc() interface{} { return h.Download } -func (h *DummyCommunicator) Download( - machine plugincore.Machine, - source, destination string, +func (h *DummyCommunicator) Download(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 } @@ -95,7 +101,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/plugins/commands/serve/client/communicator.rb b/plugins/commands/serve/client/communicator.rb index 2042b98e8..3da06129d 100644 --- a/plugins/commands/serve/client/communicator.rb +++ b/plugins/commands/serve/client/communicator.rb @@ -68,6 +68,10 @@ module VagrantPlugins # @param [String] remote path # @param [String] local path def download(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( @@ -76,14 +80,12 @@ 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", + value: Google::Protobuf::Any.pack(from_val) + ), + SDK::FuncSpec::Value.new( + name: "destination", + value: Google::Protobuf::Any.pack(to_val) ), ] ) diff --git a/plugins/commands/serve/service/communicator_service.rb b/plugins/commands/serve/service/communicator_service.rb index 85fa43ecd..0a7265a2b 100644 --- a/plugins/commands/serve/service/communicator_service.rb +++ b/plugins/commands/serve/service/communicator_service.rb @@ -110,7 +110,10 @@ module VagrantPlugins name: "", ), SDK::FuncSpec::Value.new( - type: "hashicorp.vagrant.sdk.Args.NamedPaths", + name: "source" + ), + SDK::FuncSpec::Value.new( + name: "destination" ), ], result: [] @@ -123,23 +126,26 @@ module VagrantPlugins plugin_name = info.plugin_name logger.debug("Got plugin #{plugin_name}") - target, paths = mapper.funcspec_map(req) + # Need to specifically now use funcspec map since the funcspec map + # will inject results into the mappers. This causes duplicate values + # to come up for arguments of the same type + expected_types = [Client::Target::Machine, String, String] + to, target, from = req.args.map do |r| + logger.debug("mapping #{r}") + mapper.map(r, expected_types.shift) + end logger.debug("Got target #{target}") - logger.debug("Got paths #{paths}") - from = paths.paths.select{ |p| p.name == "from" }.first - to = paths.paths.select{ |p| p.name == "to" }.first + logger.debug("Got to #{to}") + logger.debug("Got from #{from}") - logger.info("mapping received arguments to guest machine") - machine = mapper.map(target, to: Vagrant::Machine) - logger.debug("Got machine #{machine}") + project = target.project + env = Vagrant::Environment.new({client: project}) + machine = env.machine(target.name.to_sym, target.provider_name.to_sym) plugin = Vagrant.plugin("2").manager.communicators[plugin_name.to_s.to_sym] logger.debug("Got plugin #{plugin}") - communicator = plugin.new(machine) - logger.debug("communicator: #{communicator}") - - communicator.download(from.path, to.path) + communicator.download(from, to) Empty.new end @@ -188,11 +194,7 @@ module VagrantPlugins plugin = Vagrant.plugin("2").manager.communicators[plugin_name.to_s.to_sym] logger.debug("Got plugin #{plugin}") communicator = plugin.new(machine) - logger.debug("communicator: #{communicator}") - logger.debug("uploading: #{from} -> #{to}") - communicator.upload(from, to) - Empty.new end end