Add mappers for host and plugin manager clients

This commit is contained in:
Chris Roberts 2021-12-17 14:58:31 -08:00 committed by Paul Hinze
parent 3f7b7ee65a
commit de18081a35
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
3 changed files with 80 additions and 0 deletions

View File

@ -268,9 +268,11 @@ require Vagrant.source_root.join("plugins/commands/serve/mappers/communicator.rb
require Vagrant.source_root.join("plugins/commands/serve/mappers/direct.rb").to_s
require Vagrant.source_root.join("plugins/commands/serve/mappers/environment.rb").to_s
require Vagrant.source_root.join("plugins/commands/serve/mappers/guest.rb").to_s
require Vagrant.source_root.join("plugins/commands/serve/mappers/host.rb").to_s
require Vagrant.source_root.join("plugins/commands/serve/mappers/known_types.rb").to_s
require Vagrant.source_root.join("plugins/commands/serve/mappers/machine.rb").to_s
require Vagrant.source_root.join("plugins/commands/serve/mappers/pathname.rb").to_s
require Vagrant.source_root.join("plugins/commands/serve/mappers/plugin_manager.rb").to_s
require Vagrant.source_root.join("plugins/commands/serve/mappers/project.rb").to_s
require Vagrant.source_root.join("plugins/commands/serve/mappers/state_bag.rb").to_s
require Vagrant.source_root.join("plugins/commands/serve/mappers/synced_folder.rb").to_s

View File

@ -0,0 +1,56 @@
module VagrantPlugins
module CommandServe
class Mappers
class HostProtoFromSpec < Mapper
def initialize
super(
inputs: [Input.new(type: SDK::FuncSpec::Value) { |arg|
arg.type == "hashicorp.vagrant.sdk.Args.Host" &&
!arg&.value&.value.nil?
}
],
output: SDK::Args::Host,
func: method(:converter)
)
end
def converter(fv)
SDK::Args::Host.decode(fv.value.value)
end
end
# Build a guest client from a FuncSpec value
class HostFromSpec < Mapper
def initialize
inputs = [].tap do |i|
i << Input.new(type: SDK::FuncSpec::Value) { |arg|
arg.type == "hashicorp.vagrant.sdk.Args.Host" &&
!arg&.value&.value.nil?
}
i << Input.new(type: Broker)
end
super(inputs: inputs, output: Client::Host, func: method(:converter))
end
def converter(proto, broker)
Client::Host.load(proto.value.value, broker: broker)
end
end
# Build a guest client from a proto instance
class HostFromProto < Mapper
def initialize
inputs = [].tap do |i|
i << Input.new(type: SDK::Args::Host)
i << Input.new(type: Broker)
end
super(inputs: inputs, output: Client::Host, func: method(:converter))
end
def converter(proto, broker)
Client::Host.load(proto, broker: broker)
end
end
end
end
end

View File

@ -0,0 +1,22 @@
module VagrantPlugins
module CommandServe
class Mappers
class PluginManagerFromProto < Mapper
def initialize
super(
inputs: [
Input.new(type: SDK::Args::PluginManager),
Input.new(type: Broker),
],
output: Client::PluginManager,
func: method(:converter)
)
end
def converter(proto, broker)
Client::PluginManager.load(proto, broker: broker)
end
end
end
end
end