2018-07-13 17:35:08 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/hashicorp/vault/api"
|
2019-04-12 21:54:35 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/helper/consts"
|
2018-07-13 17:35:08 +00:00
|
|
|
"github.com/mitchellh/cli"
|
|
|
|
"github.com/posener/complete"
|
|
|
|
)
|
|
|
|
|
2021-04-08 16:43:39 +00:00
|
|
|
var (
|
|
|
|
_ cli.Command = (*PluginInfoCommand)(nil)
|
|
|
|
_ cli.CommandAutocomplete = (*PluginInfoCommand)(nil)
|
|
|
|
)
|
2018-07-13 17:35:08 +00:00
|
|
|
|
|
|
|
type PluginInfoCommand struct {
|
|
|
|
*BaseCommand
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *PluginInfoCommand) Synopsis() string {
|
|
|
|
return "Read information about a plugin in the catalog"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *PluginInfoCommand) Help() string {
|
|
|
|
helpText := `
|
2018-11-07 01:21:24 +00:00
|
|
|
Usage: vault plugin info [options] TYPE NAME
|
2018-07-13 17:35:08 +00:00
|
|
|
|
|
|
|
Displays information about a plugin in the catalog with the given name. If
|
2018-11-07 01:21:24 +00:00
|
|
|
the plugin does not exist, an error is returned. The argument of type
|
|
|
|
takes "auth", "database", or "secret".
|
2018-07-13 17:35:08 +00:00
|
|
|
|
|
|
|
Get info about a plugin:
|
|
|
|
|
2018-11-07 01:21:24 +00:00
|
|
|
$ vault plugin info database mysql-database-plugin
|
2018-07-13 17:35:08 +00:00
|
|
|
|
|
|
|
` + c.Flags().Help()
|
|
|
|
|
|
|
|
return strings.TrimSpace(helpText)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *PluginInfoCommand) Flags() *FlagSets {
|
|
|
|
return c.flagSet(FlagSetHTTP | FlagSetOutputField | FlagSetOutputFormat)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *PluginInfoCommand) AutocompleteArgs() complete.Predictor {
|
2018-11-07 01:21:24 +00:00
|
|
|
return c.PredictVaultPlugins(consts.PluginTypeUnknown)
|
2018-07-13 17:35:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *PluginInfoCommand) AutocompleteFlags() complete.Flags {
|
|
|
|
return c.Flags().Completions()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *PluginInfoCommand) Run(args []string) int {
|
|
|
|
f := c.Flags()
|
|
|
|
|
|
|
|
if err := f.Parse(args); err != nil {
|
|
|
|
c.UI.Error(err.Error())
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2018-11-15 22:33:11 +00:00
|
|
|
var pluginNameRaw, pluginTypeRaw string
|
2018-07-13 17:35:08 +00:00
|
|
|
args = f.Args()
|
|
|
|
switch {
|
2018-11-15 22:33:11 +00:00
|
|
|
case len(args) < 1:
|
|
|
|
c.UI.Error(fmt.Sprintf("Not enough arguments (expected 1 or 2, got %d)", len(args)))
|
2018-07-13 17:35:08 +00:00
|
|
|
return 1
|
2018-11-07 01:21:24 +00:00
|
|
|
case len(args) > 2:
|
2018-11-15 22:33:11 +00:00
|
|
|
c.UI.Error(fmt.Sprintf("Too many arguments (expected 1 or 2, got %d)", len(args)))
|
2018-07-13 17:35:08 +00:00
|
|
|
return 1
|
2018-11-15 22:33:11 +00:00
|
|
|
|
|
|
|
// These cases should come after invalid cases have been checked
|
|
|
|
case len(args) == 1:
|
|
|
|
pluginTypeRaw = "unknown"
|
|
|
|
pluginNameRaw = args[0]
|
|
|
|
case len(args) == 2:
|
|
|
|
pluginTypeRaw = args[0]
|
|
|
|
pluginNameRaw = args[1]
|
2018-07-13 17:35:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
client, err := c.Client()
|
|
|
|
if err != nil {
|
|
|
|
c.UI.Error(err.Error())
|
|
|
|
return 2
|
|
|
|
}
|
|
|
|
|
2018-11-15 22:33:11 +00:00
|
|
|
pluginType, err := consts.ParsePluginType(strings.TrimSpace(pluginTypeRaw))
|
2018-11-07 01:21:24 +00:00
|
|
|
if err != nil {
|
|
|
|
c.UI.Error(err.Error())
|
|
|
|
return 2
|
|
|
|
}
|
2018-11-15 22:33:11 +00:00
|
|
|
pluginName := strings.TrimSpace(pluginNameRaw)
|
2018-07-13 17:35:08 +00:00
|
|
|
|
|
|
|
resp, err := client.Sys().GetPlugin(&api.GetPluginInput{
|
|
|
|
Name: pluginName,
|
2018-11-07 01:21:24 +00:00
|
|
|
Type: pluginType,
|
2018-07-13 17:35:08 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
c.UI.Error(fmt.Sprintf("Error reading plugin named %s: %s", pluginName, err))
|
|
|
|
return 2
|
|
|
|
}
|
|
|
|
|
2018-11-15 22:33:11 +00:00
|
|
|
if resp == nil {
|
|
|
|
c.UI.Error(fmt.Sprintf("No value found for plugin %q", pluginName))
|
|
|
|
return 2
|
|
|
|
}
|
|
|
|
|
2018-07-13 17:35:08 +00:00
|
|
|
data := map[string]interface{}{
|
2022-09-09 20:03:07 +00:00
|
|
|
"args": resp.Args,
|
|
|
|
"builtin": resp.Builtin,
|
|
|
|
"command": resp.Command,
|
|
|
|
"name": resp.Name,
|
|
|
|
"sha256": resp.SHA256,
|
|
|
|
"deprecation_status": resp.DeprecationStatus,
|
2018-07-13 17:35:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if c.flagField != "" {
|
|
|
|
return PrintRawField(c.UI, data, c.flagField)
|
|
|
|
}
|
|
|
|
return OutputData(c.UI, data)
|
|
|
|
}
|