Skip to content

Commit

Permalink
CLI makes request to incorrect URL when namespace is both provided as…
Browse files Browse the repository at this point in the history
… argument and part of the path

fixes #12675
  • Loading branch information
hghaf099 committed Oct 4, 2021
1 parent 77e8f0f commit ad3c0a7
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions command/kv_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,24 @@ func addPrefixToVKVPath(p, mountPath, apiPrefix string) string {
case 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)
}
}

Expand Down

0 comments on commit ad3c0a7

Please sign in to comment.