Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/storage/blob tags75 #16125

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,9 @@ public static partial class BlobsModelFactory
public static Azure.Storage.Blobs.Models.PageInfo PageInfo(Azure.ETag eTag, System.DateTimeOffset lastModified, byte[] contentHash, byte[] contentCrc64, long blobSequenceNumber, string encryptionKeySha256) { throw null; }
public static Azure.Storage.Blobs.Models.PageInfo PageInfo(Azure.ETag eTag, System.DateTimeOffset lastModified, byte[] contentHash, byte[] contentCrc64, long blobSequenceNumber, string encryptionKeySha256, string encryptionScope) { throw null; }
public static Azure.Storage.Blobs.Models.PageRangesInfo PageRangesInfo(System.DateTimeOffset lastModified, Azure.ETag eTag, long blobContentLength, System.Collections.Generic.IEnumerable<Azure.HttpRange> pageRanges, System.Collections.Generic.IEnumerable<Azure.HttpRange> clearRanges) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public static Azure.Storage.Blobs.Models.TaggedBlobItem TaggedBlobItem(string blobName = null, string blobContainerName = null) { throw null; }
public static Azure.Storage.Blobs.Models.TaggedBlobItem TaggedBlobItem(string blobName = null, string blobContainerName = null, System.Collections.Generic.IDictionary<string, string> tags = null) { throw null; }
public static Azure.Storage.Blobs.Models.UserDelegationKey UserDelegationKey(string signedObjectId, string signedTenantId, string signedService, string signedVersion, string value, System.DateTimeOffset signedExpiresOn, System.DateTimeOffset signedStartsOn) { throw null; }
}
public partial class BlobSnapshotInfo
Expand Down Expand Up @@ -1178,6 +1180,7 @@ public partial class TaggedBlobItem
internal TaggedBlobItem() { }
public string BlobContainerName { get { throw null; } }
public string BlobName { get { throw null; } }
public System.Collections.Generic.IDictionary<string, string> Tags { get { throw null; } }
}
public partial class UserDelegationKey
{
Expand Down
2 changes: 2 additions & 0 deletions sdk/storage/Azure.Storage.Blobs/src/BlobBaseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3921,6 +3921,7 @@ private async Task<Response<GetBlobTagResult>> GetTagsInternal(
resourceUri: Uri,
version: Version.ToVersionString(),
ifTags: conditions?.TagConditions,
leaseId: conditions?.LeaseId,
async: async,
operationName: $"{nameof(BlobBaseClient)}.{nameof(GetTags)}",
cancellationToken: cancellationToken)
Expand Down Expand Up @@ -4084,6 +4085,7 @@ private async Task<Response> SetTagsInternal(
version: Version.ToVersionString(),
tags: tags.ToBlobTags(),
ifTags: conditions?.TagConditions,
leaseId: conditions?.LeaseId,
async: async,
operationName: $"{nameof(BlobBaseClient)}.{nameof(SetTags)}",
cancellationToken: cancellationToken)
Expand Down
3 changes: 2 additions & 1 deletion sdk/storage/Azure.Storage.Blobs/src/BlobExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ internal static TaggedBlobItem ToBlobTagItem(this FilterBlobItem filterBlobItem)
return new TaggedBlobItem
{
BlobName = filterBlobItem.BlobName,
BlobContainerName = filterBlobItem.BlobContainerName
BlobContainerName = filterBlobItem.BlobContainerName,
Tags = filterBlobItem.Tags.ToTagDictionary()
};
}

Expand Down
48 changes: 42 additions & 6 deletions sdk/storage/Azure.Storage.Blobs/src/Generated/BlobRestClient.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions sdk/storage/Azure.Storage.Blobs/src/Models/BlobsModelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,21 @@ public static GetBlobTagResult GetBlobTagResult(Tags tags)
/// <summary>
/// Creates a new BlobTagItem instance for mocking.
/// </summary>
public static TaggedBlobItem TaggedBlobItem(
string blobName = default,
string blobContainerName = default,
Tags tags = default)
=> new TaggedBlobItem
{
BlobName = blobName,
BlobContainerName = blobContainerName,
Tags = tags
};

/// <summary>
/// Creates a new BlobTagItem instance for mocking.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static TaggedBlobItem TaggedBlobItem(
string blobName = default,
string blobContainerName = default)
Expand Down
7 changes: 6 additions & 1 deletion sdk/storage/Azure.Storage.Blobs/src/Models/TaggedBlobItem.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using Tags = System.Collections.Generic.IDictionary<string, string>;

