Skip to content

Commit

Permalink
Use http client provided by bosh-utils
Browse files Browse the repository at this point in the history
[#125442951]

Signed-off-by: Tyler Schultz <tschultz@pivotal.io>
  • Loading branch information
medvedzver authored and tylerschultz committed Jul 16, 2016
1 parent 2d7d17d commit 0c7bd96
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 38 deletions.
2 changes: 1 addition & 1 deletion cmd/deployment_deleter.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (c *deploymentDeleter) deploymentManager(installation biinstall.Installatio

c.logger.Debug(c.logTag, "Creating blobstore client...")

blobstore, err := c.blobstoreFactory.Create(installationMbus, bihttpclient.CreateDefaultClient())
blobstore, err := c.blobstoreFactory.Create(installationMbus, bihttpclient.CreateDefaultClientInsecureSkipVerify())
if err != nil {
return nil, bosherr.WrapError(err, "Creating blobstore client")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/deployment_preparer.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (c *DeploymentPreparer) deploy(
agentClient := c.agentClientFactory.NewAgentClient(deploymentState.DirectorID, installationManifest.Mbus)
vmManager := c.vmManagerFactory.NewManager(cloud, agentClient)

blobstore, err := c.blobstoreFactory.Create(installationManifest.Mbus, bihttpclient.CreateDefaultClient())
blobstore, err := c.blobstoreFactory.Create(installationManifest.Mbus, bihttpclient.CreateDefaultClientInsecureSkipVerify())
if err != nil {
return bosherr.WrapError(err, "Creating blobstore client")
}
Expand Down
26 changes: 6 additions & 20 deletions director/factory.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package director

import (
"crypto/tls"
"fmt"
"net"
"net/http"
"net/url"
"time"

bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshhttp "github.com/cloudfoundry/bosh-utils/httpclient"
Expand Down Expand Up @@ -52,18 +49,12 @@ func (f Factory) httpClient(config Config, taskReporter TaskReporter, fileReport
f.logger.Debug(f.logTag, "Using custom root CAs")
}

httpTransport := &http.Transport{
TLSClientConfig: &tls.Config{RootCAs: certPool},
TLSHandshakeTimeout: 10 * time.Second,

Dial: (&net.Dialer{Timeout: 30 * time.Second, KeepAlive: 0}).Dial,
Proxy: http.ProxyFromEnvironment,
}
rawClient := boshhttp.CreateDefaultClient(certPool)

authAdjustment := NewAuthRequestAdjustment(
config.TokenFunc, config.Username, config.Password)

redirectFunc := func(req *http.Request, via []*http.Request) error {
rawClient.CheckRedirect = func(req *http.Request, via []*http.Request) error {
if len(via) > 10 {
return bosherr.Error("Too many redirects")
}
Expand All @@ -82,19 +73,14 @@ func (f Factory) httpClient(config Config, taskReporter TaskReporter, fileReport
return nil
}

authedClient := NewAdjustableClient(rawClient, authAdjustment)

httpClient := boshhttp.NewHTTPClient(authedClient, f.logger)

endpoint := url.URL{
Scheme: "https",
Host: fmt.Sprintf("%s:%d", config.Host, config.Port),
}

rawClient := &http.Client{
Transport: httpTransport,
CheckRedirect: redirectFunc,
}

authedClient := NewAdjustableClient(rawClient, authAdjustment)

httpClient := boshhttp.NewHTTPClient(authedClient, f.logger)

return NewClient(endpoint.String(), httpClient, taskReporter, fileReporter, f.logger), nil
}
18 changes: 2 additions & 16 deletions uaa/factory.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package uaa

import (
"crypto/tls"
"fmt"
"net"
"net/http"
"net/url"
"time"

bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshhttp "github.com/cloudfoundry/bosh-utils/httpclient"
Expand Down Expand Up @@ -52,25 +48,15 @@ func (f Factory) httpClient(config Config) (Client, error) {
f.logger.Debug(f.logTag, "Using custom root CAs")
}

httpTransport := &http.Transport{
TLSClientConfig: &tls.Config{RootCAs: certPool},
TLSHandshakeTimeout: 10 * time.Second,
rawClient := boshhttp.CreateDefaultClient(certPool)

Dial: (&net.Dialer{Timeout: 30 * time.Second, KeepAlive: 0}).Dial,
Proxy: http.ProxyFromEnvironment,
}
httpClient := boshhttp.NewHTTPClient(rawClient, f.logger)

endpoint := url.URL{
Scheme: "https",
Host: fmt.Sprintf("%s:%d", config.Host, config.Port),
User: url.UserPassword(config.Client, config.ClientSecret),
}

rawClient := &http.Client{
Transport: httpTransport,
}

httpClient := boshhttp.NewHTTPClient(rawClient, f.logger)

return NewClient(endpoint.String(), httpClient, f.logger), nil
}

0 comments on commit 0c7bd96

Please sign in to comment.