open-vault/command/unmount.go

68 lines
1.3 KiB
Go
Raw Normal View History

2015-04-07 17:38:51 +00:00
package command
import (
"fmt"
"strings"
2016-04-01 17:16:05 +00:00
"github.com/hashicorp/vault/meta"
2015-04-07 17:38:51 +00:00
)
// UnmountCommand is a Command that mounts a new mount.
type UnmountCommand struct {
2016-04-01 17:16:05 +00:00
meta.Meta
2015-04-07 17:38:51 +00:00
}
func (c *UnmountCommand) Run(args []string) int {
2016-04-01 17:16:05 +00:00
flags := c.Meta.FlagSet("mount", meta.FlagSetDefault)
2015-04-07 17:38:51 +00:00
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(
"\nunmount expects one argument: the path to unmount"))
2015-04-07 17:38:51 +00:00
return 1
}
path := args[0]
client, err := c.Client()
if err != nil {
c.Ui.Error(fmt.Sprintf(
"Error initializing client: %s", err))
return 2
}
if err := client.Sys().Unmount(path); err != nil {
c.Ui.Error(fmt.Sprintf(
"Unmount error: %s", err))
return 2
}
c.Ui.Output(fmt.Sprintf(
"Successfully unmounted '%s' if it was mounted", path))
2015-04-07 17:38:51 +00:00
return 0
}
func (c *UnmountCommand) Synopsis() string {
return "Unmount a secret backend"
}
func (c *UnmountCommand) Help() string {
helpText := `
2015-11-09 20:23:49 +00:00
Usage: vault unmount [options] path
2015-04-07 17:38:51 +00:00
Unmount a secret backend.
This command unmounts a secret backend. All the secrets created
by this backend will be revoked and its Vault data will be deleted.
General Options:
` + meta.GeneralOptionsUsage()
2015-04-07 17:38:51 +00:00
return strings.TrimSpace(helpText)
}