Update mappers to include maps from funcspec value to proto

This commit is contained in:
Chris Roberts 2021-11-18 15:12:45 -08:00 committed by Paul Hinze
parent 2513d21054
commit 3cc92280f8
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
10 changed files with 202 additions and 17 deletions

View File

@ -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

View File

@ -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|

View File

@ -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

View File

@ -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

View File

@ -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(

View File

@ -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

View File

@ -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|

View File

@ -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

View File

@ -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

View File

@ -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