cli: Fix broken KV import on Windows (#10820)

Consul 1.10 (PR #9792) introduced the ability to specify a prefix when
importing KV's. This however introduced a regression on Windows
systems which breaks `kv import`. The key name is joined with
specified`-prefix` using `filepath.Join()` which uses a forward slash
(/) to delimit values on Unix-based systems, and a backslash (\) to
delimit values on Windows – the latter of which is incompatible with
Consul KV paths.

This commit replaces filepath.Join() with path.Join() which uses a
forward slash as the delimiter, providing consistent key join behavior
across supported operating systems.

Fixes #10583
This commit is contained in:
Blake Covarrubias 2021-08-10 14:42:05 -07:00 committed by GitHub
parent 82565fdf55
commit 41b2f08695
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

3
.changelog/10820.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
cli: Fix broken KV import command on Windows.
```

View File

@ -10,7 +10,7 @@ import (
"io"
"io/ioutil"
"os"
"path/filepath"
"path"
"github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/command/flags"
@ -79,7 +79,7 @@ func (c *cmd) Run(args []string) int {
}
pair := &api.KVPair{
Key: filepath.Join(c.prefix, entry.Key),
Key: path.Join(c.prefix, entry.Key),
Flags: entry.Flags,
Value: value,
}