forked from hashicorp/vault
-
Notifications
You must be signed in to change notification settings - Fork 0
/
policy_delete.go
64 lines (51 loc) · 1.37 KB
/
policy_delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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.
One the policy is deleted, all users associated with the policy will
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:
` + generalOptionsUsage()
return strings.TrimSpace(helpText)
}