From bf34484d9ddb4ede8ef67caa4e91f0a94b2f4d12 Mon Sep 17 00:00:00 2001 From: Lee Avital Date: Thu, 13 Apr 2017 14:06:38 -0400 Subject: [PATCH] Respect the configured address's path in the client (#2588) --- api/client.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/api/client.go b/api/client.go index 5f8a6f61d..85b895328 100644 --- a/api/client.go +++ b/api/client.go @@ -10,6 +10,7 @@ import ( "strings" "sync" "time" + "path" "golang.org/x/net/http2" @@ -329,14 +330,14 @@ func (c *Client) ClearToken() { // NewRequest creates a new raw request object to query the Vault server // configured for this client. This is an advanced method and generally // doesn't need to be called externally. -func (c *Client) NewRequest(method, path string) *Request { +func (c *Client) NewRequest(method, requestPath string) *Request { req := &Request{ Method: method, URL: &url.URL{ User: c.addr.User, Scheme: c.addr.Scheme, Host: c.addr.Host, - Path: path, + Path: path.Join(c.addr.Path, requestPath), }, ClientToken: c.token, Params: make(map[string][]string), @@ -344,12 +345,12 @@ func (c *Client) NewRequest(method, path string) *Request { var lookupPath string switch { - case strings.HasPrefix(path, "/v1/"): - lookupPath = strings.TrimPrefix(path, "/v1/") - case strings.HasPrefix(path, "v1/"): - lookupPath = strings.TrimPrefix(path, "v1/") + case strings.HasPrefix(requestPath, "/v1/"): + lookupPath = strings.TrimPrefix(requestPath, "/v1/") + case strings.HasPrefix(requestPath, "v1/"): + lookupPath = strings.TrimPrefix(requestPath, "v1/") default: - lookupPath = path + lookupPath = requestPath } if c.wrappingLookupFunc != nil { req.WrapTTL = c.wrappingLookupFunc(method, lookupPath)