-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathacl_policy_delete.go
More file actions
81 lines (60 loc) · 1.45 KB
/
Copy pathacl_policy_delete.go
File metadata and controls
81 lines (60 loc) · 1.45 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package command
import (
"context"
"fmt"
"strings"
"github.com/spf13/pflag"
cli "github.com/seashell/drago/pkg/cli"
)
// ACLPolicyDeleteCommand :
type ACLPolicyDeleteCommand struct {
UI cli.UI
Command
}
func (c *ACLPolicyDeleteCommand) FlagSet() *pflag.FlagSet {
flags := c.Command.FlagSet(c.Name())
flags.Usage = func() { c.UI.Output("\n" + c.Help() + "\n") }
return flags
}
// Name :
func (c *ACLPolicyDeleteCommand) Name() string {
return "acl policy delete"
}
// Synopsis :
func (c *ACLPolicyDeleteCommand) Synopsis() string {
return "Delete ACL policy"
}
// Run :
func (c *ACLPolicyDeleteCommand) Run(ctx context.Context, args []string) int {
flags := c.FlagSet()
if err := flags.Parse(args); err != nil {
return 1
}
args = flags.Args()
if len(args) != 1 {
c.UI.Error("This command takes one argument: <name>")
c.UI.Error(`For additional help, try 'drago acl policy delete --help'`)
return 1
}
name := args[0]
// Get the HTTP client
api, err := c.Command.APIClient()
if err != nil {
c.UI.Error(fmt.Sprintf("Error setting up API client: %s", err))
return 1
}
if err := api.ACLPolicies().Delete(name); err != nil {
c.UI.Error(fmt.Sprintf("Error deleting ACL policies: %s", err))
return 1
}
return 0
}
// Help :
func (c *ACLPolicyDeleteCommand) Help() string {
h := `
Usage: drago acl policy delete <name> [options]
Delete an existing ACL policy.
General Options:
` + GlobalOptions()
return strings.TrimSpace(h)
}