From 3cc92280f88397b087162d06765b7906c82d0646 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Thu, 18 Nov 2021 15:12:45 -0800 Subject: [PATCH] Update mappers to include maps from funcspec value to proto --- .../commands/serve/mappers/capabilities.rb | 33 ++++++++++++++++ plugins/commands/serve/mappers/command.rb | 2 +- plugins/commands/serve/mappers/guest.rb | 33 ++++++++-------- plugins/commands/serve/mappers/machine.rb | 19 ++++++++++ plugins/commands/serve/mappers/pathname.rb | 19 ++++++++++ plugins/commands/serve/mappers/project.rb | 18 +++++++++ plugins/commands/serve/mappers/state_bag.rb | 38 ++++++++++++++++++- plugins/commands/serve/mappers/target.rb | 19 ++++++++++ .../commands/serve/mappers/target_index.rb | 19 ++++++++++ plugins/commands/serve/mappers/terminal.rb | 19 ++++++++++ 10 files changed, 202 insertions(+), 17 deletions(-) diff --git a/plugins/commands/serve/mappers/capabilities.rb b/plugins/commands/serve/mappers/capabilities.rb index f368ecae0..7faaa7fec 100644 --- a/plugins/commands/serve/mappers/capabilities.rb +++ b/plugins/commands/serve/mappers/capabilities.rb @@ -1,6 +1,39 @@ module VagrantPlugins module CommandServe class Mappers + class NamedCapabilityProtoFromSpec < Mapper + def initialize + super( + inputs: [ + Input.new(type: SDK::FuncSpec::Value) { |arg| + arg.type == "hashicorp.vagrant.sdk.Args.NamedCapability" && + !arg&.value&.value.nil? + } + ], + output: SDK::Args::NamedCapability, + func: method(:converter), + ) + end + + def converter(fv) + SDK::Args::NamedCapability.decode(fv.value.value) + end + end + + class NamedCapabilityFromProto < Mapper + def initialize + super( + inputs: [Input.new(type: SDK::Args::NamedCapability)], + output: Symbol, + func: method(:converter), + ) + end + + def converter(n) + n.capability.to_s.to_sym + end + end + # Build a machine client from a FuncSpec value class NamedCapabilityFromSpec < Mapper def initialize diff --git a/plugins/commands/serve/mappers/command.rb b/plugins/commands/serve/mappers/command.rb index 195475115..8429f571e 100644 --- a/plugins/commands/serve/mappers/command.rb +++ b/plugins/commands/serve/mappers/command.rb @@ -2,7 +2,7 @@ module VagrantPlugins module CommandServe class Mappers # Build a command arguments from a FuncSpec value - class CommandArgumentsFromSpec < Mapper + class CommandArgumentsProtoFromSpec < Mapper def initialize inputs = [].tap do |i| i << Input.new(type: SDK::FuncSpec::Value) { |arg| diff --git a/plugins/commands/serve/mappers/guest.rb b/plugins/commands/serve/mappers/guest.rb index 02e38779c..5d5956960 100644 --- a/plugins/commands/serve/mappers/guest.rb +++ b/plugins/commands/serve/mappers/guest.rb @@ -1,6 +1,24 @@ module VagrantPlugins module CommandServe class Mappers + class GuestProtoFromSpec < Mapper + def initialize + super( + inputs: [Input.new(type: SDK::FuncSpec::Value) { |arg| + arg.type == "hashicorp.vagrant.sdk.Args.Guest" && + !arg&.value&.value.nil? + } + ], + output: SDK::Args::Guest, + func: method(:converter) + ) + end + + def converter(fv) + SDK::Args::Guest.decode(fv.value.value) + end + end + # Build a guest client from a FuncSpec value class GuestFromSpec < Mapper def initialize @@ -33,21 +51,6 @@ module VagrantPlugins Client::Guest.load(proto, broker: broker) end end - - # Build a guest client from a serialized proto string - class GuestFromString < Mapper - def initialize - inputs = [].tap do |i| - i << Input.new(type: String) - i << Input.new(type: Broker) - end - super(inputs: inputs, output: Client::Guest, func: method(:converter)) - end - - def converter(proto, broker) - Client::Guest.load(proto, broker: broker) - end - end end end end diff --git a/plugins/commands/serve/mappers/machine.rb b/plugins/commands/serve/mappers/machine.rb index 011811612..16994fc61 100644 --- a/plugins/commands/serve/mappers/machine.rb +++ b/plugins/commands/serve/mappers/machine.rb @@ -1,6 +1,25 @@ module VagrantPlugins module CommandServe class Mappers + class MachineProtoFromSpec < Mapper + def initialize + super( + inputs: [ + Input.new(type: SDK::FuncSpec::Value) { |arg| + arg.type == "hashicorp.vagrant.sdk.Args.Target.Machine" && + !arg&.value&.value.nil? + } + ], + output: SDK::Args::Target::Machine, + func: method(:converter) + ) + end + + def converter(fv) + SDK::Args::Target::Machine.decode(fv.value.value) + end + end + # Build a machine client from a FuncSpec value class MachineFromSpec < Mapper def initialize diff --git a/plugins/commands/serve/mappers/pathname.rb b/plugins/commands/serve/mappers/pathname.rb index 04d36b460..7b26b2c10 100644 --- a/plugins/commands/serve/mappers/pathname.rb +++ b/plugins/commands/serve/mappers/pathname.rb @@ -1,6 +1,25 @@ module VagrantPlugins module CommandServe class Mappers + class PathnameProtoFromSpec < Mapper + def initialize + super( + inputs: [ + Input.new(type: SDK::FuncSpec::Value) { |arg| + arg.type == "hashicorp.vagrant.sdk.Args.Path" && + !arg&.value&.value.nil? + } + ], + output: SDK::Args::Path, + func: method(:converter), + ) + end + + def converter(fv) + SDK::Args::Path.decode(fv.value.value) + end + end + class PathnameToProto < Mapper def initialize super( diff --git a/plugins/commands/serve/mappers/project.rb b/plugins/commands/serve/mappers/project.rb index e41dac681..4ffad3c01 100644 --- a/plugins/commands/serve/mappers/project.rb +++ b/plugins/commands/serve/mappers/project.rb @@ -1,6 +1,24 @@ module VagrantPlugins module CommandServe class Mappers + class ProjectProtoFromSpec < Mapper + def initialize + super( + inputs: [Input.new(type: SDK::FuncSpec::Value) { |arg| + arg.type == "hashicorp.vagrant.sdk.Args.Project" && + !arg&.value&.value.nil? + } + ], + output: SDK::Args::Project, + func: method(:converter), + ) + end + + def converter(fv) + SDK::Args::Project.decode(fv.value.value) + end + end + # Build a project client from a FuncSpec value class ProjectFromSpec < Mapper def initialize diff --git a/plugins/commands/serve/mappers/state_bag.rb b/plugins/commands/serve/mappers/state_bag.rb index 34b5a0abf..7fbe5780f 100644 --- a/plugins/commands/serve/mappers/state_bag.rb +++ b/plugins/commands/serve/mappers/state_bag.rb @@ -1,8 +1,44 @@ module VagrantPlugins module CommandServe class Mappers + class StateBagProtoFromSpec < Mapper + def initialize + super( + inputs: [ + Input.new(type: SDK::FuncSpec::Value) { |arg| + arg.type == "hashicorp.vagrant.sdk.Args.StateBag" && + !arg&.value&.value.nil? + } + ], + output: SDK::Args::StateBag, + func: method(:converter), + ) + end + + def converter(fv) + SDK::Args::StateBag.decode(fv.value.value) + end + end + + class StateBagFromProto < Mapper + def initialize + super( + inputs: [ + Input.new(type: SDK::Args::StateBag), + Input.new(type: Broker), + ], + output: Client::StateBag, + func: method(:converter) + ) + end + + def converter(proto, broker) + Client::StateBag.load(proto, broker) + end + end + # Extracts a statebag from a Funcspec value - class StateBag < Mapper + class StateBagFromSpec < Mapper def initialize inputs = [].tap do |i| i << Input.new(type: SDK::FuncSpec::Value) { |arg| diff --git a/plugins/commands/serve/mappers/target.rb b/plugins/commands/serve/mappers/target.rb index 5d0a8c10a..fb2b0d4bd 100644 --- a/plugins/commands/serve/mappers/target.rb +++ b/plugins/commands/serve/mappers/target.rb @@ -1,6 +1,25 @@ module VagrantPlugins module CommandServe class Mappers + class TargetProtoFromSpec < Mapper + def initialize + super( + inputs: [ + Input.new(type: SDK::FuncSpec::Value) { |arg| + arg.type == "hashicorp.vagrant.sdk.Args.Target" && + !arg&.value&.value.nil? + } + ], + output: SDK::Args::Target, + func: method(:converter) + ) + end + + def converter(fv) + SDK::Args::Target.decode(fv.value.value) + end + end + # Build a target client from a FuncSpec value class TargetFromSpec < Mapper def initialize diff --git a/plugins/commands/serve/mappers/target_index.rb b/plugins/commands/serve/mappers/target_index.rb index 8a18017cf..9083f9210 100644 --- a/plugins/commands/serve/mappers/target_index.rb +++ b/plugins/commands/serve/mappers/target_index.rb @@ -1,6 +1,25 @@ module VagrantPlugins module CommandServe class Mappers + class TargetIndexProtoFromSpec < Mapper + def initialize + super( + inputs: [ + Input.new(type: SDK::FuncSpec::Value) { |arg| + arg.type == "hashicorp.vagrant.sdk.Args.TargetIndex" && + !arg&.value&.value.nil? + } + ], + output: SDK::Args::TargetIndex, + func: method(:converter) + ) + end + + def converter(fv) + SDK::Args::TargetIndex.decode(fv.value.value) + end + end + # Build a target index client from a FuncSpec value class TargetIndexFromSpec < Mapper def initialize diff --git a/plugins/commands/serve/mappers/terminal.rb b/plugins/commands/serve/mappers/terminal.rb index 8d063993a..a6a06ebb3 100644 --- a/plugins/commands/serve/mappers/terminal.rb +++ b/plugins/commands/serve/mappers/terminal.rb @@ -1,6 +1,25 @@ module VagrantPlugins module CommandServe class Mappers + class TerminalProtoFromSpec < Mapper + def initialize + super( + inputs: [ + Input.new(type: SDK::FuncSpec::Value) { |arg| + arg.type == "hashicorp.vagrant.sdk.Args.TerminalUI" && + !arg&.value&.value.nil? + } + ], + output: SDK::Args::TerminalUI, + func: method(:converter), + ) + end + + def converter(fv) + SDK::Args::TerminalUI.decode(fv.value.value) + end + end + # Build a terminal client from a FuncSpec value class TerminalFromSpec < Mapper def initialize