Skip to content

Commit

Permalink
backport of commit dc5133f (#16490)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Capurso <1036769+ccapurso@users.noreply.github.com>
  • Loading branch information
1 parent d7c1e3d commit 0935c8b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
3 changes: 3 additions & 0 deletions changelog/16443.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
secrets/kv: Fix `kv get` issue preventing the ability to read a secret when providing a leading slash
```
12 changes: 5 additions & 7 deletions command/kv_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,16 @@ func (c *KVGetCommand) Run(args []string) int {
mountFlagSyntax := (c.flagMount != "")

var (
mountPath string
partialPath string
v2 bool
mountPath string
v2 bool
)

// Ignore leading slash
partialPath := strings.TrimPrefix(args[0], "/")

// Parse the paths and grab the KV version
if mountFlagSyntax {
// In this case, this arg is the secret path (e.g. "foo").
partialPath = args[0]

mountPath = sanitizePath(c.flagMount)
_, v2, err = isKVv2(mountPath, client)
if err != nil {
Expand All @@ -135,8 +135,6 @@ func (c *KVGetCommand) Run(args []string) int {
} else {
// In this case, this arg is a path-like combination of mountPath/secretPath.
// (e.g. "secret/foo")
partialPath = args[0]

mountPath, v2, err = isKVv2(partialPath, client)
if err != nil {
c.UI.Error(err.Error())
Expand Down
12 changes: 12 additions & 0 deletions command/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,12 @@ func TestKVGetCommand(t *testing.T) {
append(baseV2ExpectedFields, "foo"),
0,
},
{
"v2_mount_flag_syntax_leading_slash",
[]string{"-mount", "kv", "/read/foo"},
append(baseV2ExpectedFields, "foo"),
0,
},
{
"v2_not_found",
[]string{"kv/nope/not/once/never"},
Expand All @@ -470,6 +476,12 @@ func TestKVGetCommand(t *testing.T) {
append(baseV2ExpectedFields, "foo"),
0,
},
{
"v2_read_leading_slash",
[]string{"/kv/read/foo"},
append(baseV2ExpectedFields, "foo"),
0,
},
{
"v2_read_version",
[]string{"--version", "1", "kv/read/foo"},
Expand Down

0 comments on commit 0935c8b

Please sign in to comment.