From 6be33f1f845de98a1fbe333dc74866c6fee2b45b Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Fri, 15 Oct 2021 10:08:02 -0700 Subject: [PATCH] Add seed methods to capability client and adjust capability request --- .../serve/client/capability_platform.rb | 48 ++++++++++++------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/plugins/commands/serve/client/capability_platform.rb b/plugins/commands/serve/client/capability_platform.rb index 79fefea7d..eb3fdaf76 100644 --- a/plugins/commands/serve/client/capability_platform.rb +++ b/plugins/commands/serve/client/capability_platform.rb @@ -5,51 +5,67 @@ module VagrantPlugins module Client module CapabilityPlatform - attr_reader :client + def seed(*args) + raise NotImplementedError, + "Seeding is not currently supported via Ruby client" + end + + def seeds + res = client.seeds(Empty.new) + res.list + end # @param [Symbol] cap_name Capability name # @return [Boolean] def has_capability?(cap_name) - @logger.debug("checking for capability #{cap_name}") - val = SDK::Args::NamedCapability.new(Capability: cap_name.to_s) + logger.debug("checking for capability #{cap_name}") + val = SDK::Args::NamedCapability.new(capability: cap_name.to_s) req = SDK::FuncSpec::Args.new( args: [SDK::FuncSpec::Value.new( - name: "", - type: "hashicorp.vagrant.sdk.Args.NamedCapability", + name: "", + type: "hashicorp.vagrant.sdk.Args.NamedCapability", value: Google::Protobuf::Any.pack(val) )] ) - res = @client.has_capability(req) - @logger.debug("got result #{res}") + res = client.has_capability(req) + logger.debug("got result #{res}") res.has_capability end # @param [Symbol] cap_name Name of the capability def capability(cap_name, *args) - arg_protos = [] - args.each do |a| + arg_protos = seeds.map do |any| + SDK::FuncSpec::Value.new( + name: "", + type: any.type_name, + value: any, + ) + end + any_args = args.map do |a| if a.class.ancestors.include?(Google::Protobuf::MessageExts) val = a else val = Google::Protobuf::Value.new val.from_ruby(a) end - arg_protos << SDK::FuncSpec::Value.new( - name: "", - type: "", - value: Google::Protobuf::Any.pack(val) - ) + Google::Protobuf::Any.pack(val) end + arg_protos << SDK::FuncSpec::Value.new( + name: "", + type: "hashicorp.vagrant.sdk.Args.Direct", + value: Google::Protobuf::Any.pack(SDK::Args::Direct.new(list: any_args)), + ) + req = SDK::Platform::Capability::NamedRequest.new( name: cap_name.to_s, func_args: SDK::FuncSpec::Args.new( - args: arg_protos + args: arg_protos, ) ) - @client.capability(req) + client.capability(req) end end end