Skip to content

Commit

Permalink
Audit listing with format json returns json, not a string (#6776)
Browse files Browse the repository at this point in the history
* Audit listing with format json returns json, not a string

Fixes #6775

* list, kv list and namespace list with format json returns json, not a string

* Changed audit list return code to 2 which aligns with other list commands return codes
  • Loading branch information
jefferai authored and briankassouf committed Jun 4, 2019
1 parent e390a86 commit 72cb483
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
10 changes: 5 additions & 5 deletions command/audit_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 2
}

if c.flagDetailed {
c.UI.Output(tableOutput(c.detailedAudits(audits), nil))
return 0
Expand Down
11 changes: 10 additions & 1 deletion command/kv_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
11 changes: 10 additions & 1 deletion command/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
11 changes: 10 additions & 1 deletion command/namespace_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit 72cb483

Please sign in to comment.