From 4df3b0ca034a553d1ad0b4994139dfdf75901e9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hozza?= Date: Mon, 24 Oct 2022 14:11:45 +0200 Subject: [PATCH] internal/upload/azure: make `location` optional in various methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make the `location` argument optional (can be now empty "") in `RegisterImage()` and `CreateStorageAccount()` methods. If the provided `location` argument is an empty string, then the location is determined from the provided Resource Group instead. Signed-off-by: Tomáš Hozza --- internal/upload/azure/azure.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/internal/upload/azure/azure.go b/internal/upload/azure/azure.go index afc07a697..ce92db95a 100644 --- a/internal/upload/azure/azure.go +++ b/internal/upload/azure/azure.go @@ -74,10 +74,20 @@ func (ac Client) GetResourceGroupLocation(ctx context.Context, subscriptionID, r // CreateStorageAccount creates a storage account in the specified resource // group. The location parameter can be used to specify its location. The tag // can be used to specify a tag attached to the account. +// The location is optional and if not provided, it is determined +// from the resource group. func (ac Client) CreateStorageAccount(ctx context.Context, subscriptionID, resourceGroup, name, location string, tag Tag) error { c := storage.NewAccountsClient(subscriptionID) c.Authorizer = ac.authorizer + var err error + if location == "" { + location, err = ac.GetResourceGroupLocation(ctx, subscriptionID, resourceGroup) + if err != nil { + return fmt.Errorf("retrieving resource group location failed: %v", err) + } + } + result, err := c.Create(ctx, resourceGroup, name, storage.AccountCreateParameters{ Sku: &storage.Sku{ Name: storage.StandardLRS, @@ -125,12 +135,22 @@ func (ac Client) GetStorageAccountKey(ctx context.Context, subscriptionID, resou } // RegisterImage creates a generalized V1 Linux image from a given blob. +// The location is optional and if not provided, it is determined +// from the resource group. func (ac Client) RegisterImage(ctx context.Context, subscriptionID, resourceGroup, storageAccount, storageContainer, blobName, imageName, location string) error { c := compute.NewImagesClient(subscriptionID) c.Authorizer = ac.authorizer blobURI := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s", storageAccount, storageContainer, blobName) + var err error + if location == "" { + location, err = ac.GetResourceGroupLocation(ctx, subscriptionID, resourceGroup) + if err != nil { + return fmt.Errorf("retrieving resource group location failed: %v", err) + } + } + imageFuture, err := c.CreateOrUpdate(ctx, resourceGroup, imageName, compute.Image{ Response: autorest.Response{}, ImageProperties: &compute.ImageProperties{