Skip to content

Commit

Permalink
Library: Update to latest v2 package of juju/http
Browse files Browse the repository at this point in the history
The following just brings in the latest changes from juju/http, which
standardize the underlying transport.
  • Loading branch information
SimonRichardson committed Jun 2, 2021
1 parent 0e01edc commit 6120903
Show file tree
Hide file tree
Showing 28 changed files with 54 additions and 52 deletions.
2 changes: 1 addition & 1 deletion api/apiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/gorilla/websocket"
"github.com/juju/clock"
"github.com/juju/errors"
jujuhttp "github.com/juju/http"
jujuhttp "github.com/juju/http/v2"
"github.com/juju/loggo"
"github.com/juju/names/v4"
"github.com/juju/utils/v2"
Expand Down
2 changes: 1 addition & 1 deletion apiserver/apiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/juju/clock"
"github.com/juju/cmd"
"github.com/juju/collections/set"
jujuhttp "github.com/juju/http"
jujuhttp "github.com/juju/http/v2"
"github.com/juju/loggo"
"github.com/juju/names/v4"
jc "github.com/juju/testing/checkers"
Expand Down
2 changes: 1 addition & 1 deletion apiserver/debuglog_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"net/url"

"github.com/gorilla/websocket"
jujuhttp "github.com/juju/http"
jujuhttp "github.com/juju/http/v2"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"

Expand Down
2 changes: 1 addition & 1 deletion apiserver/facades/client/charms/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/juju/charm/v8"
"github.com/juju/collections/set"
"github.com/juju/errors"
"github.com/juju/http"
"github.com/juju/http/v2"
"github.com/juju/juju/state"
"github.com/juju/mgo/v2"
"github.com/juju/names/v4"
Expand Down
2 changes: 1 addition & 1 deletion apiserver/logsink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"time"

"github.com/gorilla/websocket"
jujuhttp "github.com/juju/http"
jujuhttp "github.com/juju/http/v2"
"github.com/juju/loggo"
"github.com/juju/mgo/v2/bson"
"github.com/juju/names/v4"
Expand Down
2 changes: 1 addition & 1 deletion apiserver/logtransfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/gorilla/websocket"
"github.com/juju/errors"
jujuhttp "github.com/juju/http"
jujuhttp "github.com/juju/http/v2"
"github.com/juju/loggo"
"github.com/juju/mgo/v2/bson"
"github.com/juju/names/v4"
Expand Down
2 changes: 1 addition & 1 deletion apiserver/pubsub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"time"

"github.com/gorilla/websocket"
jujuhttp "github.com/juju/http"
jujuhttp "github.com/juju/http/v2"
"github.com/juju/loggo"
"github.com/juju/names/v4"
"github.com/juju/pubsub"
Expand Down
8 changes: 4 additions & 4 deletions apiserver/registration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"net/http"
"strings"

