From 83406f23ddd5c3e6a97a9003055ac02692608989 Mon Sep 17 00:00:00 2001 From: JinmingHu Date: Fri, 10 Jul 2020 12:03:32 +0800 Subject: [PATCH] Storage Blob Service Access Conditions, Bitwise enum class (#252) * access conditions * bitwise enum class * Update x-ms-date on each retry * add a header for all constant strings * fix some ut * rename ModifiedTimeAccessConditons->LastModifiedTimeAccessConditions --- sdk/storage/CMakeLists.txt | 2 + sdk/storage/inc/blobs/blob_options.hpp | 709 ++++-------------- .../internal/protocol/blob_rest_client.hpp | 262 ++++--- sdk/storage/inc/common/access_conditions.hpp | 61 ++ sdk/storage/inc/common/constant.hpp | 16 - sdk/storage/inc/common/constants.hpp | 10 + sdk/storage/src/blobs/append_blob_client.cpp | 42 +- sdk/storage/src/blobs/blob_client.cpp | 82 +- .../src/blobs/blob_container_client.cpp | 10 +- sdk/storage/src/blobs/blob_service_client.cpp | 9 +- sdk/storage/src/blobs/block_blob_client.cpp | 39 +- sdk/storage/src/blobs/page_blob_client.cpp | 70 +- .../common/common_headers_request_policy.cpp | 6 +- sdk/storage/test/append_blob_client_test.cpp | 10 +- .../test/blob_container_client_test.cpp | 4 +- sdk/storage/test/blob_service_client_test.cpp | 4 +- sdk/storage/test/block_blob_client_test.cpp | 4 +- sdk/storage/test/page_blob_client_test.cpp | 2 +- 18 files changed, 506 insertions(+), 836 deletions(-) create mode 100644 sdk/storage/inc/common/access_conditions.hpp delete mode 100644 sdk/storage/inc/common/constant.hpp create mode 100644 sdk/storage/inc/common/constants.hpp diff --git a/sdk/storage/CMakeLists.txt b/sdk/storage/CMakeLists.txt index 0ac64b7e2..8b2a77dba 100644 --- a/sdk/storage/CMakeLists.txt +++ b/sdk/storage/CMakeLists.txt @@ -11,6 +11,7 @@ set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) option(BUILD_STORAGE_SAMPLES "Build sample codes" ON) set (AZURE_STORAGE_BLOB_HEADER + inc/common/constants.hpp inc/common/storage_common.hpp inc/common/storage_credential.hpp inc/common/storage_url_builder.hpp @@ -20,6 +21,7 @@ set (AZURE_STORAGE_BLOB_HEADER inc/common/xml_wrapper.hpp inc/common/concurrent_transfer.hpp inc/common/file_io.hpp + inc/common/access_conditions.hpp inc/blobs/blob.hpp inc/blobs/blob_service_client.hpp inc/blobs/blob_container_client.hpp diff --git a/sdk/storage/inc/blobs/blob_options.hpp b/sdk/storage/inc/blobs/blob_options.hpp index 4693478d0..445077909 100644 --- a/sdk/storage/inc/blobs/blob_options.hpp +++ b/sdk/storage/inc/blobs/blob_options.hpp @@ -3,6 +3,7 @@ #pragma once +#include "common/access_conditions.hpp" #include "internal/protocol/blob_rest_client.hpp" #include @@ -11,6 +12,65 @@ namespace Azure { namespace Storage { namespace Blobs { + /** + * @brief Specifies access conditions for a container. + */ + struct ContainerAccessConditions : public LastModifiedTimeAccessConditions, + public LeaseAccessConditions + { + }; + + /** + * @brief Specifies access conditions for a blob. + */ + struct BlobAccessConditions : public LastModifiedTimeAccessConditions, + public ETagAccessConditions, + public LeaseAccessConditions + { + }; + + /** + * @brief Specifies access conditions for a append blob. + */ + struct AppendBlobAccessConditions : public BlobAccessConditions + { + /** + * @brief Ensures that the AppendBlock operation succeeds only if the append blob's size + * is less than or equal to this value. + */ + Azure::Core::Nullable MaxSize; + + /** + * @brief Ensures that the AppendBlock operation succeeds only if the append position is equal + * to this value. + */ + Azure::Core::Nullable AppendPosition; + }; + + /** + * @brief Specifies access conditions for a page blob. + */ + struct PageBlobAccessConditions : public BlobAccessConditions + { + /** + * @brief IfSequenceNumberLessThan ensures that the page blob operation succeeds only if + * the blob's sequence number is less than a value. + */ + Azure::Core::Nullable IfSequenceNumberLessThan; + + /** + * @brief IfSequenceNumberLessThanOrEqual ensures that the page blob operation succeeds + * only if the blob's sequence number is less than or equal to a value. + */ + Azure::Core::Nullable IfSequenceNumberLessThanOrEqual; + + /** + * @brief IfSequenceNumberEqual ensures that the page blob operation succeeds only + * if the blob's sequence number is equal to a value. + */ + Azure::Core::Nullable IfSequenceNumberEqual; + }; + /** * @brief Service client options used to initalize BlobServiceClient. */ @@ -63,7 +123,7 @@ namespace Azure { namespace Storage { namespace Blobs { /** * @brief Specifies that the container's metadata be returned. */ - std::vector Include; + ListBlobContainersIncludeOption Include = ListBlobContainersIncludeOption::None; }; /** @@ -128,16 +188,9 @@ namespace Azure { namespace Storage { namespace Blobs { Azure::Core::Context Context; /** - * @brief Specify this header to perform the operation only if the resource has been - * modified since the specified time. + * @brief Optional conditions that must be met to perform this operation. */ - Azure::Core::Nullable IfModifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource has not been - * modified since the specified date/time. - */ - Azure::Core::Nullable IfUnmodifiedSince; + ContainerAccessConditions Conditions; }; /** @@ -149,6 +202,11 @@ namespace Azure { namespace Storage { namespace Blobs { * @brief Context for cancelling long running operations. */ Azure::Core::Context Context; + + /** + * @brief Optional conditions that must be met to perform this operation. + */ + LeaseAccessConditions Conditions; }; /** @@ -162,10 +220,9 @@ namespace Azure { namespace Storage { namespace Blobs { Azure::Core::Context Context; /** - * @brief Specify this header to perform the operation only if the resource has been - * modified since the specified time. + * @brief Optional conditions that must be met to perform this operation. */ - Azure::Core::Nullable IfModifiedSince; + ContainerAccessConditions Conditions; }; /** @@ -208,7 +265,7 @@ namespace Azure { namespace Storage { namespace Blobs { /** * @brief Specifies one or more datasets to include in the response. */ - std::vector Include; + ListBlobsIncludeItem Include = ListBlobsIncludeItem::None; }; /** @@ -261,29 +318,9 @@ namespace Azure { namespace Storage { namespace Blobs { Azure::Core::Context Context; /** - * @brief Specify this header to perform the operation only if the resource has been - * modified since the specified time. + * @brief Optional conditions that must be met to perform this operation. */ - Azure::Core::Nullable IfModifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource has not been - * modified since the specified date/time. - */ - Azure::Core::Nullable IfUnmodifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag - * matches the value specified. - */ - Azure::Core::Nullable IfMatch; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag does - * not match the value specified. Specify the wildcard character (*) to perform the operation - * only if the resource does not exist, and fail the operation if it does exist. - */ - Azure::Core::Nullable IfNoneMatch; + BlobAccessConditions Conditions; }; /** @@ -297,29 +334,9 @@ namespace Azure { namespace Storage { namespace Blobs { Azure::Core::Context Context; /** - * @brief Specify this header to perform the operation only if the resource has been - * modified since the specified time. + * @brief Optional conditions that must be met to perform this operation. */ - Azure::Core::Nullable IfModifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource has not been - * modified since the specified date/time. - */ - Azure::Core::Nullable IfUnmodifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag - * matches the value specified. - */ - Azure::Core::Nullable IfMatch; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag does - * not match the value specified. Specify the wildcard character (*) to perform the operation - * only if the resource does not exist, and fail the operation if it does exist. - */ - Azure::Core::Nullable IfNoneMatch; + BlobAccessConditions Conditions; }; /** @@ -333,29 +350,9 @@ namespace Azure { namespace Storage { namespace Blobs { Azure::Core::Context Context; /** - * @brief Specify this header to perform the operation only if the resource has been - * modified since the specified time. + * @brief Optional conditions that must be met to perform this operation. */ - Azure::Core::Nullable IfModifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource has not been - * modified since the specified date/time. - */ - Azure::Core::Nullable IfUnmodifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag - * matches the value specified. - */ - Azure::Core::Nullable IfMatch; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag does - * not match the value specified. Specify the wildcard character (*) to perform the operation - * only if the resource does not exist, and fail the operation if it does exist. - */ - Azure::Core::Nullable IfNoneMatch; + BlobAccessConditions Conditions; }; /** @@ -396,16 +393,14 @@ namespace Azure { namespace Storage { namespace Blobs { std::map Metadata; /** - * @brief Specify this header to perform the operation only if the resource has an - * active lease mathing this id. + * @brief Optional conditions that must be met to perform this operation. */ - Azure::Core::Nullable LeaseId; + BlobAccessConditions Conditions; /** - * @brief Specify this header to perform the operation only if the lease id given - * matches the active lease id of the source blob. + * @brief Optional conditions that the source must meet to perform this operation. */ - Azure::Core::Nullable SourceLeaseId; + BlobAccessConditions SourceConditions; /** * @brief Specifies the tier to be set on the target blob. @@ -418,55 +413,6 @@ namespace Azure { namespace Storage { namespace Blobs { * same blob. */ Azure::Core::Nullable RehydratePriority; - - /** - * @brief Specify this header to perform the operation only if the resource has been - * modified since the specified time. - */ - Azure::Core::Nullable IfModifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource has not been - * modified since the specified date/time. - */ - Azure::Core::Nullable IfUnmodifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag - * matches the value specified. - */ - Azure::Core::Nullable IfMatch; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag does - * not match the value specified. Specify the wildcard character (*) to perform the operation - * only if the resource does not exist, and fail the operation if it does exist. - */ - Azure::Core::Nullable IfNoneMatch; - - /** - * @brief Specify this conditional header to copy the blob only if the source blob has - * been modified since the specified date/time. - */ - Azure::Core::Nullable SourceIfModifiedSince; - - /** - * @brief Specify this conditional header to copy the blob only if the source blob has - * not been modified since the specified date/time. - */ - Azure::Core::Nullable SourceIfUnmodifiedSince; - - /** - * @brief Specify this conditional header to copy the source blob only if its ETag - * matches the value specified. - */ - Azure::Core::Nullable SourceIfMatch; - - /** - * @brief Specify this conditional header to copy the blob only if its ETag does not - * match the value specified. - */ - Azure::Core::Nullable SourceIfNoneMatch; }; /** @@ -480,10 +426,9 @@ namespace Azure { namespace Storage { namespace Blobs { Azure::Core::Context Context; /** - * @brief Specify this header to perform the operation only if the resource has an - * active lease mathing this id. + * @brief Optional conditions that must be met to perform this operation. */ - Azure::Core::Nullable LeaseId; + LeaseAccessConditions Conditions; }; /** @@ -508,29 +453,9 @@ namespace Azure { namespace Storage { namespace Blobs { Azure::Core::Nullable Length; /** - * @brief Specify this header to perform the operation only if the resource has been - * modified since the specified time. + * @brief Optional conditions that must be met to perform this operation. */ - Azure::Core::Nullable IfModifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource has not been - * modified since the specified date/time. - */ - Azure::Core::Nullable IfUnmodifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag - * matches the value specified. - */ - Azure::Core::Nullable IfMatch; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag does - * not match the value specified. Specify the wildcard character (*) to perform the operation - * only if the resource does not exist, and fail the operation if it does exist. - */ - Azure::Core::Nullable IfNoneMatch; + BlobAccessConditions Conditions; }; /** @@ -596,35 +521,9 @@ namespace Azure { namespace Storage { namespace Blobs { std::map Metadata; /** - * @brief Specify this header to perform the operation only if the resource has an - * active lease mathing this id. + * @brief Optional conditions that must be met to perform this operation. */ - Azure::Core::Nullable LeaseId; - - /** - * @brief Specify this header to perform the operation only if the resource has been - * modified since the specified time. - */ - Azure::Core::Nullable IfModifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource has not been - * modified since the specified date/time. - */ - Azure::Core::Nullable IfUnmodifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag - * matches the value specified. - */ - Azure::Core::Nullable IfMatch; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag does - * not match the value specified. Specify the wildcard character (*) to perform the operation - * only if the resource does not exist, and fail the operation if it does exist. - */ - Azure::Core::Nullable IfNoneMatch; + BlobAccessConditions Conditions; }; /** @@ -645,29 +544,9 @@ namespace Azure { namespace Storage { namespace Blobs { Azure::Core::Nullable DeleteSnapshots; /** - * @brief Specify this header to perform the operation only if the resource has been - * modified since the specified time. + * @brief Optional conditions that must be met to perform this operation. */ - Azure::Core::Nullable IfModifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource has not been - * modified since the specified date/time. - */ - Azure::Core::Nullable IfUnmodifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag - * matches the value specified. - */ - Azure::Core::Nullable IfMatch; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag does - * not match the value specified. Specify the wildcard character (*) to perform the operation - * only if the resource does not exist, and fail the operation if it does exist. - */ - Azure::Core::Nullable IfNoneMatch; + BlobAccessConditions Conditions; }; /** @@ -721,29 +600,9 @@ namespace Azure { namespace Storage { namespace Blobs { Azure::Core::Nullable Tier; /** - * @brief Specify this header to perform the operation only if the resource has been - * modified since the specified time. + * @brief Optional conditions that must be met to perform this operation. */ - Azure::Core::Nullable IfModifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource has not been - * modified since the specified date/time. - */ - Azure::Core::Nullable IfUnmodifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag - * matches the value specified. - */ - Azure::Core::Nullable IfMatch; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag does - * not match the value specified. Specify the wildcard character (*) to perform the operation - * only if the resource does not exist, and fail the operation if it does exist. - */ - Azure::Core::Nullable IfNoneMatch; + BlobAccessConditions Conditions; }; /** @@ -805,6 +664,11 @@ namespace Azure { namespace Storage { namespace Blobs { * that has arrived with the one that was sent. */ Azure::Core::Nullable ContentCRC64; + + /** + * @brief Optional conditions that must be met to perform this operation. + */ + LeaseAccessConditions Conditions; }; /** @@ -843,34 +707,14 @@ namespace Azure { namespace Storage { namespace Blobs { Azure::Core::Nullable ContentCRC64; /** - * @brief Specify this header to perform the operation only if the resource has an - * active lease mathing this id. + * @brief Optional conditions that must be met to perform this operation. */ - Azure::Core::Nullable LeaseId; + LeaseAccessConditions Conditions; /** - * @brief Specify this conditional header to copy the blob only if the source blob has - * been modified since the specified date/time. + * @brief Optional conditions that the source must meet to perform this operation. */ - Azure::Core::Nullable SourceIfModifiedSince; - - /** - * @brief Specify this conditional header to copy the blob only if the source blob has - * not been modified since the specified date/time. - */ - Azure::Core::Nullable SourceIfUnmodifiedSince; - - /** - * @brief Specify this conditional header to copy the source blob only if its ETag - * matches the value specified. - */ - Azure::Core::Nullable SourceIfMatch; - - /** - * @brief Specify this conditional header to copy the blob only if its ETag does not - * match the value specified. - */ - Azure::Core::Nullable SourceIfNoneMatch; + BlobAccessConditions SourceConditions; }; /** @@ -899,29 +743,9 @@ namespace Azure { namespace Storage { namespace Blobs { Azure::Core::Nullable Tier; /** - * @brief Specify this header to perform the operation only if the resource has been - * modified since the specified time. + * @brief Optional conditions that must be met to perform this operation. */ - Azure::Core::Nullable IfModifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource has not been - * modified since the specified date/time. - */ - Azure::Core::Nullable IfUnmodifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag - * matches the value specified. - */ - Azure::Core::Nullable IfMatch; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag does - * not match the value specified. Specify the wildcard character (*) to perform the operation - * only if the resource does not exist, and fail the operation if it does exist. - */ - Azure::Core::Nullable IfNoneMatch; + BlobAccessConditions Conditions; }; /** @@ -933,32 +757,17 @@ namespace Azure { namespace Storage { namespace Blobs { * @brief Context for cancelling long running operations. */ Azure::Core::Context Context; + + /** + * @brief Specifies whether to return the list of committed blocks, the list of uncommitted + * blocks, or both lists together. + */ Azure::Core::Nullable ListType; /** - * @brief Specify this header to perform the operation only if the resource has been - * modified since the specified time. + * @brief Optional conditions that must be met to perform this operation. */ - Azure::Core::Nullable IfModifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource has not been - * modified since the specified date/time. - */ - Azure::Core::Nullable IfUnmodifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag - * matches the value specified. - */ - Azure::Core::Nullable IfMatch; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag does - * not match the value specified. Specify the wildcard character (*) to perform the operation - * only if the resource does not exist, and fail the operation if it does exist. - */ - Azure::Core::Nullable IfNoneMatch; + LeaseAccessConditions Conditions; }; /** @@ -982,29 +791,9 @@ namespace Azure { namespace Storage { namespace Blobs { std::map Metadata; /** - * @brief Specify this header to perform the operation only if the resource has been - * modified since the specified time. + * @brief Optional conditions that must be met to perform this operation. */ - Azure::Core::Nullable IfModifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource has not been - * modified since the specified date/time. - */ - Azure::Core::Nullable IfUnmodifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag - * matches the value specified. - */ - Azure::Core::Nullable IfMatch; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag does - * not match the value specified. Specify the wildcard character (*) to perform the operation - * only if the resource does not exist, and fail the operation if it does exist. - */ - Azure::Core::Nullable IfNoneMatch; + BlobAccessConditions Conditions; }; /** @@ -1032,47 +821,9 @@ namespace Azure { namespace Storage { namespace Blobs { Azure::Core::Nullable ContentCRC64; /** - * @brief Specify this header to perform the operation only if the resource has an - * active lease mathing this id. + * @brief Optional conditions that must be met to perform this operation. */ - Azure::Core::Nullable LeaseId; - - /** - * @brief Ensures that the AppendBlock operation succeeds only if the append blob's size - * is less than or equal to this value. - */ - Azure::Core::Nullable MaxSize; - - /** - * @brief Ensures that the AppendBlock operation succeeds only if the append position is equal - * to this value. - */ - Azure::Core::Nullable AppendPosition; - - /** - * @brief Specify this header to perform the operation only if the resource has been - * modified since the specified time. - */ - Azure::Core::Nullable IfModifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource has not been - * modified since the specified date/time. - */ - Azure::Core::Nullable IfUnmodifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag - * matches the value specified. - */ - Azure::Core::Nullable IfMatch; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag does - * not match the value specified. Specify the wildcard character (*) to perform the operation - * only if the resource does not exist, and fail the operation if it does exist. - */ - Azure::Core::Nullable IfNoneMatch; + AppendBlobAccessConditions Conditions; }; /** @@ -1111,47 +862,9 @@ namespace Azure { namespace Storage { namespace Blobs { Azure::Core::Nullable ContentCRC64; /** - * @brief Specify this header to perform the operation only if the resource has an - * active lease mathing this id. + * @brief Optional conditions that must be met to perform this operation. */ - Azure::Core::Nullable LeaseId; - - /** - * @brief Ensures that the AppendBlock operation succeeds only if the append blob's size - * is less than or equal to this value. - */ - Azure::Core::Nullable MaxSize; - - /** - * @brief Ensures that the AppendBlock operation succeeds only if the append position is - * equal to this value. - */ - Azure::Core::Nullable AppendPosition; - - /** - * @brief Specify this header to perform the operation only if the resource has been - * modified since the specified time. - */ - Azure::Core::Nullable IfModifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource has not been - * modified since the specified date/time. - */ - Azure::Core::Nullable IfUnmodifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag - * matches the value specified. - */ - Azure::Core::Nullable IfMatch; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag does - * not match the value specified. Specify the wildcard character (*) to perform the operation - * only if the resource does not exist, and fail the operation if it does exist. - */ - Azure::Core::Nullable IfNoneMatch; + AppendBlobAccessConditions Conditions; }; /** @@ -1181,29 +894,9 @@ namespace Azure { namespace Storage { namespace Blobs { Azure::Core::Nullable Tier; /** - * @brief Specify this header to perform the operation only if the resource has been - * modified since the specified time. + * @brief Optional conditions that must be met to perform this operation. */ - Azure::Core::Nullable IfModifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource has not been - * modified since the specified date/time. - */ - Azure::Core::Nullable IfUnmodifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag - * matches the value specified. - */ - Azure::Core::Nullable IfMatch; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag does - * not match the value specified. Specify the wildcard character (*) to perform the operation - * only if the resource does not exist, and fail the operation if it does exist. - */ - Azure::Core::Nullable IfNoneMatch; + BlobAccessConditions Conditions; }; /** @@ -1231,35 +924,9 @@ namespace Azure { namespace Storage { namespace Blobs { Azure::Core::Nullable ContentCRC64; /** - * @brief Specify this header to perform the operation only if the resource has an - * active lease mathing this id. + * @brief Optional conditions that must be met to perform this operation. */ - Azure::Core::Nullable LeaseId; - - /** - * @brief Specify this header to perform the operation only if the resource has been - * modified since the specified time. - */ - Azure::Core::Nullable IfModifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource has not been - * modified since the specified date/time. - */ - Azure::Core::Nullable IfUnmodifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag - * matches the value specified. - */ - Azure::Core::Nullable IfMatch; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag does - * not match the value specified. Specify the wildcard character (*) to perform the operation - * only if the resource does not exist, and fail the operation if it does exist. - */ - Azure::Core::Nullable IfNoneMatch; + PageBlobAccessConditions Conditions; }; /** @@ -1287,35 +954,9 @@ namespace Azure { namespace Storage { namespace Blobs { Azure::Core::Nullable ContentCRC64; /** - * @brief Specify this header to perform the operation only if the resource has an - * active lease mathing this id. + * @brief Optional conditions that must be met to perform this operation. */ - Azure::Core::Nullable LeaseId; - - /** - * @brief Specify this header to perform the operation only if the resource has been - * modified since the specified time. - */ - Azure::Core::Nullable IfModifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource has not been - * modified since the specified date/time. - */ - Azure::Core::Nullable IfUnmodifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag - * matches the value specified. - */ - Azure::Core::Nullable IfMatch; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag does - * not match the value specified. Specify the wildcard character (*) to perform the operation - * only if the resource does not exist, and fail the operation if it does exist. - */ - Azure::Core::Nullable IfNoneMatch; + PageBlobAccessConditions Conditions; }; /** @@ -1329,35 +970,9 @@ namespace Azure { namespace Storage { namespace Blobs { Azure::Core::Context Context; /** - * @brief Specify this header to perform the operation only if the resource has an - * active lease mathing this id. + * @brief Optional conditions that must be met to perform this operation. */ - Azure::Core::Nullable LeaseId; - - /** - * @brief Specify this header to perform the operation only if the resource has been - * modified since the specified time. - */ - Azure::Core::Nullable IfModifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource has not been - * modified since the specified date/time. - */ - Azure::Core::Nullable IfUnmodifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag - * matches the value specified. - */ - Azure::Core::Nullable IfMatch; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag does - * not match the value specified. Specify the wildcard character (*) to perform the operation - * only if the resource does not exist, and fail the operation if it does exist. - */ - Azure::Core::Nullable IfNoneMatch; + PageBlobAccessConditions Conditions; }; /** @@ -1371,29 +986,9 @@ namespace Azure { namespace Storage { namespace Blobs { Azure::Core::Context Context; /** - * @brief Specify this header to perform the operation only if the resource has been - * modified since the specified time. + * @brief Optional conditions that must be met to perform this operation. */ - Azure::Core::Nullable IfModifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource has not been - * modified since the specified date/time. - */ - Azure::Core::Nullable IfUnmodifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag - * matches the value specified. - */ - Azure::Core::Nullable IfMatch; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag does - * not match the value specified. Specify the wildcard character (*) to perform the operation - * only if the resource does not exist, and fail the operation if it does exist. - */ - Azure::Core::Nullable IfNoneMatch; + BlobAccessConditions Conditions; }; /** @@ -1433,35 +1028,9 @@ namespace Azure { namespace Storage { namespace Blobs { Azure::Core::Nullable Length; /** - * @brief Specify this header to perform the operation only if the resource has an - * active lease mathing this id. + * @brief Optional conditions that must be met to perform this operation. */ - Azure::Core::Nullable LeaseId; - - /** - * @brief Specify this header to perform the operation only if the resource has been - * modified since the specified time. - */ - Azure::Core::Nullable IfModifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource has not been - * modified since the specified date/time. - */ - Azure::Core::Nullable IfUnmodifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag - * matches the value specified. - */ - Azure::Core::Nullable IfMatch; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag does - * not match the value specified. Specify the wildcard character (*) to perform the operation - * only if the resource does not exist, and fail the operation if it does exist. - */ - Azure::Core::Nullable IfNoneMatch; + BlobAccessConditions Conditions; }; /** @@ -1475,29 +1044,9 @@ namespace Azure { namespace Storage { namespace Blobs { Azure::Core::Context Context; /** - * @brief Specify this header to perform the operation only if the resource has been - * modified since the specified time. + * @brief Optional conditions that must be met to perform this operation. */ - Azure::Core::Nullable IfModifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource has not been - * modified since the specified date/time. - */ - Azure::Core::Nullable IfUnmodifiedSince; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag - * matches the value specified. - */ - Azure::Core::Nullable IfMatch; - - /** - * @brief Specify this header to perform the operation only if the resource's ETag does - * not match the value specified. Specify the wildcard character (*) to perform the operation - * only if the resource does not exist, and fail the operation if it does exist. - */ - Azure::Core::Nullable IfNoneMatch; + BlobAccessConditions Conditions; }; }}} // namespace Azure::Storage::Blobs diff --git a/sdk/storage/inc/blobs/internal/protocol/blob_rest_client.hpp b/sdk/storage/inc/blobs/internal/protocol/blob_rest_client.hpp index 1018dc5a3..bb9af380b 100644 --- a/sdk/storage/inc/blobs/internal/protocol/blob_rest_client.hpp +++ b/sdk/storage/inc/blobs/internal/protocol/blob_rest_client.hpp @@ -611,94 +611,131 @@ namespace Azure { namespace Storage { namespace Blobs { enum class ListBlobContainersIncludeOption { - None, - Metadata, - }; // enum class ListBlobContainersIncludeOption + None = 0, + Metadata = 1, + }; // bitwise enum ListBlobContainersIncludeOption - inline std::string ListBlobContainersIncludeOptionToString( - const ListBlobContainersIncludeOption& list_blob_containers_include_option) + inline ListBlobContainersIncludeOption operator|( + ListBlobContainersIncludeOption lhs, + ListBlobContainersIncludeOption rhs) { - switch (list_blob_containers_include_option) - { - case ListBlobContainersIncludeOption::None: - return ""; - case ListBlobContainersIncludeOption::Metadata: - return "metadata"; - default: - return std::string(); - } + using type = std::underlying_type_t; + return static_cast( + static_cast(lhs) | static_cast(rhs)); } - inline ListBlobContainersIncludeOption ListBlobContainersIncludeOptionFromString( - const std::string& list_blob_containers_include_option) + inline ListBlobContainersIncludeOption& operator|=( + ListBlobContainersIncludeOption& lhs, + ListBlobContainersIncludeOption rhs) { - if (list_blob_containers_include_option == "") + lhs = lhs | rhs; + return lhs; + } + + inline ListBlobContainersIncludeOption operator&( + ListBlobContainersIncludeOption lhs, + ListBlobContainersIncludeOption rhs) + { + using type = std::underlying_type_t; + return static_cast( + static_cast(lhs) & static_cast(rhs)); + } + + inline ListBlobContainersIncludeOption& operator&=( + ListBlobContainersIncludeOption& lhs, + ListBlobContainersIncludeOption rhs) + { + lhs = lhs & rhs; + return lhs; + } + + inline std::string ListBlobContainersIncludeOptionToString( + const ListBlobContainersIncludeOption& val) + { + ListBlobContainersIncludeOption value_list[] = { + ListBlobContainersIncludeOption::Metadata, + }; + const char* string_list[] = { + "metadata", + }; + std::string ret; + for (std::size_t i = 0; i < sizeof(value_list) / sizeof(ListBlobContainersIncludeOption); ++i) { - return ListBlobContainersIncludeOption::None; + if ((val & value_list[i]) == value_list[i]) + { + if (!ret.empty()) + { + ret += ","; + } + ret += string_list[i]; + } } - if (list_blob_containers_include_option == "metadata") - { - return ListBlobContainersIncludeOption::Metadata; - } - throw std::runtime_error( - "cannot convert " + list_blob_containers_include_option - + " to ListBlobContainersIncludeOption"); + return ret; } enum class ListBlobsIncludeItem { - Copy, - Deleted, - Metadata, - Snapshots, - UncomittedBlobs, - }; // enum class ListBlobsIncludeItem + None = 0, + Copy = 1, + Deleted = 2, + Metadata = 4, + Snapshots = 8, + UncomittedBlobs = 16, + }; // bitwise enum ListBlobsIncludeItem - inline std::string ListBlobsIncludeItemToString( - const ListBlobsIncludeItem& list_blobs_include_item) + inline ListBlobsIncludeItem operator|(ListBlobsIncludeItem lhs, ListBlobsIncludeItem rhs) { - switch (list_blobs_include_item) - { - case ListBlobsIncludeItem::Copy: - return "copy"; - case ListBlobsIncludeItem::Deleted: - return "deleted"; - case ListBlobsIncludeItem::Metadata: - return "metadata"; - case ListBlobsIncludeItem::Snapshots: - return "snapshots"; - case ListBlobsIncludeItem::UncomittedBlobs: - return "uncommittedblobs"; - default: - return std::string(); - } + using type = std::underlying_type_t; + return static_cast(static_cast(lhs) | static_cast(rhs)); } - inline ListBlobsIncludeItem ListBlobsIncludeItemFromString( - const std::string& list_blobs_include_item) + inline ListBlobsIncludeItem& operator|=(ListBlobsIncludeItem& lhs, ListBlobsIncludeItem rhs) { - if (list_blobs_include_item == "copy") + lhs = lhs | rhs; + return lhs; + } + + inline ListBlobsIncludeItem operator&(ListBlobsIncludeItem lhs, ListBlobsIncludeItem rhs) + { + using type = std::underlying_type_t; + return static_cast(static_cast(lhs) & static_cast(rhs)); + } + + inline ListBlobsIncludeItem& operator&=(ListBlobsIncludeItem& lhs, ListBlobsIncludeItem rhs) + { + lhs = lhs & rhs; + return lhs; + } + + inline std::string ListBlobsIncludeItemToString(const ListBlobsIncludeItem& val) + { + ListBlobsIncludeItem value_list[] = { + ListBlobsIncludeItem::Copy, + ListBlobsIncludeItem::Deleted, + ListBlobsIncludeItem::Metadata, + ListBlobsIncludeItem::Snapshots, + ListBlobsIncludeItem::UncomittedBlobs, + }; + const char* string_list[] = { + "copy", + "deleted", + "metadata", + "snapshots", + "uncommittedblobs", + }; + std::string ret; + for (std::size_t i = 0; i < sizeof(value_list) / sizeof(ListBlobsIncludeItem); ++i) { - return ListBlobsIncludeItem::Copy; + if ((val & value_list[i]) == value_list[i]) + { + if (!ret.empty()) + { + ret += ","; + } + ret += string_list[i]; + } } - if (list_blobs_include_item == "deleted") - { - return ListBlobsIncludeItem::Deleted; - } - if (list_blobs_include_item == "metadata") - { - return ListBlobsIncludeItem::Metadata; - } - if (list_blobs_include_item == "snapshots") - { - return ListBlobsIncludeItem::Snapshots; - } - if (list_blobs_include_item == "uncommittedblobs") - { - return ListBlobsIncludeItem::UncomittedBlobs; - } - throw std::runtime_error( - "cannot convert " + list_blobs_include_item + " to ListBlobsIncludeItem"); + return ret; } struct PageBlobInfo @@ -1052,7 +1089,7 @@ namespace Azure { namespace Storage { namespace Blobs { Azure::Core::Nullable Prefix; Azure::Core::Nullable Marker; Azure::Core::Nullable MaxResults; - Azure::Core::Nullable IncludeMetadata; + ListBlobContainersIncludeOption IncludeMetadata = ListBlobContainersIncludeOption::None; }; // struct ListBlobContainersOptions static Azure::Core::Http::Request ListBlobContainersConstructRequest( @@ -1081,10 +1118,10 @@ namespace Azure { namespace Storage { namespace Blobs { { request.AddQueryParameter("maxresults", std::to_string(options.MaxResults.GetValue())); } - if (options.IncludeMetadata.HasValue()) + std::string list_blob_containers_include_option + = ListBlobContainersIncludeOptionToString(options.IncludeMetadata); + if (!list_blob_containers_include_option.empty()) { - std::string list_blob_containers_include_option - = ListBlobContainersIncludeOptionToString(options.IncludeMetadata.GetValue()); request.AddQueryParameter("include", list_blob_containers_include_option); } return request; @@ -1752,6 +1789,7 @@ namespace Azure { namespace Storage { namespace Blobs { struct DeleteOptions { Azure::Core::Nullable Timeout; + Azure::Core::Nullable LeaseId; Azure::Core::Nullable IfModifiedSince; Azure::Core::Nullable IfUnmodifiedSince; }; // struct DeleteOptions @@ -1770,6 +1808,10 @@ namespace Azure { namespace Storage { namespace Blobs { { request.AddQueryParameter("timeout", std::to_string(options.Timeout.GetValue())); } + if (options.LeaseId.HasValue()) + { + request.AddHeader("x-ms-lease-id", options.LeaseId.GetValue()); + } if (options.IfModifiedSince.HasValue()) { request.AddHeader("If-Modified-Since", options.IfModifiedSince.GetValue()); @@ -1826,6 +1868,7 @@ namespace Azure { namespace Storage { namespace Blobs { Azure::Core::Nullable EncryptionKey; Azure::Core::Nullable EncryptionKeySHA256; Azure::Core::Nullable EncryptionAlgorithm; + Azure::Core::Nullable LeaseId; }; // struct GetPropertiesOptions static Azure::Core::Http::Request GetPropertiesConstructRequest( @@ -1854,6 +1897,10 @@ namespace Azure { namespace Storage { namespace Blobs { { request.AddHeader("x-ms-encryption-algorithm", options.EncryptionAlgorithm.GetValue()); } + if (options.LeaseId.HasValue()) + { + request.AddHeader("x-ms-lease-id", options.LeaseId.GetValue()); + } return request; } @@ -1927,6 +1974,7 @@ namespace Azure { namespace Storage { namespace Blobs { { Azure::Core::Nullable Timeout; std::map Metadata; + Azure::Core::Nullable LeaseId; Azure::Core::Nullable IfModifiedSince; }; // struct SetMetadataOptions @@ -1959,6 +2007,10 @@ namespace Azure { namespace Storage { namespace Blobs { request.AddHeader("x-ms-meta-" + pair.first, pair.second); } metadataKeys.clear(); + if (options.LeaseId.HasValue()) + { + request.AddHeader("x-ms-lease-id", options.LeaseId.GetValue()); + } if (options.IfModifiedSince.HasValue()) { request.AddHeader("If-Modified-Since", options.IfModifiedSince.GetValue()); @@ -2014,7 +2066,7 @@ namespace Azure { namespace Storage { namespace Blobs { Azure::Core::Nullable Delimiter; Azure::Core::Nullable Marker; Azure::Core::Nullable MaxResults; - std::vector Include; + ListBlobsIncludeItem Include = ListBlobsIncludeItem::None; }; // struct ListBlobsOptions static Azure::Core::Http::Request ListBlobsConstructRequest( @@ -2048,18 +2100,10 @@ namespace Azure { namespace Storage { namespace Blobs { { request.AddQueryParameter("maxresults", std::to_string(options.MaxResults.GetValue())); } - std::string options_include_str; - for (auto i : options.Include) + std::string list_blobs_include_item = ListBlobsIncludeItemToString(options.Include); + if (!list_blobs_include_item.empty()) { - if (!options_include_str.empty()) - { - options_include_str += ","; - } - options_include_str += ListBlobsIncludeItemToString(i); - } - if (!options_include_str.empty()) - { - request.AddQueryParameter("include", options_include_str); + request.AddQueryParameter("include", list_blobs_include_item); } return request; } @@ -2563,6 +2607,7 @@ namespace Azure { namespace Storage { namespace Blobs { Azure::Core::Nullable EncryptionKey; Azure::Core::Nullable EncryptionKeySHA256; Azure::Core::Nullable EncryptionAlgorithm; + Azure::Core::Nullable LeaseId; Azure::Core::Nullable IfModifiedSince; Azure::Core::Nullable IfUnmodifiedSince; Azure::Core::Nullable IfMatch; @@ -2625,6 +2670,10 @@ namespace Azure { namespace Storage { namespace Blobs { { request.AddHeader("If-None-Match", options.IfNoneMatch.GetValue()); } + if (options.LeaseId.HasValue()) + { + request.AddHeader("x-ms-lease-id", options.LeaseId.GetValue()); + } return request; } @@ -2776,6 +2825,7 @@ namespace Azure { namespace Storage { namespace Blobs { { Azure::Core::Nullable Timeout; Azure::Core::Nullable DeleteSnapshots; + Azure::Core::Nullable LeaseId; Azure::Core::Nullable IfModifiedSince; Azure::Core::Nullable IfUnmodifiedSince; Azure::Core::Nullable IfMatch; @@ -2801,6 +2851,10 @@ namespace Azure { namespace Storage { namespace Blobs { "x-ms-delete-snapshots", DeleteSnapshotsOptionToString(options.DeleteSnapshots.GetValue())); } + if (options.LeaseId.HasValue()) + { + request.AddHeader("x-ms-lease-id", options.LeaseId.GetValue()); + } if (options.IfModifiedSince.HasValue()) { request.AddHeader("If-Modified-Since", options.IfModifiedSince.GetValue()); @@ -2923,6 +2977,7 @@ namespace Azure { namespace Storage { namespace Blobs { struct GetPropertiesOptions { Azure::Core::Nullable Timeout; + Azure::Core::Nullable LeaseId; Azure::Core::Nullable IfModifiedSince; Azure::Core::Nullable IfUnmodifiedSince; Azure::Core::Nullable IfMatch; @@ -2942,6 +2997,10 @@ namespace Azure { namespace Storage { namespace Blobs { { request.AddQueryParameter("timeout", std::to_string(options.Timeout.GetValue())); } + if (options.LeaseId.HasValue()) + { + request.AddHeader("x-ms-lease-id", options.LeaseId.GetValue()); + } if (options.IfModifiedSince.HasValue()) { request.AddHeader("If-Modified-Since", options.IfModifiedSince.GetValue()); @@ -3147,6 +3206,7 @@ namespace Azure { namespace Storage { namespace Blobs { Azure::Core::Nullable EncryptionKey; Azure::Core::Nullable EncryptionKeySHA256; Azure::Core::Nullable EncryptionAlgorithm; + Azure::Core::Nullable LeaseId; Azure::Core::Nullable IfModifiedSince; Azure::Core::Nullable IfUnmodifiedSince; Azure::Core::Nullable IfMatch; @@ -3204,6 +3264,10 @@ namespace Azure { namespace Storage { namespace Blobs { { request.AddHeader("x-ms-encryption-algorithm", options.EncryptionAlgorithm.GetValue()); } + if (options.LeaseId.HasValue()) + { + request.AddHeader("x-ms-lease-id", options.LeaseId.GetValue()); + } if (options.IfModifiedSince.HasValue()) { request.AddHeader("If-Modified-Since", options.IfModifiedSince.GetValue()); @@ -3277,6 +3341,7 @@ namespace Azure { namespace Storage { namespace Blobs { Azure::Core::Nullable EncryptionKey; Azure::Core::Nullable EncryptionKeySHA256; Azure::Core::Nullable EncryptionAlgorithm; + Azure::Core::Nullable LeaseId; Azure::Core::Nullable IfModifiedSince; Azure::Core::Nullable IfUnmodifiedSince; Azure::Core::Nullable IfMatch; @@ -3323,6 +3388,10 @@ namespace Azure { namespace Storage { namespace Blobs { { request.AddHeader("x-ms-encryption-algorithm", options.EncryptionAlgorithm.GetValue()); } + if (options.LeaseId.HasValue()) + { + request.AddHeader("x-ms-lease-id", options.LeaseId.GetValue()); + } if (options.IfModifiedSince.HasValue()) { request.AddHeader("If-Modified-Since", options.IfModifiedSince.GetValue()); @@ -4437,10 +4506,7 @@ namespace Azure { namespace Storage { namespace Blobs { { Azure::Core::Nullable Timeout; Azure::Core::Nullable ListType; - Azure::Core::Nullable IfModifiedSince; - Azure::Core::Nullable IfUnmodifiedSince; - Azure::Core::Nullable IfMatch; - Azure::Core::Nullable IfNoneMatch; + Azure::Core::Nullable LeaseId; }; // struct GetBlockListOptions static Azure::Core::Http::Request GetBlockListConstructRequest( @@ -4463,21 +4529,9 @@ namespace Azure { namespace Storage { namespace Blobs { { request.AddQueryParameter("timeout", std::to_string(options.Timeout.GetValue())); } - if (options.IfModifiedSince.HasValue()) + if (options.LeaseId.HasValue()) { - request.AddHeader("If-Modified-Since", options.IfModifiedSince.GetValue()); - } - if (options.IfUnmodifiedSince.HasValue()) - { - request.AddHeader("If-Unmodified-Since", options.IfUnmodifiedSince.GetValue()); - } - if (options.IfMatch.HasValue()) - { - request.AddHeader("If-Match", options.IfMatch.GetValue()); - } - if (options.IfNoneMatch.HasValue()) - { - request.AddHeader("If-None-Match", options.IfNoneMatch.GetValue()); + request.AddHeader("x-ms-lease-id", options.LeaseId.GetValue()); } return request; } diff --git a/sdk/storage/inc/common/access_conditions.hpp b/sdk/storage/inc/common/access_conditions.hpp new file mode 100644 index 000000000..77663125b --- /dev/null +++ b/sdk/storage/inc/common/access_conditions.hpp @@ -0,0 +1,61 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT + +#pragma once + +#include "nullable.hpp" + +#include + +namespace Azure { namespace Storage { + + /** + * @brief Specifies HTTP options for conditional requests based on modification time value. + */ + struct LastModifiedTimeAccessConditions + { + /** + * @brief Specify this header to perform the operation only if the resource has been + * modified since the specified time. + */ + Azure::Core::Nullable IfModifiedSince; + + /** + * @brief Specify this header to perform the operation only if the resource has not been + * modified since the specified date/time. + */ + Azure::Core::Nullable IfUnmodifiedSince; + }; + + /** + * @brief Specifies HTTP options for conditional requests based on and ETag value. + */ + struct ETagAccessConditions + { + /** + * @brief Specify this header to perform the operation only if the resource's ETag + * matches the value specified. + */ + Azure::Core::Nullable IfMatch; + + /** + * @brief Specify this header to perform the operation only if the resource's ETag does + * not match the value specified. Specify the wildcard character (*) to perform the operation + * only if the resource does not exist, and fail the operation if it does exist. + */ + Azure::Core::Nullable IfNoneMatch; + }; + + /** + * @brief Specifies HTTP options for conditional requests based on lease. + */ + struct LeaseAccessConditions + { + /** + * @brief Specify this header to perform the operation only if the resource has an + * active lease mathing this id. + */ + Azure::Core::Nullable LeaseId; + }; + +}} // namespace Azure::Storage diff --git a/sdk/storage/inc/common/constant.hpp b/sdk/storage/inc/common/constant.hpp deleted file mode 100644 index 495e024d5..000000000 --- a/sdk/storage/inc/common/constant.hpp +++ /dev/null @@ -1,16 +0,0 @@ - -// Copyright (c) Microsoft Corporation. All rights reserved. -// SPDX-License-Identifier: MIT - -#pragma once - -namespace Azure { namespace Storage { namespace Details { - constexpr static const char* c_ConnectionStringTagAccountName = "AccountName"; - constexpr static const char* c_ConnectionStringTagAccountKey = "AccountKey"; - constexpr static const char* c_ConnectionStringTagBlobEndpoint = "BlobEndpoint"; - constexpr static const char* c_ConnectionStringTagDataLakeEndpoint = "AdlsEndpoint"; - constexpr static const char* c_ConnectionStringTagEndpointSuffix = "EndpointSuffix"; - constexpr static const char* c_ConnectionStringTagDefaultEndpointsProtocol - = "DefaultEndpointsProtocol"; - constexpr static const char* c_DfsEndpointIdentifier = "dfs"; -}}} // namespace Azure::Storage::Details diff --git a/sdk/storage/inc/common/constants.hpp b/sdk/storage/inc/common/constants.hpp new file mode 100644 index 000000000..9fe2706d1 --- /dev/null +++ b/sdk/storage/inc/common/constants.hpp @@ -0,0 +1,10 @@ + +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT + +#pragma once + +namespace Azure { namespace Storage { namespace Details { + constexpr static const char* c_HttpQuerySnapshot = "snapshot"; + constexpr static const char* c_HttpQueryVersionId = "versionid"; +}}} // namespace Azure::Storage::Details diff --git a/sdk/storage/src/blobs/append_blob_client.cpp b/sdk/storage/src/blobs/append_blob_client.cpp index bf12317a1..7c210bb69 100644 --- a/sdk/storage/src/blobs/append_blob_client.cpp +++ b/sdk/storage/src/blobs/append_blob_client.cpp @@ -3,6 +3,7 @@ #include "blobs/append_blob_client.hpp" +#include "common/constants.hpp" #include "common/storage_common.hpp" namespace Azure { namespace Storage { namespace Blobs { @@ -48,11 +49,11 @@ namespace Azure { namespace Storage { namespace Blobs { AppendBlobClient newClient(*this); if (snapshot.empty()) { - newClient.m_blobUrl.RemoveQuery("snapshot"); + newClient.m_blobUrl.RemoveQuery(Details::c_HttpQuerySnapshot); } else { - newClient.m_blobUrl.AppendQuery("snapshot", snapshot); + newClient.m_blobUrl.AppendQuery(Details::c_HttpQuerySnapshot, snapshot); } return newClient; } @@ -62,10 +63,11 @@ namespace Azure { namespace Storage { namespace Blobs { BlobRestClient::AppendBlob::CreateOptions protocolLayerOptions; protocolLayerOptions.HttpHeaders = options.HttpHeaders; protocolLayerOptions.Metadata = options.Metadata; - protocolLayerOptions.IfModifiedSince = options.IfModifiedSince; - protocolLayerOptions.IfUnmodifiedSince = options.IfUnmodifiedSince; - protocolLayerOptions.IfMatch = options.IfMatch; - protocolLayerOptions.IfNoneMatch = options.IfNoneMatch; + protocolLayerOptions.LeaseId = options.Conditions.LeaseId; + protocolLayerOptions.IfModifiedSince = options.Conditions.IfModifiedSince; + protocolLayerOptions.IfUnmodifiedSince = options.Conditions.IfUnmodifiedSince; + protocolLayerOptions.IfMatch = options.Conditions.IfMatch; + protocolLayerOptions.IfNoneMatch = options.Conditions.IfNoneMatch; return BlobRestClient::AppendBlob::Create( options.Context, *m_pipeline, m_blobUrl.ToString(), protocolLayerOptions); } @@ -77,13 +79,13 @@ namespace Azure { namespace Storage { namespace Blobs { BlobRestClient::AppendBlob::AppendBlockOptions protocolLayerOptions; protocolLayerOptions.ContentMD5 = options.ContentMD5; protocolLayerOptions.ContentCRC64 = options.ContentCRC64; - protocolLayerOptions.LeaseId = options.LeaseId; - protocolLayerOptions.MaxSize = options.MaxSize; - protocolLayerOptions.AppendPosition = options.AppendPosition; - protocolLayerOptions.IfModifiedSince = options.IfModifiedSince; - protocolLayerOptions.IfUnmodifiedSince = options.IfUnmodifiedSince; - protocolLayerOptions.IfMatch = options.IfMatch; - protocolLayerOptions.IfNoneMatch = options.IfNoneMatch; + protocolLayerOptions.LeaseId = options.Conditions.LeaseId; + protocolLayerOptions.MaxSize = options.Conditions.MaxSize; + protocolLayerOptions.AppendPosition = options.Conditions.AppendPosition; + protocolLayerOptions.IfModifiedSince = options.Conditions.IfModifiedSince; + protocolLayerOptions.IfUnmodifiedSince = options.Conditions.IfUnmodifiedSince; + protocolLayerOptions.IfMatch = options.Conditions.IfMatch; + protocolLayerOptions.IfNoneMatch = options.Conditions.IfNoneMatch; return BlobRestClient::AppendBlob::AppendBlock( options.Context, *m_pipeline, m_blobUrl.ToString(), content, protocolLayerOptions); } @@ -109,13 +111,13 @@ namespace Azure { namespace Storage { namespace Blobs { } protocolLayerOptions.ContentMD5 = options.ContentMD5; protocolLayerOptions.ContentCRC64 = options.ContentCRC64; - protocolLayerOptions.LeaseId = options.LeaseId; - protocolLayerOptions.MaxSize = options.MaxSize; - protocolLayerOptions.AppendPosition = options.AppendPosition; - protocolLayerOptions.IfModifiedSince = options.IfModifiedSince; - protocolLayerOptions.IfUnmodifiedSince = options.IfUnmodifiedSince; - protocolLayerOptions.IfMatch = options.IfMatch; - protocolLayerOptions.IfNoneMatch = options.IfNoneMatch; + protocolLayerOptions.LeaseId = options.Conditions.LeaseId; + protocolLayerOptions.MaxSize = options.Conditions.MaxSize; + protocolLayerOptions.AppendPosition = options.Conditions.AppendPosition; + protocolLayerOptions.IfModifiedSince = options.Conditions.IfModifiedSince; + protocolLayerOptions.IfUnmodifiedSince = options.Conditions.IfUnmodifiedSince; + protocolLayerOptions.IfMatch = options.Conditions.IfMatch; + protocolLayerOptions.IfNoneMatch = options.Conditions.IfNoneMatch; return BlobRestClient::AppendBlob::AppendBlockFromUri( options.Context, *m_pipeline, m_blobUrl.ToString(), protocolLayerOptions); } diff --git a/sdk/storage/src/blobs/blob_client.cpp b/sdk/storage/src/blobs/blob_client.cpp index e7b628456..e2c1c1cac 100644 --- a/sdk/storage/src/blobs/blob_client.cpp +++ b/sdk/storage/src/blobs/blob_client.cpp @@ -8,6 +8,7 @@ #include "blobs/page_blob_client.hpp" #include "common/common_headers_request_policy.hpp" #include "common/concurrent_transfer.hpp" +#include "common/constants.hpp" #include "common/file_io.hpp" #include "common/shared_key_policy.hpp" #include "common/storage_common.hpp" @@ -113,11 +114,11 @@ namespace Azure { namespace Storage { namespace Blobs { BlobClient newClient(*this); if (snapshot.empty()) { - newClient.m_blobUrl.RemoveQuery("snapshot"); + newClient.m_blobUrl.RemoveQuery(Details::c_HttpQuerySnapshot); } else { - newClient.m_blobUrl.AppendQuery("snapshot", snapshot); + newClient.m_blobUrl.AppendQuery(Details::c_HttpQuerySnapshot, snapshot); } return newClient; } @@ -136,10 +137,11 @@ namespace Azure { namespace Storage { namespace Blobs { options.Offset.GetValue(), std::numeric_limits>::max()); } - protocolLayerOptions.IfModifiedSince = options.IfModifiedSince; - protocolLayerOptions.IfUnmodifiedSince = options.IfUnmodifiedSince; - protocolLayerOptions.IfMatch = options.IfMatch; - protocolLayerOptions.IfNoneMatch = options.IfNoneMatch; + protocolLayerOptions.LeaseId = options.Conditions.LeaseId; + protocolLayerOptions.IfModifiedSince = options.Conditions.IfModifiedSince; + protocolLayerOptions.IfUnmodifiedSince = options.Conditions.IfUnmodifiedSince; + protocolLayerOptions.IfMatch = options.Conditions.IfMatch; + protocolLayerOptions.IfNoneMatch = options.Conditions.IfNoneMatch; return BlobRestClient::Blob::Download( options.Context, *m_pipeline, m_blobUrl.ToString(), protocolLayerOptions); @@ -402,10 +404,11 @@ namespace Azure { namespace Storage { namespace Blobs { BlobProperties BlobClient::GetProperties(const GetBlobPropertiesOptions& options) const { BlobRestClient::Blob::GetPropertiesOptions protocolLayerOptions; - protocolLayerOptions.IfModifiedSince = options.IfModifiedSince; - protocolLayerOptions.IfUnmodifiedSince = options.IfUnmodifiedSince; - protocolLayerOptions.IfMatch = options.IfMatch; - protocolLayerOptions.IfNoneMatch = options.IfNoneMatch; + protocolLayerOptions.LeaseId = options.Conditions.LeaseId; + protocolLayerOptions.IfModifiedSince = options.Conditions.IfModifiedSince; + protocolLayerOptions.IfUnmodifiedSince = options.Conditions.IfUnmodifiedSince; + protocolLayerOptions.IfMatch = options.Conditions.IfMatch; + protocolLayerOptions.IfNoneMatch = options.Conditions.IfNoneMatch; return BlobRestClient::Blob::GetProperties( options.Context, *m_pipeline, m_blobUrl.ToString(), protocolLayerOptions); } @@ -416,10 +419,11 @@ namespace Azure { namespace Storage { namespace Blobs { { BlobRestClient::Blob::SetHttpHeadersOptions protocolLayerOptions; protocolLayerOptions.HttpHeaders = std::move(httpHeaders); - protocolLayerOptions.IfModifiedSince = options.IfModifiedSince; - protocolLayerOptions.IfUnmodifiedSince = options.IfUnmodifiedSince; - protocolLayerOptions.IfMatch = options.IfMatch; - protocolLayerOptions.IfNoneMatch = options.IfNoneMatch; + protocolLayerOptions.LeaseId = options.Conditions.LeaseId; + protocolLayerOptions.IfModifiedSince = options.Conditions.IfModifiedSince; + protocolLayerOptions.IfUnmodifiedSince = options.Conditions.IfUnmodifiedSince; + protocolLayerOptions.IfMatch = options.Conditions.IfMatch; + protocolLayerOptions.IfNoneMatch = options.Conditions.IfNoneMatch; return BlobRestClient::Blob::SetHttpHeaders( options.Context, *m_pipeline, m_blobUrl.ToString(), protocolLayerOptions); } @@ -430,10 +434,11 @@ namespace Azure { namespace Storage { namespace Blobs { { BlobRestClient::Blob::SetMetadataOptions protocolLayerOptions; protocolLayerOptions.Metadata = std::move(metadata); - protocolLayerOptions.IfModifiedSince = options.IfModifiedSince; - protocolLayerOptions.IfUnmodifiedSince = options.IfUnmodifiedSince; - protocolLayerOptions.IfMatch = options.IfMatch; - protocolLayerOptions.IfNoneMatch = options.IfNoneMatch; + protocolLayerOptions.LeaseId = options.Conditions.LeaseId; + protocolLayerOptions.IfModifiedSince = options.Conditions.IfModifiedSince; + protocolLayerOptions.IfUnmodifiedSince = options.Conditions.IfUnmodifiedSince; + protocolLayerOptions.IfMatch = options.Conditions.IfMatch; + protocolLayerOptions.IfNoneMatch = options.Conditions.IfNoneMatch; return BlobRestClient::Blob::SetMetadata( options.Context, *m_pipeline, m_blobUrl.ToString(), protocolLayerOptions); } @@ -456,18 +461,18 @@ namespace Azure { namespace Storage { namespace Blobs { BlobRestClient::Blob::StartCopyFromUriOptions protocolLayerOptions; protocolLayerOptions.Metadata = options.Metadata; protocolLayerOptions.SourceUri = sourceUri; - protocolLayerOptions.LeaseId = options.LeaseId; - protocolLayerOptions.SourceLeaseId = options.SourceLeaseId; protocolLayerOptions.Tier = options.Tier; protocolLayerOptions.RehydratePriority = options.RehydratePriority; - protocolLayerOptions.IfModifiedSince = options.IfModifiedSince; - protocolLayerOptions.IfUnmodifiedSince = options.IfUnmodifiedSince; - protocolLayerOptions.IfMatch = options.IfMatch; - protocolLayerOptions.IfNoneMatch = options.IfNoneMatch; - protocolLayerOptions.SourceIfModifiedSince = options.SourceIfModifiedSince; - protocolLayerOptions.SourceIfUnmodifiedSince = options.IfUnmodifiedSince; - protocolLayerOptions.SourceIfMatch = options.SourceIfMatch; - protocolLayerOptions.SourceIfNoneMatch = options.SourceIfNoneMatch; + protocolLayerOptions.LeaseId = options.Conditions.LeaseId; + protocolLayerOptions.IfModifiedSince = options.Conditions.IfModifiedSince; + protocolLayerOptions.IfUnmodifiedSince = options.Conditions.IfUnmodifiedSince; + protocolLayerOptions.IfMatch = options.Conditions.IfMatch; + protocolLayerOptions.IfNoneMatch = options.Conditions.IfNoneMatch; + protocolLayerOptions.SourceLeaseId = options.SourceConditions.LeaseId; + protocolLayerOptions.SourceIfModifiedSince = options.SourceConditions.IfModifiedSince; + protocolLayerOptions.SourceIfUnmodifiedSince = options.Conditions.IfUnmodifiedSince; + protocolLayerOptions.SourceIfMatch = options.SourceConditions.IfMatch; + protocolLayerOptions.SourceIfNoneMatch = options.SourceConditions.IfNoneMatch; return BlobRestClient::Blob::StartCopyFromUri( options.Context, *m_pipeline, m_blobUrl.ToString(), protocolLayerOptions); } @@ -478,7 +483,7 @@ namespace Azure { namespace Storage { namespace Blobs { { BlobRestClient::Blob::AbortCopyFromUriOptions protocolLayerOptions; protocolLayerOptions.CopyId = copyId; - protocolLayerOptions.LeaseId = options.LeaseId; + protocolLayerOptions.LeaseId = options.Conditions.LeaseId; return BlobRestClient::Blob::AbortCopyFromUri( options.Context, *m_pipeline, m_blobUrl.ToString(), protocolLayerOptions); } @@ -487,11 +492,11 @@ namespace Azure { namespace Storage { namespace Blobs { { BlobRestClient::Blob::CreateSnapshotOptions protocolLayerOptions; protocolLayerOptions.Metadata = options.Metadata; - protocolLayerOptions.LeaseId = options.LeaseId; - protocolLayerOptions.IfModifiedSince = options.IfModifiedSince; - protocolLayerOptions.IfUnmodifiedSince = options.IfUnmodifiedSince; - protocolLayerOptions.IfMatch = options.IfMatch; - protocolLayerOptions.IfNoneMatch = options.IfNoneMatch; + protocolLayerOptions.LeaseId = options.Conditions.LeaseId; + protocolLayerOptions.IfModifiedSince = options.Conditions.IfModifiedSince; + protocolLayerOptions.IfUnmodifiedSince = options.Conditions.IfUnmodifiedSince; + protocolLayerOptions.IfMatch = options.Conditions.IfMatch; + protocolLayerOptions.IfNoneMatch = options.Conditions.IfNoneMatch; return BlobRestClient::Blob::CreateSnapshot( options.Context, *m_pipeline, m_blobUrl.ToString(), protocolLayerOptions); } @@ -500,10 +505,11 @@ namespace Azure { namespace Storage { namespace Blobs { { BlobRestClient::Blob::DeleteOptions protocolLayerOptions; protocolLayerOptions.DeleteSnapshots = options.DeleteSnapshots; - protocolLayerOptions.IfModifiedSince = options.IfModifiedSince; - protocolLayerOptions.IfUnmodifiedSince = options.IfUnmodifiedSince; - protocolLayerOptions.IfMatch = options.IfMatch; - protocolLayerOptions.IfNoneMatch = options.IfNoneMatch; + protocolLayerOptions.LeaseId = options.Conditions.LeaseId; + protocolLayerOptions.IfModifiedSince = options.Conditions.IfModifiedSince; + protocolLayerOptions.IfUnmodifiedSince = options.Conditions.IfUnmodifiedSince; + protocolLayerOptions.IfMatch = options.Conditions.IfMatch; + protocolLayerOptions.IfNoneMatch = options.Conditions.IfNoneMatch; return BlobRestClient::Blob::Delete( options.Context, *m_pipeline, m_blobUrl.ToString(), protocolLayerOptions); } diff --git a/sdk/storage/src/blobs/blob_container_client.cpp b/sdk/storage/src/blobs/blob_container_client.cpp index b9b3e2529..8cafb2912 100644 --- a/sdk/storage/src/blobs/blob_container_client.cpp +++ b/sdk/storage/src/blobs/blob_container_client.cpp @@ -136,8 +136,9 @@ namespace Azure { namespace Storage { namespace Blobs { const DeleteBlobContainerOptions& options) const { BlobRestClient::Container::DeleteOptions protocolLayerOptions; - protocolLayerOptions.IfModifiedSince = options.IfModifiedSince; - protocolLayerOptions.IfUnmodifiedSince = options.IfUnmodifiedSince; + protocolLayerOptions.LeaseId = options.Conditions.LeaseId; + protocolLayerOptions.IfModifiedSince = options.Conditions.IfModifiedSince; + protocolLayerOptions.IfUnmodifiedSince = options.Conditions.IfUnmodifiedSince; return BlobRestClient::Container::Delete( options.Context, *m_pipeline, m_containerUrl.ToString(), protocolLayerOptions); } @@ -145,8 +146,8 @@ namespace Azure { namespace Storage { namespace Blobs { BlobContainerProperties BlobContainerClient::GetProperties( const GetBlobContainerPropertiesOptions& options) const { - unused(options); BlobRestClient::Container::GetPropertiesOptions protocolLayerOptions; + protocolLayerOptions.LeaseId = options.Conditions.LeaseId; return BlobRestClient::Container::GetProperties( options.Context, *m_pipeline, m_containerUrl.ToString(), protocolLayerOptions); } @@ -157,7 +158,8 @@ namespace Azure { namespace Storage { namespace Blobs { { BlobRestClient::Container::SetMetadataOptions protocolLayerOptions; protocolLayerOptions.Metadata = metadata; - protocolLayerOptions.IfModifiedSince = options.IfModifiedSince; + protocolLayerOptions.LeaseId = options.Conditions.LeaseId; + protocolLayerOptions.IfModifiedSince = options.Conditions.IfModifiedSince; return BlobRestClient::Container::SetMetadata( options.Context, *m_pipeline, m_containerUrl.ToString(), protocolLayerOptions); } diff --git a/sdk/storage/src/blobs/blob_service_client.cpp b/sdk/storage/src/blobs/blob_service_client.cpp index bb77e866d..7cf45d2e2 100644 --- a/sdk/storage/src/blobs/blob_service_client.cpp +++ b/sdk/storage/src/blobs/blob_service_client.cpp @@ -111,14 +111,7 @@ namespace Azure { namespace Storage { namespace Blobs { protocolLayerOptions.Prefix = options.Prefix; protocolLayerOptions.Marker = options.Marker; protocolLayerOptions.MaxResults = options.MaxResults; - protocolLayerOptions.IncludeMetadata = ListBlobContainersIncludeOption::None; - for (auto i : options.Include) - { - if (i == ListBlobContainersIncludeOption::Metadata) - { - protocolLayerOptions.IncludeMetadata = i; - } - } + protocolLayerOptions.IncludeMetadata = options.Include; return BlobRestClient::Service::ListBlobContainers( options.Context, *m_pipeline, m_serviceUrl.ToString(), protocolLayerOptions); } diff --git a/sdk/storage/src/blobs/block_blob_client.cpp b/sdk/storage/src/blobs/block_blob_client.cpp index 3dd09da88..e63f68969 100644 --- a/sdk/storage/src/blobs/block_blob_client.cpp +++ b/sdk/storage/src/blobs/block_blob_client.cpp @@ -4,6 +4,7 @@ #include "blobs/block_blob_client.hpp" #include "common/concurrent_transfer.hpp" +#include "common/constants.hpp" #include "common/crypt.hpp" #include "common/file_io.hpp" #include "common/storage_common.hpp" @@ -51,11 +52,11 @@ namespace Azure { namespace Storage { namespace Blobs { BlockBlobClient newClient(*this); if (snapshot.empty()) { - newClient.m_blobUrl.RemoveQuery("snapshot"); + newClient.m_blobUrl.RemoveQuery(Details::c_HttpQuerySnapshot); } else { - newClient.m_blobUrl.AppendQuery("snapshot", snapshot); + newClient.m_blobUrl.AppendQuery(Details::c_HttpQuerySnapshot, snapshot); } return newClient; } @@ -70,10 +71,11 @@ namespace Azure { namespace Storage { namespace Blobs { protocolLayerOptions.HttpHeaders = options.HttpHeaders; protocolLayerOptions.Metadata = options.Metadata; protocolLayerOptions.Tier = options.Tier; - protocolLayerOptions.IfModifiedSince = options.IfModifiedSince; - protocolLayerOptions.IfUnmodifiedSince = options.IfUnmodifiedSince; - protocolLayerOptions.IfMatch = options.IfMatch; - protocolLayerOptions.IfNoneMatch = options.IfNoneMatch; + protocolLayerOptions.LeaseId = options.Conditions.LeaseId; + protocolLayerOptions.IfModifiedSince = options.Conditions.IfModifiedSince; + protocolLayerOptions.IfUnmodifiedSince = options.Conditions.IfUnmodifiedSince; + protocolLayerOptions.IfMatch = options.Conditions.IfMatch; + protocolLayerOptions.IfNoneMatch = options.Conditions.IfNoneMatch; return BlobRestClient::BlockBlob::Upload( options.Context, *m_pipeline, m_blobUrl.ToString(), content, protocolLayerOptions); } @@ -206,6 +208,7 @@ namespace Azure { namespace Storage { namespace Blobs { protocolLayerOptions.BlockId = blockId; protocolLayerOptions.ContentMD5 = options.ContentMD5; protocolLayerOptions.ContentCRC64 = options.ContentCRC64; + protocolLayerOptions.LeaseId = options.Conditions.LeaseId; return BlobRestClient::BlockBlob::StageBlock( options.Context, *m_pipeline, m_blobUrl.ToString(), content, protocolLayerOptions); } @@ -233,11 +236,11 @@ namespace Azure { namespace Storage { namespace Blobs { } protocolLayerOptions.ContentMD5 = options.ContentMD5; protocolLayerOptions.ContentCRC64 = options.ContentCRC64; - protocolLayerOptions.LeaseId = options.LeaseId; - protocolLayerOptions.SourceIfModifiedSince = options.SourceIfModifiedSince; - protocolLayerOptions.SourceIfUnmodifiedSince = options.SourceIfUnmodifiedSince; - protocolLayerOptions.SourceIfMatch = options.SourceIfMatch; - protocolLayerOptions.SourceIfNoneMatch = options.SourceIfNoneMatch; + protocolLayerOptions.LeaseId = options.Conditions.LeaseId; + protocolLayerOptions.SourceIfModifiedSince = options.SourceConditions.IfModifiedSince; + protocolLayerOptions.SourceIfUnmodifiedSince = options.SourceConditions.IfUnmodifiedSince; + protocolLayerOptions.SourceIfMatch = options.SourceConditions.IfMatch; + protocolLayerOptions.SourceIfNoneMatch = options.SourceConditions.IfNoneMatch; return BlobRestClient::BlockBlob::StageBlockFromUri( options.Context, *m_pipeline, m_blobUrl.ToString(), protocolLayerOptions); } @@ -251,10 +254,11 @@ namespace Azure { namespace Storage { namespace Blobs { protocolLayerOptions.HttpHeaders = options.HttpHeaders; protocolLayerOptions.Metadata = options.Metadata; protocolLayerOptions.Tier = options.Tier; - protocolLayerOptions.IfModifiedSince = options.IfModifiedSince; - protocolLayerOptions.IfUnmodifiedSince = options.IfUnmodifiedSince; - protocolLayerOptions.IfMatch = options.IfMatch; - protocolLayerOptions.IfNoneMatch = options.IfNoneMatch; + protocolLayerOptions.LeaseId = options.Conditions.LeaseId; + protocolLayerOptions.IfModifiedSince = options.Conditions.IfModifiedSince; + protocolLayerOptions.IfUnmodifiedSince = options.Conditions.IfUnmodifiedSince; + protocolLayerOptions.IfMatch = options.Conditions.IfMatch; + protocolLayerOptions.IfNoneMatch = options.Conditions.IfNoneMatch; return BlobRestClient::BlockBlob::CommitBlockList( options.Context, *m_pipeline, m_blobUrl.ToString(), protocolLayerOptions); } @@ -263,10 +267,7 @@ namespace Azure { namespace Storage { namespace Blobs { { BlobRestClient::BlockBlob::GetBlockListOptions protocolLayerOptions; protocolLayerOptions.ListType = options.ListType; - protocolLayerOptions.IfModifiedSince = options.IfModifiedSince; - protocolLayerOptions.IfUnmodifiedSince = options.IfUnmodifiedSince; - protocolLayerOptions.IfMatch = options.IfMatch; - protocolLayerOptions.IfNoneMatch = options.IfNoneMatch; + protocolLayerOptions.LeaseId = options.Conditions.LeaseId; return BlobRestClient::BlockBlob::GetBlockList( options.Context, *m_pipeline, m_blobUrl.ToString(), protocolLayerOptions); } diff --git a/sdk/storage/src/blobs/page_blob_client.cpp b/sdk/storage/src/blobs/page_blob_client.cpp index 397b82788..45c2926c1 100644 --- a/sdk/storage/src/blobs/page_blob_client.cpp +++ b/sdk/storage/src/blobs/page_blob_client.cpp @@ -3,6 +3,7 @@ #include "blobs/page_blob_client.hpp" +#include "common/constants.hpp" #include "common/storage_common.hpp" namespace Azure { namespace Storage { namespace Blobs { @@ -46,11 +47,11 @@ namespace Azure { namespace Storage { namespace Blobs { PageBlobClient newClient(*this); if (snapshot.empty()) { - newClient.m_blobUrl.RemoveQuery("snapshot"); + newClient.m_blobUrl.RemoveQuery(Details::c_HttpQuerySnapshot); } else { - newClient.m_blobUrl.AppendQuery("snapshot", snapshot); + newClient.m_blobUrl.AppendQuery(Details::c_HttpQuerySnapshot, snapshot); } return newClient; } @@ -65,10 +66,11 @@ namespace Azure { namespace Storage { namespace Blobs { protocolLayerOptions.HttpHeaders = options.HttpHeaders; protocolLayerOptions.Metadata = options.Metadata; protocolLayerOptions.Tier = options.Tier; - protocolLayerOptions.IfModifiedSince = options.IfModifiedSince; - protocolLayerOptions.IfUnmodifiedSince = options.IfUnmodifiedSince; - protocolLayerOptions.IfMatch = options.IfMatch; - protocolLayerOptions.IfNoneMatch = options.IfNoneMatch; + protocolLayerOptions.LeaseId = options.Conditions.LeaseId; + protocolLayerOptions.IfModifiedSince = options.Conditions.IfModifiedSince; + protocolLayerOptions.IfUnmodifiedSince = options.Conditions.IfUnmodifiedSince; + protocolLayerOptions.IfMatch = options.Conditions.IfMatch; + protocolLayerOptions.IfNoneMatch = options.Conditions.IfNoneMatch; return BlobRestClient::PageBlob::Create( options.Context, *m_pipeline, m_blobUrl.ToString(), protocolLayerOptions); } @@ -82,11 +84,11 @@ namespace Azure { namespace Storage { namespace Blobs { protocolLayerOptions.Range = std::make_pair(offset, offset + content.Length() - 1); protocolLayerOptions.ContentMD5 = options.ContentMD5; protocolLayerOptions.ContentCRC64 = options.ContentCRC64; - protocolLayerOptions.LeaseId = options.LeaseId; - protocolLayerOptions.IfModifiedSince = options.IfModifiedSince; - protocolLayerOptions.IfUnmodifiedSince = options.IfUnmodifiedSince; - protocolLayerOptions.IfMatch = options.IfMatch; - protocolLayerOptions.IfNoneMatch = options.IfNoneMatch; + protocolLayerOptions.LeaseId = options.Conditions.LeaseId; + protocolLayerOptions.IfModifiedSince = options.Conditions.IfModifiedSince; + protocolLayerOptions.IfUnmodifiedSince = options.Conditions.IfUnmodifiedSince; + protocolLayerOptions.IfMatch = options.Conditions.IfMatch; + protocolLayerOptions.IfNoneMatch = options.Conditions.IfNoneMatch; return BlobRestClient::PageBlob::UploadPages( options.Context, *m_pipeline, m_blobUrl.ToString(), content, protocolLayerOptions); } @@ -106,11 +108,11 @@ namespace Azure { namespace Storage { namespace Blobs { = std::make_pair(destinationoffset, destinationoffset + sourceLength - 1); protocolLayerOptions.ContentMD5 = options.ContentMD5; protocolLayerOptions.ContentCRC64 = options.ContentCRC64; - protocolLayerOptions.LeaseId = options.LeaseId; - protocolLayerOptions.IfModifiedSince = options.IfModifiedSince; - protocolLayerOptions.IfUnmodifiedSince = options.IfUnmodifiedSince; - protocolLayerOptions.IfMatch = options.IfMatch; - protocolLayerOptions.IfNoneMatch = options.IfNoneMatch; + protocolLayerOptions.LeaseId = options.Conditions.LeaseId; + protocolLayerOptions.IfModifiedSince = options.Conditions.IfModifiedSince; + protocolLayerOptions.IfUnmodifiedSince = options.Conditions.IfUnmodifiedSince; + protocolLayerOptions.IfMatch = options.Conditions.IfMatch; + protocolLayerOptions.IfNoneMatch = options.Conditions.IfNoneMatch; return BlobRestClient::PageBlob::UploadPagesFromUri( options.Context, *m_pipeline, m_blobUrl.ToString(), protocolLayerOptions); } @@ -122,11 +124,11 @@ namespace Azure { namespace Storage { namespace Blobs { { BlobRestClient::PageBlob::ClearPagesOptions protocolLayerOptions; protocolLayerOptions.Range = std::make_pair(offset, offset + length - 1); - protocolLayerOptions.LeaseId = options.LeaseId; - protocolLayerOptions.IfModifiedSince = options.IfModifiedSince; - protocolLayerOptions.IfUnmodifiedSince = options.IfUnmodifiedSince; - protocolLayerOptions.IfMatch = options.IfMatch; - protocolLayerOptions.IfNoneMatch = options.IfNoneMatch; + protocolLayerOptions.LeaseId = options.Conditions.LeaseId; + protocolLayerOptions.IfModifiedSince = options.Conditions.IfModifiedSince; + protocolLayerOptions.IfUnmodifiedSince = options.Conditions.IfUnmodifiedSince; + protocolLayerOptions.IfMatch = options.Conditions.IfMatch; + protocolLayerOptions.IfNoneMatch = options.Conditions.IfNoneMatch; return BlobRestClient::PageBlob::ClearPages( options.Context, *m_pipeline, m_blobUrl.ToString(), protocolLayerOptions); } @@ -137,10 +139,11 @@ namespace Azure { namespace Storage { namespace Blobs { { BlobRestClient::PageBlob::ResizeOptions protocolLayerOptions; protocolLayerOptions.BlobContentLength = blobContentLength; - protocolLayerOptions.IfModifiedSince = options.IfModifiedSince; - protocolLayerOptions.IfUnmodifiedSince = options.IfUnmodifiedSince; - protocolLayerOptions.IfMatch = options.IfMatch; - protocolLayerOptions.IfNoneMatch = options.IfNoneMatch; + protocolLayerOptions.LeaseId = options.Conditions.LeaseId; + protocolLayerOptions.IfModifiedSince = options.Conditions.IfModifiedSince; + protocolLayerOptions.IfUnmodifiedSince = options.Conditions.IfUnmodifiedSince; + protocolLayerOptions.IfMatch = options.Conditions.IfMatch; + protocolLayerOptions.IfNoneMatch = options.Conditions.IfNoneMatch; return BlobRestClient::PageBlob::Resize( options.Context, *m_pipeline, m_blobUrl.ToString(), protocolLayerOptions); } @@ -155,10 +158,11 @@ namespace Azure { namespace Storage { namespace Blobs { protocolLayerOptions.Range = std::make_pair( options.Offset.GetValue(), options.Offset.GetValue() + options.Length.GetValue() - 1); } - protocolLayerOptions.IfModifiedSince = options.IfModifiedSince; - protocolLayerOptions.IfUnmodifiedSince = options.IfUnmodifiedSince; - protocolLayerOptions.IfMatch = options.IfMatch; - protocolLayerOptions.IfNoneMatch = options.IfNoneMatch; + protocolLayerOptions.LeaseId = options.Conditions.LeaseId; + protocolLayerOptions.IfModifiedSince = options.Conditions.IfModifiedSince; + protocolLayerOptions.IfUnmodifiedSince = options.Conditions.IfUnmodifiedSince; + protocolLayerOptions.IfMatch = options.Conditions.IfMatch; + protocolLayerOptions.IfNoneMatch = options.Conditions.IfNoneMatch; auto protocolLayerResponse = BlobRestClient::PageBlob::GetPageRanges( options.Context, *m_pipeline, m_blobUrl.ToString(), protocolLayerOptions); @@ -187,10 +191,10 @@ namespace Azure { namespace Storage { namespace Blobs { { BlobRestClient::PageBlob::CopyIncrementalOptions protocolLayerOptions; protocolLayerOptions.CopySource = sourceUri; - protocolLayerOptions.IfModifiedSince = options.IfModifiedSince; - protocolLayerOptions.IfUnmodifiedSince = options.IfUnmodifiedSince; - protocolLayerOptions.IfMatch = options.IfMatch; - protocolLayerOptions.IfNoneMatch = options.IfNoneMatch; + protocolLayerOptions.IfModifiedSince = options.Conditions.IfModifiedSince; + protocolLayerOptions.IfUnmodifiedSince = options.Conditions.IfUnmodifiedSince; + protocolLayerOptions.IfMatch = options.Conditions.IfMatch; + protocolLayerOptions.IfNoneMatch = options.Conditions.IfNoneMatch; return BlobRestClient::PageBlob::CopyIncremental( options.Context, *m_pipeline, m_blobUrl.ToString(), protocolLayerOptions); } diff --git a/sdk/storage/src/common/common_headers_request_policy.cpp b/sdk/storage/src/common/common_headers_request_policy.cpp index 5d81fd5a3..e7ad7b945 100644 --- a/sdk/storage/src/common/common_headers_request_policy.cpp +++ b/sdk/storage/src/common/common_headers_request_policy.cpp @@ -12,9 +12,11 @@ namespace Azure { namespace Storage { Core::Http::Request& request, Core::Http::NextHttpPolicy nextHttpPolicy) const { + const char* c_HttpHeaderDate = "Date"; + const char* c_HttpHeaderXMsDate = "x-ms-date"; const auto& headers = request.GetHeaders(); - if (headers.find("Date") == headers.end() && headers.find("x-ms-date") == headers.end()) + if (headers.find(c_HttpHeaderDate) == headers.end()) { // add x-ms-date header in RFC1123 format // TODO: call helper function provided by Azure Core when they provide one. @@ -27,7 +29,7 @@ namespace Azure { namespace Storage { #endif char dateString[128]; strftime(dateString, sizeof(dateString), "%a, %d %b %Y %H:%M:%S GMT", &ct); - request.AddHeader("x-ms-date", dateString); + request.AddHeader(c_HttpHeaderXMsDate, dateString); } return nextHttpPolicy.Send(ctx, request); diff --git a/sdk/storage/test/append_blob_client_test.cpp b/sdk/storage/test/append_blob_client_test.cpp index 5f6e80d5a..c38f9ad51 100644 --- a/sdk/storage/test/append_blob_client_test.cpp +++ b/sdk/storage/test/append_blob_client_test.cpp @@ -21,7 +21,7 @@ namespace Azure { namespace Storage { namespace Test { = std::make_shared(std::move(appendBlobClient)); m_blobContent.resize(100); RandomBuffer(reinterpret_cast(&m_blobContent[0]), m_blobContent.size()); - m_blobUploadOptions.Metadata = {{"key1", "V1"}, {"KEY2", "Value2"}}; + m_blobUploadOptions.Metadata = {{"key1", "V1"}, {"key2", "Value2"}}; m_blobUploadOptions.HttpHeaders.ContentType = "application/x-binary"; m_blobUploadOptions.HttpHeaders.ContentLanguage = "en-US"; m_blobUploadOptions.HttpHeaders.ContentDisposition = "attachment"; @@ -57,19 +57,19 @@ namespace Azure { namespace Storage { namespace Test { EXPECT_EQ(properties.ContentLength, static_cast(m_blobContent.size())); Azure::Storage::Blobs::AppendBlockOptions options; - options.AppendPosition = 1_MB; + options.Conditions.AppendPosition = 1_MB; blockContent = Azure::Core::Http::MemoryBodyStream(m_blobContent.data(), m_blobContent.size()); EXPECT_THROW(appendBlobClient.AppendBlock(blockContent, options), std::runtime_error); - options.AppendPosition = properties.ContentLength; + options.Conditions.AppendPosition = properties.ContentLength; blockContent = Azure::Core::Http::MemoryBodyStream(m_blobContent.data(), m_blobContent.size()); appendBlobClient.AppendBlock(blockContent, options); properties = appendBlobClient.GetProperties(); options = Azure::Storage::Blobs::AppendBlockOptions(); - options.MaxSize = properties.ContentLength + m_blobContent.size() - 1; + options.Conditions.MaxSize = properties.ContentLength + m_blobContent.size() - 1; blockContent = Azure::Core::Http::MemoryBodyStream(m_blobContent.data(), m_blobContent.size()); EXPECT_THROW(appendBlobClient.AppendBlock(blockContent, options), std::runtime_error); - options.MaxSize = properties.ContentLength + m_blobContent.size(); + options.Conditions.MaxSize = properties.ContentLength + m_blobContent.size(); blockContent = Azure::Core::Http::MemoryBodyStream(m_blobContent.data(), m_blobContent.size()); appendBlobClient.AppendBlock(blockContent, options); diff --git a/sdk/storage/test/blob_container_client_test.cpp b/sdk/storage/test/blob_container_client_test.cpp index 3758d5320..eabbba193 100644 --- a/sdk/storage/test/blob_container_client_test.cpp +++ b/sdk/storage/test/blob_container_client_test.cpp @@ -29,7 +29,7 @@ namespace Azure { namespace Storage { namespace Test { Azure::Storage::Blobs::CreateBlobContainerOptions options; std::map metadata; metadata["key1"] = "one"; - metadata["KEY2"] = "TWO"; + metadata["key2"] = "TWO"; options.Metadata = metadata; auto res = container_client.Create(options); EXPECT_FALSE(res.RequestId.empty()); @@ -49,7 +49,7 @@ namespace Azure { namespace Storage { namespace Test { { std::map metadata; metadata["key1"] = "one"; - metadata["KEY2"] = "TWO"; + metadata["key2"] = "TWO"; auto res = m_blobContainerClient->SetMetadata(metadata); EXPECT_FALSE(res.RequestId.empty()); EXPECT_FALSE(res.Date.empty()); diff --git a/sdk/storage/test/blob_service_client_test.cpp b/sdk/storage/test/blob_service_client_test.cpp index 94c2952b1..9b2e6fc51 100644 --- a/sdk/storage/test/blob_service_client_test.cpp +++ b/sdk/storage/test/blob_service_client_test.cpp @@ -19,8 +19,8 @@ namespace Azure { namespace Storage { namespace Test { TEST_F(BlobServiceClientTest, ListContainers) { - const std::string prefix1 = "prefix1-"; - const std::string prefix2 = "prefix2-"; + const std::string prefix1 = "prefix1-" + LowercaseRandomString() + "-"; + const std::string prefix2 = "prefix2-" + LowercaseRandomString() + "-"; std::set p1Containers; std::set p2Containers; diff --git a/sdk/storage/test/block_blob_client_test.cpp b/sdk/storage/test/block_blob_client_test.cpp index e9d7a8b1a..f94ff7234 100644 --- a/sdk/storage/test/block_blob_client_test.cpp +++ b/sdk/storage/test/block_blob_client_test.cpp @@ -41,7 +41,7 @@ namespace Azure { namespace Storage { namespace Test { = std::make_shared(std::move(blockBlobClient)); m_blobContent.resize(static_cast(8_MB)); RandomBuffer(reinterpret_cast(&m_blobContent[0]), m_blobContent.size()); - m_blobUploadOptions.Metadata = {{"key1", "V1"}, {"KEY2", "Value2"}}; + m_blobUploadOptions.Metadata = {{"key1", "V1"}, {"key2", "Value2"}}; m_blobUploadOptions.HttpHeaders.ContentType = "application/x-binary"; m_blobUploadOptions.HttpHeaders.ContentLanguage = "en-US"; m_blobUploadOptions.HttpHeaders.ContentDisposition = "attachment"; @@ -176,7 +176,7 @@ namespace Azure { namespace Storage { namespace Test { std::runtime_error); Azure::Storage::Blobs::CreateSnapshotOptions options; - options.Metadata = {{"snapshotkey1", "snapshotvalue1"}, {"snapshotKEY2", "SNAPSHOTVALUE2"}}; + options.Metadata = {{"snapshotkey1", "snapshotvalue1"}, {"snapshotkey2", "SNAPSHOTVALUE2"}}; res = m_blockBlobClient->CreateSnapshot(options); EXPECT_FALSE(res.Snapshot.empty()); snapshotClient = m_blockBlobClient->WithSnapshot(res.Snapshot); diff --git a/sdk/storage/test/page_blob_client_test.cpp b/sdk/storage/test/page_blob_client_test.cpp index 4028a11f9..0b7cbfb12 100644 --- a/sdk/storage/test/page_blob_client_test.cpp +++ b/sdk/storage/test/page_blob_client_test.cpp @@ -21,7 +21,7 @@ namespace Azure { namespace Storage { namespace Test { = std::make_shared(std::move(pageBlobClient)); m_blobContent.resize(static_cast(1_KB)); RandomBuffer(reinterpret_cast(&m_blobContent[0]), m_blobContent.size()); - m_blobUploadOptions.Metadata = {{"key1", "V1"}, {"KEY2", "Value2"}}; + m_blobUploadOptions.Metadata = {{"key1", "V1"}, {"key2", "Value2"}}; m_blobUploadOptions.HttpHeaders.ContentType = "application/x-binary"; m_blobUploadOptions.HttpHeaders.ContentLanguage = "en-US"; m_blobUploadOptions.HttpHeaders.ContentDisposition = "attachment";