From 8df0e9714c0123d4da2c5bb25ff8f52a190f988e Mon Sep 17 00:00:00 2001 From: Steven Clark Date: Tue, 21 Feb 2023 12:41:04 -0500 Subject: [PATCH] Output default config output from pki health-check --list as json (#19269) * Output default config output from health-check --list as json - Change the output of the default configuration as JSON so it's useable as an input to the health-check command * Add cl --- changelog/19269.txt | 3 +++ command/pki_health_check.go | 21 ++++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) create mode 100644 changelog/19269.txt diff --git a/changelog/19269.txt b/changelog/19269.txt new file mode 100644 index 000000000..57ff2072a --- /dev/null +++ b/changelog/19269.txt @@ -0,0 +1,3 @@ +```release-note:improvement +cli/pki: Change the pki health-check --list default config output to JSON so it's a usable configuration file +``` diff --git a/command/pki_health_check.go b/command/pki_health_check.go index 1551dd1c1..39d3ba73f 100644 --- a/command/pki_health_check.go +++ b/command/pki_health_check.go @@ -223,20 +223,19 @@ func (c *PKIHealthCheckCommand) Run(args []string) int { // Handle listing, if necessary. if c.flagList { - c.UI.Output("Health Checks:") + c.UI.Output("Default health check config:") + config := map[string]map[string]interface{}{} for _, checker := range executor.Checkers { - c.UI.Output(" - " + checker.Name()) - - prefix := " " - cfg := checker.DefaultConfig() - marshaled, err := json.MarshalIndent(cfg, prefix, " ") - if err != nil { - c.UI.Error(fmt.Sprintf("Failed to marshal default config for check: %v", err)) - return pkiRetUsage - } - c.UI.Output(prefix + string(marshaled)) + config[checker.Name()] = checker.DefaultConfig() } + marshaled, err := json.MarshalIndent(config, "", " ") + if err != nil { + c.UI.Error(fmt.Sprintf("Failed to marshal default config for check: %v", err)) + return pkiRetUsage + } + + c.UI.Output(string(marshaled)) return pkiRetOK }