~rogpeppe/juju-core/axwalk-lp1300889-disable-mongo-keyfile

« back to all changes in this revision

Viewing changes to charm/repo.go

  • Committer: Jesse Meek
  • Date: 2014-03-07 23:03:04 UTC
  • mfrom: (2394 juju-core)
  • mto: This revision was merged to the branch mainline in revision 2433.
  • Revision ID: jesse.meek@canonical.com-20140307230304-k6rkxj7jps31am0q
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
87
87
        BaseURL   string
88
88
        authAttrs string // a list of attr=value pairs, comma separated
89
89
        jujuAttrs string // a list of attr=value pairs, comma separated
 
90
        testMode  bool
90
91
}
91
92
 
92
93
var _ Repository = (*CharmStore)(nil)
101
102
        return &authCS
102
103
}
103
104
 
 
105
// WithTestMode returns a Repository where testMode is set to value passed to
 
106
// this method.
 
107
func (s *CharmStore) WithTestMode(testMode bool) Repository {
 
108
        newRepo := *s
 
109
        newRepo.testMode = testMode
 
110
        return &newRepo
 
111
}
 
112
 
104
113
// WithJujuAttrs returns a Repository with the Juju metadata attributes set.
105
114
// jujuAttrs is a list of attr=value pairs.
106
115
func (s *CharmStore) WithJujuAttrs(jujuAttrs string) Repository {
131
140
// Info returns details for all the specified charms in the charm store.
132
141
func (s *CharmStore) Info(curls ...*URL) ([]*InfoResponse, error) {
133
142
        baseURL := s.BaseURL + "/charm-info?"
134
 
        charmSnippets := make([]string, len(curls))
 
143
        queryParams := make([]string, len(curls), len(curls)+1)
135
144
        for i, curl := range curls {
136
 
                charmSnippets[i] = "charms=" + url.QueryEscape(curl.String())
137
 
        }
138
 
        resp, err := s.get(baseURL + strings.Join(charmSnippets, "&"))
 
145
                queryParams[i] = "charms=" + url.QueryEscape(curl.String())
 
146
        }
 
147
        if s.testMode {
 
148
                queryParams = append(queryParams, "stats=0")
 
149
        }
 
150
        resp, err := s.get(baseURL + strings.Join(queryParams, "&"))
139
151
        if err != nil {
140
152
                if url_error, ok := err.(*url.Error); ok {
141
153
                        switch url_error.Err.(type) {
335
347
        }
336
348
        path := filepath.Join(CacheDir, Quote(curl.String())+".charm")
337
349
        if verify(path, digest) != nil {
338
 
                resp, err := s.get(s.BaseURL + "/charm/" + url.QueryEscape(curl.Path()))
 
350
                store_url := s.BaseURL + "/charm/" + url.QueryEscape(curl.Path())
 
351
                if s.testMode {
 
352
                        store_url = store_url + "?stats=0"
 
353
                }
 
354
                resp, err := s.get(store_url)
339
355
                if err != nil {
340
356
                        return nil, err
341
357
                }