vaguerent/plugins/commands/serve/client/plugin_manager.rb
Paul Hinze 957d0d3779
Bring plugin options back to Ruby for providers and synced folders
This removes the need for the validation workaround for Docker, because
box_updated is once again available in that context.

We don't technically need the SyncedFolder priorities back on the Ruby
side, but wiring them through for symmetry.

Depends on https://github.com/hashicorp/vagrant-plugin-sdk/pull/183
2022-07-15 12:14:47 -05:00

54 lines
1.7 KiB
Ruby

module VagrantPlugins
module CommandServe
class Client
class PluginManager < Client
def list_plugins(types=[])
resp = client.list_plugins(
SDK::PluginManager::PluginsRequest.new(
types: Array(types).map(&:to_s)
)
)
resp.plugins.map do |plg|
Vagrant::Util::HashWithIndifferentAccess.new(
name: plg.name,
type: plg.type,
proto: plg.plugin,
options: _plugin_options_to_hash(plg.options),
)
end
end
def get_plugin(name:, type:)
logger.info("fetching plugin from vagrant-agogo name: #{name}, type: #{type}")
resp = client.get_plugin(
SDK::PluginManager::Plugin.new(
name: name,
type: type
)
)
mapper.map(resp.plugin, broker)
end
# Plugin options are an Any that contains one of the types defined in
# component.*Options in the SDK.
#
# On the Ruby side, plugin options are just a value that get stuffed in
# a tuple next to the plugin in the manager. Its type is context
# dependent so we need to unpack each kind of plugin options with its
# own logic.
def _plugin_options_to_hash(plg_opts)
opts = mapper.unany(plg_opts)
case opts
when Hashicorp::Vagrant::Sdk::PluginInfo::ProviderOptions
opts.to_h
when Hashicorp::Vagrant::Sdk::PluginInfo::SyncedFolderOptions
opts.priority
else
raise ArgumentError, "unexpected plugin options #{opts.inspect}"
end
end
end
end
end
end