Storage/Added x-ms-file-request-intent to PutRangeFromUrl (#5042)
* Added x-ms-file-request-itent to PutRangeFromUrl * update test * update test case
This commit is contained in:
parent
21978a69d8
commit
1acf0ba6df
@ -2,5 +2,5 @@
|
||||
"AssetsRepo": "Azure/azure-sdk-assets",
|
||||
"AssetsRepoPrefixPath": "cpp",
|
||||
"TagPrefix": "cpp/storage",
|
||||
"Tag": "cpp/storage_f9007be11f"
|
||||
"Tag": "cpp/storage_5ae381f797"
|
||||
}
|
||||
|
||||
@ -2551,6 +2551,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
|
||||
Nullable<Models::FileLastWrittenMode> FileLastWrittenMode;
|
||||
Nullable<bool> AllowTrailingDot;
|
||||
Nullable<bool> AllowSourceTrailingDot;
|
||||
Nullable<Models::ShareTokenIntent> FileRequestIntent;
|
||||
};
|
||||
static Response<Models::UploadFileRangeFromUriResult> UploadRangeFromUri(
|
||||
Core::Http::_internal::HttpPipeline& pipeline,
|
||||
|
||||
@ -3678,6 +3678,11 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
|
||||
"x-ms-source-allow-trailing-dot",
|
||||
options.AllowSourceTrailingDot.Value() ? "true" : "false");
|
||||
}
|
||||
if (options.FileRequestIntent.HasValue()
|
||||
&& !options.FileRequestIntent.Value().ToString().empty())
|
||||
{
|
||||
request.SetHeader("x-ms-file-request-intent", options.FileRequestIntent.Value().ToString());
|
||||
}
|
||||
auto pRawResponse = pipeline.Send(request, context);
|
||||
auto httpStatusCode = pRawResponse->GetStatusCode();
|
||||
if (httpStatusCode != Core::Http::HttpStatusCode::Created)
|
||||
|
||||
@ -1271,6 +1271,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
|
||||
+ std::string("-") + std::to_string(sourceRange.Offset + sourceRange.Length.Value() - 1);
|
||||
protocolLayerOptions.AllowTrailingDot = m_allowTrailingDot;
|
||||
protocolLayerOptions.AllowSourceTrailingDot = m_allowSourceTrailingDot;
|
||||
protocolLayerOptions.FileRequestIntent = m_shareTokenIntent;
|
||||
if (!options.SourceAuthorization.empty())
|
||||
{
|
||||
protocolLayerOptions.CopySourceAuthorization = options.SourceAuthorization;
|
||||
|
||||
@ -9,7 +9,7 @@ package-name: azure-storage-files-shares
|
||||
namespace: Azure::Storage::Files::Shares
|
||||
output-folder: generated
|
||||
clear-output-folder: true
|
||||
input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/storage/data-plane/Microsoft.FileStorage/preview/2023-01-03/file.json
|
||||
input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/storage/data-plane/Microsoft.FileStorage/preview/2023-08-03/file.json
|
||||
```
|
||||
|
||||
## ModelFour Options
|
||||
|
||||
@ -1163,7 +1163,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(FileShareFileClientTest, OAuthUploadRangeFromUri)
|
||||
TEST_F(FileShareFileClientTest, SourceOAuthUploadRangeFromUri)
|
||||
{
|
||||
size_t fileSize = 1 * 1024;
|
||||
std::string containerName = LowercaseRandomString();
|
||||
@ -1221,6 +1221,71 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
EXPECT_NO_THROW(containerClient.Delete());
|
||||
}
|
||||
|
||||
TEST_F(FileShareFileClientTest, DestinationOAuthUploadRangeFromUri_PLAYBACKONLY_)
|
||||
{
|
||||
size_t fileSize = 1 * 1024;
|
||||
std::string containerName = LowercaseRandomString();
|
||||
std::string blobName = RandomString();
|
||||
std::vector<uint8_t> blobContent = RandomBuffer(fileSize);
|
||||
auto memBodyStream = Core::IO::MemoryBodyStream(blobContent);
|
||||
|
||||
auto containerClient = Storage::Blobs::BlobContainerClient::CreateFromConnectionString(
|
||||
StandardStorageConnectionString(),
|
||||
containerName,
|
||||
InitStorageClientOptions<Storage::Blobs::BlobClientOptions>());
|
||||
containerClient.Create();
|
||||
auto sourceBlobClient = containerClient.GetBlockBlobClient(blobName);
|
||||
sourceBlobClient.Upload(memBodyStream);
|
||||
|
||||
std::shared_ptr<Azure::Core::Credentials::TokenCredential> oauthCredential
|
||||
= std::make_shared<Azure::Identity::ClientSecretCredential>(
|
||||
AadTenantId(),
|
||||
AadClientId(),
|
||||
AadClientSecret(),
|
||||
InitStorageClientOptions<Azure::Identity::ClientSecretCredentialOptions>());
|
||||
auto clientOptions = InitStorageClientOptions<Files::Shares::ShareClientOptions>();
|
||||
clientOptions.ShareTokenIntent = Files::Shares::Models::ShareTokenIntent::Backup;
|
||||
|
||||
auto destFileClient
|
||||
= Files::Shares::ShareClient(m_shareClient->GetUrl(), oauthCredential, clientOptions)
|
||||
.GetRootDirectoryClient()
|
||||
.GetFileClient(RandomString());
|
||||
|
||||
destFileClient.Create(fileSize * 4);
|
||||
Azure::Core::Http::HttpRange sourceRange;
|
||||
Azure::Core::Http::HttpRange destRange;
|
||||
sourceRange.Length = fileSize;
|
||||
destRange.Length = fileSize;
|
||||
|
||||
// Get oauth token of source file
|
||||
Azure::Core::Credentials::TokenRequestContext requestContext;
|
||||
requestContext.Scopes = {Storage::_internal::StorageScope};
|
||||
auto oauthToken = oauthCredential->GetToken(requestContext, Azure::Core::Context());
|
||||
|
||||
Files::Shares::UploadFileRangeFromUriOptions options;
|
||||
options.SourceAuthorization = "Bearer " + oauthToken.Token;
|
||||
Files::Shares::Models::UploadFileRangeFromUriResult uploadResult;
|
||||
EXPECT_NO_THROW(
|
||||
uploadResult
|
||||
= destFileClient
|
||||
.UploadRangeFromUri(destRange.Offset, sourceBlobClient.GetUrl(), sourceRange, options)
|
||||
.Value);
|
||||
|
||||
Files::Shares::Models::DownloadFileResult result;
|
||||
Files::Shares::DownloadFileOptions downloadOptions;
|
||||
downloadOptions.Range = destRange;
|
||||
EXPECT_NO_THROW(result = destFileClient.Download(downloadOptions).Value);
|
||||
auto resultBuffer = result.BodyStream->ReadToEnd(Core::Context());
|
||||
EXPECT_EQ(blobContent, resultBuffer);
|
||||
Files::Shares::Models::GetFileRangeListResult getRangeResult;
|
||||
EXPECT_NO_THROW(getRangeResult = destFileClient.GetRangeList().Value);
|
||||
EXPECT_EQ(1U, getRangeResult.Ranges.size());
|
||||
EXPECT_TRUE(getRangeResult.Ranges[0].Length.HasValue());
|
||||
EXPECT_EQ(static_cast<int64_t>(fileSize), getRangeResult.Ranges[0].Length.Value());
|
||||
|
||||
EXPECT_NO_THROW(containerClient.Delete());
|
||||
}
|
||||
|
||||
TEST_F(FileShareFileClientTest, UploadFromWithOptions)
|
||||
{
|
||||
auto fileClient = m_shareClient->GetRootDirectoryClient().GetFileClient(RandomString());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user