Skip to content

Commit

Permalink
resource/api/client: Clean up helpers
Browse files Browse the repository at this point in the history
Don't export helpers which are not referred to outside the package. Move
helpers from thier own file into the file where they're used.
  • Loading branch information
Menno Smits committed Mar 19, 2017
1 parent 33f0135 commit d0de669
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 68 deletions.
1 change: 0 additions & 1 deletion resource/api/client/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/juju/juju/resource/resourcetesting"
)

// XXX figure out what here is actually used by the client tests
type BaseSuite struct {
testing.IsolationSuite

Expand Down
53 changes: 51 additions & 2 deletions resource/api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/juju/errors"
charmresource "gopkg.in/juju/charm.v6-unstable/resource"
"gopkg.in/juju/names.v2"
"gopkg.in/macaroon.v1"

"github.com/juju/juju/apiserver/common"
Expand Down Expand Up @@ -50,7 +51,7 @@ func NewClient(caller FacadeCaller, doer Doer, closer io.Closer) *Client {
// ListResources calls the ListResources API server method with
// the given application names.
func (c Client) ListResources(services []string) ([]resource.ServiceResources, error) {
args, err := NewListResourcesArgs(services)
args, err := newListResourcesArgs(services)
if err != nil {
return nil, errors.Trace(err)
}
Expand Down Expand Up @@ -84,6 +85,26 @@ func (c Client) ListResources(services []string) ([]resource.ServiceResources, e
return results, nil
}

// newListResourcesArgs returns the arguments for the ListResources endpoint.
func newListResourcesArgs(services []string) (params.ListResourcesArgs, error) {
var args params.ListResourcesArgs
var errs []error
for _, service := range services {
if !names.IsValidApplication(service) {
err := errors.Errorf("invalid application %q", service)
errs = append(errs, err)
continue
}
args.Entities = append(args.Entities, params.Entity{
Tag: names.NewApplicationTag(service).String(),
})
}
if err := resolveErrors(errs); err != nil {
return args, errors.Trace(err)
}
return args, nil
}

// Upload sends the provided resource blob up to Juju.
func (c Client) Upload(service, name, filename string, reader io.ReadSeeker) error {
uReq, err := api.NewUploadRequest(service, name, filename, reader)
Expand Down Expand Up @@ -123,7 +144,7 @@ type AddPendingResourcesArgs struct {
// AddPendingResources sends the provided resource info up to Juju
// without making it available yet.
func (c Client) AddPendingResources(args AddPendingResourcesArgs) (pendingIDs []string, err error) {
apiArgs, err := NewAddPendingResourcesArgs(args.ApplicationID, args.CharmID, args.CharmStoreMacaroon, args.Resources)
apiArgs, err := newAddPendingResourcesArgs(args.ApplicationID, args.CharmID, args.CharmStoreMacaroon, args.Resources)
if err != nil {
return nil, errors.Trace(err)
}
Expand All @@ -150,6 +171,34 @@ func (c Client) AddPendingResources(args AddPendingResourcesArgs) (pendingIDs []
return result.PendingIDs, nil
}

// newAddPendingResourcesArgs returns the arguments for the
// AddPendingResources API endpoint.
func newAddPendingResourcesArgs(applicationID string, chID charmstore.CharmID, csMac *macaroon.Macaroon, resources []charmresource.Resource) (params.AddPendingResourcesArgs, error) {
var args params.AddPendingResourcesArgs

if !names.IsValidApplication(applicationID) {
return args, errors.Errorf("invalid application %q", applicationID)
}
tag := names.NewApplicationTag(applicationID).String()

var apiResources []params.CharmResource
for _, res := range resources {
if err := res.Validate(); err != nil {
return args, errors.Trace(err)
}
apiRes := api.CharmResource2API(res)
apiResources = append(apiResources, apiRes)
}
args.Tag = tag
args.Resources = apiResources
if chID.URL != nil {
args.URL = chID.URL.String()
args.Channel = string(chID.Channel)
args.CharmStoreMacaroon = csMac
}
return args, nil
}

// AddPendingResource sends the provided resource blob up to Juju
// without making it available yet. For example, AddPendingResource()
// is used before the application is deployed.
Expand Down
65 changes: 0 additions & 65 deletions resource/api/client/data.go

This file was deleted.

0 comments on commit d0de669

Please sign in to comment.