azureblob: add support for x-ms-tags header

This commit is contained in:
Trevor Starick 2024-10-16 12:05:29 -04:00
parent a19ddffe92
commit 30edcb8474
2 changed files with 27 additions and 1 deletions

View File

@ -519,6 +519,7 @@ type Object struct {
mimeType string // Content-Type of the object mimeType string // Content-Type of the object
accessTier blob.AccessTier // Blob Access Tier accessTier blob.AccessTier // Blob Access Tier
meta map[string]string // blob metadata - take metadataMu when accessing 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 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 // getBlobSVC creates a blob client
func (o *Object) getBlobSVC() *blob.Client { func (o *Object) getBlobSVC() *blob.Client {
container, directory := o.split() container, directory := o.split()
@ -2226,6 +2235,7 @@ func (w *azChunkWriter) Close(ctx context.Context) (err error) {
options := blockblob.CommitBlockListOptions{ options := blockblob.CommitBlockListOptions{
Metadata: w.o.getMetadata(), Metadata: w.o.getMetadata(),
Tags: w.o.getTags(),
Tier: parseTier(w.f.opt.AccessTier), Tier: parseTier(w.f.opt.AccessTier),
HTTPHeaders: &w.ui.httpHeaders, HTTPHeaders: &w.ui.httpHeaders,
} }
@ -2281,6 +2291,7 @@ func (o *Object) uploadSinglepart(ctx context.Context, in io.Reader, size int64,
options := blockblob.UploadOptions{ options := blockblob.UploadOptions{
Metadata: o.getMetadata(), Metadata: o.getMetadata(),
Tags: o.getTags(),
Tier: parseTier(o.fs.opt.AccessTier), Tier: parseTier(o.fs.opt.AccessTier),
HTTPHeaders: &ui.httpHeaders, HTTPHeaders: &ui.httpHeaders,
} }
@ -2351,6 +2362,20 @@ func (o *Object) prepareUpload(ctx context.Context, src fs.ObjectInfo, options [
switch lowerKey { switch lowerKey {
case "": case "":
// ignore // 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": case "cache-control":
ui.httpHeaders.BlobCacheControl = pString(value) ui.httpHeaders.BlobCacheControl = pString(value)
case "content-disposition": case "content-disposition":

View File

@ -896,8 +896,9 @@ You can set custom upload headers with the `--header-upload` flag.
- Content-Encoding - Content-Encoding
- Content-Language - Content-Language
- Content-Type - 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 ## Limitations