2015-04-19 23:36:11 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// PolicyDeleteCommand is a Command that enables a new endpoint.
|
|
|
|
type PolicyDeleteCommand struct {
|
|
|
|
Meta
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *PolicyDeleteCommand) Run(args []string) int {
|
|
|
|
flags := c.Meta.FlagSet("policy-delete", FlagSetDefault)
|
|
|
|
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(
|
|
|
|
"\npolicy-delete expects exactly one argument"))
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
client, err := c.Client()
|
|
|
|
if err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf(
|
|
|
|
"Error initializing client: %s", err))
|
|
|
|
return 2
|
|
|
|
}
|
|
|
|
|
|
|
|
name := args[0]
|
|
|
|
if err := client.Sys().DeletePolicy(name); err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf(
|
|
|
|
"Error: %s", err))
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Ui.Output(fmt.Sprintf("Policy '%s' deleted.", name))
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *PolicyDeleteCommand) Synopsis() string {
|
|
|
|
return "Delete a policy from the server"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *PolicyDeleteCommand) Help() string {
|
|
|
|
helpText := `
|
|
|
|
Usage: vault policy-delete [options] name
|
|
|
|
|
|
|
|
Delete a policy with the given name.
|
|
|
|
|
2016-03-01 16:48:17 +00:00
|
|
|
Once the policy is deleted, all users associated with the policy will
|
2015-04-19 23:36:11 +00:00
|
|
|
be affected immediately. When a user is associated with a policy that
|
|
|
|
doesn't exist, it is identical to not being associated with that policy.
|
|
|
|
|
|
|
|
General Options:
|
|
|
|
|
2015-06-30 19:01:23 +00:00
|
|
|
` + generalOptionsUsage()
|
2015-04-19 23:36:11 +00:00
|
|
|
return strings.TrimSpace(helpText)
|
|
|
|
}
|