Skip to content

Commit

Permalink
CLI request when namespace is in argument and part of the path (#12720)
Browse files Browse the repository at this point in the history
* CLI makes request to incorrect URL when namespace is both provided as argument and part of the path
fixes #12675

* adding change log

* removing a switch and addressing a possibility of out of bound index
  • Loading branch information
hghaf099 committed Oct 22, 2021
1 parent adfbe42 commit fd76783
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
3 changes: 3 additions & 0 deletions changelog/12720.txt
@@ -0,0 +1,3 @@
```release-note:bug
cli: fixes CLI requests when namespace is both provided as argument and part of the path
```
26 changes: 21 additions & 5 deletions command/kv_helpers.go
Expand Up @@ -106,13 +106,29 @@ func isKVv2(path string, client *api.Client) (string, bool, error) {
}

func addPrefixToVKVPath(p, mountPath, apiPrefix string) string {
switch {
case p == mountPath, p == strings.TrimSuffix(mountPath, "/"):

if p == mountPath || p == strings.TrimSuffix(mountPath, "/") {
return path.Join(mountPath, apiPrefix)
default:
p = strings.TrimPrefix(p, mountPath)
return path.Join(mountPath, apiPrefix, p)
}

tp := strings.TrimPrefix(p, mountPath)
for {
// If the entire mountPath is included in the path, we are done
if tp != p {
break
}
// Trim the parts of the mountPath that are not included in the
// path, for example, in cases where the mountPath contains
// namespaces which are not included in the path.
partialMountPath := strings.SplitN(mountPath, "/", 2)
if len(partialMountPath) <= 1 || partialMountPath[1] == ""{
break
}
mountPath = partialMountPath[1]
tp = strings.TrimPrefix(p, mountPath)
}

return path.Join(mountPath, apiPrefix, tp)
}

func getHeaderForMap(header string, data map[string]interface{}) string {
Expand Down

0 comments on commit fd76783

Please sign in to comment.