From ce29c48931a0067d3dc84ac40094b920fdbcd60e Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Thu, 26 Aug 2021 15:03:07 -0700 Subject: [PATCH] Use mapper when loading funcspec arguments in services --- plugins/commands/serve/service/command_service.rb | 14 ++------------ plugins/commands/serve/service/guest_service.rb | 8 +++----- plugins/commands/serve/service/host_service.rb | 8 +++----- plugins/commands/serve/service/provider_service.rb | 10 +++------- 4 files changed, 11 insertions(+), 29 deletions(-) diff --git a/plugins/commands/serve/service/command_service.rb b/plugins/commands/serve/service/command_service.rb index 04f920f53..69db750f6 100644 --- a/plugins/commands/serve/service/command_service.rb +++ b/plugins/commands/serve/service/command_service.rb @@ -5,6 +5,7 @@ module VagrantPlugins module Service class CommandService < SDK::CommandService::Service + prepend Util::HasMapper prepend Util::HasBroker prepend Util::ExceptionLogger LOGGER = Log4r::Logger.new("vagrant::command::serve::command") @@ -52,19 +53,8 @@ module VagrantPlugins def execute(req, ctx) ServiceInfo.with_info(ctx) do |info| plugin_name = info.plugin_name - raw_terminal = req.spec.args.detect { |a| - a.type == "hashicorp.vagrant.sdk.Args.TerminalUI" - }&.value&.value - raw_args = req.spec.args.detect { |a| - a.type == "hashicorp.vagrant.sdk.Command.Arguments" - }&.value&.value - raw_project = req.spec.args.detect { |a| - a.type == "hashicorp.vagrant.sdk.Args.Project" - }&.value&.value - arguments = SDK::Command::Arguments.decode(raw_args) - ui_client = Client::Terminal.load(raw_terminal, broker: broker) - env_client = Client::Project.load(raw_project, broker: broker) + ui_client, env_client, arguments = mapper.funcspec_map(req.spec) ui = Vagrant::UI::Remote.new(ui_client) env = Vagrant::Environment.new( diff --git a/plugins/commands/serve/service/guest_service.rb b/plugins/commands/serve/service/guest_service.rb index 0540ba6ba..89a84b50e 100644 --- a/plugins/commands/serve/service/guest_service.rb +++ b/plugins/commands/serve/service/guest_service.rb @@ -4,6 +4,7 @@ module VagrantPlugins module CommandServe module Service class GuestService < Hashicorp::Vagrant::Sdk::GuestService::Service + prepend Util::HasMapper prepend Util::HasBroker prepend Util::ExceptionLogger LOGGER = Log4r::Logger.new("vagrant::command::serve::guest") @@ -29,11 +30,8 @@ module VagrantPlugins def detect(req, ctx) ServiceInfo.with_info(ctx) do |info| plugin_name = info.plugin_name - raw_target = req.args.detect { |a| - a.type == "hashicorp.vagrant.sdk.Args.Target" - }&.value&.value + target = mapper.funcspec_map(req.args) - target = Client::Target.load(raw_target, broker: broker) project = target.project env = Vagrant::Environment.new({client: project}) machine = env.machine(target.name.to_sym, target.provider_name.to_sym) @@ -46,7 +44,7 @@ module VagrantPlugins begin detected = guest.detect?(machine) rescue => err - LOGGER.debug("error detecting") + LOGGER.debug("error encountered detecting guest: #{err.class} - #{err}") detected = false end LOGGER.debug("detected #{detected} for guest #{plugin_name}") diff --git a/plugins/commands/serve/service/host_service.rb b/plugins/commands/serve/service/host_service.rb index 96d5ffcbd..7c533614f 100644 --- a/plugins/commands/serve/service/host_service.rb +++ b/plugins/commands/serve/service/host_service.rb @@ -4,6 +4,7 @@ module VagrantPlugins module CommandServe module Service class HostService < Hashicorp::Vagrant::Sdk::HostService::Service + prepend Util::HasMapper prepend Util::HasBroker prepend Util::ExceptionLogger @@ -110,14 +111,11 @@ module VagrantPlugins def capability(req, ctx) ServiceInfo.with_info(ctx) do |info| begin - res = nil plugin_name = info.plugin_name n_cap = req.name - raw_terminal = req.func_args.args.detect { |a| - a.type == "hashicorp.vagrant.sdk.Args.TerminalUI" - }&.value&.value - ui_client = Client::Terminal.load(raw_terminal, broker: broker) + + ui_client = mapper.funcspec_map(req.spec) ui = Vagrant::UI::Remote.new(ui_client) p = Vagrant::Host.new( diff --git a/plugins/commands/serve/service/provider_service.rb b/plugins/commands/serve/service/provider_service.rb index f441102a6..87745d19d 100644 --- a/plugins/commands/serve/service/provider_service.rb +++ b/plugins/commands/serve/service/provider_service.rb @@ -6,6 +6,7 @@ module VagrantPlugins module CommandServe module Service class ProviderService < SDK::ProviderService::Service + prepend Util::HasMapper prepend Util::HasBroker prepend Util::ExceptionLogger @@ -36,13 +37,8 @@ module VagrantPlugins def action_up(req, ctx) ServiceInfo.with_info(ctx) do |info| plugin_name = info.plugin_name - raw_terminal = req.args.detect { |a| - a.type == "hashicorp.vagrant.sdk.Args.TerminalUI" - }&.value&.value - raw_machine = req.args.detect { |a| - a.type == "hashicorp.vagrant.sdk.Args.Machine" - }&.value&.value - ui = Client::Terminal.load(raw_terminal, broker: broker) + ui, machine = mapper.funcspec_map(req.spec) + machine = Client::Machine.load(raw_machine, ui) machine.ui.warn("hello from vagrant") SDK::Provider::ActionResp.new(success: true)