~ubuntu-branches/ubuntu/saucy/juju-core/saucy-updates

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/environs/simplestreams/simplestreams.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-09-03 14:22:22 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20130903142222-9mes2r8wqr0bs7lp
Tags: 1.13.3-0ubuntu1
New upstream point release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
        "io/ioutil"
18
18
        "net/http"
19
19
        "os"
20
 
        "path"
21
20
        "reflect"
22
21
        "sort"
23
22
        "strings"
330
329
        ValueTemplate interface{}
331
330
}
332
331
 
 
332
// urlJoin returns baseURL + relpath making sure to have a '/' inbetween them
 
333
// This doesn't try to do anything fancy with URL query or parameter bits
 
334
// It also doesn't use path.Join because that normalizes slashes, and you need
 
335
// to keep both slashes in 'http://'.
 
336
func urlJoin(baseURL, relpath string) string {
 
337
        if strings.HasSuffix(baseURL, "/") {
 
338
                return baseURL + relpath
 
339
        }
 
340
        return baseURL + "/" + relpath
 
341
}
 
342
 
333
343
// GetMaybeSignedMetadata returns metadata records matching the specified constraint.
334
344
func GetMaybeSignedMetadata(baseURLs []string, indexPath string, cons LookupConstraint, requireSigned bool, params ValueParams) ([]interface{}, error) {
335
345
        var items []interface{}
336
346
        for _, baseURL := range baseURLs {
 
347
                indexURL := urlJoin(baseURL, indexPath)
337
348
                indexRef, err := GetIndexWithFormat(baseURL, indexPath, "index:1.0", requireSigned, params)
338
349
                if err != nil {
339
350
                        if errors.IsNotFoundError(err) || errors.IsUnauthorizedError(err) {
340
 
                                logger.Debugf("cannot load index %q/%q: %v", baseURL, indexPath, err)
 
351
                                logger.Debugf("cannot load index %q: %v", indexURL, err)
341
352
                                continue
342
353
                        }
343
354
                        return nil, err
344
355
                }
 
356
                logger.Debugf("read metadata index at %q", indexURL)
345
357
                items, err = indexRef.getLatestMetadataWithFormat(cons, "products:1.0", requireSigned)
346
358
                if err != nil {
347
359
                        if errors.IsNotFoundError(err) {
348
 
                                logger.Debugf("skipping index because of error getting latest metadata %q/%q: %v", baseURL, indexPath, err)
 
360
                                logger.Debugf("skipping index because of error getting latest metadata %q: %v", indexURL, err)
349
361
                                continue
350
362
                        }
351
363
                        return nil, err
364
376
                mirrorRefs, err := GetMirrorRefsWithFormat(baseURL, indexPath, "index:1.0", requireSigned)
365
377
                if err != nil {
366
378
                        if errors.IsNotFoundError(err) || errors.IsUnauthorizedError(err) {
367
 
                                logger.Debugf("cannot load index %q: %v", path.Join(baseURL, indexPath), err)
 
379
                                logger.Debugf("cannot load index %q: %v", urlJoin(baseURL, indexPath), err)
368
380
                                continue
369
381
                        }
370
382
                        return nil, err
372
384
                mirrorRef, err := mirrorRefs.GetMirrorReference(contentId, cloudSpec)
373
385
                if err != nil {
374
386
                        if errors.IsNotFoundError(err) {
375
 
                                logger.Debugf("skipping index because of error getting latest metadata %q: %v", path.Join(baseURL, indexPath), err)
 
387
                                logger.Debugf("skipping index because of error getting latest metadata %q: %v", urlJoin(baseURL, indexPath), err)
376
388
                                continue
377
389
                        }
378
390
                        return nil, err
390
402
 
391
403
// fetchData gets all the data from the given path relative to the given base URL.
392
404
// It returns the data found and the full URL used.
393
 
func fetchData(baseURL, path string, requireSigned bool) (data []byte, dataURL string, err error) {
394
 
        dataURL = baseURL
395
 
        if !strings.HasSuffix(dataURL, "/") {
396
 
                dataURL += "/"
397
 
        }
398
 
        dataURL += path
 
405
func fetchData(baseURL, relpath string, requireSigned bool) (data []byte, dataURL string, err error) {
 
406
        dataURL = urlJoin(baseURL, relpath)
399
407
        resp, err := httpClient.Get(dataURL)
400
408
        if err != nil {
401
409
                return nil, dataURL, errors.NotFoundf("invalid URL %q", dataURL)
825
833
        if err != nil {
826
834
                return nil, err
827
835
        }
 
836
        logger.Debugf("finding products at path %q", productFilesPath)
828
837
        data, url, err := fetchData(indexRef.BaseURL, productFilesPath, requireSigned)
829
838
        if err != nil {
830
839
                return nil, fmt.Errorf("cannot read product data, %v", err)