330
329
ValueTemplate interface{}
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
340
return baseURL + "/" + relpath
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)
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)
356
logger.Debugf("read metadata index at %q", indexURL)
345
357
items, err = indexRef.getLatestMetadataWithFormat(cons, "products:1.0", requireSigned)
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)
364
376
mirrorRefs, err := GetMirrorRefsWithFormat(baseURL, indexPath, "index:1.0", requireSigned)
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)
372
384
mirrorRef, err := mirrorRefs.GetMirrorReference(contentId, cloudSpec)
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)
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) {
395
if !strings.HasSuffix(dataURL, "/") {
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)
401
409
return nil, dataURL, errors.NotFoundf("invalid URL %q", dataURL)
836
logger.Debugf("finding products at path %q", productFilesPath)
828
837
data, url, err := fetchData(indexRef.BaseURL, productFilesPath, requireSigned)
830
839
return nil, fmt.Errorf("cannot read product data, %v", err)