From f4811af75926ebfc15a4f2312f12b8e99cb1743f Mon Sep 17 00:00:00 2001 From: sophia Date: Thu, 31 Mar 2022 14:57:28 -0500 Subject: [PATCH] Use symbol proto when protoizing plugin configs --- lib/vagrant/config/v2/dummy_config.rb | 2 ++ plugins/kernel_v2/config/vm.rb | 12 +++++++----- plugins/kernel_v2/config/vm_provisioner.rb | 3 ++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/vagrant/config/v2/dummy_config.rb b/lib/vagrant/config/v2/dummy_config.rb index 8a5db0663..ebf2ddd10 100644 --- a/lib/vagrant/config/v2/dummy_config.rb +++ b/lib/vagrant/config/v2/dummy_config.rb @@ -59,6 +59,8 @@ module Vagrant # @param type [String] a name to put into the type field, e.g. plugin name # @return [Hashicorp::Vagrant::Sdk::Vagrantfile::GeneralConfig] def to_proto(type) + mapper = VagrantPlugins::CommandServe::Mappers.new + protoize = self.instance_variables_hash protoize.delete_if{|k,v| k.start_with?("_") } config_struct = Google::Protobuf::Struct.from_hash(protoize) diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index 4d05e0221..02c9bc8c0 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -71,6 +71,9 @@ module VagrantPlugins def initialize @logger = Log4r::Logger.new("vagrant::config::vm") + # Mappers are used by functions that produce a proto + @mapper = VagrantPlugins::CommandServe::Mappers.new + @allowed_synced_folder_types = UNSET_VALUE @allow_fstab_modification = UNSET_VALUE @base_mac = UNSET_VALUE @@ -1065,12 +1068,11 @@ module VagrantPlugins vm_config.define_singleton_method(:compiled_provider_configs) do return @__compiled_provider_configs end - + vm_config.compiled_provider_configs.each do |type, config| c = clean_up_config_object(config.instance_variables_hash) - provider_proto = PROVIDER_PROTO_CLS.new(type: type) - config_struct = Google::Protobuf::Struct.from_hash(c) + config_struct = @mapper.map(c, to: Hashicorp::Vagrant::Sdk::Args::Hash) config_any = Google::Protobuf::Any.pack(config_struct) provider_proto.config = config_any target << provider_proto @@ -1088,7 +1090,7 @@ module VagrantPlugins network_proto = NETWORK_PROTO_CLS.new(type: type, id: opts.fetch(:id, "")) opts.delete(:id) opts.transform_keys!(&:to_s) - config_struct = Google::Protobuf::Struct.from_hash(opts) + config_struct = @mapper.map(opts, to: Hashicorp::Vagrant::Sdk::Args::Hash) config_any = Google::Protobuf::Any.pack(config_struct) network_proto.config = config_any target << network_proto @@ -1124,7 +1126,7 @@ module VagrantPlugins sf_proto.send("#{opt.to_s}=", val) end - config_struct = Google::Protobuf::Struct.from_hash(config_opts) + 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 target << sf_proto diff --git a/plugins/kernel_v2/config/vm_provisioner.rb b/plugins/kernel_v2/config/vm_provisioner.rb index 241531b82..7e7b66ef3 100644 --- a/plugins/kernel_v2/config/vm_provisioner.rb +++ b/plugins/kernel_v2/config/vm_provisioner.rb @@ -65,6 +65,7 @@ module VagrantPlugins def initialize(name, type, **options) @logger = Log4r::Logger.new("vagrant::config::vm::provisioner") @logger.debug("Provisioner defined: #{name}") + @mapper = VagrantPlugins::CommandServe::Mappers.new @id = name || SecureRandom.uuid @config = nil @@ -201,7 +202,7 @@ module VagrantPlugins begin if k == "config" protoize = clean_up_config_object(c.config.instance_variables_hash) - 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) proto.config = config_any next