jujuhttp "github.com/juju/http"
jujuhttp "github.com/juju/http/v2"
jc "github.com/juju/testing/checkers"
"github.com/juju/testing/httptesting"
"golang.org/x/crypto/nacl/secretbox"
Expand Down Expand Up @@ -48,7 +48,7 @@ func (s *registrationSuite) TestRegister(c *gc.C) {
ciphertext := s.sealBox(
c, validNonce, secretKey, fmt.Sprintf(`{"password": "%s"}`, password),
)
client := jujuhttp.NewClient(jujuhttp.Config{SkipHostnameVerification: true})
client := jujuhttp.NewClient(jujuhttp.WithSkipHostnameVerification(true))
resp := httptesting.Do(c, httptesting.DoRequestParams{
Do: client.Do,
URL: s.registrationURL,
Expand Down Expand Up @@ -88,7 +88,7 @@ func (s *registrationSuite) TestRegister(c *gc.C) {
}

func (s *registrationSuite) TestRegisterInvalidMethod(c *gc.C) {
client := jujuhttp.NewClient(jujuhttp.Config{SkipHostnameVerification: true})
client := jujuhttp.NewClient(jujuhttp.WithSkipHostnameVerification(true))
httptesting.AssertJSONCall(c, httptesting.JSONCallParams{
Do: client.Do,
URL: s.registrationURL,
Expand Down Expand Up @@ -163,7 +163,7 @@ func (s *registrationSuite) TestRegisterInvalidRequestPayload(c *gc.C) {
}

func (s *registrationSuite) testInvalidRequest(c *gc.C, requestBody, errorMessage, errorCode string, statusCode int) {
client := jujuhttp.NewClient(jujuhttp.Config{SkipHostnameVerification: true})
client := jujuhttp.NewClient(jujuhttp.WithSkipHostnameVerification(true))
httptesting.AssertJSONCall(c, httptesting.JSONCallParams{
Do: client.Do,
URL: s.registrationURL,
Expand Down
2 changes: 1 addition & 1 deletion apiserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/go-macaroon-bakery/macaroon-bakery/v3/bakery"
"github.com/gorilla/websocket"
"github.com/juju/errors"
jujuhttp "github.com/juju/http"
jujuhttp "github.com/juju/http/v2"
"github.com/juju/loggo"
"github.com/juju/names/v4"
jc "github.com/juju/testing/checkers"
Expand Down
2 changes: 1 addition & 1 deletion apiserver/testing/fakeapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/bmizerany/pat"
"github.com/gorilla/websocket"
jujuhttp "github.com/juju/http"
jujuhttp "github.com/juju/http/v2"
"github.com/juju/rpcreflect"

"github.com/juju/juju/apiserver/observer"
Expand Down
4 changes: 2 additions & 2 deletions apiserver/testing/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"io/ioutil"
"net/http"

jujuhttp "github.com/juju/http"
jujuhttp "github.com/juju/http/v2"
jc "github.com/juju/testing/checkers"
"github.com/juju/testing/httptesting"
gc "gopkg.in/check.v1"
Expand Down Expand Up @@ -91,7 +91,7 @@ func SendHTTPRequest(c *gc.C, p HTTPRequestParams) *http.Response {
hp.Header.Set(params.MachineNonceHeader, p.Nonce)
}
if hp.Do == nil {
client := jujuhttp.NewClient(jujuhttp.Config{SkipHostnameVerification: true})
client := jujuhttp.NewClient(jujuhttp.WithSkipHostnameVerification(true))
hp.Do = client.Do
}
return httptesting.Do(c, hp)
Expand Down
4 changes: 2 additions & 2 deletions apiserver/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"strings"

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

"github.com/juju/juju/apiserver/common"
Expand Down Expand Up @@ -253,7 +253,7 @@ func (h *toolsDownloadHandler) fetchAndCacheTools(

// No need to verify the server's identity because we verify the SHA-256 hash.
logger.Infof("fetching %v agent binaries from %v", v, exactTools.URL)
client := jujuhttp.NewClient(jujuhttp.Config{SkipHostnameVerification: true})
client := jujuhttp.NewClient(jujuhttp.WithSkipHostnameVerification(true))
resp, err := client.Get(context.TODO(), exactTools.URL)
if err != nil {
return md, nil, err
Expand Down
6 changes: 2 additions & 4 deletions charmhub/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"sort"

"github.com/juju/errors"
jujuhttp "github.com/juju/http"
jujuhttp "github.com/juju/http/v2"
"gopkg.in/httprequest.v1"

"github.com/juju/juju/charmhub/path"
Expand All @@ -37,9 +37,7 @@ type Transport interface {

// DefaultHTTPTransport creates a new HTTPTransport.
func DefaultHTTPTransport(logger Logger) Transport {
return jujuhttp.NewClient(jujuhttp.Config{
Logger: logger,
})
return jujuhttp.NewClient(jujuhttp.WithLogger(logger))
}

// APIRequester creates a wrapper around the transport to allow for better
Expand Down
4 changes: 2 additions & 2 deletions cmd/juju/cloud/updatepublicclouds.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/juju/cmd"
"github.com/juju/collections/set"
"github.com/juju/errors"
jujuhttp "github.com/juju/http"
jujuhttp "github.com/juju/http/v2"
"github.com/juju/names/v4"
"golang.org/x/crypto/openpgp"
"golang.org/x/crypto/openpgp/clearsign"
Expand Down Expand Up @@ -108,7 +108,7 @@ func (c *updatePublicCloudsCommand) Init(args []string) error {
}

func PublishedPublicClouds(url, key string) (map[string]jujucloud.Cloud, error) {
client := jujuhttp.NewClient(jujuhttp.Config{})
client := jujuhttp.NewClient()
resp, err := client.Get(context.TODO(), url)
if err != nil {
return nil, err
Expand Down
7 changes: 5 additions & 2 deletions cmd/juju/controller/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/juju/cmd"
"github.com/juju/collections/set"
"github.com/juju/errors"
jujuhttp "github.com/juju/http"
jujuhttp "github.com/juju/http/v2"
"github.com/juju/names/v4"
"golang.org/x/crypto/nacl/secretbox"
"golang.org/x/crypto/ssh/terminal"
Expand Down Expand Up @@ -516,7 +516,10 @@ func (c *registerCommand) secretKeyLogin(addrs []string, request params.SecretKe
}
httpReq.Header.Set("Content-Type", "application/json")
httpReq.Header.Set(httpbakery.BakeryProtocolHeader, fmt.Sprint(bakery.LatestVersion))
httpClient := jujuhttp.NewClient(jujuhttp.Config{SkipHostnameVerification: true, Jar: cookieJar})
httpClient := jujuhttp.NewClient(
jujuhttp.WithSkipHostnameVerification(true),
jujuhttp.WithCookieJar(cookieJar),
)
httpResp, err := httpClient.Do(httpReq)
if err != nil {
return nil, errors.Trace(err)
Expand Down
8 changes: 4 additions & 4 deletions downloader/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"os"

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

Expand All @@ -21,9 +21,9 @@ import (
func NewHTTPBlobOpener(hostnameVerification utils.SSLHostnameVerification) func(*url.URL) (io.ReadCloser, error) {
return func(url *url.URL) (io.ReadCloser, error) {
// TODO(rog) make the download operation interruptible.
client := jujuhttp.NewClient(jujuhttp.Config{
SkipHostnameVerification: !bool(hostnameVerification),
})
client := jujuhttp.NewClient(
jujuhttp.WithSkipHostnameVerification(!bool(hostnameVerification)),
)

resp, err := client.Get(context.TODO(), url.String())
if err != nil {
Expand Down
13 changes: 6 additions & 7 deletions environs/simplestreams/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"strings"

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

Expand Down Expand Up @@ -168,12 +168,11 @@ func (h *urlDataSource) Fetch(path string) (io.ReadCloser, string, error) {
// dataURL can be http:// or file://
// MakeFileURL will only modify the URL if it's a file URL
dataURL = utils.MakeFileURL(dataURL)
cfg := jujuhttp.Config{
SkipHostnameVerification: !h.hostnameVerification,
CACertificates: h.caCertificates,
Logger: logger.Child("http"),
}
client := jujuhttp.NewClient(cfg)
client := jujuhttp.NewClient(
jujuhttp.WithSkipHostnameVerification(!h.hostnameVerification),
jujuhttp.WithCACertificates(h.caCertificates...),
jujuhttp.WithLogger(logger.Child("http")),
)
resp, err := client.Get(context.TODO(), dataURL)
if err != nil {
if !errors.IsNotFound(err) {
Expand Down
2 changes: 1 addition & 1 deletion environs/simplestreams/testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"net/http"
"strings"

jujuhttp "github.com/juju/http"
jujuhttp "github.com/juju/http/v2"
jc "github.com/juju/testing/checkers"
"github.com/juju/utils/v2"
gc "gopkg.in/check.v1"
Expand Down
4 changes: 2 additions & 2 deletions environs/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"path/filepath"

"github.com/juju/errors"
"github.com/juju/http"
"github.com/juju/http/v2"
"github.com/juju/loggo"
"github.com/juju/utils/v2"
"github.com/juju/version/v2"
Expand Down Expand Up @@ -187,7 +187,7 @@ func copyTools(toolsDir, stream string, tools []*coretools.Tools, u ToolsUploade
func copyOneToolsPackage(toolsDir, stream string, tools *coretools.Tools, u ToolsUploader) error {
toolsName := envtools.StorageName(tools.Version, toolsDir)
logger.Infof("downloading %q %v (%v)", stream, toolsName, tools.URL)
client := http.NewClient(http.Config{})
client := http.NewClient()
resp, err := client.Get(context.TODO(), tools.URL)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions environs/sync/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"testing"

"github.com/juju/errors"
jujuhttp "github.com/juju/http"
jujuhttp "github.com/juju/http/v2"
jujutesting "github.com/juju/testing"
jc "github.com/juju/testing/checkers"
"github.com/juju/utils/v2/arch"
Expand Down Expand Up @@ -316,7 +316,7 @@ func (s *uploadSuite) assertUploadedTools(c *gc.C, t *coretools.Tools, expectOST

// downloadToolsRaw downloads the supplied tools and returns the raw bytes.
func downloadToolsRaw(c *gc.C, t *coretools.Tools) []byte {
client := jujuhttp.NewClient(jujuhttp.Config{})
client := jujuhttp.NewClient()
resp, err := client.Get(context.TODO(), t.URL)
c.Assert(err, jc.ErrorIsNil)
defer func() { _ = resp.Body.Close() }()
Expand Down
4 changes: 2 additions & 2 deletions environs/testing/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"strings"

"github.com/juju/collections/set"
"github.com/juju/http"
"github.com/juju/http/v2"
jc "github.com/juju/testing/checkers"
"github.com/juju/utils/v2/arch"
"github.com/juju/version/v2"
Expand Down Expand Up @@ -109,7 +109,7 @@ func PrimeTools(c *gc.C, stor storage.Storage, dataDir, toolsDir string, vers ve
c.Assert(err, jc.ErrorIsNil)
agentTools, err := uploadFakeToolsVersion(stor, toolsDir, vers)
c.Assert(err, jc.ErrorIsNil)
client := http.NewClient(http.Config{})
client := http.NewClient()
resp, err := client.Get(context.TODO(), agentTools.URL)
c.Assert(err, jc.ErrorIsNil)
defer resp.Body.Close()
Expand Down
7 changes: 5 additions & 2 deletions featuretests/tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/go-macaroon-bakery/macaroon-bakery/v3/bakery"
"github.com/go-macaroon-bakery/macaroon-bakery/v3/httpbakery"
"github.com/juju/errors"
jujuhttp "github.com/juju/http"
jujuhttp "github.com/juju/http/v2"
"github.com/juju/names/v4"
jc "github.com/juju/testing/checkers"
"github.com/juju/version/v2"
Expand Down Expand Up @@ -250,7 +250,10 @@ func (s *toolsWithMacaroonsSuite) TestCanPostWithLocalLogin(c *gc.C) {
var prompted bool
bakeryClient := httpbakery.NewClient()
jar := apitesting.NewClearableCookieJar()
client := jujuhttp.NewClient(jujuhttp.Config{SkipHostnameVerification: true, Jar: jar})
client := jujuhttp.NewClient(
jujuhttp.WithSkipHostnameVerification(true),
jujuhttp.WithCookieJar(jar),
)
bakeryClient.Client = client.Client()
bakeryClient.AddInteractor(apiauthentication.NewInteractor(
user.UserTag().Id(),
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ require (
github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d
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
Expand Down
2 changes: 1 addition & 1 deletion mongo/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"time"

"github.com/juju/errors"
"github.com/juju/http"
"github.com/juju/http/v2"
"github.com/juju/mgo/v2"
"github.com/juju/names/v4"
"github.com/juju/utils/v2/cert"
Expand Down
2 changes: 1 addition & 1 deletion provider/openstack/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/juju/clock"
"github.com/juju/collections/set"
"github.com/juju/errors"
"github.com/juju/http"
"github.com/juju/http/v2"
"github.com/juju/jsonschema"
"github.com/juju/loggo"
"github.com/juju/names/v4"
Expand Down
2 changes: 1 addition & 1 deletion worker/caasoperator/manifold.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/juju/clock"
"github.com/juju/errors"
"github.com/juju/http"
"github.com/juju/http/v2"
"github.com/juju/loggo"
"github.com/juju/names/v4"
"github.com/juju/worker/v2"
Expand Down
2 changes: 1 addition & 1 deletion worker/httpserver/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"crypto/tls"

"github.com/juju/errors"
"github.com/juju/http"
"github.com/juju/http/v2"
"golang.org/x/crypto/acme"
"golang.org/x/crypto/acme/autocert"

Expand Down
Loading

0 comments on commit 6120903

Please sign in to comment.