diff --git a/api/client.go b/api/client.go index 5e6510df0..1341ac5b0 100644 --- a/api/client.go +++ b/api/client.go @@ -8,10 +8,10 @@ import ( "net/url" "os" "time" - - vaultHttp "github.com/hashicorp/vault/http" ) +const AuthCookieName = "token" + var ( errRedirect = errors.New("redirect") ) @@ -104,7 +104,7 @@ func NewClient(c *Config) (*Client, error) { func (c *Client) Token() string { r := c.NewRequest("GET", "/") for _, cookie := range c.config.HttpClient.Jar.Cookies(r.URL) { - if cookie.Name == vaultHttp.AuthCookieName { + if cookie.Name == AuthCookieName { return cookie.Value } } @@ -118,7 +118,7 @@ func (c *Client) SetToken(v string) { r := c.NewRequest("GET", "/") c.config.HttpClient.Jar.SetCookies(r.URL, []*http.Cookie{ &http.Cookie{ - Name: vaultHttp.AuthCookieName, + Name: AuthCookieName, Value: v, Path: "/", Expires: time.Now().Add(365 * 24 * time.Hour), @@ -131,7 +131,7 @@ func (c *Client) ClearToken() { r := c.NewRequest("GET", "/") c.config.HttpClient.Jar.SetCookies(r.URL, []*http.Cookie{ &http.Cookie{ - Name: vaultHttp.AuthCookieName, + Name: AuthCookieName, Value: "", Expires: time.Now().Add(-1 * time.Hour), }, diff --git a/api/client_test.go b/api/client_test.go index 2bad4e0b9..18a018fe0 100644 --- a/api/client_test.go +++ b/api/client_test.go @@ -7,8 +7,6 @@ import ( "os" "testing" "time" - - vaultHttp "github.com/hashicorp/vault/http" ) func init() { @@ -43,7 +41,7 @@ func TestClientToken(t *testing.T) { tokenValue := "foo" handler := func(w http.ResponseWriter, req *http.Request) { http.SetCookie(w, &http.Cookie{ - Name: vaultHttp.AuthCookieName, + Name: AuthCookieName, Value: tokenValue, Expires: time.Now().Add(time.Hour), }) @@ -82,7 +80,7 @@ func TestClientToken(t *testing.T) { func TestClientSetToken(t *testing.T) { var tokenValue string handler := func(w http.ResponseWriter, req *http.Request) { - cookie, err := req.Cookie(vaultHttp.AuthCookieName) + cookie, err := req.Cookie(AuthCookieName) if err != nil { t.Fatalf("err: %s", err) } @@ -128,7 +126,7 @@ func TestClientSetToken(t *testing.T) { func TestClientRedirect(t *testing.T) { primary := func(w http.ResponseWriter, req *http.Request) { - cookie, err := req.Cookie(vaultHttp.AuthCookieName) + cookie, err := req.Cookie(AuthCookieName) if err != nil { t.Fatalf("err: %s", err) }