mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-11-03 20:17:59 +00:00 
			
		
		
		
	Remove api dependency on http package
This commit is contained in:
		@@ -8,10 +8,10 @@ import (
 | 
				
			|||||||
	"net/url"
 | 
						"net/url"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					 | 
				
			||||||
	vaultHttp "github.com/hashicorp/vault/http"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const AuthCookieName = "token"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var (
 | 
					var (
 | 
				
			||||||
	errRedirect = errors.New("redirect")
 | 
						errRedirect = errors.New("redirect")
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -104,7 +104,7 @@ func NewClient(c *Config) (*Client, error) {
 | 
				
			|||||||
func (c *Client) Token() string {
 | 
					func (c *Client) Token() string {
 | 
				
			||||||
	r := c.NewRequest("GET", "/")
 | 
						r := c.NewRequest("GET", "/")
 | 
				
			||||||
	for _, cookie := range c.config.HttpClient.Jar.Cookies(r.URL) {
 | 
						for _, cookie := range c.config.HttpClient.Jar.Cookies(r.URL) {
 | 
				
			||||||
		if cookie.Name == vaultHttp.AuthCookieName {
 | 
							if cookie.Name == AuthCookieName {
 | 
				
			||||||
			return cookie.Value
 | 
								return cookie.Value
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -118,7 +118,7 @@ func (c *Client) SetToken(v string) {
 | 
				
			|||||||
	r := c.NewRequest("GET", "/")
 | 
						r := c.NewRequest("GET", "/")
 | 
				
			||||||
	c.config.HttpClient.Jar.SetCookies(r.URL, []*http.Cookie{
 | 
						c.config.HttpClient.Jar.SetCookies(r.URL, []*http.Cookie{
 | 
				
			||||||
		&http.Cookie{
 | 
							&http.Cookie{
 | 
				
			||||||
			Name:    vaultHttp.AuthCookieName,
 | 
								Name:    AuthCookieName,
 | 
				
			||||||
			Value:   v,
 | 
								Value:   v,
 | 
				
			||||||
			Path:    "/",
 | 
								Path:    "/",
 | 
				
			||||||
			Expires: time.Now().Add(365 * 24 * time.Hour),
 | 
								Expires: time.Now().Add(365 * 24 * time.Hour),
 | 
				
			||||||
@@ -131,7 +131,7 @@ func (c *Client) ClearToken() {
 | 
				
			|||||||
	r := c.NewRequest("GET", "/")
 | 
						r := c.NewRequest("GET", "/")
 | 
				
			||||||
	c.config.HttpClient.Jar.SetCookies(r.URL, []*http.Cookie{
 | 
						c.config.HttpClient.Jar.SetCookies(r.URL, []*http.Cookie{
 | 
				
			||||||
		&http.Cookie{
 | 
							&http.Cookie{
 | 
				
			||||||
			Name:    vaultHttp.AuthCookieName,
 | 
								Name:    AuthCookieName,
 | 
				
			||||||
			Value:   "",
 | 
								Value:   "",
 | 
				
			||||||
			Expires: time.Now().Add(-1 * time.Hour),
 | 
								Expires: time.Now().Add(-1 * time.Hour),
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,8 +7,6 @@ import (
 | 
				
			|||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					 | 
				
			||||||
	vaultHttp "github.com/hashicorp/vault/http"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func init() {
 | 
					func init() {
 | 
				
			||||||
@@ -43,7 +41,7 @@ func TestClientToken(t *testing.T) {
 | 
				
			|||||||
	tokenValue := "foo"
 | 
						tokenValue := "foo"
 | 
				
			||||||
	handler := func(w http.ResponseWriter, req *http.Request) {
 | 
						handler := func(w http.ResponseWriter, req *http.Request) {
 | 
				
			||||||
		http.SetCookie(w, &http.Cookie{
 | 
							http.SetCookie(w, &http.Cookie{
 | 
				
			||||||
			Name:    vaultHttp.AuthCookieName,
 | 
								Name:    AuthCookieName,
 | 
				
			||||||
			Value:   tokenValue,
 | 
								Value:   tokenValue,
 | 
				
			||||||
			Expires: time.Now().Add(time.Hour),
 | 
								Expires: time.Now().Add(time.Hour),
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
@@ -82,7 +80,7 @@ func TestClientToken(t *testing.T) {
 | 
				
			|||||||
func TestClientSetToken(t *testing.T) {
 | 
					func TestClientSetToken(t *testing.T) {
 | 
				
			||||||
	var tokenValue string
 | 
						var tokenValue string
 | 
				
			||||||
	handler := func(w http.ResponseWriter, req *http.Request) {
 | 
						handler := func(w http.ResponseWriter, req *http.Request) {
 | 
				
			||||||
		cookie, err := req.Cookie(vaultHttp.AuthCookieName)
 | 
							cookie, err := req.Cookie(AuthCookieName)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			t.Fatalf("err: %s", err)
 | 
								t.Fatalf("err: %s", err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -128,7 +126,7 @@ func TestClientSetToken(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func TestClientRedirect(t *testing.T) {
 | 
					func TestClientRedirect(t *testing.T) {
 | 
				
			||||||
	primary := func(w http.ResponseWriter, req *http.Request) {
 | 
						primary := func(w http.ResponseWriter, req *http.Request) {
 | 
				
			||||||
		cookie, err := req.Cookie(vaultHttp.AuthCookieName)
 | 
							cookie, err := req.Cookie(AuthCookieName)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			t.Fatalf("err: %s", err)
 | 
								t.Fatalf("err: %s", err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user