Skip to content

Commit

Permalink
GCE: Use latest juju/http version
Browse files Browse the repository at this point in the history
The latest juju/http client is used as the global http client.
  • Loading branch information
SimonRichardson committed May 28, 2021
1 parent bb8520c commit 99bdc80
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ require (
github.com/juju/gojsonschema v0.0.0-20150312170016-e1ad140384f2
github.com/juju/gomaasapi/v2 v2.0.0-20210323144809-92beddd020fe
github.com/juju/http v0.0.0-20201019013536-69ae1d429836
github.com/juju/http/v2 v2.0.0-20210527161802-e8d841c4e076
github.com/juju/idmclient/v2 v2.0.0-20210309081103-6b4a5212f851
github.com/juju/jsonschema v0.0.0-20210422141032-b0ff291abe9c
github.com/juju/jsonschema-gen v0.0.0-20200416014454-d924343d72b2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ github.com/juju/gosigma v0.0.0-20200420012028-063911838a9e h1:JoXBbhRrYNw6EIPGcM
github.com/juju/gosigma v0.0.0-20200420012028-063911838a9e/go.mod h1:OPBu48GcIJ30kNTA1cm+VbZb6GkQ6vthnr5v6NJ49eM=
github.com/juju/http v0.0.0-20201019013536-69ae1d429836 h1:F+KhYWcKHSUf/R7Ovoz+s6VnK1wGFibaCrPXPYijFa4=
github.com/juju/http v0.0.0-20201019013536-69ae1d429836/go.mod h1:lbZ9zbaOw9vMW7XMHGxYTgFadDDfzc4r8Aa7gP8GOYo=
github.com/juju/http/v2 v2.0.0-20210527161802-e8d841c4e076 h1:Y9skx/w7NYVMj5N7t+rV66BYEMItpoSDG+Stb8beRuU=
github.com/juju/http/v2 v2.0.0-20210527161802-e8d841c4e076/go.mod h1:y1PngvubGWeSpDBI4kxdaTc9f3HEThd2A5mv0MKBi74=
github.com/juju/httpprof v0.0.0-20141217160036-14bf14c30767 h1:COsaGcfAONDdIDnGS8yFdxOyReP7zKQEr7jFzCHKDkM=
github.com/juju/httpprof v0.0.0-20141217160036-14bf14c30767/go.mod h1:+MaLYz4PumRkkyHYeXJ2G5g5cIW0sli2bOfpmbaMV/g=
github.com/juju/httprequest v1.0.1/go.mod h1:K+CyYVHU/NcfbMpK7YIVobh4U4Fci3EUB2AqIRtl+xs=
Expand Down
11 changes: 4 additions & 7 deletions provider/gce/environ.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

"github.com/juju/errors"
"github.com/juju/utils"
jujuhttp "github.com/juju/http/v2"
"google.golang.org/api/compute/v1"

jujucloud "github.com/juju/juju/cloud"
Expand Down Expand Up @@ -153,18 +153,15 @@ func (e *environ) SetCloudSpec(spec environscloudspec.CloudSpec) error {
PrivateKey: []byte(credAttrs[credAttrPrivateKey]),
}

sslVerification := utils.VerifySSLHostnames
if spec.SkipTLSVerify {
sslVerification = utils.NoVerifySSLHostnames
}

connectionConfig := google.ConnectionConfig{
Region: spec.Region,
ProjectID: credential.ProjectID,

// TODO (Stickupkid): Pass the http.Client through on the construction
// of the environ.
HTTPClient: utils.GetHTTPClient(sslVerification),
HTTPClient: jujuhttp.NewClient(
jujuhttp.WithSkipHostnameVerification(spec.SkipTLSVerify),
),
}

// TODO (stickupkid): Pass the context through the method call.
Expand Down
8 changes: 4 additions & 4 deletions provider/gce/google/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ package google

import (
"context"
"net/http"

"github.com/juju/errors"
jujuhttp "github.com/juju/http/v2"
"golang.org/x/oauth2/google"
"golang.org/x/oauth2/jwt"
"google.golang.org/api/compute/v1"
Expand All @@ -29,18 +29,18 @@ var scopes = []string{
// which is then used by the Environ.
// This should also be relocated alongside its wrapper,
// rather than this "auth.go" file.
func newComputeService(ctx context.Context, creds *Credentials, httpClient *http.Client) (*compute.Service, error) {
func newComputeService(ctx context.Context, creds *Credentials, httpClient *jujuhttp.Client) (*compute.Service, error) {
cfg, err := newJWTConfig(creds)
if err != nil {
return nil, errors.Trace(err)
}

// We're substituting the transport, with a wrapped GCE specific version of
// the original http.Client.
newClient := *httpClient
newClient := *httpClient.Client()

tsOpt := option.WithTokenSource(cfg.TokenSource(ctx))
if newClient.Transport, err = transporthttp.NewTransport(ctx, httpClient.Transport, tsOpt); err != nil {
if newClient.Transport, err = transporthttp.NewTransport(ctx, newClient.Transport, tsOpt); err != nil {
return nil, errors.Trace(err)
}

Expand Down
4 changes: 2 additions & 2 deletions provider/gce/google/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"encoding/json"
"io"
"io/ioutil"
"net/http"
"net/mail"

"github.com/juju/errors"
jujuhttp "github.com/juju/http/v2"
)

// The names of OS environment variables related to GCE.
Expand Down Expand Up @@ -191,7 +191,7 @@ type ConnectionConfig struct {
ProjectID string

// HTTPClient is the client to use for all GCE connections.
HTTPClient *http.Client
HTTPClient *jujuhttp.Client
}

// Validate checks the connection's fields for invalid values.
Expand Down
4 changes: 2 additions & 2 deletions provider/gce/google/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ package google

import (
"context"
"net/http"

"github.com/juju/errors"
jujuhttp "github.com/juju/http/v2"
"google.golang.org/api/compute/v1"
)

Expand Down Expand Up @@ -154,7 +154,7 @@ func Connect(ctx context.Context, connCfg ConnectionConfig, creds *Credentials)
return conn, nil
}

var newService = func(ctx context.Context, creds *Credentials, httpClient *http.Client) (*compute.Service, error) {
var newService = func(ctx context.Context, creds *Credentials, httpClient *jujuhttp.Client) (*compute.Service, error) {
return newComputeService(ctx, creds, httpClient)
}

Expand Down

0 comments on commit 99bdc80

Please sign in to comment.