cli: separate auth method config output for easier reading. (#15892)

This commit is contained in:
James Rasell
2023-01-30 11:44:26 +01:00
committed by GitHub
parent 06e039378c
commit 166aee71f3
7 changed files with 50 additions and 41 deletions

View File

@@ -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 {