2017-09-17 05:11:32 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/posener/complete"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ACLPolicyInfoCommand struct {
|
|
|
|
Meta
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ACLPolicyInfoCommand) Help() string {
|
|
|
|
helpText := `
|
|
|
|
Usage: nomad acl policy info <name>
|
|
|
|
|
2017-10-13 21:36:02 +00:00
|
|
|
Info is used to fetch information on an existing ACL policy.
|
2017-09-17 05:11:32 +00:00
|
|
|
|
|
|
|
General Options:
|
|
|
|
|
|
|
|
` + generalOptionsUsage()
|
|
|
|
|
|
|
|
return strings.TrimSpace(helpText)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ACLPolicyInfoCommand) AutocompleteFlags() complete.Flags {
|
|
|
|
return mergeAutocompleteFlags(c.Meta.AutocompleteFlags(FlagSetClient),
|
|
|
|
complete.Flags{})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ACLPolicyInfoCommand) AutocompleteArgs() complete.Predictor {
|
|
|
|
return complete.PredictNothing
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ACLPolicyInfoCommand) Synopsis() string {
|
|
|
|
return "Fetch info on an existing ACL policy"
|
|
|
|
}
|
|
|
|
|
2018-04-18 16:02:11 +00:00
|
|
|
func (c *ACLPolicyInfoCommand) Name() string { return "acl policy info" }
|
|
|
|
|
2017-09-17 05:11:32 +00:00
|
|
|
func (c *ACLPolicyInfoCommand) Run(args []string) int {
|
2018-04-18 16:02:11 +00:00
|
|
|
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
|
2017-09-17 05:11:32 +00:00
|
|
|
flags.Usage = func() { c.Ui.Output(c.Help()) }
|
|
|
|
if err := flags.Parse(args); err != nil {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that we got exactly one argument
|
|
|
|
args = flags.Args()
|
|
|
|
if l := len(args); l != 1 {
|
2018-04-18 17:55:51 +00:00
|
|
|
c.Ui.Error("This command takes one argument: <name>")
|
2018-04-18 16:02:11 +00:00
|
|
|
c.Ui.Error(commandErrorText(c))
|
2017-09-17 05:11:32 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the policy name
|
|
|
|
policyName := 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
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fetch info on the policy
|
|
|
|
policy, _, err := client.ACLPolicies().Info(policyName, nil)
|
|
|
|
if err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error fetching info on ACL policy: %s", err))
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Ui.Output(formatKVPolicy(policy))
|
|
|
|
return 0
|
|
|
|
}
|