diff --git a/lib/vagrant/config/v2/dummy_config.rb b/lib/vagrant/config/v2/dummy_config.rb index ebf2ddd10..817bc88f3 100644 --- a/lib/vagrant/config/v2/dummy_config.rb +++ b/lib/vagrant/config/v2/dummy_config.rb @@ -63,7 +63,7 @@ module Vagrant protoize = self.instance_variables_hash protoize.delete_if{|k,v| k.start_with?("_") } - config_struct = Google::Protobuf::Struct.from_hash(protoize) + config_struct = mapper.map(protoize, to: Hashicorp::Vagrant::Sdk::Args::Hash) config_any = Google::Protobuf::Any.pack(config_struct) Hashicorp::Vagrant::Sdk::Vagrantfile::GeneralConfig.new(type: type, config: config_any) end diff --git a/lib/vagrant/plugin/v2/config.rb b/lib/vagrant/plugin/v2/config.rb index edc1cf4a9..ec0eb6c77 100644 --- a/lib/vagrant/plugin/v2/config.rb +++ b/lib/vagrant/plugin/v2/config.rb @@ -230,9 +230,55 @@ module Vagrant protoize end - def to_proto(type) - mapper = VagrantPlugins::CommandServe::Mappers.new + def build_proto_array(a) + out = Hashicorp::Vagrant::Sdk::Args::Array.new + a.each do |e| + if e.is_a?(Hash) + out.list << Google::Protobuf::Any.pack(build_proto_hash(e)) + next + end + + if e.is_a?(Array) + out.list << Google::Protobuf::Any.pack(build_proto_array(e)) + next + end + + if e.class.ancestors.include?(Google::Protobuf::MessageExts) + out.list << Google::Protobuf::Any.pack(e) + else + val = Google::Protobuf::Value.new + val.from_ruby(e) + out.list << Google::Protobuf::Any.pack(val) + end + end + return out + end + + def build_proto_hash(h) + out = Hashicorp::Vagrant::Sdk::Args::Hash.new + h.each do |k, v| + if v.is_a?(Hash) + out.fields[k] = Google::Protobuf::Any.pack(build_proto_hash(v)) + next + end + + if v.is_a?(Array) + out.fields[k] = Google::Protobuf::Any.pack(build_proto_array(v)) + next + end + + if v.class.ancestors.include?(Google::Protobuf::MessageExts) + out.fields[k] = Google::Protobuf::Any.pack(v) + else + val = Google::Protobuf::Value.new + val.from_ruby(v) + out.fields[k] = Google::Protobuf::Any.pack(val) + end + end + return out + end + def to_proto(type) protoize = self.instance_variables_hash protoize.map do |k,v| # Get embedded default struct @@ -243,7 +289,7 @@ module Vagrant end end protoize = clean_up_config_object(protoize) - config_struct = mapper.map(protoize, to: Hashicorp::Vagrant::Sdk::Args::Hash) + config_struct = build_proto_hash(protoize) config_any = Google::Protobuf::Any.pack(config_struct) GENERAL_CONFIG_CLS.new(type: type, config: config_any) end diff --git a/plugins/commands/serve/mappers/known_types.rb b/plugins/commands/serve/mappers/known_types.rb index 545a2b57b..926ebd414 100644 --- a/plugins/commands/serve/mappers/known_types.rb +++ b/plugins/commands/serve/mappers/known_types.rb @@ -198,7 +198,7 @@ module VagrantPlugins end end - class SpecialTypeSymbolToAny < Mapper + class SymbolToAny < Mapper def initialize super( inputs: [Input.new(type: SDK::SpecialTypes::Symbol)], @@ -212,7 +212,7 @@ module VagrantPlugins end end - class SpecialTypeSymbolToSymbol < Mapper + class SymbolProtoToSymbol < Mapper def initialize super( inputs: [Input.new(type: SDK::SpecialTypes::Symbol)], diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index 02c9bc8c0..b7a2e4255 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -1126,6 +1126,7 @@ module VagrantPlugins sf_proto.send("#{opt.to_s}=", val) end + config_struct = @mapper.map(config_opts, to: Hashicorp::Vagrant::Sdk::Args::Hash) config_any = Google::Protobuf::Any.pack(config_struct) sf_proto.config = config_any diff --git a/plugins/kernel_v2/config/vm_provisioner.rb b/plugins/kernel_v2/config/vm_provisioner.rb index 7e7b66ef3..a9f27e21f 100644 --- a/plugins/kernel_v2/config/vm_provisioner.rb +++ b/plugins/kernel_v2/config/vm_provisioner.rb @@ -202,7 +202,8 @@ module VagrantPlugins begin if k == "config" protoize = clean_up_config_object(c.config.instance_variables_hash) - config_struct = mapper.map(protoize, to: Hashicorp::Vagrant::Sdk::Args::Hash) + + config_struct = @mapper.map(protoize, to: Hashicorp::Vagrant::Sdk::Args::Hash) config_any = Google::Protobuf::Any.pack(config_struct) proto.config = config_any next