diff --git a/plugins/commands/serve/client/communicator.rb b/plugins/commands/serve/client/communicator.rb index 169b9d96e..0f7ec906b 100644 --- a/plugins/commands/serve/client/communicator.rb +++ b/plugins/commands/serve/client/communicator.rb @@ -4,6 +4,7 @@ module VagrantPlugins module Client class Communicator + prepend Util::HasMapper extend Util::Connector include Util::HasSeeds::Client @@ -177,10 +178,7 @@ module VagrantPlugins protected def generate_execution_request(machine, cmd, opts={}) - opts.transform_values! { |v| v.is_a?(Symbol) ? v.to_s : v} - opts_struct = Google::Protobuf::Struct.from_hash( - opts.transform_keys(&:to_s) - ) + opts_proto = mapper.map(opts, to: SDK::Args::Hash) SDK::FuncSpec::Args.new( args: [ @@ -194,8 +192,8 @@ module VagrantPlugins value: Google::Protobuf::Any.pack(SDK::Communicator::Command.new(command: cmd)), ), SDK::FuncSpec::Value.new( - type: "google.protobuf.Struct", - value: Google::Protobuf::Any.pack(opts_struct), + type: "hashicorp.vagrant.sdk.Args.Hash", + value: Google::Protobuf::Any.pack(opts_proto), ), ] ) diff --git a/plugins/commands/serve/mappers/known_types.rb b/plugins/commands/serve/mappers/known_types.rb index 0f4de83e1..4949563d3 100644 --- a/plugins/commands/serve/mappers/known_types.rb +++ b/plugins/commands/serve/mappers/known_types.rb @@ -51,6 +51,24 @@ module VagrantPlugins end end + class HashProtoFromSpec < Mapper + def initialize + super( + inputs: [Input.new(type: SDK::FuncSpec::Value) { |arg| + arg.type == "hashicorp.vagrant.sdk.Args.Hash" && + !arg&.value&.value.nil? + } + ], + output: SDK::Args::Hash, + func: method(:converter), + ) + end + + def converter(fv) + SDK::Args::Hash.decode(fv.value.value) + end + end + class HashFromProto < Mapper def initialize super( @@ -65,7 +83,7 @@ module VagrantPlugins def converter(proto, mapper) Hash.new.tap do |result| - proto.fields.each_pair do |k, v| + proto.fields.each do |k, v| r = mapper.map(v) result[k.to_s] = r end diff --git a/plugins/commands/serve/service/communicator_service.rb b/plugins/commands/serve/service/communicator_service.rb index 271f46c05..bd333d343 100644 --- a/plugins/commands/serve/service/communicator_service.rb +++ b/plugins/commands/serve/service/communicator_service.rb @@ -260,7 +260,7 @@ module VagrantPlugins name: "", ), SDK::FuncSpec::Value.new( - type: "google.protobuf.Struct", + type: "hashicorp.vagrant.sdk.Args.Hash", name: "", ) ], @@ -274,15 +274,14 @@ module VagrantPlugins def privileged_execute(req, ctx) with_info(ctx) do |info| plugin_name = info.plugin_name - target, cmd, opts = mapper.funcspec_map(req, mapper, broker) - logger.debug("Got machine client #{target}") + machine, cmd, opts = mapper.funcspec_map( + req, mapper, broker, + expect: [Vagrant::Machine, SDK::Communicator::Command, Hash] + ) + logger.debug("Got machine client #{machine}") logger.debug("Got opts #{opts}") logger.debug("Got cmd #{cmd}") - 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] communicator = plugin.new(machine) exit_code = communicator.sudo(cmd.command, opts)