2017-09-05 04:04:46 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/mitchellh/cli"
|
|
|
|
"github.com/posener/complete"
|
|
|
|
)
|
|
|
|
|
2017-09-08 02:03:12 +00:00
|
|
|
var _ cli.Command = (*OperatorStepDownCommand)(nil)
|
|
|
|
var _ cli.CommandAutocomplete = (*OperatorStepDownCommand)(nil)
|
2017-09-05 04:04:46 +00:00
|
|
|
|
2017-09-08 02:03:12 +00:00
|
|
|
type OperatorStepDownCommand struct {
|
2017-09-05 04:04:46 +00:00
|
|
|
*BaseCommand
|
|
|
|
}
|
|
|
|
|
2017-09-08 02:03:12 +00:00
|
|
|
func (c *OperatorStepDownCommand) Synopsis() string {
|
2017-09-05 04:04:46 +00:00
|
|
|
return "Forces Vault to resign active duty"
|
|
|
|
}
|
|
|
|
|
2017-09-08 02:03:12 +00:00
|
|
|
func (c *OperatorStepDownCommand) Help() string {
|
2017-09-05 04:04:46 +00:00
|
|
|
helpText := `
|
2017-09-08 02:03:12 +00:00
|
|
|
Usage: vault operator step-down [options]
|
2017-09-05 04:04:46 +00:00
|
|
|
|
|
|
|
Forces the Vault server at the given address to step down from active duty.
|
|
|
|
While the affected node will have a delay before attempting to acquire the
|
|
|
|
leader lock again, if no other Vault nodes acquire the lock beforehand, it
|
|
|
|
is possible for the same node to re-acquire the lock and become active
|
|
|
|
again.
|
|
|
|
|
|
|
|
Force Vault to step down as the leader:
|
|
|
|
|
2017-09-08 02:03:12 +00:00
|
|
|
$ vault operator step-down
|
2017-09-05 04:04:46 +00:00
|
|
|
|
|
|
|
` + c.Flags().Help()
|
|
|
|
|
|
|
|
return strings.TrimSpace(helpText)
|
|
|
|
}
|
|
|
|
|
2017-09-08 02:03:12 +00:00
|
|
|
func (c *OperatorStepDownCommand) Flags() *FlagSets {
|
2017-09-05 04:04:46 +00:00
|
|
|
return c.flagSet(FlagSetHTTP)
|
|
|
|
}
|
|
|
|
|
2017-09-08 02:03:12 +00:00
|
|
|
func (c *OperatorStepDownCommand) AutocompleteArgs() complete.Predictor {
|
2017-09-05 04:04:46 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-09-08 02:03:12 +00:00
|
|
|
func (c *OperatorStepDownCommand) AutocompleteFlags() complete.Flags {
|
2017-09-05 04:04:46 +00:00
|
|
|
return c.Flags().Completions()
|
|
|
|
}
|
|
|
|
|
2017-09-08 02:03:12 +00:00
|
|
|
func (c *OperatorStepDownCommand) Run(args []string) int {
|
2017-09-05 04:04:46 +00:00
|
|
|
f := c.Flags()
|
|
|
|
|
|
|
|
if err := f.Parse(args); err != nil {
|
|
|
|
c.UI.Error(err.Error())
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
args = f.Args()
|
|
|
|
if len(args) > 0 {
|
|
|
|
c.UI.Error(fmt.Sprintf("Too many arguments (expected 0, got %d)", len(args)))
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
client, err := c.Client()
|
|
|
|
if err != nil {
|
|
|
|
c.UI.Error(err.Error())
|
|
|
|
return 2
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := client.Sys().StepDown(); err != nil {
|
|
|
|
c.UI.Error(fmt.Sprintf("Error stepping down: %s", err))
|
|
|
|
return 2
|
|
|
|
}
|
|
|
|
|
|
|
|
c.UI.Output(fmt.Sprintf("Success! Stepped down: %s", client.Address()))
|
|
|
|
return 0
|
|
|
|
}
|