2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2017-10-13 20:45:10 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/posener/complete"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ACLTokenSelfCommand struct {
|
|
|
|
Meta
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ACLTokenSelfCommand) Help() string {
|
|
|
|
helpText := `
|
|
|
|
Usage: nomad acl token self
|
|
|
|
|
2017-10-13 23:38:13 +00:00
|
|
|
Self is used to fetch information about the currently set ACL token.
|
2017-10-13 20:45:10 +00:00
|
|
|
|
|
|
|
General Options:
|
|
|
|
|
2020-11-19 16:15:23 +00:00
|
|
|
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace)
|
2017-10-13 20:45:10 +00:00
|
|
|
|
|
|
|
return strings.TrimSpace(helpText)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ACLTokenSelfCommand) AutocompleteFlags() complete.Flags {
|
|
|
|
return c.Meta.AutocompleteFlags(FlagSetClient)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ACLTokenSelfCommand) AutocompleteArgs() complete.Predictor {
|
|
|
|
return complete.PredictNothing
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ACLTokenSelfCommand) Synopsis() string {
|
|
|
|
return "Lookup self ACL token"
|
|
|
|
}
|
|
|
|
|
2018-04-18 16:02:11 +00:00
|
|
|
func (c *ACLTokenSelfCommand) Name() string { return "acl token self" }
|
|
|
|
|
2017-10-13 20:45:10 +00:00
|
|
|
func (c *ACLTokenSelfCommand) Run(args []string) int {
|
2018-04-18 16:02:11 +00:00
|
|
|
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
|
2017-10-13 20:45:10 +00:00
|
|
|
flags.Usage = func() { c.Ui.Output(c.Help()) }
|
|
|
|
if err := flags.Parse(args); err != nil {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2018-04-18 16:02:11 +00:00
|
|
|
// Check that we have no arguments
|
2017-10-13 20:45:10 +00:00
|
|
|
args = flags.Args()
|
|
|
|
if l := len(args); l != 0 {
|
2018-04-18 16:02:11 +00:00
|
|
|
c.Ui.Error("This command takes no arguments")
|
|
|
|
c.Ui.Error(commandErrorText(c))
|
2017-10-13 20:45:10 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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().Self(nil)
|
|
|
|
if err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error fetching self token: %s", err))
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
// Format the output
|
2022-08-17 13:49:52 +00:00
|
|
|
outputACLToken(c.Ui, token)
|
2017-10-13 20:45:10 +00:00
|
|
|
return 0
|
|
|
|
}
|