mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-03 03:58:01 +00:00
Fix KV list command with whitespaces (#8017)
* Fix KV list command with whitespaces * Fix kv list whitespace * Fix list whitespace * Fix failing test Co-authored-by: swayne275 <swayne@hashicorp.com>
This commit is contained in:
@@ -36,7 +36,7 @@ func extractListData(secret *api.Secret) ([]interface{}, bool) {
|
|||||||
|
|
||||||
// sanitizePath removes any leading or trailing things from a "path".
|
// sanitizePath removes any leading or trailing things from a "path".
|
||||||
func sanitizePath(s string) string {
|
func sanitizePath(s string) string {
|
||||||
return ensureNoTrailingSlash(ensureNoLeadingSlash(strings.TrimSpace(s)))
|
return ensureNoTrailingSlash(ensureNoLeadingSlash(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensureTrailingSlash ensures the given string has a trailing slash.
|
// ensureTrailingSlash ensures the given string has a trailing slash.
|
||||||
|
|||||||
@@ -73,7 +73,14 @@ func (c *KVListCommand) Run(args []string) int {
|
|||||||
return 2
|
return 2
|
||||||
}
|
}
|
||||||
|
|
||||||
path := ensureTrailingSlash(sanitizePath(args[0]))
|
// Append trailing slash
|
||||||
|
path := args[0]
|
||||||
|
if !strings.HasSuffix(path , "/") {
|
||||||
|
path += "/"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sanitize path
|
||||||
|
path = sanitizePath(path)
|
||||||
mountPath, v2, err := isKVv2(path, client)
|
mountPath, v2, err := isKVv2(path, client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.UI.Error(err.Error())
|
c.UI.Error(err.Error())
|
||||||
|
|||||||
@@ -75,8 +75,13 @@ func (c *ListCommand) Run(args []string) int {
|
|||||||
return 2
|
return 2
|
||||||
}
|
}
|
||||||
|
|
||||||
path := ensureTrailingSlash(sanitizePath(args[0]))
|
// Append trailing slash
|
||||||
|
path := args[0]
|
||||||
|
if !strings.HasSuffix(path , "/") {
|
||||||
|
path += "/"
|
||||||
|
}
|
||||||
|
|
||||||
|
path = sanitizePath(path)
|
||||||
secret, err := client.Logical().List(path)
|
secret, err := client.Logical().List(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.UI.Error(fmt.Sprintf("Error listing %s: %s", path, err))
|
c.UI.Error(fmt.Sprintf("Error listing %s: %s", path, err))
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ func TestListCommand_Run(t *testing.T) {
|
|||||||
t.Errorf("expected %d to be %d", code, exp)
|
t.Errorf("expected %d to be %d", code, exp)
|
||||||
}
|
}
|
||||||
|
|
||||||
expected := "Error listing secret/list/: "
|
expected := "Error listing secret/list: "
|
||||||
combined := ui.OutputWriter.String() + ui.ErrorWriter.String()
|
combined := ui.OutputWriter.String() + ui.ErrorWriter.String()
|
||||||
if !strings.Contains(combined, expected) {
|
if !strings.Contains(combined, expected) {
|
||||||
t.Errorf("expected %q to contain %q", combined, expected)
|
t.Errorf("expected %q to contain %q", combined, expected)
|
||||||
|
|||||||
Reference in New Issue
Block a user