-
Notifications
You must be signed in to change notification settings - Fork 2k
/
acl_token_info.go
73 lines (56 loc) · 1.55 KB
/
acl_token_info.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
package command
import (
"fmt"
"strings"
"github.com/posener/complete"
)
type ACLTokenInfoCommand struct {
Meta
}
func (c *ACLTokenInfoCommand) Help() string {
helpText := `
Usage: nomad acl token info <token_accessor_id>
Info is used to fetch information on an existing ACL tokens. Requires a management token.
General Options:
` + generalOptionsUsage()
return strings.TrimSpace(helpText)
}
func (c *ACLTokenInfoCommand) AutocompleteFlags() complete.Flags {
return mergeAutocompleteFlags(c.Meta.AutocompleteFlags(FlagSetClient),
complete.Flags{})
}
func (c *ACLTokenInfoCommand) AutocompleteArgs() complete.Predictor {
return complete.PredictNothing
}
func (c *ACLTokenInfoCommand) Synopsis() string {
return "Fetch information on an existing ACL token"
}
func (c *ACLTokenInfoCommand) Run(args []string) int {
flags := c.Meta.FlagSet("acl token info", FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
if err := flags.Parse(args); err != nil {
return 1
}
// Check that we have exactly one argument
args = flags.Args()
if l := len(args); l != 1 {
c.Ui.Error(c.Help())
return 1
}
tokenAccessorID := args[0]
// Get the HTTP client
client, err := c.Meta.Client()
if err != nil {
c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err))
return 1
}
// Get the specified token information
token, _, err := client.ACLTokens().Info(tokenAccessorID, nil)
if err != nil {
c.Ui.Error(fmt.Sprintf("Error fetching token: %s", err))
return 1
}
// Format the output
c.Ui.Output(formatKVACLToken(token))
return 0
}