2015-09-02 19:56:58 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2015-09-09 19:24:45 +00:00
|
|
|
"github.com/hashicorp/vault/api"
|
2015-09-02 19:56:58 +00:00
|
|
|
)
|
|
|
|
|
2015-09-04 20:58:12 +00:00
|
|
|
// MountTuneCommand is a Command that remounts a mounted secret backend
|
2015-09-02 19:56:58 +00:00
|
|
|
// to a new endpoint.
|
|
|
|
type MountTuneCommand struct {
|
|
|
|
Meta
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *MountTuneCommand) Run(args []string) int {
|
|
|
|
var defaultLeaseTTL, maxLeaseTTL string
|
|
|
|
flags := c.Meta.FlagSet("mount-tune", FlagSetDefault)
|
|
|
|
flags.StringVar(&defaultLeaseTTL, "default-lease-ttl", "", "")
|
|
|
|
flags.StringVar(&maxLeaseTTL, "max-lease-ttl", "", "")
|
|
|
|
flags.Usage = func() { c.Ui.Error(c.Help()) }
|
|
|
|
if err := flags.Parse(args); err != nil {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
args = flags.Args()
|
|
|
|
if len(args) != 1 {
|
|
|
|
flags.Usage()
|
|
|
|
c.Ui.Error(fmt.Sprintf(
|
|
|
|
"\n'mount-tune' expects one arguments: the mount path"))
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
path := args[0]
|
|
|
|
|
2015-09-25 13:46:20 +00:00
|
|
|
mountConfig := api.MountConfigInput{
|
|
|
|
DefaultLeaseTTL: defaultLeaseTTL,
|
|
|
|
MaxLeaseTTL: maxLeaseTTL,
|
2015-09-02 19:56:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
client, err := c.Client()
|
|
|
|
if err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf(
|
|
|
|
"Error initializing client: %s", err))
|
|
|
|
return 2
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := client.Sys().TuneMount(path, mountConfig); err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf(
|
|
|
|
"Mount tune error: %s", err))
|
|
|
|
return 2
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Ui.Output(fmt.Sprintf(
|
|
|
|
"Successfully tuned mount '%s'!", path))
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *MountTuneCommand) Synopsis() string {
|
|
|
|
return "Tune mount configuration parameters"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *MountTuneCommand) Help() string {
|
|
|
|
helpText := `
|
|
|
|
Usage: vault mount-tune [options] path
|
|
|
|
|
2015-09-03 00:07:58 +00:00
|
|
|
Tune configuration options for a mounted secret backend.
|
2015-09-02 19:56:58 +00:00
|
|
|
|
2015-09-25 13:46:20 +00:00
|
|
|
Example: vault tune-mount -default-lease-ttl="24h" secret
|
2015-09-02 19:56:58 +00:00
|
|
|
|
|
|
|
General Options:
|
|
|
|
|
|
|
|
` + generalOptionsUsage() + `
|
|
|
|
|
|
|
|
Mount Options:
|
|
|
|
|
|
|
|
-default-lease-ttl=<duration> Default lease time-to-live for this backend.
|
2015-09-25 13:46:20 +00:00
|
|
|
If not specified, uses the system default, or
|
|
|
|
the previously set value. Set to 'system' to
|
|
|
|
explicitly set it to use the system default.
|
2015-09-02 19:56:58 +00:00
|
|
|
|
|
|
|
-max-lease-ttl=<duration> Max lease time-to-live for this backend.
|
2015-09-25 13:46:20 +00:00
|
|
|
If not specified, uses the system default, or
|
|
|
|
the previously set value. Set to 'system' to
|
|
|
|
explicitly set it to use the system default.
|
2015-09-02 19:56:58 +00:00
|
|
|
|
|
|
|
`
|
|
|
|
return strings.TrimSpace(helpText)
|
|
|
|
}
|