Run all builtins as plugins (#5536)

This commit is contained in:
Becca Petrin
2018-11-06 17:21:24 -08:00
committed by GitHub
parent f63bcdf106
commit fb89af7cfa
88 changed files with 1474 additions and 778 deletions

View File

@@ -5,6 +5,7 @@ import (
"strings"
"github.com/hashicorp/vault/api"
"github.com/hashicorp/vault/helper/consts"
"github.com/mitchellh/cli"
"github.com/posener/complete"
)
@@ -22,14 +23,15 @@ func (c *PluginInfoCommand) Synopsis() string {
func (c *PluginInfoCommand) Help() string {
helpText := `
Usage: vault plugin info [options] NAME
Usage: vault plugin info [options] TYPE NAME
Displays information about a plugin in the catalog with the given name. If
the plugin does not exist, an error is returned.
the plugin does not exist, an error is returned. The argument of type
takes "auth", "database", or "secret".
Get info about a plugin:
$ vault plugin info mysql-database-plugin
$ vault plugin info database mysql-database-plugin
` + c.Flags().Help()
@@ -41,7 +43,7 @@ func (c *PluginInfoCommand) Flags() *FlagSets {
}
func (c *PluginInfoCommand) AutocompleteArgs() complete.Predictor {
return c.PredictVaultPlugins()
return c.PredictVaultPlugins(consts.PluginTypeUnknown)
}
func (c *PluginInfoCommand) AutocompleteFlags() complete.Flags {
@@ -58,10 +60,10 @@ func (c *PluginInfoCommand) Run(args []string) int {
args = f.Args()
switch {
case len(args) < 1:
case len(args) < 2:
c.UI.Error(fmt.Sprintf("Not enough arguments (expected 1, got %d)", len(args)))
return 1
case len(args) > 1:
case len(args) > 2:
c.UI.Error(fmt.Sprintf("Too many arguments (expected 1, got %d)", len(args)))
return 1
}
@@ -72,10 +74,16 @@ func (c *PluginInfoCommand) Run(args []string) int {
return 2
}
pluginName := strings.TrimSpace(args[0])
pluginType, err := consts.ParsePluginType(strings.TrimSpace(args[0]))
if err != nil {
c.UI.Error(err.Error())
return 2
}
pluginName := strings.TrimSpace(args[1])
resp, err := client.Sys().GetPlugin(&api.GetPluginInput{
Name: pluginName,
Type: pluginType,
})
if err != nil {
c.UI.Error(fmt.Sprintf("Error reading plugin named %s: %s", pluginName, err))