diff --git a/sdk/storage/Azure.Storage.Files.Shares/CHANGELOG.md b/sdk/storage/Azure.Storage.Files.Shares/CHANGELOG.md index 9f8eded95803..de784b590f18 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/CHANGELOG.md +++ b/sdk/storage/Azure.Storage.Files.Shares/CHANGELOG.md @@ -1,12 +1,7 @@ # Release History ## 12.17.0-beta.2 (Unreleased) - -### Features Added - -### Breaking Changes - -### Bugs Fixed +- Fixed bug where the x-ms-file-request-intent request header was not being sent for ShareFileClient.UploadRangeFromUri() and .UploadRangeFromUriAsync(). ### Other Changes diff --git a/sdk/storage/Azure.Storage.Files.Shares/assets.json b/sdk/storage/Azure.Storage.Files.Shares/assets.json index 6ca5a9d8dc59..59cb51ffe975 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/assets.json +++ b/sdk/storage/Azure.Storage.Files.Shares/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "net", "TagPrefix": "net/storage/Azure.Storage.Files.Shares", - "Tag": "net/storage/Azure.Storage.Files.Shares_29361a65db" + "Tag": "net/storage/Azure.Storage.Files.Shares_6317487064" } diff --git a/sdk/storage/Azure.Storage.Files.Shares/src/Generated/DirectoryRestClient.cs b/sdk/storage/Azure.Storage.Files.Shares/src/Generated/DirectoryRestClient.cs index 039a76444c28..0b17c89cd659 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/src/Generated/DirectoryRestClient.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/src/Generated/DirectoryRestClient.cs @@ -33,7 +33,7 @@ internal partial class DirectoryRestClient /// The handler for diagnostic messaging in the client. /// The HTTP pipeline for sending and receiving REST requests and responses. /// The URL of the service account, share, directory or file that is the target of the desired operation. - /// Specifies the version of the operation to use for this request. The default value is "2023-01-03". + /// Specifies the version of the operation to use for this request. The default value is "2023-08-03". /// If true, the trailing dot will not be trimmed from the target URI. /// Valid value is backup. /// If true, the trailing dot will not be trimmed from the source URI. diff --git a/sdk/storage/Azure.Storage.Files.Shares/src/Generated/FileRestClient.cs b/sdk/storage/Azure.Storage.Files.Shares/src/Generated/FileRestClient.cs index dcecab6dd3a8..fe20eb52a386 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/src/Generated/FileRestClient.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/src/Generated/FileRestClient.cs @@ -35,7 +35,7 @@ internal partial class FileRestClient /// The handler for diagnostic messaging in the client. /// The HTTP pipeline for sending and receiving REST requests and responses. /// The URL of the service account, share, directory or file that is the target of the desired operation. - /// Specifies the version of the operation to use for this request. The default value is "2023-01-03". + /// Specifies the version of the operation to use for this request. The default value is "2023-08-03". /// Only update is supported: - Update: Writes the bytes downloaded from the source url into the specified range. The default value is "update". /// If true, the trailing dot will not be trimmed from the target URI. /// Valid value is backup. @@ -1093,6 +1093,10 @@ internal HttpMessage CreateUploadRangeFromURLRequest(string range, string copySo { request.Headers.Add("x-ms-source-allow-trailing-dot", _allowSourceTrailingDot.Value); } + if (_fileRequestIntent != null) + { + request.Headers.Add("x-ms-file-request-intent", _fileRequestIntent.Value.ToString()); + } request.Headers.Add("Accept", "application/xml"); return message; } diff --git a/sdk/storage/Azure.Storage.Files.Shares/src/Generated/ServiceRestClient.cs b/sdk/storage/Azure.Storage.Files.Shares/src/Generated/ServiceRestClient.cs index bd142b915070..f935a0fa3c3b 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/src/Generated/ServiceRestClient.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/src/Generated/ServiceRestClient.cs @@ -30,7 +30,7 @@ internal partial class ServiceRestClient /// The handler for diagnostic messaging in the client. /// The HTTP pipeline for sending and receiving REST requests and responses. /// The URL of the service account, share, directory or file that is the target of the desired operation. - /// Specifies the version of the operation to use for this request. The default value is "2023-01-03". + /// Specifies the version of the operation to use for this request. The default value is "2023-08-03". /// , , or is null. public ServiceRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string url, string version) { diff --git a/sdk/storage/Azure.Storage.Files.Shares/src/Generated/ShareRestClient.cs b/sdk/storage/Azure.Storage.Files.Shares/src/Generated/ShareRestClient.cs index 74f9f228d261..82058175998f 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/src/Generated/ShareRestClient.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/src/Generated/ShareRestClient.cs @@ -32,7 +32,7 @@ internal partial class ShareRestClient /// The handler for diagnostic messaging in the client. /// The HTTP pipeline for sending and receiving REST requests and responses. /// The URL of the service account, share, directory or file that is the target of the desired operation. - /// Specifies the version of the operation to use for this request. The default value is "2023-01-03". + /// Specifies the version of the operation to use for this request. The default value is "2023-08-03". /// Valid value is backup. /// , , or is null. public ShareRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string url, string version, ShareTokenIntent? fileRequestIntent = null) diff --git a/sdk/storage/Azure.Storage.Files.Shares/src/autorest.md b/sdk/storage/Azure.Storage.Files.Shares/src/autorest.md index 15e218aea37f..6df3f9cc7e88 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/src/autorest.md +++ b/sdk/storage/Azure.Storage.Files.Shares/src/autorest.md @@ -4,7 +4,7 @@ Run `dotnet build /t:GenerateCode` to generate code. ``` yaml input-file: - - https://raw.githubusercontent.com/Azure/azure-rest-api-specs/ccae65b66ac23a9fd891ba86f45abc4372a9c688/specification/storage/data-plane/Microsoft.FileStorage/preview/2023-01-03/file.json + - https://raw.githubusercontent.com/Azure/azure-rest-api-specs/4bafbf3ab1532e390ad5757433679e9ebb5cbf38/specification/storage/data-plane/Microsoft.FileStorage/preview/2023-08-03/file.json generation1-convenience-client: true # https://github.com/Azure/autorest/issues/4075 skip-semantics-validation: true diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/FileClientTests.cs b/sdk/storage/Azure.Storage.Files.Shares/tests/FileClientTests.cs index 7bba863f981a..c856c50f134c 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/tests/FileClientTests.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/FileClientTests.cs @@ -3331,14 +3331,22 @@ await fileClient.UploadRangeAsync( } } + [RecordedTest] [ServiceVersion(Min = ShareClientOptions.ServiceVersion.V2021_04_10)] public async Task UploadRangeAsync_OAuth() { var data = GetRandomBuffer(Constants.KB); - await using DisposingFile test = await SharesClientBuilder.GetTestFileAsync( - SharesClientBuilder.GetServiceClient_OAuth()); - ShareFileClient file = test.File; + string shareName = GetNewShareName(); + ShareServiceClient sharedKeyServiceClient = SharesClientBuilder.GetServiceClient_OAuthAccount_SharedKey(); + await using DisposingShare sharedKeyShare = await GetTestShareAsync(sharedKeyServiceClient, shareName); + ShareServiceClient oauthServiceClient = SharesClientBuilder.GetServiceClient_OAuth(); + + string directoryName = GetNewDirectoryName(); + ShareDirectoryClient directory = InstrumentClient(oauthServiceClient.GetShareClient(shareName).GetDirectoryClient(directoryName)); + await directory.CreateAsync(); + + ShareFileClient file = await directory.CreateFileAsync(GetNewFileName(), Constants.MB); using (var stream = new MemoryStream(data)) { @@ -4404,6 +4412,70 @@ await TestHelper.AssertExpectedExceptionAsync( } } + [RecordedTest] + [ServiceVersion(Min = ShareClientOptions.ServiceVersion.V2021_04_10)] + public async Task UploadRangeFromUriAsync_OAuth() + { + string shareName = GetNewShareName(); + ShareServiceClient sharedKeyServiceClient = SharesClientBuilder.GetServiceClient_OAuthAccount_SharedKey(); + await using DisposingShare sharedKeyShare = await GetTestShareAsync(sharedKeyServiceClient, shareName); + ShareServiceClient oauthServiceClient = SharesClientBuilder.GetServiceClient_OAuth(); + ShareClient oauthShareClient = InstrumentClient(oauthServiceClient.GetShareClient(shareName)); + + // Arrange + var directoryName = GetNewDirectoryName(); + var directory = InstrumentClient(oauthShareClient.GetDirectoryClient(directoryName)); + await directory.CreateIfNotExistsAsync(); + + var fileName = GetNewFileName(); + var data = GetRandomBuffer(Constants.KB); + var sourceFile = InstrumentClient(directory.GetFileClient(fileName)); + await sourceFile.CreateAsync(maxSize: 1024); + using (var stream = new MemoryStream(data)) + { + await sourceFile.UploadRangeAsync(new HttpRange(0, 1024), stream); + } + + var destFile = directory.GetFileClient("destFile"); + await destFile.CreateAsync(maxSize: 1024); + var destRange = new HttpRange(256, 256); + var sourceRange = new HttpRange(512, 256); + + var sasFile = InstrumentClient( + GetServiceClient_FileServiceSasShare(shareName) + .GetShareClient(shareName) + .GetDirectoryClient(directoryName) + .GetFileClient(fileName)); + + // Act + Response response = await destFile.UploadRangeFromUriAsync( + sourceUri: sasFile.Uri, + range: destRange, + sourceRange: sourceRange); + + // Assert + // Ensure that we grab the whole ETag value from the service without removing the quotes + Assert.AreEqual(response.Value.ETag.ToString(), $"\"{response.GetRawResponse().Headers.ETag}\""); + + // Ensure the contents of the source and destination Files after the UploadRangeFromUri call + var sourceDownloadResponse = await sourceFile.DownloadAsync(new ShareFileDownloadOptions + { + Range = sourceRange + }); + var destDownloadResponse = await destFile.DownloadAsync(new ShareFileDownloadOptions + { + Range = destRange + }); + + var sourceStream = new MemoryStream(); + await sourceDownloadResponse.Value.Content.CopyToAsync(sourceStream); + + var destStream = new MemoryStream(); + await destDownloadResponse.Value.Content.CopyToAsync(destStream); + + TestHelper.AssertSequenceEqual(sourceStream.ToArray(), destStream.ToArray()); + } + [RecordedTest] public async Task ListHandles() {