Add basic mappers for client types
This commit is contained in:
parent
c0304101f4
commit
fc88c8d580
22
plugins/commands/serve/mappers/command.rb
Normal file
22
plugins/commands/serve/mappers/command.rb
Normal file
@ -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
|
||||
53
plugins/commands/serve/mappers/guest.rb
Normal file
53
plugins/commands/serve/mappers/guest.rb
Normal file
@ -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
|
||||
53
plugins/commands/serve/mappers/machine.rb
Normal file
53
plugins/commands/serve/mappers/machine.rb
Normal file
@ -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
|
||||
53
plugins/commands/serve/mappers/project.rb
Normal file
53
plugins/commands/serve/mappers/project.rb
Normal file
@ -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
|
||||
53
plugins/commands/serve/mappers/target.rb
Normal file
53
plugins/commands/serve/mappers/target.rb
Normal file
@ -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
|
||||
53
plugins/commands/serve/mappers/target_index.rb
Normal file
53
plugins/commands/serve/mappers/target_index.rb
Normal file
@ -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
|
||||
53
plugins/commands/serve/mappers/terminal.rb
Normal file
53
plugins/commands/serve/mappers/terminal.rb
Normal file
@ -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
|
||||
Loading…
x
Reference in New Issue
Block a user