diff --git a/plugins/commands/serve/mappers/command.rb b/plugins/commands/serve/mappers/command.rb new file mode 100644 index 000000000..195475115 --- /dev/null +++ b/plugins/commands/serve/mappers/command.rb @@ -0,0 +1,22 @@ +module VagrantPlugins + module CommandServe + class Mappers + # Build a command arguments from a FuncSpec value + class CommandArgumentsFromSpec < Mapper + def initialize + inputs = [].tap do |i| + i << Input.new(type: SDK::FuncSpec::Value) { |arg| + arg.type == "hashicorp.vagrant.sdk.Command.Arguments" && + !arg&.value&.value.nil? + } + end + super(inputs: inputs, output: SDK::Command::Arguments, func: method(:converter)) + end + + def converter(proto) + SDK::Command::Arguments.decode(proto.value.value) + end + end + end + end +end diff --git a/plugins/commands/serve/mappers/guest.rb b/plugins/commands/serve/mappers/guest.rb new file mode 100644 index 000000000..02e38779c --- /dev/null +++ b/plugins/commands/serve/mappers/guest.rb @@ -0,0 +1,53 @@ +module VagrantPlugins + module CommandServe + class Mappers + # Build a guest client from a FuncSpec value + class GuestFromSpec < Mapper + def initialize + inputs = [].tap do |i| + i << Input.new(type: SDK::FuncSpec::Value) { |arg| + arg.type == "hashicorp.vagrant.sdk.Args.Guest" && + !arg&.value&.value.nil? + } + i << Input.new(type: Broker) + end + super(inputs: inputs, output: Client::Guest, func: method(:converter)) + end + + def converter(proto, broker) + Client::Guest.load(proto.value.value, broker: broker) + end + end + + # Build a guest client from a proto instance + class GuestFromProto < Mapper + def initialize + inputs = [].tap do |i| + i << Input.new(type: SDK::Args::Guest) + 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 + + # 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 new file mode 100644 index 000000000..ecf03757b --- /dev/null +++ b/plugins/commands/serve/mappers/machine.rb @@ -0,0 +1,53 @@ +module VagrantPlugins + module CommandServe + class Mappers + # Build a machine client from a FuncSpec value + class MachineFromSpec < Mapper + def initialize + inputs = [].tap do |i| + i << Input.new(type: SDK::FuncSpec::Value) { |arg| + arg.type == "hashicorp.vagrant.sdk.Args.Machine" && + !arg&.value&.value.nil? + } + i << Input.new(type: Broker) + end + super(inputs: inputs, output: Client::Machine, func: method(:converter)) + end + + def converter(proto, broker) + Client::Machine.load(proto.value.value, broker: broker) + end + end + + # Build a machine client from a proto instance + class MachineFromProto < Mapper + def initialize + inputs = [].tap do |i| + i << Input.new(type: SDK::Args::Target::Machine) + i << Input.new(type: Broker) + end + super(inputs: inputs, output: Client::Machine, func: method(:converter)) + end + + def converter(proto, broker) + Client::Machine.load(proto, broker: broker) + end + end + + # Build a machine client from a serialized proto string + class MachineFromString < Mapper + def initialize + inputs = [].tap do |i| + i << Input.new(type: String) + i << Input.new(type: Broker) + end + super(inputs: inputs, output: Client::Machine, func: method(:converter)) + end + + def converter(proto, broker) + Client::Machine.load(proto, broker: broker) + end + end + end + end +end diff --git a/plugins/commands/serve/mappers/project.rb b/plugins/commands/serve/mappers/project.rb new file mode 100644 index 000000000..375242ee1 --- /dev/null +++ b/plugins/commands/serve/mappers/project.rb @@ -0,0 +1,53 @@ +module VagrantPlugins + module CommandServe + class Mappers + # Build a project client from a FuncSpec value + class ProjectFromSpec < Mapper + def initialize + inputs = [].tap do |i| + i << Input.new(type: SDK::FuncSpec::Value) { |arg| + arg.type == "hashicorp.vagrant.sdk.Args.Project" && + !arg&.value&.value.nil? + } + i << Input.new(type: Broker) + end + super(inputs: inputs, output: Client::Project, func: method(:converter)) + end + + def converter(proto, broker) + Client::Project.load(proto.value.value, broker: broker) + end + end + + # Build a project client from a proto instance + class ProjectFromProto < Mapper + def initialize + inputs = [].tap do |i| + i << Input.new(type: SDK::Args::Project) + i << Input.new(type: Broker) + end + super(inputs: inputs, output: Client::Project, func: method(:converter)) + end + + def converter(proto, broker) + Client::Project.load(proto, broker: broker) + end + end + + # Build a machine client from a serialized proto string + class ProjectFromString < Mapper + def initialize + inputs = [].tap do |i| + i << Input.new(type: String) + i << Input.new(type: Broker) + end + super(inputs: inputs, output: Client::Project, func: method(:converter)) + end + + def converter(proto, broker) + Client::Project.load(proto, broker: broker) + end + end + end + end +end diff --git a/plugins/commands/serve/mappers/target.rb b/plugins/commands/serve/mappers/target.rb new file mode 100644 index 000000000..4db3dd5e0 --- /dev/null +++ b/plugins/commands/serve/mappers/target.rb @@ -0,0 +1,53 @@ +module VagrantPlugins + module CommandServe + class Mappers + # Build a target client from a FuncSpec value + class TargetFromSpec < Mapper + def initialize + inputs = [].tap do |i| + i << Input.new(type: SDK::FuncSpec::Value) { |arg| + arg.type == "hashicorp.vagrant.sdk.Args.Target" && + !arg&.value&.value.nil? + } + i << Input.new(type: Broker) + end + super(inputs: inputs, output: Client::Target, func: method(:converter)) + end + + def converter(proto, broker) + Client::Target.load(proto.value.value, broker: broker) + end + end + + # Build a target client from a proto instance + class TargetFromProto < Mapper + def initialize + inputs = [].tap do |i| + i << Input.new(type: SDK::Args::Target) + i << Input.new(type: Broker) + end + super(inputs: inputs, output: Client::Target, func: method(:converter)) + end + + def converter(proto, broker) + Client::Target.load(proto, broker: broker) + end + end + + # Build a target client from a serialized proto string + class TargetFromString < Mapper + def initialize + inputs = [].tap do |i| + i << Input.new(type: String) + i << Input.new(type: Broker) + end + super(inputs: inputs, output: Client::Target, func: method(:converter)) + end + + def converter(proto, broker) + Client::Target.load(proto, broker: broker) + end + end + end + end +end diff --git a/plugins/commands/serve/mappers/target_index.rb b/plugins/commands/serve/mappers/target_index.rb new file mode 100644 index 000000000..8a18017cf --- /dev/null +++ b/plugins/commands/serve/mappers/target_index.rb @@ -0,0 +1,53 @@ +module VagrantPlugins + module CommandServe + class Mappers + # Build a target index client from a FuncSpec value + class TargetIndexFromSpec < Mapper + def initialize + inputs = [].tap do |i| + i << Input.new(type: SDK::FuncSpec::Value) { |arg| + arg.type == "hashicorp.vagrant.sdk.Args.TargetIndex" && + !arg&.value&.value.nil? + } + i << Input.new(type: Broker) + end + super(inputs: inputs, output: Client::TargetIndex, func: method(:converter)) + end + + def converter(proto, broker) + Client::TargetIndex.load(proto.value.value, broker: broker) + end + end + + # Build a target index client from a proto instance + class TargetIndexFromProto < Mapper + def initialize + inputs = [].tap do |i| + i << Input.new(type: SDK::Args::TargetIndex) + i << Input.new(type: Broker) + end + super(inputs: inputs, output: Client::TargetIndex, func: method(:converter)) + end + + def converter(proto, broker) + Client::TargetIndex.load(proto, broker: broker) + end + end + + # Build a target index client from a serialized proto string + class TargetIndexFromString < Mapper + def initialize + inputs = [].tap do |i| + i << Input.new(type: String) + i << Input.new(type: Broker) + end + super(inputs: inputs, output: Client::TargetIndex, func: method(:converter)) + end + + def converter(proto, broker) + Client::TargetIndex.load(proto, broker: broker) + end + end + end + end +end diff --git a/plugins/commands/serve/mappers/terminal.rb b/plugins/commands/serve/mappers/terminal.rb new file mode 100644 index 000000000..ac5da2a10 --- /dev/null +++ b/plugins/commands/serve/mappers/terminal.rb @@ -0,0 +1,53 @@ +module VagrantPlugins + module CommandServe + class Mappers + # Build a terminal client from a FuncSpec value + class TerminalFromSpec < Mapper + def initialize + inputs = [].tap do |i| + i << Input.new(type: SDK::FuncSpec::Value) { |arg| + arg.type == "hashicorp.vagrant.sdk.Args.TerminalUI" && + !arg&.value&.value.nil? + } + i << Input.new(type: Broker) + end + super(inputs: inputs, output: Client::Terminal, func: method(:converter)) + end + + def converter(proto, broker) + Client::Terminal.load(proto.value.value, broker: broker) + end + end + + # Build a terminal client from a proto instance + class TerminalFromProto < Mapper + def initialize + inputs = [].tap do |i| + i << Input.new(type: SDK::Args::TerminalUI) + i << Input.new(type: Broker) + end + super(inputs: inputs, output: Client::Terminal, func: method(:converter)) + end + + def converter(proto, broker) + Client::Terminal.load(proto, broker: broker) + end + end + + # Build a terminal client from a serialized proto string + class TerminalFromString < Mapper + def initialize + inputs = [].tap do |i| + i << Input.new(type: String) + i << Input.new(type: Broker) + end + super(inputs: inputs, output: Client::Terminal, func: method(:converter)) + end + + def converter(proto, broker) + Client::Terminal.load(proto, broker: broker) + end + end + end + end +end