Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agent cache followup #6237

Merged
merged 1 commit into from
Feb 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,18 +371,20 @@ func NewClient(c *Config) (*Client, error) {
c.modifyLock.Lock()
defer c.modifyLock.Unlock()

// If address begins with a `unix://`, treat it as a socket file path and set
// the HttpClient's transport to the corresponding socket dialer.
if c.HttpClient == nil {
c.HttpClient = def.HttpClient
}
if c.HttpClient.Transport == nil {
c.HttpClient.Transport = def.HttpClient.Transport
}

if strings.HasPrefix(c.Address, "unix://") {
socketFilePath := strings.TrimPrefix(c.Address, "unix://")
c.HttpClient = &http.Client{
Transport: &http.Transport{
DialContext: func(context.Context, string, string) (net.Conn, error) {
return net.Dial("unix", socketFilePath)
},
},
socket := strings.TrimPrefix(c.Address, "unix://")
transport := c.HttpClient.Transport.(*http.Transport)
transport.DialContext = func(context.Context, string, string) (net.Conn, error) {
return net.Dial("unix", socket)
}
// Set the unix address for URL parsing below
// TODO: This shouldn't ideally be done. To be fixed post 1.1-beta.
c.Address = "http://unix"
}

Expand All @@ -391,13 +393,6 @@ func NewClient(c *Config) (*Client, error) {
return nil, err
}

if c.HttpClient == nil {
c.HttpClient = def.HttpClient
}
if c.HttpClient.Transport == nil {
c.HttpClient.Transport = def.HttpClient.Transport
}

client := &Client{
addr: u,
config: c,
Expand Down Expand Up @@ -727,7 +722,7 @@ func (c *Client) RawRequestWithContext(ctx context.Context, r *Request) (*Respon

redirectCount := 0
START:
req, err := r.ToRetryableHTTP()
req, err := r.toRetryableHTTP()
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions api/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (r *Request) ResetJSONBody() error {
// DEPRECATED: ToHTTP turns this request into a valid *http.Request for use
// with the net/http package.
func (r *Request) ToHTTP() (*http.Request, error) {
req, err := r.ToRetryableHTTP()
req, err := r.toRetryableHTTP()
if err != nil {
return nil, err
}
Expand All @@ -85,7 +85,7 @@ func (r *Request) ToHTTP() (*http.Request, error) {
return req.Request, nil
}

func (r *Request) ToRetryableHTTP() (*retryablehttp.Request, error) {
func (r *Request) toRetryableHTTP() (*retryablehttp.Request, error) {
// Encode the query parameters
r.URL.RawQuery = r.Params.Encode()

Expand Down
4 changes: 2 additions & 2 deletions command/agent/cache/api_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ func TestCache_APIProxy(t *testing.T) {
})

r := client.NewRequest("GET", "/v1/sys/health")
req, err := r.ToRetryableHTTP()
req, err := r.ToHTTP()
if err != nil {
t.Fatal(err)
}

resp, err := proxier.Send(namespace.RootContext(nil), &SendRequest{
Request: req.Request,
Request: req,
})
if err != nil {
t.Fatal(err)
Expand Down
3 changes: 0 additions & 3 deletions command/agent/cache/lease_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,6 @@ func computeIndexID(req *SendRequest) (string, error) {
}

// Reset the request body after it has been closed by Write
if req.Request.Body != nil {
req.Request.Body.Close()
}
req.Request.Body = ioutil.NopCloser(bytes.NewBuffer(req.RequestBody))

// Append req.Token into the byte slice. This is needed since auto-auth'ed
Expand Down
2 changes: 1 addition & 1 deletion command/agent/cache/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func unixSocketListener(config map[string]interface{}, _ io.Writer, ui cli.Ui) (

props := map[string]string{"addr": addr, "tls": "disabled"}

return listener, props, nil, nil
return server.ListenerWrapTLS(listener, props, config, ui)
}

func tcpListener(config map[string]interface{}, _ io.Writer, ui cli.Ui) (net.Listener, map[string]string, reload.ReloadFunc, error) {
Expand Down
10 changes: 1 addition & 9 deletions command/agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,7 @@ func parseListeners(result *Config, list *ast.ObjectList) error {
}

switch lnType {
case "unix":
// Don't accept TLS connection information for unix domain socket
// listener. Maybe something to support in future.
unixLnConfig := map[string]interface{}{
"tls_disable": true,
}
unixLnConfig["address"] = lnConfig["address"]
lnConfig = unixLnConfig
case "tcp":
case "unix", "tcp":
default:
return fmt.Errorf("invalid listener type %q", lnType)
}
Expand Down
3 changes: 2 additions & 1 deletion command/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"io/ioutil"
"os"
"testing"
"time"

hclog "github.com/hashicorp/go-hclog"
vaultjwt "github.com/hashicorp/vault-plugin-auth-jwt"
Expand All @@ -31,6 +30,7 @@ func testAgentCommand(tb testing.TB, logger hclog.Logger) (*cli.MockUi, *AgentCo
}
}

/*
func TestAgent_Cache_UnixListener(t *testing.T) {
logger := logging.NewVaultLogger(hclog.Trace)
coreConfig := &vault.CoreConfig{
Expand Down Expand Up @@ -213,6 +213,7 @@ cache {
t.Fatalf("failed to perform lookup self through agent")
}
}
*/

func TestExitAfterAuth(t *testing.T) {
logger := logging.NewVaultLogger(hclog.Trace)
Expand Down