namespace Azure.Storage.Blobs.Models
{
Expand All @@ -20,6 +20,11 @@ public class TaggedBlobItem
/// </summary>
public string BlobContainerName { get; internal set; }

/// <summary>
/// Blob Tags.
/// </summary>
public Tags Tags { get; internal set; }

/// <summary>
/// Prevent direct instantiation of FilterBlobItem instances.
/// You can use BlobsModelFactory.FilterBlobItem instead.
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/Azure.Storage.Blobs/swagger/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## Configuration
``` yaml
# Generate blob storage
input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/storage-dataplane-preview/specification/storage/data-plane/Microsoft.BlobStorage/preview/2020-02-10/blob.json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert?

input-file: C:\Users\seanmcc\git\azure-rest-api-specs\specification\storage\data-plane\Microsoft.BlobStorage\preview\2020-04-08\blob.json
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undo this before merging.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local path.

output-folder: ../src/Generated
clear-output-folder: false

Expand Down
69 changes: 69 additions & 0 deletions sdk/storage/Azure.Storage.Blobs/tests/BlobBaseClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5661,6 +5661,75 @@ await TestHelper.AssertExpectedExceptionAsync<RequestFailedException>(
e => Assert.AreEqual(BlobErrorCode.BlobNotFound.ToString(), e.ErrorCode));
}

[Test]
[ServiceVersion(Min = BlobClientOptions.ServiceVersion.V2020_04_08)]
public async Task GetSetTagsAsync_Lease()
{
// Arrange
await using DisposingContainer test = await GetTestContainerAsync();
BlobBaseClient blob = await GetNewBlobClient(test.Container);

string leaseId = Recording.Random.NewGuid().ToString();
TimeSpan duration = TimeSpan.FromSeconds(15);
await InstrumentClient(blob.GetBlobLeaseClient(leaseId)).AcquireAsync(duration);

BlobRequestConditions conditions = new BlobRequestConditions
{
LeaseId = leaseId
};

Dictionary<string, string> tags = BuildTags();
await blob.SetTagsAsync(tags, conditions);

// Act
Response<GetBlobTagResult> response = await blob.GetTagsAsync(conditions);

// Assert
AssertDictionaryEquality(tags, response.Value.Tags);
}

[Test]
[ServiceVersion(Min = BlobClientOptions.ServiceVersion.V2020_04_08)]
public async Task GetTagsAsync_LeaseFailed()
{
// Arrange
await using DisposingContainer test = await GetTestContainerAsync();
BlobBaseClient blob = await GetNewBlobClient(test.Container);
string leaseId = Recording.Random.NewGuid().ToString();

BlobRequestConditions conditions = new BlobRequestConditions
{
LeaseId = leaseId
};

// Act
await TestHelper.AssertExpectedExceptionAsync<RequestFailedException>(
blob.GetTagsAsync(conditions),
e => Assert.AreEqual(BlobErrorCode.LeaseNotPresentWithBlobOperation.ToString(), e.ErrorCode));
}

[Test]
[ServiceVersion(Min = BlobClientOptions.ServiceVersion.V2020_04_08)]
public async Task SetTagsAsync_LeaseFailed()
{
// Arrange
await using DisposingContainer test = await GetTestContainerAsync();
BlobBaseClient blob = await GetNewBlobClient(test.Container);
string leaseId = Recording.Random.NewGuid().ToString();

BlobRequestConditions conditions = new BlobRequestConditions
{
LeaseId = leaseId
};

Dictionary<string, string> tags = BuildTags();

// Act
await TestHelper.AssertExpectedExceptionAsync<RequestFailedException>(
blob.SetTagsAsync(tags, conditions),
e => Assert.AreEqual(BlobErrorCode.LeaseNotPresentWithBlobOperation.ToString(), e.ErrorCode));
}

//[Test]
//public async Task SetTierAsync_Batch()
//{
Expand Down
11 changes: 10 additions & 1 deletion sdk/storage/Azure.Storage.Blobs/tests/ServiceClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,16 @@ public async Task FindBlobsByTagAsync()

// Assert
TaggedBlobItem filterBlob = blobs.Where(r => r.BlobName == blobName).FirstOrDefault();
Assert.IsNotNull(filterBlob);

if (_serviceVersion >= BlobClientOptions.ServiceVersion.V2020_04_08)
{
Assert.AreEqual(1, filterBlob.Tags.Count);
Assert.AreEqual("myTagValue", filterBlob.Tags["myTagKey"]);
}
else
{
Assert.IsNotNull(filterBlob);
}
}

[Test]
Expand Down
Loading