-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into vault-monitor
- Loading branch information
Showing
103 changed files
with
1,853 additions
and
2,535 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
contact_links: | ||
- name: Ask a question | ||
url: https://discuss.hashicorp.com/c/vault | ||
about: For increased visibility, please post questions on the discussion forum. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package command | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/hashicorp/vault/api" | ||
"github.com/mitchellh/cli" | ||
"github.com/posener/complete" | ||
) | ||
|
||
var _ cli.Command = (*PluginReloadCommand)(nil) | ||
var _ cli.CommandAutocomplete = (*PluginReloadCommand)(nil) | ||
|
||
type PluginReloadCommand struct { | ||
*BaseCommand | ||
plugin string | ||
mounts []string | ||
} | ||
|
||
func (c *PluginReloadCommand) Synopsis() string { | ||
return "Reload mounted plugin backend" | ||
} | ||
|
||
func (c *PluginReloadCommand) Help() string { | ||
helpText := ` | ||
Usage: vault plugin reload [options] | ||
Reloads mounted plugins. Either the plugin name or the desired plugin | ||
mount(s) must be provided, but not both. In case the plugin name is provided, | ||
all of its corresponding mounted paths that use the plugin backend will be reloaded. | ||
Reload the plugin named "my-custom-plugin": | ||
$ vault plugin reload -plugin=my-custom-plugin | ||
` + c.Flags().Help() | ||
|
||
return strings.TrimSpace(helpText) | ||
} | ||
|
||
func (c *PluginReloadCommand) Flags() *FlagSets { | ||
set := c.flagSet(FlagSetHTTP) | ||
|
||
f := set.NewFlagSet("Command Options") | ||
|
||
f.StringVar(&StringVar{ | ||
Name: "plugin", | ||
Target: &c.plugin, | ||
Completion: complete.PredictAnything, | ||
Usage: "The name of the plugin to reload, as registered in the plugin catalog.", | ||
}) | ||
|
||
f.StringSliceVar(&StringSliceVar{ | ||
Name: "mounts", | ||
Target: &c.mounts, | ||
Completion: complete.PredictAnything, | ||
Usage: "Array or comma-separated string mount paths of the plugin backends to reload.", | ||
}) | ||
|
||
return set | ||
} | ||
|
||
func (c *PluginReloadCommand) AutocompleteArgs() complete.Predictor { | ||
return nil | ||
} | ||
|
||
func (c *PluginReloadCommand) AutocompleteFlags() complete.Flags { | ||
return c.Flags().Completions() | ||
} | ||
|
||
func (c *PluginReloadCommand) Run(args []string) int { | ||
f := c.Flags() | ||
|
||
if err := f.Parse(args); err != nil { | ||
c.UI.Error(err.Error()) | ||
return 1 | ||
} | ||
|
||
switch { | ||
case c.plugin == "" && len(c.mounts) == 0: | ||
c.UI.Error(fmt.Sprintf("Not enough arguments (expected 1, got %d)", len(args))) | ||
return 1 | ||
case c.plugin != "" && len(c.mounts) > 0: | ||
c.UI.Error(fmt.Sprintf("Too many arguments (expected 1, got %d)", len(args))) | ||
return 1 | ||
} | ||
|
||
client, err := c.Client() | ||
if err != nil { | ||
c.UI.Error(err.Error()) | ||
return 2 | ||
} | ||
|
||
if err := client.Sys().ReloadPlugin(&api.ReloadPluginInput{ | ||
Plugin: c.plugin, | ||
Mounts: c.mounts, | ||
}); err != nil { | ||
c.UI.Error(fmt.Sprintf("Error reloading plugin/mounts: %s", err)) | ||
return 2 | ||
} | ||
|
||
if len(c.mounts) > 0 { | ||
c.UI.Output(fmt.Sprintf("Success! Reloaded mounts: %s", c.mounts)) | ||
} else { | ||
c.UI.Output(fmt.Sprintf("Success! Reloaded plugin: %s", c.plugin)) | ||
} | ||
|
||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package command | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/hashicorp/vault/api" | ||
"github.com/hashicorp/vault/sdk/helper/consts" | ||
"github.com/mitchellh/cli" | ||
) | ||
|
||
func testPluginReloadCommand(tb testing.TB) (*cli.MockUi, *PluginReloadCommand) { | ||
tb.Helper() | ||
|
||
ui := cli.NewMockUi() | ||
return ui, &PluginReloadCommand{ | ||
BaseCommand: &BaseCommand{ | ||
UI: ui, | ||
}, | ||
} | ||
} | ||
|
||
func TestPluginReloadCommand_Run(t *testing.T) { | ||
t.Parallel() | ||
|
||
cases := []struct { | ||
name string | ||
args []string | ||
out string | ||
code int | ||
}{ | ||
{ | ||
"not_enough_args", | ||
nil, | ||
"Not enough arguments", | ||
1, | ||
}, | ||
{ | ||
"too_many_args", | ||
[]string{"-plugin", "foo", "-mounts", "bar"}, | ||
"Too many arguments", | ||
1, | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
tc := tc | ||
|
||
t.Run(tc.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
client, closer := testVaultServer(t) | ||
defer closer() | ||
|
||
ui, cmd := testPluginReloadCommand(t) | ||
cmd.client = client | ||
|
||
args := append([]string{}, tc.args...) | ||
code := cmd.Run(args) | ||
if code != tc.code { | ||
t.Errorf("expected %d to be %d", code, tc.code) | ||
} | ||
|
||
combined := ui.OutputWriter.String() + ui.ErrorWriter.String() | ||
if !strings.Contains(combined, tc.out) { | ||
t.Errorf("expected %q to contain %q", combined, tc.out) | ||
} | ||
}) | ||
} | ||
|
||
t.Run("integration", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
pluginDir, cleanup := testPluginDir(t) | ||
defer cleanup(t) | ||
|
||
client, _, closer := testVaultServerPluginDir(t, pluginDir) | ||
defer closer() | ||
|
||
pluginName := "my-plugin" | ||
_, sha256Sum := testPluginCreateAndRegister(t, client, pluginDir, pluginName, consts.PluginTypeCredential) | ||
|
||
ui, cmd := testPluginReloadCommand(t) | ||
cmd.client = client | ||
|
||
if err := client.Sys().RegisterPlugin(&api.RegisterPluginInput{ | ||
Name: pluginName, | ||
Type: consts.PluginTypeCredential, | ||
Command: pluginName, | ||
SHA256: sha256Sum, | ||
}); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
code := cmd.Run([]string{ | ||
"-plugin", pluginName, | ||
}) | ||
if exp := 0; code != exp { | ||
t.Errorf("expected %d to be %d", code, exp) | ||
} | ||
|
||
expected := "Success! Reloaded plugin: " | ||
combined := ui.OutputWriter.String() + ui.ErrorWriter.String() | ||
if !strings.Contains(combined, expected) { | ||
t.Errorf("expected %q to contain %q", combined, expected) | ||
} | ||
|
||
}) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.