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:
parent
f71ca8f0ca
commit
caadee87ec
20 changed files with 406 additions and 940 deletions
|
|
@ -12,6 +12,7 @@ import (
|
|||
"io"
|
||||
"net/url"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
|
|
@ -194,6 +195,33 @@ func (c StorageClient) CreateStorageContainerIfNotExist(ctx context.Context, sto
|
|||
return nil
|
||||
}
|
||||
|
||||
// Taken from https://docs.microsoft.com/en-us/rest/api/storageservices/set-blob-tags#request-body
|
||||
var tagKeyRegexp = regexp.MustCompile(`^[a-zA-Z0-9 +-./:=_]{1,256}$`)
|
||||
var tagValueRegexp = regexp.MustCompile(`^[a-zA-Z0-9 +-./:=_]{0,256}$`)
|
||||
|
||||
func (c StorageClient) TagBlob(ctx context.Context, metadata BlobMetadata, tags map[string]string) error {
|
||||
for key, value := range tags {
|
||||
if !tagKeyRegexp.MatchString(key) {
|
||||
return fmt.Errorf("tag key `%s` doesn't match the format accepted by Azure", key)
|
||||
}
|
||||
if !tagValueRegexp.MatchString(key) {
|
||||
return fmt.Errorf("tag value `%s` of key `%s` doesn't match the format accepted by Azure", value, key)
|
||||
}
|
||||
}
|
||||
|
||||
URL, _ := url.Parse(fmt.Sprintf("https://%s.blob.core.windows.net/%s", metadata.StorageAccount, metadata.ContainerName))
|
||||
containerURL := azblob.NewContainerURL(*URL, c.pipeline)
|
||||
|
||||
blobURL := containerURL.NewPageBlobURL(metadata.BlobName)
|
||||
|
||||
_, err := blobURL.SetTags(ctx, nil, nil, nil, nil, nil, nil, tags)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot tag the blob: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// RandomStorageAccountName returns a randomly generated name that can be used
|
||||
// for a storage account. This means that it must use only alphanumeric
|
||||
// characters and its length must be 24 or lower.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue