azure: add an option to tag page blobs

We want to start tagging page blobs so this commit adds a small tagging method
to our azure library and exposes it in the osbuild-upload-azure helper.

Example:

go run ./cmd/osbuild-upload-azure/ \
  -container azure-container \
  -image ./sample.vhd \
  -storage-access-key KEY \
  -storage-account account \
  -tag key:value \
  -tag hello:world \
  -tag bird:toucan

This commit also has to downgrade the azblob library version to 0.13 so the
API for blob tags is the same as the one currently shipped to Fedora.
This is suboptimal but it should unblock us for now.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
This commit is contained in:
Ondřej Budai 2022-05-05 08:31:00 +02:00 committed by Ondřej Budai
parent f71ca8f0ca
commit caadee87ec
20 changed files with 406 additions and 940 deletions

View file

@ -1,10 +1,12 @@
package main
import (
"context"
"flag"
"fmt"
"os"
"path"
"strings"
"github.com/osbuild/osbuild-composer/internal/upload/azure"
)
@ -17,17 +19,37 @@ func checkStringNotEmpty(variable string, errorMessage string) {
}
}
type tags map[string]string
func (t *tags) String() string {
return ""
}
func (t *tags) Set(value string) error {
splitValue := strings.SplitN(value, ":", 2)
if len(splitValue) < 2 {
return fmt.Errorf(`-tag must be in format key:value, "%s" is not valid`, value)
}
key := splitValue[0]
val := splitValue[1]
(*t)[key] = val
return nil
}
func main() {
var storageAccount string
var storageAccessKey string
var fileName string
var containerName string
var threads int
tagsArg := tags(make(map[string]string))
flag.StringVar(&storageAccount, "storage-account", "", "Azure storage account (mandatory)")
flag.StringVar(&storageAccessKey, "storage-access-key", "", "Azure storage access key (mandatory)")
flag.StringVar(&fileName, "image", "", "image to upload (mandatory)")
flag.StringVar(&containerName, "container", "", "name of storage container (see Azure docs for explanation, mandatory)")
flag.IntVar(&threads, "threads", 16, "number of threads for parallel upload")
flag.Var(&tagsArg, "tag", "blob tag formatted as key:value (first colon found is considered to be the delimiter), can be specified multiple times")
flag.Parse()
checkStringNotEmpty(storageAccount, "You need to specify storage account")
@ -44,18 +66,24 @@ func main() {
}
blobName := azure.EnsureVHDExtension(path.Base(fileName))
blobMetadata := azure.BlobMetadata{
StorageAccount: storageAccount,
BlobName: blobName,
ContainerName: containerName,
}
err = c.UploadPageBlob(
azure.BlobMetadata{
StorageAccount: storageAccount,
BlobName: blobName,
ContainerName: containerName,
},
blobMetadata,
fileName,
threads,
)
if err != nil {
fmt.Println("Error: ", err)
fmt.Println("Uploading error: ", err)
os.Exit(1)
}
err = c.TagBlob(context.Background(), blobMetadata, tagsArg)
if err != nil {
fmt.Println("Tagging error: ", err)
os.Exit(1)
}
}