Add provider parsing to internal endpoint

This commit is contained in:
Chris Roberts 2022-06-20 13:05:26 -07:00
parent f57ffec0fd
commit 17fc49cf41
3 changed files with 52 additions and 23 deletions

View File

@ -17,6 +17,7 @@ service RubyVagrant {
rpc ParseVagrantfile(ParseVagrantfileRequest) returns (ParseVagrantfileResponse);
rpc ParseVagrantfileProc(ParseVagrantfileProcRequest) returns (ParseVagrantfileResponse);
rpc ParseVagrantfileSubvm(ParseVagrantfileSubvmRequest) returns (ParseVagrantfileResponse);
rpc ParseVagrantfileProvider(ParseVagrantfileProviderRequest) returns (ParseVagrantfileResponse);
}
/********************************************************************
@ -80,3 +81,8 @@ message ParseVagrantfileResponse {
message ParseVagrantfileSubvmRequest {
sdk.Config.RawRubyValue subvm = 1;
}
message ParseVagrantfileProviderRequest {
sdk.Config.RawRubyValue subvm = 1;
string provider = 2;
}

View File

@ -105,3 +105,19 @@ func (r *RubyVagrantClient) ParseVagrantfileSubvm(subvm *vagrant_plugin_sdk.Conf
return resp.Data, nil
}
func (r *RubyVagrantClient) ParseVagrantfileProvider(provider string, subvm *vagrant_plugin_sdk.Config_RawRubyValue) (*vagrant_plugin_sdk.Args_Hash, error) {
resp, err := r.client.ParseVagrantfileProvider(
context.Background(),
&ruby_vagrant.ParseVagrantfileProviderRequest{
Provider: provider,
Subvm: subvm,
},
)
if err != nil {
return nil, err
}
return resp.Data, nil
}

View File

@ -41,44 +41,48 @@ module VagrantPlugins
end
def parse_vagrantfile(req, _)
path = req.path
# Load up/parse the vagrantfile
config_loader = loader
config_loader.set(:root, path.to_s)
config = config_loader.partial_load(:root)
Hashicorp::Vagrant::ParseVagrantfileResponse.new(
data: config.to_proto,
)
parse_item_to_proto(req.path.to_s)
end
def parse_vagrantfile_proc(req, _)
callable = mapper.map(req.proc, to: Proc)
config_loader = loader
config_loader.set(:root, [[2, callable]])
config = config_loader.partial_load(:root)
Hashicorp::Vagrant::ParseVagrantfileResponse.new(
data: config.to_proto,
)
parse_item_to_proto([["2", callable]])
end
def parse_vagrantfile_subvm(req, _)
subvm = mapper.map(req.subvm)
config_loader = loader
config_loader.set(:root, subvm.config_procs)
config = config_loader.partial_load(:root)
Hashicorp::Vagrant::ParseVagrantfileResponse.new(
data: config.to_proto,
)
parse_item_to_proto(subvm.config_procs)
end
def loader
Vagrant::Config::Loader.new(
def parse_vagrantfile_provider(req, _)
subvm = mapper.map(req.subvm)
provider = req.provider.to_sym
config = parse_item(subvm.config_procs)
overrides = config.vm.get_provider_overrides(provider)
return Hashicorp::Vagrant::ParseVagrantfileResponse.new(data: SDK::Args::Hash.new(entries: [])) if
overrides.empty?
parse_item_to_proto(config.vm.get_provider_overrides(provider))
end
def parse_item(item)
loader = Vagrant::Config::Loader.new(
Vagrant::Config::VERSIONS,
Vagrant::Config::VERSIONS_ORDER
)
loader.set(:item, item)
loader.partial_load(:item)
end
def parse_item_to_proto(item)
config = parse_item(item)
Hashicorp::Vagrant::ParseVagrantfileResponse.new(
data: config.to_proto,
)
end
def _convert_options_to_proto(type, class_or_tuple_with_class_and_options)
@ -89,6 +93,9 @@ module VagrantPlugins
when :COMMUNICATOR
# No options for communicators
return Google::Protobuf::Empty.new
when :CONFIG
# No options for configs
return Google::Protobuf::Empty.new
when :GUEST
# No options for guests
return Google::Protobuf::Empty.new