Merge pull request #33 from hashicorp/sethvargo/remove_Dep
Remove api dependency on http package
This commit is contained in:
commit
634a69a2fe
|
@ -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),
|
||||
},
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue