github.com/blixtra/nomad@v0.7.2-0.20171221000451-da9a1d7bb050/command/acl_token_info.go (about) 1 package command 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/posener/complete" 8 ) 9 10 type ACLTokenInfoCommand struct { 11 Meta 12 } 13 14 func (c *ACLTokenInfoCommand) Help() string { 15 helpText := ` 16 Usage: nomad acl token info <token_accessor_id> 17 18 Info is used to fetch information on an existing ACL tokens. Requires a management token. 19 20 General Options: 21 22 ` + generalOptionsUsage() 23 24 return strings.TrimSpace(helpText) 25 } 26 27 func (c *ACLTokenInfoCommand) AutocompleteFlags() complete.Flags { 28 return mergeAutocompleteFlags(c.Meta.AutocompleteFlags(FlagSetClient), 29 complete.Flags{}) 30 } 31 32 func (c *ACLTokenInfoCommand) AutocompleteArgs() complete.Predictor { 33 return complete.PredictNothing 34 } 35 36 func (c *ACLTokenInfoCommand) Synopsis() string { 37 return "Fetch information on an existing ACL token" 38 } 39 40 func (c *ACLTokenInfoCommand) Run(args []string) int { 41 flags := c.Meta.FlagSet("acl token info", FlagSetClient) 42 flags.Usage = func() { c.Ui.Output(c.Help()) } 43 if err := flags.Parse(args); err != nil { 44 return 1 45 } 46 47 // Check that we have exactly one argument 48 args = flags.Args() 49 if l := len(args); l != 1 { 50 c.Ui.Error(c.Help()) 51 return 1 52 } 53 54 tokenAccessorID := args[0] 55 56 // Get the HTTP client 57 client, err := c.Meta.Client() 58 if err != nil { 59 c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err)) 60 return 1 61 } 62 63 // Get the specified token information 64 token, _, err := client.ACLTokens().Info(tokenAccessorID, nil) 65 if err != nil { 66 c.Ui.Error(fmt.Sprintf("Error fetching token: %s", err)) 67 return 1 68 } 69 70 // Format the output 71 c.Ui.Output(formatKVACLToken(token)) 72 return 0 73 }