~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/gopkg.in/juju/charmrepo.v2-unstable/charmstore.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// Copyright 2015 Canonical Ltd.
2
2
// Licensed under the AGPLv3, see LICENCE file for details.
3
3
 
4
 
package charmrepo
 
4
package charmrepo // import "gopkg.in/juju/charmrepo.v2-unstable"
5
5
 
6
6
import (
7
7
        "crypto/sha512"
16
16
        "github.com/juju/utils"
17
17
        "gopkg.in/errgo.v1"
18
18
        "gopkg.in/juju/charm.v6-unstable"
 
19
        "gopkg.in/macaroon-bakery.v1/httpbakery"
19
20
 
20
21
        "gopkg.in/juju/charmrepo.v2-unstable/csclient"
21
22
        "gopkg.in/juju/charmrepo.v2-unstable/csclient/params"
40
41
        // If empty, the default charm store client location is used.
41
42
        URL string
42
43
 
 
44
        // BakeryClient holds the bakery client to use when making
 
45
        // requests to the store. This is used in preference to
 
46
        // HTTPClient.
 
47
        BakeryClient *httpbakery.Client
 
48
 
43
49
        // HTTPClient holds the HTTP client to use when making
44
50
        // requests to the store. If nil, httpbakery.NewHTTPClient will
45
51
        // be used.
47
53
 
48
54
        // VisitWebPage is called when authorization requires that
49
55
        // the user visits a web page to authenticate themselves.
50
 
        // If nil, a default function that returns an error will be used.
 
56
        // If nil, no interaction will be allowed. This field
 
57
        // is ignored if BakeryClient is provided.
51
58
        VisitWebPage func(url *url.URL) error
 
59
 
 
60
        // User holds the name to authenticate as for the client. If User is empty,
 
61
        // no credentials will be sent.
 
62
        User string
 
63
 
 
64
        // Password holds the password for the given user, for authenticating the
 
65
        // client.
 
66
        Password string
52
67
}
53
68
 
54
69
// NewCharmStore creates and returns a charm store repository.
58
73
// preserve the causes returned from the underlying csclient
59
74
// methods.
60
75
func NewCharmStore(p NewCharmStoreParams) *CharmStore {
 
76
        client := csclient.New(csclient.Params{
 
77
                URL:          p.URL,
 
78
                BakeryClient: p.BakeryClient,
 
79
                HTTPClient:   p.HTTPClient,
 
80
                VisitWebPage: p.VisitWebPage,
 
81
                User:         p.User,
 
82
                Password:     p.Password,
 
83
        })
 
84
        return NewCharmStoreFromClient(client)
 
85
}
 
86
 
 
87
// NewCharmStoreFromClient creates and returns a charm store repository.
 
88
// The provided client is used for charm store requests.
 
89
func NewCharmStoreFromClient(client *csclient.Client) *CharmStore {
61
90
        return &CharmStore{
62
 
                client: csclient.New(csclient.Params{
63
 
                        URL:          p.URL,
64
 
                        HTTPClient:   p.HTTPClient,
65
 
                        VisitWebPage: p.VisitWebPage,
66
 
                }),
 
91
                client: client,
67
92
        }
68
93
}
69
94
 
 
95
// Client returns the charmstore client that the CharmStore
 
96
// implementation uses under the hood.
 
97
func (s *CharmStore) Client() *csclient.Client {
 
98
        return s.client
 
99
}
 
100
 
70
101
// Get implements Interface.Get.
71
102
func (s *CharmStore) Get(curl *charm.URL) (charm.Charm, error) {
72
103
        // The cache location must have been previously set.