From 87eaf376298436c7991ff6975184961bb86bc895 Mon Sep 17 00:00:00 2001 From: Trevor Starick Date: Fri, 17 Jan 2025 14:37:56 -0500 Subject: [PATCH] azureblob: add support for `x-ms-tags` header --- backend/azureblob/azureblob.go | 25 +++++++++++++++++++++++++ docs/content/azureblob.md | 3 ++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/backend/azureblob/azureblob.go b/backend/azureblob/azureblob.go index 6b5cace0c..936b75d0f 100644 --- a/backend/azureblob/azureblob.go +++ b/backend/azureblob/azureblob.go @@ -519,6 +519,7 @@ type Object struct { mimeType string // Content-Type of the object accessTier blob.AccessTier // Blob Access Tier meta map[string]string // blob metadata - take metadataMu when accessing + tags map[string]string // blob tags } // ------------------------------------------------------------ @@ -1876,6 +1877,14 @@ func (o *Object) decodeMetaDataFromBlob(info *container.BlobItem) (err error) { return nil } +func (o *Object) getTags() (tags map[string]string) { + if o.tags != nil { + return o.tags + } + + return map[string]string{} +} + // getBlobSVC creates a blob client func (o *Object) getBlobSVC() *blob.Client { container, directory := o.split() @@ -2229,6 +2238,7 @@ func (w *azChunkWriter) Close(ctx context.Context) (err error) { options := blockblob.CommitBlockListOptions{ Metadata: w.o.getMetadata(), + Tags: w.o.getTags(), Tier: parseTier(w.f.opt.AccessTier), HTTPHeaders: &w.ui.httpHeaders, } @@ -2284,6 +2294,7 @@ func (o *Object) uploadSinglepart(ctx context.Context, in io.Reader, size int64, options := blockblob.UploadOptions{ Metadata: o.getMetadata(), + Tags: o.getTags(), Tier: parseTier(o.fs.opt.AccessTier), HTTPHeaders: &ui.httpHeaders, } @@ -2354,6 +2365,20 @@ func (o *Object) prepareUpload(ctx context.Context, src fs.ObjectInfo, options [ switch lowerKey { case "": // ignore + case "x-ms-tags": + if o.tags == nil { + o.tags = make(map[string]string) + } + + tags := strings.Split(value, ",") + for _, tag := range tags { + parts := strings.SplitN(tag, "=", 2) + if len(parts) != 2 { + return ui, fmt.Errorf("invalid tag %q", tag) + } + + o.tags[parts[0]] = parts[1] + } case "cache-control": ui.httpHeaders.BlobCacheControl = pString(value) case "content-disposition": diff --git a/docs/content/azureblob.md b/docs/content/azureblob.md index 8d197c831..8f74e072a 100644 --- a/docs/content/azureblob.md +++ b/docs/content/azureblob.md @@ -938,8 +938,9 @@ You can set custom upload headers with the `--header-upload` flag. - Content-Encoding - Content-Language - Content-Type +- X-MS-Tags -Eg `--header-upload "Content-Type: text/potato"` +Eg `--header-upload "Content-Type: text/potato"` or `--header-upload "X-MS-Tags: foo=bar"` ## Limitations