diff --git a/command/acl_auth_method.go b/command/acl_auth_method.go index 4c02e8825..1cfc32282 100644 --- a/command/acl_auth_method.go +++ b/command/acl_auth_method.go @@ -89,15 +89,15 @@ func formatAuthMethodConfig(config *api.ACLAuthMethodConfig) []string { fmt.Sprintf("Allowed redirects URIs|%s", strings.Join(config.AllowedRedirectURIs, ",")), fmt.Sprintf("Discovery CA pem|%s", strings.Join(config.DiscoveryCaPem, ",")), fmt.Sprintf("Signing algorithms|%s", strings.Join(config.SigningAlgs, ",")), - fmt.Sprintf("Claim mappings|%s", formatMap(config.ClaimMappings)), - fmt.Sprintf("List claim mappings|%s", formatMap(config.ListClaimMappings)), + fmt.Sprintf("Claim mappings|%s", strings.Join(formatMap(config.ClaimMappings), "; ")), + fmt.Sprintf("List claim mappings|%s", strings.Join(formatMap(config.ListClaimMappings), "; ")), } } -func formatMap(m map[string]string) string { +func formatMap(m map[string]string) []string { out := []string{} for k, v := range m { - out = append(out, fmt.Sprintf("%s/%s", k, v)) + out = append(out, fmt.Sprintf("{%s: %s}", k, v)) } - return formatKV(out) + return out } diff --git a/command/acl_auth_method_create.go b/command/acl_auth_method_create.go index 370920258..15e32979e 100644 --- a/command/acl_auth_method_create.go +++ b/command/acl_auth_method_create.go @@ -26,6 +26,8 @@ type ACLAuthMethodCreateCommand struct { maxTokenTTL time.Duration isDefault bool config string + json bool + tmpl string testStdin io.Reader } @@ -67,6 +69,12 @@ ACL Auth Method Create Options: Auth method configuration in JSON format. May be prefixed with '@' to indicate that the value is a file path to load the config from. '-' may also be given to indicate that the config is available on stdin. + + -json + Output the ACL auth-method in a JSON format. + + -t + Format and display the ACL auth-method using a Go template. ` return strings.TrimSpace(helpText) } @@ -80,6 +88,8 @@ func (a *ACLAuthMethodCreateCommand) AutocompleteFlags() complete.Flags { "-token-locality": complete.PredictSet("local", "global"), "-default": complete.PredictSet("true", "false"), "-config": complete.PredictNothing, + "-json": complete.PredictNothing, + "-t": complete.PredictAnything, }) } @@ -104,6 +114,8 @@ func (a *ACLAuthMethodCreateCommand) Run(args []string) int { flags.DurationVar(&a.maxTokenTTL, "max-token-ttl", 0, "") flags.BoolVar(&a.isDefault, "default", false, "") flags.StringVar(&a.config, "config", "", "") + flags.BoolVar(&a.json, "json", false, "") + flags.StringVar(&a.tmpl, "t", "", "") if err := flags.Parse(args); err != nil { return 1 } @@ -174,6 +186,17 @@ func (a *ACLAuthMethodCreateCommand) Run(args []string) int { return 1 } + if a.json || len(a.tmpl) > 0 { + out, err := Format(a.json, a.tmpl, method) + if err != nil { + a.Ui.Error(err.Error()) + return 1 + } + + a.Ui.Output(out) + return 0 + } + a.Ui.Output(fmt.Sprintf("Created ACL auth method:\n%s", formatAuthMethod(method))) return 0 } diff --git a/command/acl_auth_method_info.go b/command/acl_auth_method_info.go index 547b1d05b..5aa9c7ec9 100644 --- a/command/acl_auth_method_info.go +++ b/command/acl_auth_method_info.go @@ -34,10 +34,10 @@ General Options: ACL Info Options: -json - Output the ACL role in a JSON format. + Output the ACL auth method in a JSON format. -t - Format and display the ACL role using a Go template. + Format and display the ACL auth method using a Go template. ` return strings.TrimSpace(helpText) @@ -65,13 +65,10 @@ func (a *ACLAuthMethodInfoCommand) Name() string { return "acl auth-method info" // Run satisfies the cli.Command Run function. func (a *ACLAuthMethodInfoCommand) Run(args []string) int { - var json bool - var tmpl string - flags := a.Meta.FlagSet(a.Name(), FlagSetClient) flags.Usage = func() { a.Ui.Output(a.Help()) } - flags.BoolVar(&json, "json", false, "") - flags.StringVar(&tmpl, "t", "", "") + flags.BoolVar(&a.json, "json", false, "") + flags.StringVar(&a.tmpl, "t", "", "") if err := flags.Parse(args); err != nil { return 1 @@ -101,8 +98,8 @@ func (a *ACLAuthMethodInfoCommand) Run(args []string) int { return 1 } - if json || len(tmpl) > 0 { - out, err := Format(json, tmpl, method) + if a.json || len(a.tmpl) > 0 { + out, err := Format(a.json, a.tmpl, method) if err != nil { a.Ui.Error(err.Error()) return 1 diff --git a/command/acl_auth_method_list.go b/command/acl_auth_method_list.go index e0393a613..70f914a83 100644 --- a/command/acl_auth_method_list.go +++ b/command/acl_auth_method_list.go @@ -15,6 +15,9 @@ var _ cli.Command = &ACLAuthMethodListCommand{} // ACLAuthMethodListCommand implements cli.Command. type ACLAuthMethodListCommand struct { Meta + + json bool + tmpl string } // Help satisfies the cli.Command Help function. @@ -59,13 +62,11 @@ func (a *ACLAuthMethodListCommand) Name() string { return "acl auth-method list" // Run satisfies the cli.Command Run function. func (a *ACLAuthMethodListCommand) Run(args []string) int { - var json bool - var tmpl string flags := a.Meta.FlagSet(a.Name(), FlagSetClient) flags.Usage = func() { a.Ui.Output(a.Help()) } - flags.BoolVar(&json, "json", false, "") - flags.StringVar(&tmpl, "t", "", "") + flags.BoolVar(&a.json, "json", false, "") + flags.StringVar(&a.tmpl, "t", "", "") if err := flags.Parse(args); err != nil { return 1 @@ -92,8 +93,8 @@ func (a *ACLAuthMethodListCommand) Run(args []string) int { return 1 } - if json || len(tmpl) > 0 { - out, err := Format(json, tmpl, methods) + if a.json || len(a.tmpl) > 0 { + out, err := Format(a.json, a.tmpl, methods) if err != nil { a.Ui.Error(err.Error()) return 1 diff --git a/command/acl_auth_method_update.go b/command/acl_auth_method_update.go index 95073241b..3705bc616 100644 --- a/command/acl_auth_method_update.go +++ b/command/acl_auth_method_update.go @@ -26,6 +26,8 @@ type ACLAuthMethodUpdateCommand struct { maxTokenTTL time.Duration isDefault bool config string + json bool + tmpl string testStdin io.Reader } @@ -60,9 +62,15 @@ ACL Auth Method Update Options: case no auth method is explicitly specified for a login command. -config - Updates auth method configuration (in JSON format). May be prefixed with - '@' to indicate that the value is a file path to load the config from. '-' - may also be given to indicate that the config is available on stdin. + Updates auth method configuration (in JSON format). May be prefixed with + '@' to indicate that the value is a file path to load the config from. '-' + may also be given to indicate that the config is available on stdin. + + -json + Output the ACL auth-method in a JSON format. + + -t + Format and display the ACL auth-method using a Go template. ` return strings.TrimSpace(helpText) @@ -76,6 +84,8 @@ func (a *ACLAuthMethodUpdateCommand) AutocompleteFlags() complete.Flags { "-token-locality": complete.PredictSet("local", "global"), "-default": complete.PredictSet("true", "false"), "-config": complete.PredictNothing, + "-json": complete.PredictNothing, + "-t": complete.PredictAnything, }) } @@ -99,6 +109,8 @@ func (a *ACLAuthMethodUpdateCommand) Run(args []string) int { flags.DurationVar(&a.maxTokenTTL, "max-token-ttl", 0, "") flags.StringVar(&a.config, "config", "", "") flags.BoolVar(&a.isDefault, "default", false, "") + flags.BoolVar(&a.json, "json", false, "") + flags.StringVar(&a.tmpl, "t", "", "") if err := flags.Parse(args); err != nil { return 1 } @@ -191,6 +203,17 @@ func (a *ACLAuthMethodUpdateCommand) Run(args []string) int { return 1 } + if a.json || len(a.tmpl) > 0 { + out, err := Format(a.json, a.tmpl, method) + if err != nil { + a.Ui.Error(err.Error()) + return 1 + } + + a.Ui.Output(out) + return 0 + } + a.Ui.Output(fmt.Sprintf("Updated ACL auth method:\n%s", formatAuthMethod(method))) return 0 }