From 8513a14f9eed7698dd6a89532dd9cd9f7afa92ad Mon Sep 17 00:00:00 2001 From: sophia Date: Mon, 1 Nov 2021 11:07:03 -0500 Subject: [PATCH] Use RemotePath proto message to upload/download files --- .../proto/vagrant_plugin_sdk/plugin_pb.rb | 4 ++++ plugins/commands/serve/client/communicator.rb | 10 ++++------ .../commands/serve/mappers/communicator.rb | 16 +++++++++++++++ .../serve/service/communicator_service.rb | 20 ++++++------------- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/lib/vagrant/protobufs/proto/vagrant_plugin_sdk/plugin_pb.rb b/lib/vagrant/protobufs/proto/vagrant_plugin_sdk/plugin_pb.rb index 7b365950c..1dbd3e793 100644 --- a/lib/vagrant/protobufs/proto/vagrant_plugin_sdk/plugin_pb.rb +++ b/lib/vagrant/protobufs/proto/vagrant_plugin_sdk/plugin_pb.rb @@ -451,6 +451,9 @@ Google::Protobuf::DescriptorPool.generated_pool.build do add_message "hashicorp.vagrant.sdk.Communicator.Path" do optional :path, :string, 1 end + add_message "hashicorp.vagrant.sdk.Communicator.RemotePath" do + optional :path, :string, 1 + end add_message "hashicorp.vagrant.sdk.Platform" do end add_message "hashicorp.vagrant.sdk.Platform.DetectResp" do @@ -826,6 +829,7 @@ module Hashicorp Communicator::TestResp = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("hashicorp.vagrant.sdk.Communicator.TestResp").msgclass Communicator::Command = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("hashicorp.vagrant.sdk.Communicator.Command").msgclass Communicator::Path = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("hashicorp.vagrant.sdk.Communicator.Path").msgclass + Communicator::RemotePath = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("hashicorp.vagrant.sdk.Communicator.RemotePath").msgclass Platform = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("hashicorp.vagrant.sdk.Platform").msgclass Platform::DetectResp = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("hashicorp.vagrant.sdk.Platform.DetectResp").msgclass Platform::ParentResp = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("hashicorp.vagrant.sdk.Platform.ParentResp").msgclass diff --git a/plugins/commands/serve/client/communicator.rb b/plugins/commands/serve/client/communicator.rb index eef94c421..9e89c68a0 100644 --- a/plugins/commands/serve/client/communicator.rb +++ b/plugins/commands/serve/client/communicator.rb @@ -80,8 +80,8 @@ module VagrantPlugins value: Google::Protobuf::Any.pack(SDK::Communicator::Path.new(path: from)), ), SDK::FuncSpec::Value.new( - type: "hashicorp.vagrant.sdk.Communicator.Path", - value: Google::Protobuf::Any.pack(SDK::Communicator::Path.new(path: to)), + type: "hashicorp.vagrant.sdk.Communicator.RemotePath", + value: Google::Protobuf::Any.pack(SDK::Communicator::RemotePath.new(path: to)), ), ] ) @@ -103,13 +103,11 @@ module VagrantPlugins ), SDK::FuncSpec::Value.new( type: "hashicorp.vagrant.sdk.Communicator.Path", - name: "to", value: Google::Protobuf::Any.pack(SDK::Communicator::Path.new(path: from)), ), SDK::FuncSpec::Value.new( - type: "hashicorp.vagrant.sdk.Communicator.Path", - name: "from", - value: Google::Protobuf::Any.pack(SDK::Communicator::Path.new(path: to)), + type: "hashicorp.vagrant.sdk.Communicator.RemotePath", + value: Google::Protobuf::Any.pack(SDK::Communicator::RemotePath.new(path: to)), ), ] ) diff --git a/plugins/commands/serve/mappers/communicator.rb b/plugins/commands/serve/mappers/communicator.rb index 01af32351..450274267 100644 --- a/plugins/commands/serve/mappers/communicator.rb +++ b/plugins/commands/serve/mappers/communicator.rb @@ -34,6 +34,22 @@ module VagrantPlugins SDK::Communicator::Path.decode(proto.value.value) end end + + class CommunicatorRemotePathFromSpec < Mapper + def initialize + inputs = [].tap do |i| + i << Input.new(type: SDK::FuncSpec::Value) { |arg| + arg.type == "hashicorp.vagrant.sdk.Communicator.RemotePath" && + !arg&.value&.value.nil? + } + end + super(inputs: inputs, output: SDK::Communicator::RemotePath, func: method(:converter)) + end + + def converter(proto) + SDK::Communicator::RemotePath.decode(proto.value.value) + end + end end end end diff --git a/plugins/commands/serve/service/communicator_service.rb b/plugins/commands/serve/service/communicator_service.rb index f0d29212b..1b5b65445 100644 --- a/plugins/commands/serve/service/communicator_service.rb +++ b/plugins/commands/serve/service/communicator_service.rb @@ -114,14 +114,11 @@ module VagrantPlugins name: "", ), SDK::FuncSpec::Value.new( - type: "hashicorp.vagrant.sdk.Communicator.Path", + type: "hashicorp.vagrant.sdk.Communicator.RemotePath", name: "", ) ], - result: [ - type: "hashicorp.vagrant.sdk.Communicator.FileTransferResp", - name: "", - ] + result: [] ) end @@ -148,7 +145,7 @@ module VagrantPlugins communicator.download(from, to) - SDK::Communicator::FileTransferResp.new() + Empty.new end end @@ -162,17 +159,12 @@ module VagrantPlugins ), SDK::FuncSpec::Value.new( type: "hashicorp.vagrant.sdk.Communicator.Path", - name: "to", ), SDK::FuncSpec::Value.new( - type: "hashicorp.vagrant.sdk.Communicator.Path", - name: "from", + type: "hashicorp.vagrant.sdk.Communicator.RemotePath", ) ], - result: [ - type: "hashicorp.vagrant.sdk.Communicator.FileTransferResp", - name: "", - ] + result: [] ) end @@ -198,7 +190,7 @@ module VagrantPlugins communicator.upload(from.path, to.path) - SDK::Communicator::FileTransferResp.new() + Empty.new end end