~cmars/juju-core/1.14-azure-compile-error

« back to all changes in this revision

Viewing changes to environs/imagemetadata/simplestreams.go

Make simplestreams metadata loading more robust

When looking at each base URL to try and load the simplestreams
metadata, unauthorised errors would be considered fatal and abort
the search. This branch makes such errors similar to not found
errors in that the next URL is attempted.

R=jameinel, dimitern
CC=
https://codereview.appspot.com/9666050

Show diffs side-by-side

added added

removed removed

Lines of Context:
216
216
        for _, baseURL := range baseURLs {
217
217
                indexRef, err := getIndexWithFormat(baseURL, indexPath, "index:1.0", requireSigned)
218
218
                if err != nil {
219
 
                        if errors.IsNotFoundError(err) {
 
219
                        if errors.IsNotFoundError(err) || errors.IsUnauthorizedError(err) {
220
220
                                continue
221
221
                        }
222
222
                        return nil, err
251
251
        if resp.StatusCode == http.StatusNotFound {
252
252
                return nil, dataURL, errors.NotFoundf("cannot find URL %q", dataURL)
253
253
        }
 
254
        if resp.StatusCode == http.StatusUnauthorized {
 
255
                return nil, dataURL, errors.Unauthorizedf("unauthorised access to URL %q", dataURL)
 
256
        }
254
257
        if resp.StatusCode != http.StatusOK {
255
258
                return nil, dataURL, fmt.Errorf("cannot access URL %q, %q", dataURL, resp.Status)
256
259
        }
269
272
func getIndexWithFormat(baseURL, indexPath, format string, requireSigned bool) (*indexReference, error) {
270
273
        data, url, err := fetchData(baseURL, indexPath, requireSigned)
271
274
        if err != nil {
272
 
                if errors.IsNotFoundError(err) {
 
275
                if errors.IsNotFoundError(err) || errors.IsUnauthorizedError(err) {
273
276
                        return nil, err
274
277
                }
275
278
                return nil, fmt.Errorf("cannot read index data, %v", err)