diff --git a/plugins/commands/serve/mappers.rb b/plugins/commands/serve/mappers.rb index 44ff6a052..d33597281 100644 --- a/plugins/commands/serve/mappers.rb +++ b/plugins/commands/serve/mappers.rb @@ -258,6 +258,7 @@ end # NOTE: Always directly load mappers so they are automatically registered and # available. Using autoloading behavior will result in them being unavailable # until explicitly requested by name +require Vagrant.source_root.join("plugins/commands/serve/mappers/basis.rb").to_s require Vagrant.source_root.join("plugins/commands/serve/mappers/box.rb").to_s require Vagrant.source_root.join("plugins/commands/serve/mappers/capabilities.rb").to_s require Vagrant.source_root.join("plugins/commands/serve/mappers/command.rb").to_s @@ -269,6 +270,7 @@ require Vagrant.source_root.join("plugins/commands/serve/mappers/machine.rb").to require Vagrant.source_root.join("plugins/commands/serve/mappers/pathname.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 require Vagrant.source_root.join("plugins/commands/serve/mappers/target.rb").to_s require Vagrant.source_root.join("plugins/commands/serve/mappers/target_index.rb").to_s require Vagrant.source_root.join("plugins/commands/serve/mappers/terminal.rb").to_s diff --git a/plugins/commands/serve/mappers/basis.rb b/plugins/commands/serve/mappers/basis.rb new file mode 100644 index 000000000..7979a573f --- /dev/null +++ b/plugins/commands/serve/mappers/basis.rb @@ -0,0 +1,59 @@ +module VagrantPlugins + module CommandServe + class Mappers + class BasisProtoFromSpec < Mapper + def initialize + super( + inputs: [Input.new(type: SDK::FuncSpec::Value) { |arg| + arg.type == "hashicorp.vagrant.sdk.Args.Basis" && + !arg&.value&.value.nil? + } + ], + output: SDK::Args::Basis, + func: method(:converter), + ) + end + + def converter(fv) + SDK::Args::Basis.decode(fv.value.value) + end + end + + # Build a basis client from a proto instance + class BasisFromProto < Mapper + def initialize + inputs = [].tap do |i| + i << Input.new(type: SDK::Args::Basis) + i << Input.new(type: Broker) + i << Input.new(type: Util::Cacher) + end + super(inputs: inputs, output: Client::Basis, func: method(:converter)) + end + + def converter(proto, broker, cacher) + cid = proto.target.to_s if proto.target.to_s != "" + return cacher[cid] if cid && cacher.registered?(cid) + + project = Client::Basis.load(proto, broker: broker) + cacher[cid] = project if cid + project + end + end + + # Build a synced folder client from a serialized proto string + class BasisFromString < Mapper + def initialize + inputs = [].tap do |i| + i << Input.new(type: String) + i << Input.new(type: Broker) + end + super(inputs: inputs, output: Client::Basis, func: method(:converter)) + end + + def converter(proto, broker) + Client::Basis.load(proto, broker: broker) + end + end + end + end +end diff --git a/plugins/commands/serve/mappers/synced_folder.rb b/plugins/commands/serve/mappers/synced_folder.rb new file mode 100644 index 000000000..a37fbb372 --- /dev/null +++ b/plugins/commands/serve/mappers/synced_folder.rb @@ -0,0 +1,41 @@ +module VagrantPlugins + module CommandServe + class Mappers + # Build a synced folder client from a proto instance + class SyncedFolderFromProto < Mapper + def initialize + inputs = [].tap do |i| + i << Input.new(type: SDK::Args::SyncedFolder) + i << Input.new(type: Broker) + i << Input.new(type: Util::Cacher) + end + super(inputs: inputs, output: Client::SyncedFolder, func: method(:converter)) + end + + def converter(proto, broker, cacher) + cid = proto.target.to_s if proto.target.to_s != "" + return cacher[cid] if cid && cacher.registered?(cid) + + project = Client::SyncedFolder.load(proto, broker: broker) + cacher[cid] = project if cid + project + end + end + + # Build a synced folder client from a serialized proto string + class SyncedFolderFromString < Mapper + def initialize + inputs = [].tap do |i| + i << Input.new(type: String) + i << Input.new(type: Broker) + end + super(inputs: inputs, output: Client::SyncedFolder, func: method(:converter)) + end + + def converter(proto, broker) + Client::SyncedFolder.load(proto, broker: broker) + end + end + end + end +end