From 4c8232e9cfd5e8f811522986938691ad32c44fb3 Mon Sep 17 00:00:00 2001 From: JinmingHu Date: Mon, 25 Jan 2021 14:49:11 +0800 Subject: [PATCH] `startsOn` parameter for `GetUserDelegationKey` was changed to optional. (#1451) * GetUserDelegationKey startsOn is optional * changelog * clang-format --- sdk/storage/azure-storage-blobs/CHANGELOG.md | 1 + .../inc/azure/storage/blobs/blob_options.hpp | 6 ++++++ .../inc/azure/storage/blobs/blob_service_client.hpp | 3 --- sdk/storage/azure-storage-blobs/src/blob_service_client.cpp | 3 +-- sdk/storage/azure-storage-blobs/test/blob_sas_test.cpp | 3 +-- .../azure-storage-blobs/test/blob_service_client_test.cpp | 4 +--- sdk/storage/azure-storage-files-datalake/CHANGELOG.md | 1 + .../storage/files/datalake/datalake_service_client.hpp | 5 +---- .../azure-storage-files-datalake/test/datalake_sas_test.cpp | 2 +- 9 files changed, 13 insertions(+), 15 deletions(-) diff --git a/sdk/storage/azure-storage-blobs/CHANGELOG.md b/sdk/storage/azure-storage-blobs/CHANGELOG.md index edd745b81..4a85cfb6d 100644 --- a/sdk/storage/azure-storage-blobs/CHANGELOG.md +++ b/sdk/storage/azure-storage-blobs/CHANGELOG.md @@ -13,6 +13,7 @@ - `ListType` in `GetBlockListOptions` was changed to non-nullable. - Added `BlobLeaseClient`, all lease related APIs are moved to `BlobLeaseClient`. - Type for lease duration in requests was changed to `std::chrono::seconds`, in response was changed to enum. +- `startsOn` parameter for `GetUserDelegationKey` was changed to optional. ## 12.0.0-beta.6 (2020-01-14) diff --git a/sdk/storage/azure-storage-blobs/inc/azure/storage/blobs/blob_options.hpp b/sdk/storage/azure-storage-blobs/inc/azure/storage/blobs/blob_options.hpp index df510c843..742da11b3 100644 --- a/sdk/storage/azure-storage-blobs/inc/azure/storage/blobs/blob_options.hpp +++ b/sdk/storage/azure-storage-blobs/inc/azure/storage/blobs/blob_options.hpp @@ -203,6 +203,12 @@ namespace Azure { namespace Storage { namespace Blobs { * @brief Context for cancelling long running operations. */ Azure::Core::Context Context; + + /** + * @brief Start time for the key's validity. The time should be specified in UTC, and + * will be truncated to second. + */ + Azure::Core::DateTime startsOn = std::chrono::system_clock::now(); }; /** diff --git a/sdk/storage/azure-storage-blobs/inc/azure/storage/blobs/blob_service_client.hpp b/sdk/storage/azure-storage-blobs/inc/azure/storage/blobs/blob_service_client.hpp index 57222d3e1..8746f5fde 100644 --- a/sdk/storage/azure-storage-blobs/inc/azure/storage/blobs/blob_service_client.hpp +++ b/sdk/storage/azure-storage-blobs/inc/azure/storage/blobs/blob_service_client.hpp @@ -104,15 +104,12 @@ namespace Azure { namespace Storage { namespace Blobs { * @brief Retrieves a key that can be used to delegate Active Directory authorization to * shared access signatures. * - * @param startsOn Start time for the key's validity. The time should be specified in UTC, and - * will be truncated to second. * @param expiresOn Expiration of the key's validity. The time should be specified in UTC, and * will be truncated to second. * @param options Optional parameters to execute this function. * @return A deserialized GetUserDelegationKeyResult instance. */ Azure::Core::Response GetUserDelegationKey( - const Azure::Core::DateTime& startsOn, const Azure::Core::DateTime& expiresOn, const GetUserDelegationKeyOptions& options = GetUserDelegationKeyOptions()) const; diff --git a/sdk/storage/azure-storage-blobs/src/blob_service_client.cpp b/sdk/storage/azure-storage-blobs/src/blob_service_client.cpp index f97c43de6..d26eee5f1 100644 --- a/sdk/storage/azure-storage-blobs/src/blob_service_client.cpp +++ b/sdk/storage/azure-storage-blobs/src/blob_service_client.cpp @@ -134,12 +134,11 @@ namespace Azure { namespace Storage { namespace Blobs { } Azure::Core::Response BlobServiceClient::GetUserDelegationKey( - const Azure::Core::DateTime& startsOn, const Azure::Core::DateTime& expiresOn, const GetUserDelegationKeyOptions& options) const { Details::BlobRestClient::Service::GetUserDelegationKeyOptions protocolLayerOptions; - protocolLayerOptions.StartsOn = startsOn; + protocolLayerOptions.StartsOn = options.startsOn; protocolLayerOptions.ExpiresOn = expiresOn; return Details::BlobRestClient::Service::GetUserDelegationKey( options.Context, *m_pipeline, m_serviceUrl, protocolLayerOptions); diff --git a/sdk/storage/azure-storage-blobs/test/blob_sas_test.cpp b/sdk/storage/azure-storage-blobs/test/blob_sas_test.cpp index 8ffc01bed..2f1354a54 100644 --- a/sdk/storage/azure-storage-blobs/test/blob_sas_test.cpp +++ b/sdk/storage/azure-storage-blobs/test/blob_sas_test.cpp @@ -52,8 +52,7 @@ namespace Azure { namespace Storage { namespace Test { serviceUrl, std::make_shared( AadTenantId(), AadClientId(), AadClientSecret())); - auto userDelegationKey - = blobServiceClient1.GetUserDelegationKey(sasStartsOn, sasExpiresOn)->Key; + auto userDelegationKey = blobServiceClient1.GetUserDelegationKey(sasExpiresOn)->Key; auto verify_blob_read = [&](const std::string& sas) { EXPECT_NO_THROW(blobClient0.Create()); diff --git a/sdk/storage/azure-storage-blobs/test/blob_service_client_test.cpp b/sdk/storage/azure-storage-blobs/test/blob_service_client_test.cpp index 4ff575345..607463a6f 100644 --- a/sdk/storage/azure-storage-blobs/test/blob_service_client_test.cpp +++ b/sdk/storage/azure-storage-blobs/test/blob_service_client_test.cpp @@ -425,7 +425,6 @@ namespace Azure { namespace Storage { namespace Test { TEST_F(BlobServiceClientTest, UserDelegationKey) { - auto sasStartsOn = std::chrono::system_clock::now() - std::chrono::minutes(5); auto sasExpiresOn = std::chrono::system_clock::now() + std::chrono::minutes(60); auto blobServiceClient1 = Blobs::BlobServiceClient( @@ -433,8 +432,7 @@ namespace Azure { namespace Storage { namespace Test { std::make_shared( AadTenantId(), AadClientId(), AadClientSecret())); - auto getUserDelegationKeyResult - = blobServiceClient1.GetUserDelegationKey(sasStartsOn, sasExpiresOn); + auto getUserDelegationKeyResult = blobServiceClient1.GetUserDelegationKey(sasExpiresOn); EXPECT_FALSE(getUserDelegationKeyResult->RequestId.empty()); diff --git a/sdk/storage/azure-storage-files-datalake/CHANGELOG.md b/sdk/storage/azure-storage-files-datalake/CHANGELOG.md index cee250d93..087e75241 100644 --- a/sdk/storage/azure-storage-files-datalake/CHANGELOG.md +++ b/sdk/storage/azure-storage-files-datalake/CHANGELOG.md @@ -30,6 +30,7 @@ - Removed `Directory` in `ListPathsSinglePageOptions`. - Removed unused type `AccountResourceType` and `PathLeaseAction`. - Changed all previous `LeaseDuration` members to a new type named `LeaseDurationType`. +- `startsOn` parameter for `GetUserDelegationKey` was changed to optional. ### Other Changes and Improvements diff --git a/sdk/storage/azure-storage-files-datalake/inc/azure/storage/files/datalake/datalake_service_client.hpp b/sdk/storage/azure-storage-files-datalake/inc/azure/storage/files/datalake/datalake_service_client.hpp index dea89fa3a..2eb9233e5 100644 --- a/sdk/storage/azure-storage-files-datalake/inc/azure/storage/files/datalake/datalake_service_client.hpp +++ b/sdk/storage/azure-storage-files-datalake/inc/azure/storage/files/datalake/datalake_service_client.hpp @@ -92,8 +92,6 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake { * @brief Retrieves a key that can be used to delegate Active Directory authorization to * shared access signatures. * - * @param startsOn Start time for the key's validity. The time should be specified in UTC, and - * will be truncated to second. * @param expiresOn Expiration of the key's validity. The time should be specified in UTC, and * will be truncated to second. * @param options Optional parameters to execute @@ -103,11 +101,10 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake { * @remark This request is sent to blob endpoint. */ Azure::Core::Response GetUserDelegationKey( - const Azure::Core::DateTime& startsOn, const Azure::Core::DateTime& expiresOn, const GetUserDelegationKeyOptions& options = GetUserDelegationKeyOptions()) const { - return m_blobServiceClient.GetUserDelegationKey(startsOn, expiresOn, options); + return m_blobServiceClient.GetUserDelegationKey(expiresOn, options); } private: diff --git a/sdk/storage/azure-storage-files-datalake/test/datalake_sas_test.cpp b/sdk/storage/azure-storage-files-datalake/test/datalake_sas_test.cpp index 7cf80fdfa..578277dc1 100644 --- a/sdk/storage/azure-storage-files-datalake/test/datalake_sas_test.cpp +++ b/sdk/storage/azure-storage-files-datalake/test/datalake_sas_test.cpp @@ -62,7 +62,7 @@ namespace Azure { namespace Storage { namespace Test { serviceUrl, std::make_shared( AadTenantId(), AadClientId(), AadClientSecret())); - auto userDelegationKey = serviceClient1.GetUserDelegationKey(sasStartsOn, sasExpiresOn)->Key; + auto userDelegationKey = serviceClient1.GetUserDelegationKey(sasExpiresOn)->Key; auto verify_file_read = [&](const std::string& sas) { EXPECT_NO_THROW(fileClient0.Create());