func ParseBlobURL()

in pkg/blobutil/url.go [31:61]


func ParseBlobURL(blobURL string) (v AzureBlobRef, err error) {
	u, err := url.Parse(blobURL)
	if err != nil {
		return v, errors.Wrapf(err, "cannot parse URL: %q", blobURL)
	}
	v.Scheme = strings.ToLower(u.Scheme)
	if v.Scheme != "http" && v.Scheme != "https" {
		return v, fmt.Errorf("unsupported scheme in URL: %q", blobURL)
	}

	hostParts := strings.Split(u.Host, ".") // {account}.blob.{storageBase}
	if len(hostParts) < 3 {
		return v, fmt.Errorf("cannot parse azure blob URL: %q", blobURL)
	}
	if strings.ToLower(hostParts[1]) != "blob" {
		return v, fmt.Errorf("blob host not in *.blob.* format: %q", blobURL)
	}

	v.StorageBase = strings.Join(hostParts[2:], ".") // glue them back
	if v.StorageBase == "" {
		return v, fmt.Errorf("cannot parse azure storage endpoint in blob URL: %q", blobURL)
	}

	var ok bool
	v.Container, v.Blob, ok = parseAzureContainerBlobNameFromPath(u.Path)
	if !ok {
		return v, fmt.Errorf("cannot extract Azure container/blob name from: %q", blobURL)
	}

	return v, nil
}