/
acl_token_delete.go
80 lines (60 loc) · 1.49 KB
/
acl_token_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package command
import (
"context"
"fmt"
"strings"
cli "github.com/seashell/drago/pkg/cli"
"github.com/spf13/pflag"
)
// ACLTokenDeleteCommand :
type ACLTokenDeleteCommand struct {
UI cli.UI
Command
}
func (c *ACLTokenDeleteCommand) FlagSet() *pflag.FlagSet {
flags := c.Command.FlagSet(c.Name())
flags.Usage = func() { c.UI.Output("\n" + c.Help() + "\n") }
return flags
}
// Name :
func (c *ACLTokenDeleteCommand) Name() string {
return "acl token delete"
}
// Synopsis :
func (c *ACLTokenDeleteCommand) Synopsis() string {
return "Delete an existing ACL token"
}
// Run :
func (c *ACLTokenDeleteCommand) 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: <token_id>")
c.UI.Error(`For additional help, try 'drago acl token delete --help'`)
return 1
}
id := 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.ACLTokens().Delete(id); err != nil {
c.UI.Error(fmt.Sprintf("Error deleting ACL token: %s", err))
return 1
}
return 0
}
// Help :
func (c *ACLTokenDeleteCommand) Help() string {
h := `
Usage: drago acl token delete <token_id> [options]
Delete is used to delete an existing ACL token. Requires a management token.
General Options:
` + GlobalOptions()
return strings.TrimSpace(h)
}