4
4
package resourceadapters
7
9
"github.com/juju/errors"
10
"gopkg.in/juju/charm.v6-unstable"
8
11
charmresource "gopkg.in/juju/charm.v6-unstable/resource"
12
"gopkg.in/macaroon.v1"
10
14
"github.com/juju/juju/api"
15
"github.com/juju/juju/resource/api/client"
11
16
"github.com/juju/juju/resource/cmd"
14
19
// DeployResources uploads the bytes for the given files to the server and
15
20
// creates pending resource metadata for the all resource mentioned in the
16
21
// metadata. It returns a map of resource name to pending resource IDs.
17
func DeployResources(serviceID string, files map[string]string, resources map[string]charmresource.Meta, conn api.Connection) (ids map[string]string, err error) {
22
func DeployResources(serviceID string, cURL *charm.URL, csMac *macaroon.Macaroon, filesAndRevisions map[string]string, resources map[string]charmresource.Meta, conn api.Connection) (ids map[string]string, err error) {
18
23
client, err := newAPIClient(conn)
20
25
return nil, errors.Trace(err)
23
ids, err = cmd.DeployResources(serviceID, files, resources, client)
28
filenames := make(map[string]string)
29
revisions := make(map[string]int)
30
for name, val := range filesAndRevisions {
31
rev, err := strconv.Atoi(val)
39
ids, err = cmd.DeployResources(cmd.DeployResourcesArgs{
42
CharmStoreMacaroon: csMac,
45
ResourcesMeta: resources,
46
Client: &deployClient{client},
25
49
return nil, errors.Trace(err)
54
type deployClient struct {
58
// AddPendingResources adds pending metadata for store-based resources.
59
func (cl *deployClient) AddPendingResources(serviceID string, cURL *charm.URL, csMac *macaroon.Macaroon, resources []charmresource.Resource) ([]string, error) {
60
return cl.Client.AddPendingResources(client.AddPendingResourcesArgs{
63
CharmStoreMacaroon: csMac,