cli: separate auth method config output for easier reading. (#15892)
This commit is contained in:
parent
06664baeb1
commit
6accfb1f43
|
@ -57,6 +57,16 @@ func (a *ACLAuthMethodCommand) Name() string { return "acl auth-method" }
|
|||
// Run satisfies the cli.Command Run function.
|
||||
func (a *ACLAuthMethodCommand) Run(_ []string) int { return cli.RunResultHelp }
|
||||
|
||||
// outputAuthMethod can be used to output the auth method to the UI within the
|
||||
// passed meta object.
|
||||
func outputAuthMethod(meta Meta, authMethod *api.ACLAuthMethod) {
|
||||
meta.Ui.Output(formatAuthMethod(authMethod))
|
||||
if authMethod.Config != nil {
|
||||
meta.Ui.Output(meta.Colorize().Color("\n[bold]Auth Method Config[reset]\n"))
|
||||
meta.Ui.Output(formatAuthMethodConfig(authMethod.Config))
|
||||
}
|
||||
}
|
||||
|
||||
// formatAuthMethod formats and converts the ACL auth method API object into a
|
||||
// string KV representation suitable for console output.
|
||||
func formatAuthMethod(authMethod *api.ACLAuthMethod) string {
|
||||
|
@ -66,22 +76,14 @@ func formatAuthMethod(authMethod *api.ACLAuthMethod) string {
|
|||
fmt.Sprintf("Locality|%s", authMethod.TokenLocality),
|
||||
fmt.Sprintf("MaxTokenTTL|%s", authMethod.MaxTokenTTL.String()),
|
||||
fmt.Sprintf("Default|%t", authMethod.Default),
|
||||
fmt.Sprintf("Create Index|%d", authMethod.CreateIndex),
|
||||
fmt.Sprintf("Modify Index|%d", authMethod.ModifyIndex),
|
||||
}
|
||||
|
||||
if authMethod.Config != nil {
|
||||
out = append(out, formatAuthMethodConfig(authMethod.Config)...)
|
||||
}
|
||||
out = append(out,
|
||||
[]string{fmt.Sprintf("Create Index|%d", authMethod.CreateIndex),
|
||||
fmt.Sprintf("Modify Index|%d", authMethod.ModifyIndex),
|
||||
}...,
|
||||
)
|
||||
|
||||
return formatKV(out)
|
||||
}
|
||||
|
||||
func formatAuthMethodConfig(config *api.ACLAuthMethodConfig) []string {
|
||||
return []string{
|
||||
func formatAuthMethodConfig(config *api.ACLAuthMethodConfig) string {
|
||||
out := []string{
|
||||
fmt.Sprintf("OIDC Discovery URL|%s", config.OIDCDiscoveryURL),
|
||||
fmt.Sprintf("OIDC Client ID|%s", config.OIDCClientID),
|
||||
fmt.Sprintf("OIDC Client Secret|%s", config.OIDCClientSecret),
|
||||
|
@ -93,6 +95,7 @@ func formatAuthMethodConfig(config *api.ACLAuthMethodConfig) []string {
|
|||
fmt.Sprintf("Claim mappings|%s", strings.Join(formatMap(config.ClaimMappings), "; ")),
|
||||
fmt.Sprintf("List claim mappings|%s", strings.Join(formatMap(config.ListClaimMappings), "; ")),
|
||||
}
|
||||
return formatKV(out)
|
||||
}
|
||||
|
||||
func formatMap(m map[string]string) []string {
|
||||
|
|
|
@ -197,6 +197,6 @@ func (a *ACLAuthMethodCreateCommand) Run(args []string) int {
|
|||
return 0
|
||||
}
|
||||
|
||||
a.Ui.Output(fmt.Sprintf("Created ACL auth method:\n%s", formatAuthMethod(method)))
|
||||
outputAuthMethod(a.Meta, method)
|
||||
return 0
|
||||
}
|
||||
|
|
|
@ -110,7 +110,6 @@ func (a *ACLAuthMethodInfoCommand) Run(args []string) int {
|
|||
}
|
||||
|
||||
// Format the output.
|
||||
a.Ui.Output(formatAuthMethod(method))
|
||||
|
||||
outputAuthMethod(a.Meta, method)
|
||||
return 0
|
||||
}
|
||||
|
|
|
@ -214,7 +214,7 @@ func (a *ACLAuthMethodUpdateCommand) Run(args []string) int {
|
|||
return 0
|
||||
}
|
||||
|
||||
a.Ui.Output(fmt.Sprintf("Updated ACL auth method:\n%s", formatAuthMethod(method)))
|
||||
outputAuthMethod(a.Meta, method)
|
||||
return 0
|
||||
}
|
||||
|
||||
|
|
|
@ -55,12 +55,16 @@ Create a new ACL Auth Method:
|
|||
|
||||
```shell-session
|
||||
$ nomad acl auth-method create -name "example-acl-auth-method" -type "OIDC" -max-token-ttl "1h" -token-locality "local" -config "@config.json"
|
||||
Created ACL auth method:
|
||||
Name = example-acl-auth-method
|
||||
Type = OIDC
|
||||
Locality = local
|
||||
MaxTokenTTL = 1h0m0s
|
||||
Default = false
|
||||
Name = example-acl-auth-method
|
||||
Type = OIDC
|
||||
Locality = local
|
||||
MaxTokenTTL = 1h0m0s
|
||||
Default = false
|
||||
Create Index = 14
|
||||
Modify Index = 14
|
||||
|
||||
Auth Method Config
|
||||
|
||||
OIDC Discovery URL = https://my-corp-app-name.auth0.com/
|
||||
OIDC Client ID = V1RPi2MYptMV1RPi2MYptMV1RPi2MYpt
|
||||
OIDC Client Secret = example-client-secret
|
||||
|
@ -70,8 +74,6 @@ Discovery CA pem = <none>
|
|||
Signing algorithms = <none>
|
||||
Claim mappings = {http://example.com/first_name: first_name}; {http://example.com/last_name: last_name}
|
||||
List claim mappings = {http://nomad.com/groups: groups}
|
||||
Create Index = 14
|
||||
Modify Index = 14
|
||||
```
|
||||
|
||||
Example config file:
|
||||
|
@ -97,4 +99,4 @@ Example config file:
|
|||
}
|
||||
```
|
||||
|
||||
[configuration]: /nomad/api-docs/acl/auth-methods#config
|
||||
[configuration]: /nomad/api-docs/acl/auth-methods#config
|
||||
|
|
|
@ -34,11 +34,16 @@ Fetch information about an existing ACL Auth Method:
|
|||
|
||||
```shell-session
|
||||
$ nomad acl auth-method info example-acl-auth-method
|
||||
Name = example-acl-auth-method
|
||||
Type = OIDC
|
||||
Locality = local
|
||||
MaxTokenTTL = 1h0m0s
|
||||
Default = false
|
||||
Name = example-acl-auth-method
|
||||
Type = OIDC
|
||||
Locality = local
|
||||
MaxTokenTTL = 1h0m0s
|
||||
Default = false
|
||||
Create Index = 14
|
||||
Modify Index = 14
|
||||
|
||||
Auth Method Config
|
||||
|
||||
OIDC Discovery URL = https://my-corp-app-name.auth0.com/
|
||||
OIDC Client ID = V1RPi2MYptMV1RPi2MYptMV1RPi2MYpt
|
||||
OIDC Client Secret = example-client-secret
|
||||
|
@ -48,6 +53,4 @@ Discovery CA pem = <none>
|
|||
Signing algorithms = <none>
|
||||
Claim mappings = {http://example.com/first_name: first_name}; {http://example.com/last_name: last_name}
|
||||
List claim mappings = {http://nomad.com/groups: groups}
|
||||
Create Index = 14
|
||||
Modify Index = 33
|
||||
```
|
||||
|
|
|
@ -63,13 +63,17 @@ Update an existing ACL auth method:
|
|||
|
||||
```shell-session
|
||||
$ nomad acl auth-method update -token-locality "global" -config @config.json example-acl-auth-method
|
||||
Updated ACL auth method:
|
||||
Name = example-acl-auth-method
|
||||
Type = OIDC
|
||||
Locality = global
|
||||
MaxTokenTTL = 1h0m0s
|
||||
Default = false
|
||||
OIDC Discovery URL = https://my-new-corp-app-name.auth0.com/
|
||||
Name = example-acl-auth-method
|
||||
Type = OIDC
|
||||
Locality = global
|
||||
MaxTokenTTL = 1h0m0s
|
||||
Default = false
|
||||
Create Index = 14
|
||||
Modify Index = 33
|
||||
|
||||
Auth Method Config
|
||||
|
||||
OIDC Discovery URL = https://my-corp-app-name.auth0.com/
|
||||
OIDC Client ID = V1RPi2MYptMV1RPi2MYptMV1RPi2MYpt
|
||||
OIDC Client Secret = example-client-secret
|
||||
Bound audiences = V1RPi2MYptMV1RPi2MYptMV1RPi2MYpt
|
||||
|
@ -78,6 +82,4 @@ Discovery CA pem = <none>
|
|||
Signing algorithms = <none>
|
||||
Claim mappings = {http://example.com/first_name: first_name}; {http://example.com/last_name: last_name}
|
||||
List claim mappings = {http://nomad.com/groups: groups}
|
||||
Create Index = 14
|
||||
Modify Index = 33
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue