Skip to content

Commit

Permalink
Drop usage of charmstore.WrapBaseClient().
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsnowcurrently committed Mar 11, 2016
1 parent 58787a3 commit 0c7aa1d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 39 deletions.
2 changes: 2 additions & 0 deletions charmstore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (

var logger = loggo.GetLogger("juju.charmstore")

// TODO(ericsnow) Build around charmrepo.CharmStore instead of csclient.Client.

// BaseClient exposes the functionality of the charm store, as provided
// by github.com/juju/charmrepo/csclient.Client.
//
Expand Down
19 changes: 9 additions & 10 deletions charmstore/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type ClientSuite struct {

stub *testing.Stub
client *stubClient
config csclient.Params
config charmstore.ClientConfig
}

var _ = gc.Suite(&ClientSuite{})
Expand All @@ -32,13 +32,15 @@ func (s *ClientSuite) SetUpTest(c *gc.C) {

s.stub = &testing.Stub{}
s.client = &stubClient{Stub: s.stub}
s.config = csclient.Params{
URL: "<something>",
s.config = charmstore.ClientConfig{
charmrepo.NewCharmStoreParams{
URL: "<something>",
},
}
}

func (s *ClientSuite) TestWrapBaseClient(c *gc.C) {
base := csclient.New(s.config)
base := csclient.New(csclient.Params{URL: s.config.URL})

client := charmstore.WrapBaseClient(base, s.client)
err := client.Close()
Expand All @@ -53,8 +55,7 @@ func (s *ClientSuite) TestWithMetadata(c *gc.C) {
meta := charmstore.JujuMetadata{
ModelUUID: uuidVal.String(),
}
base := csclient.New(s.config)
client := charmstore.WrapBaseClient(base, s.client)
client := charmstore.NewClient(s.config)
metaBefore := client.Metadata()

newClient, err := client.WithMetadata(meta)
Expand Down Expand Up @@ -95,8 +96,7 @@ func (s *ClientSuite) TestFakeListResources(c *gc.C) {
charm.MustParseURL("cs:quantal/spam-17"),
charm.MustParseURL("cs:quantal/eggs-2"),
}
base := csclient.New(s.config)
client := charmstore.WrapBaseClient(base, s.client)
client := charmstore.NewClient(s.config)

results, err := client.ListResources(cURLs)
c.Assert(err, jc.ErrorIsNil)
Expand All @@ -106,8 +106,7 @@ func (s *ClientSuite) TestFakeListResources(c *gc.C) {

func (s *ClientSuite) TestFakeGetResource(c *gc.C) {
cURL := charm.MustParseURL("cs:quantal/spam-17")
base := csclient.New(s.config)
client := charmstore.WrapBaseClient(base, s.client)
client := charmstore.NewClient(s.config)

_, err := client.GetResource(cURL, "spam", 3)

Expand Down
35 changes: 13 additions & 22 deletions cmd/juju/charmcmd/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (

"github.com/juju/errors"
"github.com/juju/persistent-cookiejar"
"gopkg.in/juju/charmrepo.v2-unstable"
"gopkg.in/juju/charmrepo.v2-unstable/csclient"
"gopkg.in/macaroon-bakery.v1/httpbakery"

"github.com/juju/juju/charmstore"
Expand All @@ -31,49 +29,42 @@ type CharmstoreSpec interface {
}

type charmstoreSpec struct {
params charmrepo.NewCharmStoreParams
config charmstore.ClientConfig
}

// newCharmstoreSpec creates a new charm store spec with default
// settings.
func newCharmstoreSpec() CharmstoreSpec {
var config charmstore.ClientConfig
// We use the default for URL and set HTTPClient later.
config.VisitWebPage = httpbakery.OpenWebBrowser
return &charmstoreSpec{
params: charmrepo.NewCharmStoreParams{
//URL: We use the default.
//HTTPClient: We set it later.
VisitWebPage: httpbakery.OpenWebBrowser,
},
config: config,
}
}

// Connect implements CharmstoreSpec.
func (cs charmstoreSpec) Connect() (*charmstore.Client, error) {
params, apiContext, err := cs.connect()
config, apiContext, err := cs.connect()
if err != nil {
return nil, errors.Trace(err)
}

baseClient := csclient.New(csclient.Params{
URL: params.URL,
HTTPClient: params.HTTPClient,
VisitWebPage: params.VisitWebPage,
})

csClient := charmstore.WrapBaseClient(baseClient, apiContext)
csClient := charmstore.NewClient(config)
csClient.Closer = apiContext
return csClient, nil
}

// TODO(ericsnow) Also add charmstoreSpec.Repo() -> charmrepo.Interface?

func (cs charmstoreSpec) connect() (charmrepo.NewCharmStoreParams, *apiContext, error) {
func (cs charmstoreSpec) connect() (charmstore.ClientConfig, *apiContext, error) {
apiContext, err := newAPIContext()
if err != nil {
return charmrepo.NewCharmStoreParams{}, nil, errors.Trace(err)
return charmstore.ClientConfig{}, nil, errors.Trace(err)
}

params := cs.params // a copy
params.HTTPClient = apiContext.HTTPClient()
return params, apiContext, nil
config := cs.config // a copy
config.HTTPClient = apiContext.HTTPClient()
return config, apiContext, nil
}

///////////////////
Expand Down
12 changes: 5 additions & 7 deletions resource/resourceadapters/charmstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package resourceadapters

import (
"io"
"io/ioutil"
"time"

"github.com/juju/errors"
Expand All @@ -14,7 +13,6 @@ import (
"github.com/juju/utils/clock"
"gopkg.in/juju/charm.v6-unstable"
charmresource "gopkg.in/juju/charm.v6-unstable/resource"
"gopkg.in/juju/charmrepo.v2-unstable/csclient"

"github.com/juju/juju/charmstore"
"github.com/juju/juju/resource"
Expand Down Expand Up @@ -59,11 +57,11 @@ func newCharmstoreOpener(cURL *charm.URL) *charmstoreOpener {
// NewClient opens a new charm store client.
func (cs *charmstoreOpener) NewClient() (*CSRetryClient, error) {
// TODO(ericsnow) Use a valid charm store client.
base := csclient.New(csclient.Params{URL: "<not valid>"})
// TODO(ericsnow) closer will be meaningful once we factor out the
// Juju HTTP context (a la cmd/juju/charmcmd/store.go).
closer := ioutil.NopCloser(nil)
client := charmstore.WrapBaseClient(base, closer)
var config charmstore.ClientConfig
config.URL = "<not valid>"
client := charmstore.NewClient(config)
// TODO(ericsnow) client.Closer will be meaningful once we factor
// out the Juju HTTP context (a la cmd/juju/charmcmd/store.go).
return newCSRetryClient(client), nil
}

Expand Down

0 comments on commit 0c7aa1d

Please sign in to comment.