diff --git a/command/plugin-exec.go b/command/plugin-exec.go index 18dc3e1453..f0d6a8d51a 100644 --- a/command/plugin-exec.go +++ b/command/plugin-exec.go @@ -4,6 +4,7 @@ import ( "fmt" "strings" + "github.com/hashicorp/vault/helper/pluginutil" "github.com/hashicorp/vault/meta" ) @@ -11,11 +12,6 @@ type PluginExec struct { meta.Meta } -var builtinFactories = map[string]func() error{ -// "mysql-database-plugin": mysql.Factory, -// "postgres-database-plugin": postgres.Factory, -} - func (c *PluginExec) Run(args []string) int { flags := c.Meta.FlagSet("plugin-exec", meta.FlagSetDefault) flags.Usage = func() { c.Ui.Error(c.Help()) } @@ -33,14 +29,14 @@ func (c *PluginExec) Run(args []string) int { pluginName := args[0] - factory, ok := builtinFactories[pluginName] + runner, ok := pluginutil.BuiltinPlugins[pluginName] if !ok { c.Ui.Error(fmt.Sprintf( "No plugin with the name %s found", pluginName)) return 1 } - err := factory() + err := runner() if err != nil { c.Ui.Error(fmt.Sprintf( "Error running plugin: %s", err)) @@ -51,19 +47,18 @@ func (c *PluginExec) Run(args []string) int { } func (c *PluginExec) Synopsis() string { - return "Force the Vault node to give up active duty" + return "Runs a builtin plugin. Should only be called by vault." } func (c *PluginExec) Help() string { helpText := ` -Usage: vault step-down [options] +Usage: vault plugin-exec type - Force the Vault node to step down from active duty. + Runs a builtin plugin. Should only be called by vault. - This causes the indicated node to give up active status. Note that while the - affected node will have a short delay before attempting to grab the lock - again, if no other node grabs the lock beforehand, it is possible for the - same node to re-grab the lock and become active again. + This will execute a plugin for use in a plugable location in vault. If run by + a cli user it will print a message indicating it can not be executed by anyone + other than vault. For supported plugin types see the vault documentation. General Options: ` + meta.GeneralOptionsUsage() diff --git a/helper/pluginutil/builtin.go b/helper/pluginutil/builtin.go new file mode 100644 index 0000000000..6a464bb824 --- /dev/null +++ b/helper/pluginutil/builtin.go @@ -0,0 +1,6 @@ +package pluginutil + +var BuiltinPlugins = map[string]func() error{ +// "mysql-database-plugin": mysql.Run, +// "postgres-database-plugin": postgres.Run, +} diff --git a/vault/plugin_catalog.go b/vault/plugin_catalog.go index eccac2bd1b..c6e4e4059b 100644 --- a/vault/plugin_catalog.go +++ b/vault/plugin_catalog.go @@ -10,13 +10,11 @@ import ( "github.com/hashicorp/vault/helper/jsonutil" "github.com/hashicorp/vault/helper/pluginutil" - "github.com/hashicorp/vault/helper/strutil" "github.com/hashicorp/vault/logical" ) var ( pluginCatalogPrefix = "plugin-catalog/" - builtinPlugins = []string{"mysql-database-plugin", "postgres-database-plugin"} ) type PluginCatalog struct { @@ -55,7 +53,7 @@ func (c *PluginCatalog) Get(name string) (*pluginutil.PluginRunner, error) { } // Look for builtin plugins - if !strutil.StrListContains(builtinPlugins, name) { + if _, ok := pluginutil.BuiltinPlugins[name]; !ok { return nil, fmt.Errorf("no plugin found with name: %s", name) }