From d901cefca3e285e027e2870ca66a2a30daf5ad75 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Wed, 22 May 2019 13:06:25 -0400 Subject: [PATCH 1/3] Audit listing with format json returns json, not a string Fixes #6775 --- command/audit_list.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/command/audit_list.go b/command/audit_list.go index be3c87807579..6c8ae2f6bb81 100644 --- a/command/audit_list.go +++ b/command/audit_list.go @@ -94,13 +94,13 @@ func (c *AuditListCommand) Run(args []string) int { return 2 } - if len(audits) == 0 { - c.UI.Output(fmt.Sprintf("No audit devices are enabled.")) - return 0 - } - switch Format(c.UI) { case "table": + if len(audits) == 0 { + c.UI.Output(fmt.Sprintf("No audit devices are enabled.")) + return 0 + } + if c.flagDetailed { c.UI.Output(tableOutput(c.detailedAudits(audits), nil)) return 0 From 0975731a19a082f8e797007284945f32d203c41f Mon Sep 17 00:00:00 2001 From: Michel Vocks Date: Fri, 24 May 2019 08:54:36 +0200 Subject: [PATCH 2/3] list, kv list and namespace list with format json returns json, not a string --- command/kv_list.go | 11 ++++++++++- command/list.go | 11 ++++++++++- command/namespace_list.go | 11 ++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/command/kv_list.go b/command/kv_list.go index faedd6f3f429..0066c1f13215 100644 --- a/command/kv_list.go +++ b/command/kv_list.go @@ -93,6 +93,15 @@ func (c *KVListCommand) Run(args []string) int { c.UI.Error(fmt.Sprintf("Error listing %s: %s", path, err)) return 2 } + + _, ok := extractListData(secret) + if Format(c.UI) != "table" { + if secret == nil || secret.Data == nil || !ok { + OutputData(c.UI, map[string]interface{}{}) + return 2 + } + } + if secret == nil || secret.Data == nil { c.UI.Error(fmt.Sprintf("No value found at %s", path)) return 2 @@ -103,7 +112,7 @@ func (c *KVListCommand) Run(args []string) int { return OutputSecret(c.UI, secret) } - if _, ok := extractListData(secret); !ok { + if !ok { c.UI.Error(fmt.Sprintf("No entries found at %s", path)) return 2 } diff --git a/command/list.go b/command/list.go index 56762151ac24..e29b842a9cf1 100644 --- a/command/list.go +++ b/command/list.go @@ -82,6 +82,15 @@ func (c *ListCommand) Run(args []string) int { c.UI.Error(fmt.Sprintf("Error listing %s: %s", path, err)) return 2 } + + _, ok := extractListData(secret) + if Format(c.UI) != "table" { + if secret == nil || secret.Data == nil || !ok { + OutputData(c.UI, map[string]interface{}{}) + return 2 + } + } + if secret == nil { c.UI.Error(fmt.Sprintf("No value found at %s", path)) return 2 @@ -97,7 +106,7 @@ func (c *ListCommand) Run(args []string) int { return OutputSecret(c.UI, secret) } - if _, ok := extractListData(secret); !ok { + if !ok { c.UI.Error(fmt.Sprintf("No entries found at %s", path)) return 2 } diff --git a/command/namespace_list.go b/command/namespace_list.go index 893e1a76e4cd..f06579b0d898 100644 --- a/command/namespace_list.go +++ b/command/namespace_list.go @@ -71,6 +71,15 @@ func (c *NamespaceListCommand) Run(args []string) int { c.UI.Error(fmt.Sprintf("Error listing namespaces: %s", err)) return 2 } + + _, ok := extractListData(secret) + if Format(c.UI) != "table" { + if secret == nil || secret.Data != nil || !ok { + OutputData(c.UI, map[string]interface{}{}) + return 2 + } + } + if secret == nil { c.UI.Error(fmt.Sprintf("No namespaces found")) return 2 @@ -85,7 +94,7 @@ func (c *NamespaceListCommand) Run(args []string) int { return OutputSecret(c.UI, secret) } - if _, ok := extractListData(secret); !ok { + if !ok { c.UI.Error(fmt.Sprintf("No entries found")) return 2 } From 7dc0d3ca535c2abf13350d753ccda1bfa09f94ba Mon Sep 17 00:00:00 2001 From: Michel Vocks Date: Wed, 29 May 2019 20:37:00 -0500 Subject: [PATCH 3/3] Changed audit list return code to 2 which aligns with other list commands return codes --- command/audit_list.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command/audit_list.go b/command/audit_list.go index 6c8ae2f6bb81..392d55bae222 100644 --- a/command/audit_list.go +++ b/command/audit_list.go @@ -98,7 +98,7 @@ func (c *AuditListCommand) Run(args []string) int { case "table": if len(audits) == 0 { c.UI.Output(fmt.Sprintf("No audit devices are enabled.")) - return 0 + return 2 } if c.flagDetailed {