2023-08-10 16:53:25 -04:00
|
|
|
# Copyright (c) HashiCorp, Inc.
|
|
|
|
|
# SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
2021-12-17 17:57:52 -05:00
|
|
|
module VagrantPlugins
|
|
|
|
|
module CommandServe
|
2022-01-21 17:11:32 -05:00
|
|
|
class Client
|
|
|
|
|
class PluginManager < Client
|
2021-12-17 17:57:52 -05:00
|
|
|
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,
|
2022-07-11 18:07:22 -04:00
|
|
|
proto: plg.plugin,
|
|
|
|
|
options: _plugin_options_to_hash(plg.options),
|
2021-12-17 17:57:52 -05:00
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def get_plugin(name:, type:)
|
2022-06-15 12:44:42 -04:00
|
|
|
logger.info("fetching plugin from vagrant-agogo name: #{name}, type: #{type}")
|
2021-12-17 17:57:52 -05:00
|
|
|
resp = client.get_plugin(
|
|
|
|
|
SDK::PluginManager::Plugin.new(
|
|
|
|
|
name: name,
|
|
|
|
|
type: type
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
mapper.map(resp.plugin, broker)
|
|
|
|
|
end
|
2022-07-11 18:07:22 -04:00
|
|
|
|
|
|
|
|
# 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)
|
2022-07-20 18:23:19 -04:00
|
|
|
return {} if plg_opts.nil?
|
2022-07-11 18:07:22 -04:00
|
|
|
opts = mapper.unany(plg_opts)
|
|
|
|
|
case opts
|
2022-07-26 14:47:59 -04:00
|
|
|
when Hashicorp::Vagrant::Sdk::PluginInfo::CommandOptions
|
|
|
|
|
opts.to_h
|
2022-07-11 18:07:22 -04:00
|
|
|
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
|
2021-12-17 17:57:52 -05:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|