github.com/mwhudson/juju@v0.0.0-20160512215208-90ff01f3497f/environs/imagemetadata/urls.go (about)

     1  // Copyright 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package imagemetadata
     5  
     6  import (
     7  	"fmt"
     8  
     9  	"github.com/juju/juju/environs/storage"
    10  	"github.com/juju/juju/environs/utils"
    11  )
    12  
    13  // ImageMetadataURL returns a valid image metadata URL constructed from source.
    14  // source may be a directory, or a URL like file://foo or http://foo.
    15  func ImageMetadataURL(source, stream string) (string, error) {
    16  	if source == "" {
    17  		return "", nil
    18  	}
    19  	// If the image metadata is coming from the official cloud images site,
    20  	// set up the correct path according to the images stream requested.
    21  	if source == UbuntuCloudImagesURL || source == JujuStreamsImagesURL {
    22  		cloudImagesPath := ReleasedImagesPath
    23  		if stream != "" && stream != ReleasedStream {
    24  			cloudImagesPath = stream
    25  		}
    26  		source = fmt.Sprintf("%s/%s", source, cloudImagesPath)
    27  	}
    28  
    29  	return utils.GetURL(source, storage.BaseImagesPath)
    30  }