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:
parent
9030ec32ef
commit
22d55c00e6
|
@ -36,7 +36,7 @@ func extractListData(secret *api.Secret) ([]interface{}, bool) {
|
|||
|
||||
// sanitizePath removes any leading or trailing things from a "path".
|
||||
func sanitizePath(s string) string {
|
||||
return ensureNoTrailingSlash(ensureNoLeadingSlash(strings.TrimSpace(s)))
|
||||
return ensureNoTrailingSlash(ensureNoLeadingSlash(s))
|
||||
}
|
||||
|
||||
// ensureTrailingSlash ensures the given string has a trailing slash.
|
||||
|
|
|
@ -73,7 +73,14 @@ func (c *KVListCommand) Run(args []string) int {
|
|||
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)
|
||||
if err != nil {
|
||||
c.UI.Error(err.Error())
|
||||
|
|
|
@ -75,8 +75,13 @@ func (c *ListCommand) Run(args []string) int {
|
|||
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)
|
||||
if err != nil {
|
||||
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)
|
||||
}
|
||||
|
||||
expected := "Error listing secret/list/: "
|
||||
expected := "Error listing secret/list: "
|
||||
combined := ui.OutputWriter.String() + ui.ErrorWriter.String()
|
||||
if !strings.Contains(combined, expected) {
|
||||
t.Errorf("expected %q to contain %q", combined, expected)
|
||||
|
|
Loading…
Reference in New Issue