upload/azure: force .vhd extension

Azure cannot create an image from a storage blob without .vhd extension.
This commit ensures that image always has the right extension.
This commit is contained in:
Ondřej Budai 2020-04-28 13:53:16 +02:00
parent 1d52dfcc2b
commit 6513263a14

View file

@ -10,6 +10,7 @@ import (
"io"
"net/url"
"os"
"strings"
"sync"
"github.com/Azure/azure-storage-blob-go/azblob"
@ -34,6 +35,11 @@ type ImageMetadata struct {
// It can speed up the upload by using goroutines. The number of parallel goroutines is bounded by
// the `threads` argument.
func UploadImage(credentials Credentials, metadata ImageMetadata, fileName string, threads int) error {
// Azure cannot create an image from a storage blob without .vhd extension
if !strings.HasSuffix(metadata.ImageName, ".vhd") {
metadata.ImageName = metadata.ImageName + ".vhd"
}
// Create a default request pipeline using your storage account name and account key.
credential, err := azblob.NewSharedKeyCredential(credentials.StorageAccount, credentials.StorageAccessKey)
if err != nil {