diff --git a/sdk/storage/azure-storage-blob/HISTORY.md b/sdk/storage/azure-storage-blob/HISTORY.md index 4a5031c7fedd..5889e8b0637b 100644 --- a/sdk/storage/azure-storage-blob/HISTORY.md +++ b/sdk/storage/azure-storage-blob/HISTORY.md @@ -9,9 +9,9 @@ - Removed types that were accidentally exposed from two modules. Only `BlobServiceClient`, `ContainerClient`, `BlobClient` and `LeaseClient` should be imported from azure.storage.blob.aio - `Logging` has been renamed to `BlobAnalyticsLogging`. +- All operations that take Etag conditional parameters (`if_match` and `if_none_match`) now take explicit `etag` and `match_condition` parameters, where `etag` is the Etag value, and `match_condition` is an instance of `azure.core.MatchConditions`. - The `generate_shared_access_signature` methods on each of `BlobServiceClient`, `ContainerClient` and `BlobClient` have been replaced by module level functions `generate_account_sas`, `generate_container_sas` and `generate_blob_sas`. - **New features** - `ResourceTypes`, and `Services` now have method `from_string` which takes parameters as a string. diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_serialize.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_serialize.py new file mode 100644 index 000000000000..2f21d8b400b0 --- /dev/null +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_serialize.py @@ -0,0 +1,57 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +# pylint: disable=no-self-use + +from azure.core import MatchConditions + +from ._generated.models import ModifiedAccessConditions, SourceModifiedAccessConditions + + +def _get_match_headers(kwargs, match_param, etag_param): + # type: (str) -> Tuple(Dict[str, Any], Optional[str], Optional[str]) + if_match = None + if_none_match = None + match_condition = kwargs.pop(match_param, None) + if match_condition == MatchConditions.IfNotModified: + if_match = kwargs.pop(etag_param, None) + if not if_match: + raise ValueError("'{}' specified without '{}'.".format(match_param, etag_param)) + elif match_condition == MatchConditions.IfPresent: + if_match = '*' + elif match_condition == MatchConditions.IfModified: + if_none_match = kwargs.pop(etag_param, None) + if not if_none_match: + raise ValueError("'{}' specified without '{}'.".format(match_param, etag_param)) + elif match_condition == MatchConditions.IfMissing: + if_none_match = '*' + elif match_condition is None: + if etag_param in kwargs: + raise ValueError("'{}' specified without '{}'.".format(etag_param, match_param)) + else: + raise TypeError("Invalid match condition: {}".format(match_condition)) + return if_match, if_none_match + + +def get_modify_conditions(kwargs): + # type: (Dict[str, Any]) -> ModifiedAccessConditions + if_match, if_none_match = _get_match_headers(kwargs, 'match_condition', 'etag') + return ModifiedAccessConditions( + if_modified_since=kwargs.pop('if_modified_since', None), + if_unmodified_since=kwargs.pop('if_unmodified_since', None), + if_match=if_match or kwargs.pop('if_match', None), + if_none_match=if_none_match or kwargs.pop('if_none_match', None) + ) + + +def get_source_conditions(kwargs): + # type: (Dict[str, Any]) -> SourceModifiedAccessConditions + if_match, if_none_match = _get_match_headers(kwargs, 'source_match_condition', 'source_etag') + return SourceModifiedAccessConditions( + source_if_modified_since=kwargs.pop('source_if_modified_since', None), + source_if_unmodified_since=kwargs.pop('source_if_unmodified_since', None), + source_if_match=if_match or kwargs.pop('source_if_match', None), + source_if_none_match=if_none_match or kwargs.pop('source_if_none_match', None) + ) diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/blob_client_async.py b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/blob_client_async.py index cdd6c80e513b..6318453ef1b0 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/blob_client_async.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/blob_client_async.py @@ -16,8 +16,9 @@ from .._shared.policies_async import ExponentialRetry from .._shared.response_handlers import return_response_headers, process_storage_error from .._deserialize import get_page_ranges_result +from .._serialize import get_modify_conditions from .._generated.aio import AzureBlobStorage -from .._generated.models import ModifiedAccessConditions, StorageErrorException, CpkInfo +from .._generated.models import StorageErrorException, CpkInfo from .._deserialize import deserialize_blob_properties from ..blob_client import BlobClient as BlobClientBase from ._upload_helpers import ( @@ -184,15 +185,11 @@ async def upload_blob( If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword ~azure.storage.blob.PremiumPageBlobTier premium_page_blob_tier: A page blob tier value to set the blob to. The tier correlates to the size of the blob and number of allowed IOPS. This is only applicable to page blobs on @@ -280,15 +277,11 @@ async def download_blob(self, offset=None, length=None, **kwargs): If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword ~azure.storage.blob.CustomerProvidedEncryptionKey cpk: Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. @@ -358,15 +351,11 @@ async def delete_blob(self, delete_snapshots=False, **kwargs): If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: None @@ -434,15 +423,11 @@ async def get_blob_properties(self, **kwargs): If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword ~azure.storage.blob.CustomerProvidedEncryptionKey cpk: Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. @@ -463,11 +448,7 @@ async def get_blob_properties(self, **kwargs): :caption: Getting the properties for a blob. """ access_conditions = get_access_conditions(kwargs.pop('lease', None)) - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None), - if_match=kwargs.pop('if_match', None), - if_none_match=kwargs.pop('if_none_match', None)) + mod_conditions = get_modify_conditions(kwargs) cpk = kwargs.pop('cpk', None) cpk_info = None if cpk: @@ -515,15 +496,11 @@ async def set_http_headers(self, content_settings=None, **kwargs): If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. :returns: Blob-updated property dict (Etag and last modified) @@ -561,15 +538,11 @@ async def set_blob_metadata(self, metadata=None, **kwargs): If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword ~azure.storage.blob.CustomerProvidedEncryptionKey cpk: Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. @@ -629,15 +602,11 @@ async def create_page_blob( # type: ignore If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword ~azure.storage.blob.CustomerProvidedEncryptionKey cpk: Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. @@ -685,15 +654,11 @@ async def create_append_blob(self, content_settings=None, metadata=None, **kwarg If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword ~azure.storage.blob.CustomerProvidedEncryptionKey cpk: Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. @@ -741,15 +706,11 @@ async def create_snapshot(self, metadata=None, **kwargs): If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword lease: Required if the blob has an active lease. Value can be a LeaseClient object or the lease ID as a string. @@ -850,19 +811,12 @@ async def start_copy_from_url(self, source_url, metadata=None, incremental_copy= If a date is passed in without timezone info, it is assumed to be UTC. Specify this conditional header to copy the blob only if the source blob has not been modified since the specified date/time. - :keyword str source_if_match: - An ETag value, or the wildcard character (*). Specify this conditional - header to copy the source blob only if its ETag matches the value - specified. If the ETag values do not match, the Blob service returns - status code 412 (Precondition Failed). This header cannot be specified - if the source is an Azure File. - :keyword str source_if_none_match: - An ETag value, or the wildcard character (*). Specify this conditional - header to copy the blob only if its ETag does not match the value - specified. If the values are identical, the Blob service returns status - code 412 (Precondition Failed). This header cannot be specified if the - source is an Azure File. - :keyword ~datetime.datetime destination_if_modified_since: + :keyword str source_etag: + The source ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` source_match_condition: + The source match condition to use upon the etag. + :keyword ~datetime.datetime if_modified_since: A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. @@ -870,7 +824,7 @@ async def start_copy_from_url(self, source_url, metadata=None, incremental_copy= if the destination blob has been modified since the specified date/time. If the destination blob has not been modified, the Blob service returns status code 412 (Precondition Failed). - :keyword ~datetime.datetime destination_if_unmodified_since: + :keyword ~datetime.datetime if_unmodified_since: A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. @@ -878,19 +832,11 @@ async def start_copy_from_url(self, source_url, metadata=None, incremental_copy= if the destination blob has not been modified since the specified date/time. If the destination blob has been modified, the Blob service returns status code 412 (Precondition Failed). - :keyword str destination_if_match: - An ETag value, or the wildcard character (*). Specify an ETag value for - this conditional header to copy the blob only if the specified ETag value - matches the ETag value for an existing destination blob. If the ETag for - the destination blob does not match the ETag specified for If-Match, the - Blob service returns status code 412 (Precondition Failed). - :keyword str destination_if_none_match: - An ETag value, or the wildcard character (*). Specify an ETag value for - this conditional header to copy the blob only if the specified ETag value - does not match the ETag value for the destination blob. Specify the wildcard - character (*) to perform the operation only if the destination blob does not - exist. If the specified condition isn't met, the Blob service returns status - code 412 (Precondition Failed). + :keyword str etag: + The destination ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The destination match condition to use upon the etag. :keyword destination_lease: The lease ID specified for this header must match the lease ID of the destination blob. If the request does not include the lease ID or it is not @@ -995,15 +941,11 @@ async def acquire_lease(self, lease_duration=-1, lease_id=None, **kwargs): If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. :returns: A LeaseClient object. @@ -1232,15 +1174,11 @@ async def commit_block_list( # type: ignore If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword ~azure.storage.blob.StandardBlobTier standard_blob_tier: A standard blob tier value to set the blob to. For this version of the library, this is only applicable to block blobs on standard storage accounts. @@ -1335,15 +1273,11 @@ async def get_page_ranges( # type: ignore If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. :keyword lease: @@ -1401,15 +1335,11 @@ async def set_sequence_number( # type: ignore If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. :returns: Blob-updated property dict (Etag and last modified). @@ -1448,15 +1378,11 @@ async def resize_blob(self, size, **kwargs): If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword ~azure.storage.blob.PremiumPageBlobTier premium_page_blob_tier: A page blob tier value to set the blob to. The tier correlates to the size of the blob and number of allowed IOPS. This is only applicable to page blobs on @@ -1527,15 +1453,11 @@ async def upload_page( # type: ignore If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify an ETag value for this conditional - header to write the page only if the blob's ETag value matches the - value specified. If the values do not match, the Blob service fails. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). Specify an ETag value for this conditional - header to write the page only if the blob's ETag value does not - match the value specified. If the values are identical, the Blob - service fails. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword ~azure.storage.blob.CustomerProvidedEncryptionKey cpk: Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. @@ -1597,15 +1519,11 @@ async def upload_pages_from_url(self, source_url, # type: str If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the source resource has not been modified since the specified date/time. - :keyword str source_if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the source resource's ETag matches the value specified. - :keyword str source_if_none_match: - An ETag value, or the wildcard character (*). Specify this header - to perform the operation only if the source resource's ETag does not match - the value specified. Specify the wildcard character (*) to perform - the operation only if the source resource does not exist, and fail the - operation if it does exist. + :keyword str source_etag: + The source ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` source_match_condition: + The source match condition to use upon the etag. :keyword str lease: Required if the blob has an active lease. :keyword int if_sequence_number_lte: @@ -1629,15 +1547,11 @@ async def upload_pages_from_url(self, source_url, # type: str If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + The destination ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The destination match condition to use upon the etag. :keyword ~azure.storage.blob.CustomerProvidedEncryptionKey cpk: Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. @@ -1699,15 +1613,11 @@ async def clear_page(self, offset, length, **kwargs): If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify an ETag value for this conditional - header to write the page only if the blob's ETag value matches the - value specified. If the values do not match, the Blob service fails. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). Specify an ETag value for this conditional - header to write the page only if the blob's ETag value does not - match the value specified. If the values are identical, the Blob - service fails. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword ~azure.storage.blob.PremiumPageBlobTier premium_page_blob_tier: A page blob tier value to set the blob to. The tier correlates to the size of the blob and number of allowed IOPS. This is only applicable to page blobs on @@ -1771,15 +1681,11 @@ async def append_block( # type: ignore If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword str encoding: Defaults to UTF-8. :keyword ~azure.storage.blob.CustomerProvidedEncryptionKey cpk: @@ -1848,15 +1754,11 @@ async def append_block_from_url(self, copy_source_url, # type: str If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + The destination ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The destination match condition to use upon the etag. :keyword ~datetime.datetime source_if_modified_since: A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. @@ -1869,15 +1771,11 @@ async def append_block_from_url(self, copy_source_url, # type: str If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the source resource has not been modified since the specified date/time. - :keyword str source_if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the source resource's ETag matches the value specified. - :keyword str source_if_none_match: - An ETag value, or the wildcard character (*). Specify this header - to perform the operation only if the source resource's ETag does not match - the value specified. Specify the wildcard character (*) to perform - the operation only if the source resource does not exist, and fail the - operation if it does exist. + :keyword str source_etag: + The source ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` source_match_condition: + The source match condition to use upon the etag. :keyword ~azure.storage.blob.CustomerProvidedEncryptionKey cpk: Encrypts the data on the service-side with the given key. diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/blob_service_client_async.py b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/blob_service_client_async.py index cca75e3c69c0..d7d8607740f2 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/blob_service_client_async.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/blob_service_client_async.py @@ -432,15 +432,11 @@ async def delete_container( If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: None diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/container_client_async.py b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/container_client_async.py index 684034ed93ff..3e87ddf8df9c 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/container_client_async.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/container_client_async.py @@ -25,10 +25,10 @@ return_headers_and_deserialized) from .._generated.aio import AzureBlobStorage from .._generated.models import ( - ModifiedAccessConditions, StorageErrorException, SignedIdentifier) from .._deserialize import deserialize_container_properties +from .._serialize import get_modify_conditions from ..container_client import ContainerClient as ContainerClientBase from ..lease import get_access_conditions from ..models import ContainerProperties, BlobProperties, BlobType # pylint: disable=unused-import @@ -180,15 +180,11 @@ async def delete_container( If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: None @@ -204,11 +200,7 @@ async def delete_container( """ lease = kwargs.pop('lease', None) access_conditions = get_access_conditions(lease) - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None), - if_match=kwargs.pop('if_match', None), - if_none_match=kwargs.pop('if_none_match', None)) + mod_conditions = get_modify_conditions(kwargs) timeout = kwargs.pop('timeout', None) try: await self._client.container.delete( @@ -250,15 +242,11 @@ async def acquire_lease( If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. :returns: A LeaseClient object, that can be run in a context manager. @@ -373,7 +361,7 @@ async def set_container_metadata( # type: ignore headers.update(add_metadata_headers(metadata)) lease = kwargs.pop('lease', None) access_conditions = get_access_conditions(lease) - mod_conditions = ModifiedAccessConditions(if_modified_since=kwargs.pop('if_modified_since', None)) + mod_conditions = get_modify_conditions(kwargs) timeout = kwargs.pop('timeout', None) try: return await self._client.container.set_metadata( # type: ignore @@ -485,9 +473,7 @@ async def set_container_access_policy( identifiers.append(SignedIdentifier(id=key, access_policy=value)) # type: ignore signed_identifiers = identifiers # type: ignore - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None)) + mod_conditions = get_modify_conditions(kwargs) access_conditions = get_access_conditions(lease) try: return await self._client.container.set_access_policy( @@ -647,15 +633,11 @@ async def upload_blob( If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. This method may make multiple calls to the Azure service and the timeout will apply to @@ -753,15 +735,11 @@ async def delete_blob( If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: None @@ -821,15 +799,11 @@ async def delete_blobs( # pylint: disable=arguments-differ If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. :return: An async iterator of responses, one for each blob in order diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/lease_async.py b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/lease_async.py index bfca10c9ec33..21a27093f9ad 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/lease_async.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/lease_async.py @@ -14,8 +14,8 @@ from .._shared.response_handlers import return_response_headers, process_storage_error from .._generated.models import ( StorageErrorException, - ModifiedAccessConditions, LeaseAccessConditions) +from .._serialize import get_modify_conditions from ..lease import LeaseClient as LeaseClientBase if TYPE_CHECKING: @@ -86,24 +86,16 @@ async def acquire(self, lease_duration=-1, **kwargs): If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: None """ - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None), - if_match=kwargs.pop('if_match', None), - if_none_match=kwargs.pop('if_none_match', None)) + mod_conditions = get_modify_conditions(kwargs) try: response = await self._client.acquire_lease( timeout=kwargs.pop('timeout', None), @@ -141,24 +133,16 @@ async def renew(self, **kwargs): If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. :return: None """ - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None), - if_match=kwargs.pop('if_match', None), - if_none_match=kwargs.pop('if_none_match', None)) + mod_conditions = get_modify_conditions(kwargs) try: response = await self._client.renew_lease( lease_id=self.id, @@ -193,24 +177,16 @@ async def release(self, **kwargs): If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. :return: None """ - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None), - if_match=kwargs.pop('if_match', None), - if_none_match=kwargs.pop('if_none_match', None)) + mod_conditions = get_modify_conditions(kwargs) try: response = await self._client.release_lease( lease_id=self.id, @@ -244,24 +220,16 @@ async def change(self, proposed_lease_id, **kwargs): If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. :return: None """ - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None), - if_match=kwargs.pop('if_match', None), - if_none_match=kwargs.pop('if_none_match', None)) + mod_conditions = get_modify_conditions(kwargs) try: response = await self._client.change_lease( lease_id=self.id, @@ -315,9 +283,7 @@ async def break_lease(self, lease_break_period=None, **kwargs): :return: Approximate time remaining in the lease period, in seconds. :rtype: int """ - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None)) + mod_conditions = get_modify_conditions(kwargs) try: response = await self._client.break_lease( timeout=kwargs.pop('timeout', None), diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/blob_client.py b/sdk/storage/azure-storage-blob/azure/storage/blob/blob_client.py index d093a6db587c..bcd30dad5c85 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/blob_client.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/blob_client.py @@ -27,21 +27,18 @@ add_metadata_headers, get_length, read_length, validate_and_format_range_headers) from ._shared.response_handlers import return_response_headers, process_storage_error -from ._deserialize import get_page_ranges_result from ._generated import AzureBlobStorage from ._generated.models import ( # pylint: disable=unused-import DeleteSnapshotsOptionType, BlobHTTPHeaders, BlockLookupList, AppendPositionAccessConditions, - SourceModifiedAccessConditions, - ModifiedAccessConditions, SequenceNumberAccessConditions, StorageErrorException, UserDelegationKey, CpkInfo) - -from ._deserialize import deserialize_blob_properties, deserialize_blob_stream +from ._serialize import get_modify_conditions, get_source_conditions +from ._deserialize import get_page_ranges_result, deserialize_blob_properties, deserialize_blob_stream from ._upload_helpers import ( upload_block_blob, upload_append_blob, @@ -332,11 +329,7 @@ def _upload_blob_options( # pylint:disable=too-many-statements headers = kwargs.pop('headers', {}) headers.update(add_metadata_headers(metadata)) kwargs['lease_access_conditions'] = get_access_conditions(kwargs.pop('lease', None)) - kwargs['modified_access_conditions'] = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None), - if_match=kwargs.pop('if_match', None), - if_none_match=kwargs.pop('if_none_match', None)) + kwargs['modified_access_conditions'] = get_modify_conditions(kwargs) if content_settings: kwargs['blob_headers'] = BlobHTTPHeaders( blob_cache_control=content_settings.cache_control, @@ -420,15 +413,11 @@ def upload_blob( # pylint: disable=too-many-locals If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword ~azure.storage.blob.PremiumPageBlobTier premium_page_blob_tier: A page blob tier value to set the blob to. The tier correlates to the size of the blob and number of allowed IOPS. This is only applicable to page blobs on @@ -491,11 +480,7 @@ def _download_blob_options(self, offset=None, length=None, **kwargs): validate_content = kwargs.pop('validate_content', False) access_conditions = get_access_conditions(kwargs.pop('lease', None)) - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None), - if_match=kwargs.pop('if_match', None), - if_none_match=kwargs.pop('if_none_match', None)) + mod_conditions = get_modify_conditions(kwargs) cpk = kwargs.pop('cpk', None) cpk_info = None @@ -559,15 +544,11 @@ def download_blob(self, offset=None, length=None, **kwargs): If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword ~azure.storage.blob.CustomerProvidedEncryptionKey cpk: Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. @@ -603,11 +584,7 @@ def download_blob(self, offset=None, length=None, **kwargs): def _generic_delete_blob_options(delete_snapshots=False, **kwargs): # type: (bool, **Any) -> Dict[str, Any] access_conditions = get_access_conditions(kwargs.pop('lease', None)) - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None), - if_match=kwargs.pop('if_match', None), - if_none_match=kwargs.pop('if_none_match', None)) + mod_conditions = get_modify_conditions(kwargs) if delete_snapshots: delete_snapshots = DeleteSnapshotsOptionType(delete_snapshots) options = { @@ -662,15 +639,11 @@ def delete_blob(self, delete_snapshots=False, **kwargs): If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: None @@ -738,15 +711,11 @@ def get_blob_properties(self, **kwargs): If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword ~azure.storage.blob.CustomerProvidedEncryptionKey cpk: Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. @@ -767,11 +736,7 @@ def get_blob_properties(self, **kwargs): """ # TODO: extract this out as _get_blob_properties_options access_conditions = get_access_conditions(kwargs.pop('lease', None)) - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None), - if_match=kwargs.pop('if_match', None), - if_none_match=kwargs.pop('if_none_match', None)) + mod_conditions = get_modify_conditions(kwargs) cpk = kwargs.pop('cpk', None) cpk_info = None if cpk: @@ -797,11 +762,7 @@ def get_blob_properties(self, **kwargs): def _set_http_headers_options(self, content_settings=None, **kwargs): # type: (Optional[ContentSettings], **Any) -> Dict[str, Any] access_conditions = get_access_conditions(kwargs.pop('lease', None)) - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None), - if_match=kwargs.pop('if_match', None), - if_none_match=kwargs.pop('if_none_match', None)) + mod_conditions = get_modify_conditions(kwargs) blob_headers = None if content_settings: blob_headers = BlobHTTPHeaders( @@ -846,15 +807,11 @@ def set_http_headers(self, content_settings=None, **kwargs): If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. :returns: Blob-updated property dict (Etag and last modified) @@ -871,11 +828,7 @@ def _set_blob_metadata_options(self, metadata=None, **kwargs): headers = kwargs.pop('headers', {}) headers.update(add_metadata_headers(metadata)) access_conditions = get_access_conditions(kwargs.pop('lease', None)) - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None), - if_match=kwargs.pop('if_match', None), - if_none_match=kwargs.pop('if_none_match', None)) + mod_conditions = get_modify_conditions(kwargs) cpk = kwargs.pop('cpk', None) cpk_info = None @@ -920,15 +873,11 @@ def set_blob_metadata(self, metadata=None, **kwargs): If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword ~azure.storage.blob.CustomerProvidedEncryptionKey cpk: Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. @@ -957,11 +906,7 @@ def _create_page_blob_options( # type: ignore headers = kwargs.pop('headers', {}) headers.update(add_metadata_headers(metadata)) access_conditions = get_access_conditions(kwargs.pop('lease', None)) - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None), - if_match=kwargs.pop('if_match', None), - if_none_match=kwargs.pop('if_none_match', None)) + mod_conditions = get_modify_conditions(kwargs) blob_headers = None if content_settings: blob_headers = BlobHTTPHeaders( @@ -1045,15 +990,11 @@ def create_page_blob( # type: ignore If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword ~azure.storage.blob.CustomerProvidedEncryptionKey cpk: Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. @@ -1082,11 +1023,7 @@ def _create_append_blob_options(self, content_settings=None, metadata=None, **kw headers = kwargs.pop('headers', {}) headers.update(add_metadata_headers(metadata)) access_conditions = get_access_conditions(kwargs.pop('lease', None)) - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None), - if_match=kwargs.pop('if_match', None), - if_none_match=kwargs.pop('if_none_match', None)) + mod_conditions = get_modify_conditions(kwargs) blob_headers = None if content_settings: blob_headers = BlobHTTPHeaders( @@ -1144,15 +1081,11 @@ def create_append_blob(self, content_settings=None, metadata=None, **kwargs): If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword ~azure.storage.blob.CustomerProvidedEncryptionKey cpk: Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. @@ -1177,11 +1110,7 @@ def _create_snapshot_options(self, metadata=None, **kwargs): headers = kwargs.pop('headers', {}) headers.update(add_metadata_headers(metadata)) access_conditions = get_access_conditions(kwargs.pop('lease', None)) - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None), - if_match=kwargs.pop('if_match', None), - if_none_match=kwargs.pop('if_none_match', None)) + mod_conditions = get_modify_conditions(kwargs) cpk = kwargs.pop('cpk', None) cpk_info = None @@ -1229,15 +1158,11 @@ def create_snapshot(self, metadata=None, **kwargs): If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword lease: Required if the blob has an active lease. Value can be a LeaseClient object or the lease ID as a string. @@ -1284,11 +1209,7 @@ def _start_copy_from_url_options(self, source_url, metadata=None, incremental_co headers['x-ms-requires-sync'] = str(kwargs.pop('requires_sync')) timeout = kwargs.pop('timeout', None) - dest_mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('destination_if_modified_since', None), - if_unmodified_since=kwargs.pop('destination_if_unmodified_since', None), - if_match=kwargs.pop('destination_if_match', None), - if_none_match=kwargs.pop('destination_if_none_match', None)) + dest_mod_conditions = get_modify_conditions(kwargs) options = { 'copy_source': source_url, 'timeout': timeout, @@ -1297,11 +1218,7 @@ def _start_copy_from_url_options(self, source_url, metadata=None, incremental_co 'cls': return_response_headers, } if not incremental_copy: - source_mod_conditions = SourceModifiedAccessConditions( - source_if_modified_since=kwargs.pop('source_if_modified_since', None), - source_if_unmodified_since=kwargs.pop('source_if_unmodified_since', None), - source_if_match=kwargs.pop('source_if_match', None), - source_if_none_match=kwargs.pop('source_if_none_match', None)) + source_mod_conditions = get_source_conditions(kwargs) dest_access_conditions = get_access_conditions(kwargs.pop('destination_lease', None)) options['source_modified_access_conditions'] = source_mod_conditions options['lease_access_conditions'] = dest_access_conditions @@ -1380,19 +1297,12 @@ def start_copy_from_url(self, source_url, metadata=None, incremental_copy=False, If a date is passed in without timezone info, it is assumed to be UTC. Specify this conditional header to copy the blob only if the source blob has not been modified since the specified date/time. - :keyword str source_if_match: - An ETag value, or the wildcard character (*). Specify this conditional - header to copy the source blob only if its ETag matches the value - specified. If the ETag values do not match, the Blob service returns - status code 412 (Precondition Failed). This header cannot be specified - if the source is an Azure File. - :keyword str source_if_none_match: - An ETag value, or the wildcard character (*). Specify this conditional - header to copy the blob only if its ETag does not match the value - specified. If the values are identical, the Blob service returns status - code 412 (Precondition Failed). This header cannot be specified if the - source is an Azure File. - :keyword ~datetime.datetime destination_if_modified_since: + :keyword str source_etag: + The source ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` source_match_condition: + The source match condition to use upon the etag. + :keyword ~datetime.datetime if_modified_since: A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. @@ -1400,7 +1310,7 @@ def start_copy_from_url(self, source_url, metadata=None, incremental_copy=False, if the destination blob has been modified since the specified date/time. If the destination blob has not been modified, the Blob service returns status code 412 (Precondition Failed). - :keyword ~datetime.datetime destination_if_unmodified_since: + :keyword ~datetime.datetime if_unmodified_since: A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. @@ -1408,19 +1318,11 @@ def start_copy_from_url(self, source_url, metadata=None, incremental_copy=False, if the destination blob has not been modified since the specified date/time. If the destination blob has been modified, the Blob service returns status code 412 (Precondition Failed). - :keyword str destination_if_match: - An ETag value, or the wildcard character (*). Specify an ETag value for - this conditional header to copy the blob only if the specified ETag value - matches the ETag value for an existing destination blob. If the ETag for - the destination blob does not match the ETag specified for If-Match, the - Blob service returns status code 412 (Precondition Failed). - :keyword str destination_if_none_match: - An ETag value, or the wildcard character (*). Specify an ETag value for - this conditional header to copy the blob only if the specified ETag value - does not match the ETag value for the destination blob. Specify the wildcard - character (*) to perform the operation only if the destination blob does not - exist. If the specified condition isn't met, the Blob service returns status - code 412 (Precondition Failed). + :keyword str etag: + The destination ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The destination match condition to use upon the etag. :keyword destination_lease: The lease ID specified for this header must match the lease ID of the destination blob. If the request does not include the lease ID or it is not @@ -1542,15 +1444,11 @@ def acquire_lease(self, lease_duration=-1, lease_id=None, **kwargs): If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. :returns: A LeaseClient object. @@ -1854,11 +1752,7 @@ def _commit_block_list_options( # type: ignore headers.update(add_metadata_headers(metadata)) blob_headers = None access_conditions = get_access_conditions(kwargs.pop('lease', None)) - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None), - if_match=kwargs.pop('if_match', None), - if_none_match=kwargs.pop('if_none_match', None)) + mod_conditions = get_modify_conditions(kwargs) if content_settings: blob_headers = BlobHTTPHeaders( blob_cache_control=content_settings.cache_control, @@ -1935,15 +1829,11 @@ def commit_block_list( # type: ignore If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :param ~azure.storage.blob.StandardBlobTier standard_blob_tier: A standard blob tier value to set the blob to. For this version of the library, this is only applicable to block blobs on standard storage accounts. @@ -2007,11 +1897,7 @@ def _get_page_ranges_options( # type: ignore ): # type: (...) -> Dict[str, Any] access_conditions = get_access_conditions(kwargs.pop('lease', None)) - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None), - if_match=kwargs.pop('if_match', None), - if_none_match=kwargs.pop('if_none_match', None)) + mod_conditions = get_modify_conditions(kwargs) if length is not None: length = offset + length - 1 # Reformat to an inclusive range index page_range, _ = validate_and_format_range_headers( @@ -2079,15 +1965,11 @@ def get_page_ranges( # type: ignore If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. :returns: @@ -2112,11 +1994,7 @@ def get_page_ranges( # type: ignore def _set_sequence_number_options(self, sequence_number_action, sequence_number=None, **kwargs): # type: (Union[str, SequenceNumberAction], Optional[str], **Any) -> Dict[str, Any] access_conditions = get_access_conditions(kwargs.pop('lease', None)) - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None), - if_match=kwargs.pop('if_match', None), - if_none_match=kwargs.pop('if_none_match', None)) + mod_conditions = get_modify_conditions(kwargs) if sequence_number_action is None: raise ValueError("A sequence number action must be specified") options = { @@ -2157,15 +2035,11 @@ def set_sequence_number(self, sequence_number_action, sequence_number=None, **kw If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. :returns: Blob-updated property dict (Etag and last modified). @@ -2181,11 +2055,7 @@ def set_sequence_number(self, sequence_number_action, sequence_number=None, **kw def _resize_blob_options(self, size, **kwargs): # type: (int, **Any) -> Dict[str, Any] access_conditions = get_access_conditions(kwargs.pop('lease', None)) - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None), - if_match=kwargs.pop('if_match', None), - if_none_match=kwargs.pop('if_none_match', None)) + mod_conditions = get_modify_conditions(kwargs) if size is None: raise ValueError("A content length must be specified for a Page Blob.") @@ -2232,15 +2102,11 @@ def resize_blob(self, size, **kwargs): If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword ~azure.storage.blob.PremiumPageBlobTier premium_page_blob_tier: A page blob tier value to set the blob to. The tier correlates to the size of the blob and number of allowed IOPS. This is only applicable to page blobs on @@ -2280,11 +2146,7 @@ def _upload_page_options( # type: ignore if_sequence_number_less_than=kwargs.pop('if_sequence_number_lt', None), if_sequence_number_equal_to=kwargs.pop('if_sequence_number_eq', None) ) - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None), - if_match=kwargs.pop('if_match', None), - if_none_match=kwargs.pop('if_none_match', None)) + mod_conditions = get_modify_conditions(kwargs) validate_content = kwargs.pop('validate_content', False) cpk = kwargs.pop('cpk', None) @@ -2363,15 +2225,11 @@ def upload_page( # type: ignore If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify an ETag value for this conditional - header to write the page only if the blob's ETag value matches the - value specified. If the values do not match, the Blob service fails. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). Specify an ETag value for this conditional - header to write the page only if the blob's ETag value does not - match the value specified. If the values are identical, the Blob - service fails. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :param ~azure.storage.blob.CustomerProvidedEncryptionKey cpk: Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. @@ -2424,16 +2282,8 @@ def _upload_pages_from_url_options( # type: ignore if_sequence_number_equal_to=kwargs.pop('if_sequence_number_eq', None) ) access_conditions = get_access_conditions(kwargs.pop('lease', None)) - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None), - if_match=kwargs.pop('if_match', None), - if_none_match=kwargs.pop('if_none_match', None)) - source_mod_conditions = SourceModifiedAccessConditions( - source_if_modified_since=kwargs.pop('source_if_modified_since', None), - source_if_unmodified_since=kwargs.pop('source_if_unmodified_since', None), - source_if_match=kwargs.pop('source_if_match', None), - source_if_none_match=kwargs.pop('source_if_none_match', None)) + mod_conditions = get_modify_conditions(kwargs) + source_mod_conditions = get_source_conditions(kwargs) source_content_md5 = kwargs.pop('source_content_md5', None) cpk = kwargs.pop('cpk', None) @@ -2501,15 +2351,11 @@ def upload_pages_from_url(self, source_url, # type: str If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the source resource has not been modified since the specified date/time. - :keyword str source_if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the source resource's ETag matches the value specified. - :keyword str source_if_none_match: - An ETag value, or the wildcard character (*). Specify this header - to perform the operation only if the source resource's ETag does not match - the value specified. Specify the wildcard character (*) to perform - the operation only if the source resource does not exist, and fail the - operation if it does exist. + :keyword str source_etag: + The source ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` source_match_condition: + The source match condition to use upon the etag. :param str lease: Required if the blob has an active lease. :keyword int if_sequence_number_lte: @@ -2533,15 +2379,11 @@ def upload_pages_from_url(self, source_url, # type: str If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + The destination ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The destination match condition to use upon the etag. :keyword ~azure.storage.blob.CustomerProvidedEncryptionKey cpk: Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. @@ -2573,12 +2415,7 @@ def _clear_page_options(self, offset, length, **kwargs): if_sequence_number_less_than=kwargs.pop('if_sequence_number_lt', None), if_sequence_number_equal_to=kwargs.pop('if_sequence_number_eq', None) ) - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None), - if_match=kwargs.pop('if_match', None), - if_none_match=kwargs.pop('if_none_match', None) - ) + mod_conditions = get_modify_conditions(kwargs) if offset is None or offset % 512 != 0: raise ValueError("offset must be an integer that aligns with 512 page size") if length is None or length % 512 != 0: @@ -2646,15 +2483,11 @@ def clear_page(self, offset, length, **kwargs): If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify an ETag value for this conditional - header to write the page only if the blob's ETag value matches the - value specified. If the values do not match, the Blob service fails. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). Specify an ETag value for this conditional - header to write the page only if the blob's ETag value does not - match the value specified. If the values are identical, the Blob - service fails. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword ~azure.storage.blob.CustomerProvidedEncryptionKey cpk: Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. @@ -2701,11 +2534,7 @@ def _append_block_options( # type: ignore append_position=appendpos_condition ) access_conditions = get_access_conditions(kwargs.pop('lease', None)) - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None), - if_match=kwargs.pop('if_match', None), - if_none_match=kwargs.pop('if_none_match', None)) + mod_conditions = get_modify_conditions(kwargs) cpk = kwargs.pop('cpk', None) cpk_info = None @@ -2776,15 +2605,11 @@ def append_block( # type: ignore If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword str encoding: Defaults to UTF-8. :keyword ~azure.storage.blob.CustomerProvidedEncryptionKey cpk: @@ -2838,16 +2663,8 @@ def _append_block_from_url_options( # type: ignore append_position=appendpos_condition ) access_conditions = get_access_conditions(kwargs.pop('lease', None)) - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None), - if_match=kwargs.pop('if_match', None), - if_none_match=kwargs.pop('if_none_match', None)) - source_mod_conditions = SourceModifiedAccessConditions( - source_if_modified_since=kwargs.pop('source_if_modified_since', None), - source_if_unmodified_since=kwargs.pop('source_if_unmodified_since', None), - source_if_match=kwargs.pop('source_if_match', None), - source_if_none_match=kwargs.pop('source_if_none_match', None)) + mod_conditions = get_modify_conditions(kwargs) + source_mod_conditions = get_source_conditions(kwargs) cpk = kwargs.pop('cpk', None) cpk_info = None @@ -2919,15 +2736,11 @@ def append_block_from_url(self, copy_source_url, # type: str If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + The destination ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The destination match condition to use upon the etag. :keyword ~datetime.datetime source_if_modified_since: A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. @@ -2940,15 +2753,11 @@ def append_block_from_url(self, copy_source_url, # type: str If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the source resource has not been modified since the specified date/time. - :keyword str source_if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the source resource's ETag matches the value specified. - :keyword str source_if_none_match: - An ETag value, or the wildcard character (*). Specify this header - to perform the operation only if the source resource's ETag does not match - the value specified. Specify the wildcard character (*) to perform - the operation only if the source resource does not exist, and fail the - operation if it does exist. + :keyword str source_etag: + The source ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` source_match_condition: + The source match condition to use upon the etag. :keyword ~azure.storage.blob.CustomerProvidedEncryptionKey cpk: Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/blob_service_client.py b/sdk/storage/azure-storage-blob/azure/storage/blob/blob_service_client.py index 57b74da0abc8..084deb301a42 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/blob_service_client.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/blob_service_client.py @@ -477,15 +477,11 @@ def delete_container( If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: None diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/container_client.py b/sdk/storage/azure-storage-blob/azure/storage/blob/container_client.py index 6df9e9b03b11..d2e5b576d41a 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/container_client.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/container_client.py @@ -31,10 +31,10 @@ return_headers_and_deserialized) from ._generated import AzureBlobStorage from ._generated.models import ( - ModifiedAccessConditions, StorageErrorException, SignedIdentifier) from ._deserialize import deserialize_container_properties +from ._serialize import get_modify_conditions from .models import ( # pylint: disable=unused-import ContainerProperties, BlobProperties, @@ -274,15 +274,11 @@ def delete_container( If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: None @@ -298,11 +294,7 @@ def delete_container( """ lease = kwargs.pop('lease', None) access_conditions = get_access_conditions(lease) - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None), - if_match=kwargs.pop('if_match', None), - if_none_match=kwargs.pop('if_none_match', None)) + mod_conditions = get_modify_conditions(kwargs) timeout = kwargs.pop('timeout', None) try: self._client.container.delete( @@ -344,15 +336,11 @@ def acquire_lease( If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. :returns: A LeaseClient object, that can be run in a context manager. @@ -467,7 +455,7 @@ def set_container_metadata( # type: ignore headers.update(add_metadata_headers(metadata)) lease = kwargs.pop('lease', None) access_conditions = get_access_conditions(lease) - mod_conditions = ModifiedAccessConditions(if_modified_since=kwargs.pop('if_modified_since', None)) + mod_conditions = get_modify_conditions(kwargs) timeout = kwargs.pop('timeout', None) try: return self._client.container.set_metadata( # type: ignore @@ -578,9 +566,7 @@ def set_container_access_policy( identifiers.append(SignedIdentifier(id=key, access_policy=value)) # type: ignore signed_identifiers = identifiers # type: ignore lease = kwargs.pop('lease', None) - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None)) + mod_conditions = get_modify_conditions(kwargs) access_conditions = get_access_conditions(lease) timeout = kwargs.pop('timeout', None) try: @@ -740,15 +726,11 @@ def upload_blob( If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. This method may make multiple calls to the Azure service and the timeout will apply to @@ -848,15 +830,11 @@ def delete_blob( If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: None @@ -973,15 +951,11 @@ def delete_blobs(self, *blobs, **kwargs): If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. :return: An iterator of responses, one for each blob in order diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/lease.py b/sdk/storage/azure-storage-blob/azure/storage/blob/lease.py index 0ed9d8aa05f0..200adab9d432 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/lease.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/lease.py @@ -14,10 +14,8 @@ from azure.core.tracing.decorator import distributed_trace from ._shared.response_handlers import return_response_headers, process_storage_error -from ._generated.models import ( - StorageErrorException, - ModifiedAccessConditions, - LeaseAccessConditions) +from ._generated.models import StorageErrorException, LeaseAccessConditions +from ._serialize import get_modify_conditions if TYPE_CHECKING: from datetime import datetime @@ -103,24 +101,16 @@ def acquire(self, lease_duration=-1, **kwargs): If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: None """ - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None), - if_match=kwargs.pop('if_match', None), - if_none_match=kwargs.pop('if_none_match', None)) + mod_conditions = get_modify_conditions(kwargs) try: response = self._client.acquire_lease( timeout=kwargs.pop('timeout', None), @@ -158,24 +148,16 @@ def renew(self, **kwargs): If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. :return: None """ - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None), - if_match=kwargs.pop('if_match', None), - if_none_match=kwargs.pop('if_none_match', None)) + mod_conditions = get_modify_conditions(kwargs) try: response = self._client.renew_lease( lease_id=self.id, @@ -210,24 +192,16 @@ def release(self, **kwargs): If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. :return: None """ - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None), - if_match=kwargs.pop('if_match', None), - if_none_match=kwargs.pop('if_none_match', None)) + mod_conditions = get_modify_conditions(kwargs) try: response = self._client.release_lease( lease_id=self.id, @@ -261,24 +235,16 @@ def change(self, proposed_lease_id, **kwargs): If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time. - :keyword str if_match: - An ETag value, or the wildcard character (*). Specify this header to perform - the operation only if the resource's ETag matches the value specified. - :keyword str if_none_match: - An ETag value, or the wildcard character (*). 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. + :keyword str etag: + An ETag value, or the wildcard character (*). Used to check if the resource has changed, + and act according to the condition specified by the `match_condition` parameter. + :keyword :class:`MatchConditions` match_condition: + The match condition to use upon the etag. :keyword int timeout: The timeout parameter is expressed in seconds. :return: None """ - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None), - if_match=kwargs.pop('if_match', None), - if_none_match=kwargs.pop('if_none_match', None)) + mod_conditions = get_modify_conditions(kwargs) try: response = self._client.change_lease( lease_id=self.id, @@ -332,9 +298,7 @@ def break_lease(self, lease_break_period=None, **kwargs): :return: Approximate time remaining in the lease period, in seconds. :rtype: int """ - mod_conditions = ModifiedAccessConditions( - if_modified_since=kwargs.pop('if_modified_since', None), - if_unmodified_since=kwargs.pop('if_unmodified_since', None)) + mod_conditions = get_modify_conditions(kwargs) try: response = self._client.break_lease( timeout=kwargs.pop('timeout', None), diff --git a/sdk/storage/azure-storage-blob/tests/test_append_blob.py b/sdk/storage/azure-storage-blob/tests/test_append_blob.py index 7fc9e7e6dbb2..d5c8874c632b 100644 --- a/sdk/storage/azure-storage-blob/tests/test_append_blob.py +++ b/sdk/storage/azure-storage-blob/tests/test_append_blob.py @@ -11,6 +11,7 @@ import unittest from datetime import datetime, timedelta +from azure.core import MatchConditions from azure.core.exceptions import ResourceNotFoundError, ResourceModifiedError, HttpResponseError from azure.storage.blob import ( generate_blob_sas, @@ -385,7 +386,8 @@ def test_append_block_from_url_with_source_if_match(self): resp = destination_blob_client. \ append_block_from_url(source_blob_client.url + '?' + sas, source_offset=0, source_length=LARGE_BLOB_SIZE, - source_if_match=source_blob_properties.get('etag')) + source_etag=source_blob_properties.get('etag'), + source_match_condition=MatchConditions.IfNotModified) self.assertEqual(resp.get('blob_append_offset'), '0') self.assertEqual(resp.get('blob_committed_block_count'), 1) self.assertIsNotNone(resp.get('etag')) @@ -402,7 +404,8 @@ def test_append_block_from_url_with_source_if_match(self): with self.assertRaises(ResourceNotFoundError): destination_blob_client.append_block_from_url(source_blob_client.url + '?' + sas, source_offset=0, source_length=LARGE_BLOB_SIZE, - source_if_match='0x111111111111111') + source_etag='0x111111111111111', + source_match_condition=MatchConditions.IfNotModified) @record def test_append_block_from_url_with_source_if_none_match(self): @@ -426,7 +429,8 @@ def test_append_block_from_url_with_source_if_none_match(self): resp = destination_blob_client. \ append_block_from_url(source_blob_client.url + '?' + sas, source_offset=0, source_length=LARGE_BLOB_SIZE, - source_if_none_match='0x111111111111111') + source_etag='0x111111111111111', + source_match_condition=MatchConditions.IfModified) self.assertEqual(resp.get('blob_append_offset'), '0') self.assertEqual(resp.get('blob_committed_block_count'), 1) self.assertIsNotNone(resp.get('etag')) @@ -443,7 +447,8 @@ def test_append_block_from_url_with_source_if_none_match(self): with self.assertRaises(ResourceNotFoundError): destination_blob_client.append_block_from_url(source_blob_client.url + '?' + sas, source_offset=0, source_length=LARGE_BLOB_SIZE, - source_if_none_match=source_blob_properties.get('etag')) + source_etag=source_blob_properties.get('etag'), + source_match_condition=MatchConditions.IfModified) @record def test_append_block_from_url_with_if_match(self): @@ -470,7 +475,8 @@ def test_append_block_from_url_with_if_match(self): resp = destination_blob_client. \ append_block_from_url(source_blob_client.url + '?' + sas, source_offset=0, source_length=LARGE_BLOB_SIZE, - if_match=destination_blob_properties_on_creation.get('etag')) + etag=destination_blob_properties_on_creation.get('etag'), + match_condition=MatchConditions.IfNotModified) self.assertEqual(resp.get('blob_append_offset'), '0') self.assertEqual(resp.get('blob_committed_block_count'), 1) self.assertIsNotNone(resp.get('etag')) @@ -487,7 +493,8 @@ def test_append_block_from_url_with_if_match(self): with self.assertRaises(ResourceModifiedError): destination_blob_client.append_block_from_url(source_blob_client.url + '?' + sas, source_offset=0, source_length=LARGE_BLOB_SIZE, - if_match='0x111111111111111') + etag='0x111111111111111', + match_condition=MatchConditions.IfNotModified) @record def test_append_block_from_url_with_if_none_match(self): @@ -510,7 +517,7 @@ def test_append_block_from_url_with_if_none_match(self): resp = destination_blob_client. \ append_block_from_url(source_blob_client.url + '?' + sas, source_offset=0, source_length=LARGE_BLOB_SIZE, - if_none_match='0x111111111111111') + etag='0x111111111111111', match_condition=MatchConditions.IfModified) self.assertEqual(resp.get('blob_append_offset'), '0') self.assertEqual(resp.get('blob_committed_block_count'), 1) self.assertIsNotNone(resp.get('etag')) @@ -527,7 +534,8 @@ def test_append_block_from_url_with_if_none_match(self): with self.assertRaises(ResourceModifiedError): destination_blob_client.append_block_from_url(source_blob_client.url + '?' + sas, source_offset=0, source_length=LARGE_BLOB_SIZE, - if_none_match=destination_blob_properties.get('etag')) + etag=destination_blob_properties.get('etag'), + match_condition=MatchConditions.IfModified) @record def test_append_block_from_url_with_maxsize_condition(self): diff --git a/sdk/storage/azure-storage-blob/tests/test_append_blob_async.py b/sdk/storage/azure-storage-blob/tests/test_append_blob_async.py index 60d621f8f850..360b63bd8bba 100644 --- a/sdk/storage/azure-storage-blob/tests/test_append_blob_async.py +++ b/sdk/storage/azure-storage-blob/tests/test_append_blob_async.py @@ -13,8 +13,8 @@ import os import unittest -from azure.core.exceptions import HttpResponseError -from azure.core.exceptions import ResourceNotFoundError, ResourceModifiedError +from azure.core import MatchConditions +from azure.core.exceptions import HttpResponseError, ResourceNotFoundError, ResourceModifiedError from azure.core.pipeline.transport import AioHttpTransport from multidict import CIMultiDict, CIMultiDictProxy @@ -462,7 +462,8 @@ async def _test_append_block_from_url_with_source_if_match(self): resp = await destination_blob_client. \ append_block_from_url(source_blob_client.url + '?' + sas, source_offset=0, source_length=LARGE_BLOB_SIZE, - source_if_match=source_properties.get('etag')) + source_etag=source_properties.get('etag'), + source_match_condition=MatchConditions.IfNotModified) self.assertEqual(resp.get('blob_append_offset'), '0') self.assertEqual(resp.get('blob_committed_block_count'), 1) self.assertIsNotNone(resp.get('etag')) @@ -479,7 +480,8 @@ async def _test_append_block_from_url_with_source_if_match(self): await destination_blob_client.append_block_from_url(source_blob_client.url + '?' + sas, source_offset=0, source_length=LARGE_BLOB_SIZE, - source_if_match='0x111111111111111') + source_etag='0x111111111111111', + source_match_condition=MatchConditions.IfNotModified) @record def test_append_block_from_url_with_source_if_match_async(self): @@ -508,7 +510,8 @@ async def _test_append_block_from_url_with_source_if_none_match(self): resp = await destination_blob_client. \ append_block_from_url(source_blob_client.url + '?' + sas, source_offset=0, source_length=LARGE_BLOB_SIZE, - source_if_none_match='0x111111111111111') + source_etag='0x111111111111111', + source_match_condition=MatchConditions.IfModified) self.assertEqual(resp.get('blob_append_offset'), '0') self.assertEqual(resp.get('blob_committed_block_count'), 1) self.assertIsNotNone(resp.get('etag')) @@ -525,7 +528,8 @@ async def _test_append_block_from_url_with_source_if_none_match(self): await destination_blob_client.append_block_from_url(source_blob_client.url + '?' + sas, source_offset=0, source_length=LARGE_BLOB_SIZE, - source_if_none_match=source_properties.get('etag')) + source_etag=source_properties.get('etag'), + source_match_condition=MatchConditions.IfModified) @record def test_append_block_from_url_with_source_if_none_match_async(self): @@ -557,7 +561,8 @@ async def _test_append_block_from_url_with_if_match(self): resp = await destination_blob_client. \ append_block_from_url(source_blob_client.url + '?' + sas, source_offset=0, source_length=LARGE_BLOB_SIZE, - if_match=destination_blob_properties_on_creation.get('etag')) + etag=destination_blob_properties_on_creation.get('etag'), + match_condition=MatchConditions.IfNotModified) self.assertEqual(resp.get('blob_append_offset'), '0') self.assertEqual(resp.get('blob_committed_block_count'), 1) self.assertIsNotNone(resp.get('etag')) @@ -574,7 +579,8 @@ async def _test_append_block_from_url_with_if_match(self): await destination_blob_client.append_block_from_url(source_blob_client.url + '?' + sas, source_offset=0, source_length=LARGE_BLOB_SIZE, - if_match='0x111111111111111') + etag='0x111111111111111', + match_condition=MatchConditions.IfNotModified) @record def test_append_block_from_url_with_if_match_async(self): @@ -602,7 +608,7 @@ async def _test_append_block_from_url_with_if_none_match(self): resp = await destination_blob_client. \ append_block_from_url(source_blob_client.url + '?' + sas, source_offset=0, source_length=LARGE_BLOB_SIZE, - if_none_match='0x111111111111111') + etag='0x111111111111111', match_condition=MatchConditions.IfModified) self.assertEqual(resp.get('blob_append_offset'), '0') self.assertEqual(resp.get('blob_committed_block_count'), 1) self.assertIsNotNone(resp.get('etag')) @@ -620,7 +626,8 @@ async def _test_append_block_from_url_with_if_none_match(self): await destination_blob_client.append_block_from_url(source_blob_client.url + '?' + sas, source_offset=0, source_length=LARGE_BLOB_SIZE, - if_none_match=destination_blob_properties.get('etag')) + etag=destination_blob_properties.get('etag'), + match_condition=MatchConditions.IfModified) @record def test_append_block_from_url_with_if_none_match_async(self): diff --git a/sdk/storage/azure-storage-blob/tests/test_blob_access_conditions.py b/sdk/storage/azure-storage-blob/tests/test_blob_access_conditions.py index aff426ffe27c..3559fbc2b783 100644 --- a/sdk/storage/azure-storage-blob/tests/test_blob_access_conditions.py +++ b/sdk/storage/azure-storage-blob/tests/test_blob_access_conditions.py @@ -11,6 +11,7 @@ import os import unittest +from azure.core import MatchConditions from azure.core.exceptions import HttpResponseError, ResourceNotFoundError, ResourceModifiedError from azure.storage.blob import ( @@ -361,11 +362,16 @@ def test_put_blob_with_if_match(self): etag = blob.get_blob_properties().etag # Act - resp = blob.upload_blob(data, length=len(data), if_match=etag) + resp = blob.upload_blob(data, length=len(data), etag=etag, match_condition=MatchConditions.IfNotModified) # Assert self.assertIsNotNone(resp.get('etag')) + with self.assertRaises(ValueError): + blob.upload_blob(data, length=len(data), etag=etag) + with self.assertRaises(ValueError): + blob.upload_blob(data, length=len(data), match_condition=MatchConditions.IfNotModified) + @record def test_put_blob_with_if_match_fail(self): # Arrange @@ -375,7 +381,12 @@ def test_put_blob_with_if_match_fail(self): # Act with self.assertRaises(ResourceModifiedError) as e: - blob.upload_blob(data, length=len(data), if_match='0x111111111111111', overwrite=True) + blob.upload_blob( + data, + length=len(data), + etag='0x111111111111111', + match_condition=MatchConditions.IfNotModified, + overwrite=True) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -388,10 +399,14 @@ def test_put_blob_with_if_none_match(self): self.container_name, 'blob1', data) # Act - resp = blob.upload_blob(data, length=len(data), if_none_match='0x111111111111111') + resp = blob.upload_blob(data, length=len(data), etag='0x111111111111111', match_condition=MatchConditions.IfModified) # Assert self.assertIsNotNone(resp.get('etag')) + with self.assertRaises(ValueError): + blob.upload_blob(data, length=len(data), etag='0x111111111111111') + with self.assertRaises(ValueError): + blob.upload_blob(data, length=len(data), match_condition=MatchConditions.IfModified) @record def test_put_blob_with_if_none_match_fail(self): @@ -403,7 +418,7 @@ def test_put_blob_with_if_none_match_fail(self): # Act with self.assertRaises(ResourceModifiedError) as e: - blob.upload_blob(data, length=len(data), if_none_match=etag, overwrite=True) + blob.upload_blob(data, length=len(data), etag=etag, match_condition=MatchConditions.IfModified, overwrite=True) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -476,7 +491,7 @@ def test_get_blob_with_if_match(self): etag = blob.get_blob_properties().etag # Act - content = blob.download_blob(if_match=etag) + content = blob.download_blob(etag=etag, match_condition=MatchConditions.IfNotModified) content = b"".join(list(content)) # Assert @@ -490,7 +505,7 @@ def test_get_blob_with_if_match_fail(self): # Act with self.assertRaises(ResourceModifiedError) as e: - blob.download_blob(if_match='0x111111111111111') + blob.download_blob(etag='0x111111111111111', match_condition=MatchConditions.IfNotModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -502,7 +517,7 @@ def test_get_blob_with_if_none_match(self): self.container_name, 'blob1', b'hello world') # Act - content = blob.download_blob(if_none_match='0x111111111111111') + content = blob.download_blob(etag='0x111111111111111', match_condition=MatchConditions.IfModified) content = b"".join(list(content)) # Assert @@ -517,7 +532,7 @@ def test_get_blob_with_if_none_match_fail(self): # Act with self.assertRaises(ResourceModifiedError) as e: - blob.download_blob(if_none_match=etag) + blob.download_blob(etag=etag, match_condition=MatchConditions.IfModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -608,7 +623,7 @@ def test_set_blob_properties_with_if_match(self): content_settings = ContentSettings( content_language='spanish', content_disposition='inline') - blob.set_http_headers(content_settings, if_match=etag) + blob.set_http_headers(content_settings, etag=etag, match_condition=MatchConditions.IfNotModified) # Assert properties = blob.get_blob_properties() @@ -627,7 +642,7 @@ def test_set_blob_properties_with_if_match_fail(self): content_language='spanish', content_disposition='inline') blob = self.bsc.get_blob_client(self.container_name, 'blob1') - blob.set_http_headers(content_settings, if_match='0x111111111111111') + blob.set_http_headers(content_settings, etag='0x111111111111111', match_condition=MatchConditions.IfNotModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -643,7 +658,7 @@ def test_set_blob_properties_with_if_none_match(self): content_language='spanish', content_disposition='inline') blob = self.bsc.get_blob_client(self.container_name, 'blob1') - blob.set_http_headers(content_settings, if_none_match='0x111111111111111') + blob.set_http_headers(content_settings, etag='0x111111111111111', match_condition=MatchConditions.IfModified) # Assert properties = blob.get_blob_properties() @@ -663,7 +678,7 @@ def test_set_blob_properties_with_if_none_match_fail(self): content_settings = ContentSettings( content_language='spanish', content_disposition='inline') - blob.set_http_headers(content_settings, if_none_match=etag) + blob.set_http_headers(content_settings, etag=etag, match_condition=MatchConditions.IfModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -741,7 +756,7 @@ def test_get_blob_properties_with_if_match(self): etag = blob.get_blob_properties().etag # Act - properties = blob.get_blob_properties(if_match=etag) + properties = blob.get_blob_properties(etag=etag, match_condition=MatchConditions.IfNotModified) # Assert self.assertIsNotNone(properties) @@ -758,7 +773,7 @@ def test_get_blob_properties_with_if_match_fail(self): # Act with self.assertRaises(ResourceModifiedError) as e: blob = self.bsc.get_blob_client(self.container_name, 'blob1') - blob.get_blob_properties(if_match='0x111111111111111') + blob.get_blob_properties(etag='0x111111111111111', match_condition=MatchConditions.IfNotModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -771,7 +786,7 @@ def test_get_blob_properties_with_if_none_match(self): # Act blob = self.bsc.get_blob_client(self.container_name, 'blob1') - properties = blob.get_blob_properties(if_none_match='0x111111111111111') + properties = blob.get_blob_properties(etag='0x111111111111111', match_condition=MatchConditions.IfModified) # Assert self.assertIsNotNone(properties) @@ -789,7 +804,7 @@ def test_get_blob_properties_with_if_none_match_fail(self): # Act with self.assertRaises(ResourceModifiedError) as e: - blob.get_blob_properties(if_none_match=etag) + blob.get_blob_properties(etag=etag, match_condition=MatchConditions.IfModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -865,7 +880,7 @@ def test_get_blob_metadata_with_if_match(self): etag = blob.get_blob_properties().etag # Act - md = blob.get_blob_properties(if_match=etag).metadata + md = blob.get_blob_properties(etag=etag, match_condition=MatchConditions.IfNotModified).metadata # Assert self.assertIsNotNone(md) @@ -879,7 +894,7 @@ def test_get_blob_metadata_with_if_match_fail(self): # Act with self.assertRaises(ResourceModifiedError) as e: blob = self.bsc.get_blob_client(self.container_name, 'blob1') - blob.get_blob_properties(if_match='0x111111111111111').metadata + blob.get_blob_properties(etag='0x111111111111111', match_condition=MatchConditions.IfNotModified).metadata # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -892,7 +907,7 @@ def test_get_blob_metadata_with_if_none_match(self): # Act blob = self.bsc.get_blob_client(self.container_name, 'blob1') - md = blob.get_blob_properties(if_none_match='0x111111111111111').metadata + md = blob.get_blob_properties(etag='0x111111111111111', match_condition=MatchConditions.IfModified).metadata # Assert self.assertIsNotNone(md) @@ -907,7 +922,7 @@ def test_get_blob_metadata_with_if_none_match_fail(self): # Act with self.assertRaises(ResourceModifiedError) as e: - blob.get_blob_properties(if_none_match=etag).metadata + blob.get_blob_properties(etag=etag, match_condition=MatchConditions.IfModified).metadata # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -990,7 +1005,7 @@ def test_set_blob_metadata_with_if_match(self): # Act metadata = {'hello': 'world', 'number': '42'} - blob.set_blob_metadata(metadata, if_match=etag) + blob.set_blob_metadata(metadata, etag=etag, match_condition=MatchConditions.IfNotModified) # Assert md = blob.get_blob_properties().metadata @@ -1006,7 +1021,7 @@ def test_set_blob_metadata_with_if_match_fail(self): with self.assertRaises(ResourceModifiedError) as e: metadata = {'hello': 'world', 'number': '42'} blob = self.bsc.get_blob_client(self.container_name, 'blob1') - blob.set_blob_metadata(metadata, if_match='0x111111111111111') + blob.set_blob_metadata(metadata, etag='0x111111111111111', match_condition=MatchConditions.IfNotModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -1020,7 +1035,7 @@ def test_set_blob_metadata_with_if_none_match(self): # Act metadata = {'hello': 'world', 'number': '42'} blob = self.bsc.get_blob_client(self.container_name, 'blob1') - blob.set_blob_metadata(metadata, if_none_match='0x111111111111111') + blob.set_blob_metadata(metadata, etag='0x111111111111111', match_condition=MatchConditions.IfModified) # Assert md = blob.get_blob_properties().metadata @@ -1037,7 +1052,7 @@ def test_set_blob_metadata_with_if_none_match_fail(self): # Act with self.assertRaises(ResourceModifiedError) as e: metadata = {'hello': 'world', 'number': '42'} - blob.set_blob_metadata(metadata, if_none_match=etag) + blob.set_blob_metadata(metadata, etag=etag, match_condition=MatchConditions.IfModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -1114,7 +1129,7 @@ def test_delete_blob_with_if_match(self): # Act - resp = blob.delete_blob(if_match=etag) + resp = blob.delete_blob(etag=etag, match_condition=MatchConditions.IfNotModified) # Assert self.assertIsNone(resp) @@ -1128,7 +1143,7 @@ def test_delete_blob_with_if_match_fail(self): # Act blob = self.bsc.get_blob_client(self.container_name, 'blob1') with self.assertRaises(ResourceModifiedError) as e: - blob.delete_blob(if_match='0x111111111111111') + blob.delete_blob(etag='0x111111111111111', match_condition=MatchConditions.IfNotModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -1141,7 +1156,7 @@ def test_delete_blob_with_if_none_match(self): # Act blob = self.bsc.get_blob_client(self.container_name, 'blob1') - resp = blob.delete_blob(if_none_match='0x111111111111111') + resp = blob.delete_blob(etag='0x111111111111111', match_condition=MatchConditions.IfModified) # Assert self.assertIsNone(resp) @@ -1156,7 +1171,7 @@ def test_delete_blob_with_if_none_match_fail(self): # Act with self.assertRaises(ResourceModifiedError) as e: - blob.delete_blob(if_none_match=etag) + blob.delete_blob(etag=etag, match_condition=MatchConditions.IfModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -1234,7 +1249,7 @@ def test_snapshot_blob_with_if_match(self): etag = blob.get_blob_properties().etag # Act - resp = blob.create_snapshot(if_match=etag) + resp = blob.create_snapshot(etag=etag, match_condition=MatchConditions.IfNotModified) # Assert self.assertIsNotNone(resp) @@ -1249,7 +1264,7 @@ def test_snapshot_blob_with_if_match_fail(self): # Act with self.assertRaises(ResourceModifiedError) as e: blob = self.bsc.get_blob_client(self.container_name, 'blob1') - blob.create_snapshot(if_match='0x111111111111111') + blob.create_snapshot(etag='0x111111111111111', match_condition=MatchConditions.IfNotModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -1262,7 +1277,7 @@ def test_snapshot_blob_with_if_none_match(self): # Act blob = self.bsc.get_blob_client(self.container_name, 'blob1') - resp = blob.create_snapshot(if_none_match='0x111111111111111') + resp = blob.create_snapshot(etag='0x111111111111111', match_condition=MatchConditions.IfModified) # Assert self.assertIsNotNone(resp) @@ -1278,7 +1293,7 @@ def test_snapshot_blob_with_if_none_match_fail(self): # Act with self.assertRaises(ResourceModifiedError) as e: - blob.create_snapshot(if_none_match=etag) + blob.create_snapshot(etag=etag, match_condition=MatchConditions.IfModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -1369,7 +1384,7 @@ def test_lease_blob_with_if_match(self): # Act lease = blob.acquire_lease( lease_id=test_lease_id, - if_match=etag) + etag=etag, match_condition=MatchConditions.IfNotModified) lease.break_lease() @@ -1386,7 +1401,7 @@ def test_lease_blob_with_if_match_fail(self): # Act blob = self.bsc.get_blob_client(self.container_name, 'blob1') with self.assertRaises(ResourceModifiedError) as e: - blob.acquire_lease(if_match='0x111111111111111') + blob.acquire_lease(etag='0x111111111111111', match_condition=MatchConditions.IfNotModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -1402,7 +1417,8 @@ def test_lease_blob_with_if_none_match(self): blob = self.bsc.get_blob_client(self.container_name, 'blob1') lease = blob.acquire_lease( lease_id=test_lease_id, - if_none_match='0x111111111111111') + etag='0x111111111111111', + match_condition=MatchConditions.IfModified) lease.break_lease() @@ -1420,7 +1436,7 @@ def test_lease_blob_with_if_none_match_fail(self): # Act with self.assertRaises(ResourceModifiedError) as e: - blob.acquire_lease(if_none_match=etag) + blob.acquire_lease(etag=etag, match_condition=MatchConditions.IfModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -1515,7 +1531,7 @@ def test_put_block_list_with_if_match(self): # Act block_list = [BlobBlock(block_id='1'), BlobBlock(block_id='2'), BlobBlock(block_id='3')] - blob.commit_block_list(block_list, if_match=etag) + blob.commit_block_list(block_list, etag=etag, match_condition=MatchConditions.IfNotModified) # Assert content = blob.download_blob() @@ -1534,7 +1550,7 @@ def test_put_block_list_with_if_match_fail(self): with self.assertRaises(ResourceModifiedError) as e: blob.commit_block_list( [BlobBlock(block_id='1'), BlobBlock(block_id='2'), BlobBlock(block_id='3')], - if_match='0x111111111111111') + etag='0x111111111111111', match_condition=MatchConditions.IfNotModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -1550,7 +1566,7 @@ def test_put_block_list_with_if_none_match(self): # Act block_list = [BlobBlock(block_id='1'), BlobBlock(block_id='2'), BlobBlock(block_id='3')] - blob.commit_block_list(block_list, if_none_match='0x111111111111111') + blob.commit_block_list(block_list, etag='0x111111111111111', match_condition=MatchConditions.IfModified) # Assert content = blob.download_blob() @@ -1569,7 +1585,7 @@ def test_put_block_list_with_if_none_match_fail(self): # Act with self.assertRaises(ResourceModifiedError) as e: block_list = [BlobBlock(block_id='1'), BlobBlock(block_id='2'), BlobBlock(block_id='3')] - blob.commit_block_list(block_list, if_none_match=etag) + blob.commit_block_list(block_list, etag=etag, match_condition=MatchConditions.IfModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -1648,7 +1664,7 @@ def test_update_page_with_if_match(self): etag = blob.get_blob_properties().etag # Act - blob.upload_page(data, offset=0, length=512, if_match=etag) + blob.upload_page(data, offset=0, length=512, etag=etag, match_condition=MatchConditions.IfNotModified) # Assert @@ -1662,7 +1678,7 @@ def test_update_page_with_if_match_fail(self): # Act blob = self.bsc.get_blob_client(self.container_name, 'blob1') with self.assertRaises(ResourceModifiedError) as e: - blob.upload_page(data, offset=0, length=512, if_match='0x111111111111111') + blob.upload_page(data, offset=0, length=512, etag='0x111111111111111', match_condition=MatchConditions.IfNotModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -1676,7 +1692,7 @@ def test_update_page_with_if_none_match(self): # Act blob = self.bsc.get_blob_client(self.container_name, 'blob1') - blob.upload_page(data, offset=0, length=512, if_none_match='0x111111111111111') + blob.upload_page(data, offset=0, length=512, etag='0x111111111111111', match_condition=MatchConditions.IfModified) # Assert @@ -1691,7 +1707,7 @@ def test_update_page_with_if_none_match_fail(self): # Act with self.assertRaises(ResourceModifiedError) as e: - blob.upload_page(data, offset=0, length=512, if_none_match=etag) + blob.upload_page(data, offset=0, length=512, etag=etag, match_condition=MatchConditions.IfModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -1781,7 +1797,7 @@ def test_get_page_ranges_iter_with_if_match(self): etag = blob.get_blob_properties().etag # Act - ranges = blob.get_page_ranges(if_match=etag) + ranges = blob.get_page_ranges(etag=etag, match_condition=MatchConditions.IfNotModified) # Assert self.assertEqual(len(ranges[0]), 2) @@ -1799,7 +1815,7 @@ def test_get_page_ranges_iter_with_if_match_fail(self): # Act with self.assertRaises(ResourceModifiedError) as e: - blob.get_page_ranges(if_match='0x111111111111111') + blob.get_page_ranges(etag='0x111111111111111', match_condition=MatchConditions.IfNotModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -1814,7 +1830,7 @@ def test_get_page_ranges_iter_with_if_none_match(self): blob.upload_page(data, offset=1024, length=512) # Act - ranges = blob.get_page_ranges(if_none_match='0x111111111111111') + ranges = blob.get_page_ranges(etag='0x111111111111111', match_condition=MatchConditions.IfModified) # Assert self.assertEqual(len(ranges[0]), 2) @@ -1834,7 +1850,7 @@ def test_get_page_ranges_iter_with_if_none_match_fail(self): # Act with self.assertRaises(ResourceModifiedError) as e: - blob.get_page_ranges(if_none_match=etag) + blob.get_page_ranges(etag=etag, match_condition=MatchConditions.IfModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -1905,7 +1921,7 @@ def test_append_block_with_if_match(self): # Act for i in range(5): etag = blob.get_blob_properties().etag - resp = blob.append_block(u'block {0}'.format(i), if_match=etag) + resp = blob.append_block(u'block {0}'.format(i), etag=etag, match_condition=MatchConditions.IfNotModified) self.assertIsNotNone(resp) # Assert @@ -1920,7 +1936,7 @@ def test_append_block_with_if_match_fail(self): # Act with self.assertRaises(HttpResponseError) as e: for i in range(5): - resp = blob.append_block(u'block {0}'.format(i), if_match='0x111111111111111') + resp = blob.append_block(u'block {0}'.format(i), etag='0x111111111111111', match_condition=MatchConditions.IfNotModified) # Assert #self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -1932,7 +1948,7 @@ def test_append_block_with_if_none_match(self): # Act for i in range(5): - resp = blob.append_block(u'block {0}'.format(i), if_none_match='0x8D2C9167D53FC2C') + resp = blob.append_block(u'block {0}'.format(i), etag='0x8D2C9167D53FC2C', match_condition=MatchConditions.IfModified) self.assertIsNotNone(resp) # Assert @@ -1948,7 +1964,7 @@ def test_append_block_with_if_none_match_fail(self): with self.assertRaises(ResourceModifiedError) as e: for i in range(5): etag = blob.get_blob_properties().etag - resp = blob.append_block(u'block {0}'.format(i), if_none_match=etag) + resp = blob.append_block(u'block {0}'.format(i), etag=etag, match_condition=MatchConditions.IfModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -2020,7 +2036,7 @@ def test_append_blob_from_bytes_with_if_match(self): # Act data = self.get_random_bytes(LARGE_APPEND_BLOB_SIZE) - blob.upload_blob(data, blob_type=BlobType.AppendBlob, if_match=test_etag) + blob.upload_blob(data, blob_type=BlobType.AppendBlob, etag=test_etag, match_condition=MatchConditions.IfNotModified) # Assert content = b"".join(list(blob.download_blob())) @@ -2036,7 +2052,7 @@ def test_append_blob_from_bytes_with_if_match_fail(self): # Act with self.assertRaises(ResourceModifiedError) as e: data = self.get_random_bytes(LARGE_APPEND_BLOB_SIZE) - blob.upload_blob(data, blob_type=BlobType.AppendBlob, if_match=test_etag) + blob.upload_blob(data, blob_type=BlobType.AppendBlob, etag=test_etag, match_condition=MatchConditions.IfNotModified) self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -2049,7 +2065,7 @@ def test_append_blob_from_bytes_with_if_none_match(self): # Act data = self.get_random_bytes(LARGE_APPEND_BLOB_SIZE) - blob.upload_blob(data, blob_type=BlobType.AppendBlob, if_none_match=test_etag) + blob.upload_blob(data, blob_type=BlobType.AppendBlob, etag=test_etag, match_condition=MatchConditions.IfModified) # Assert content = b"".join(list(blob.download_blob())) @@ -2065,7 +2081,7 @@ def test_append_blob_from_bytes_with_if_none_match_fail(self): # Act with self.assertRaises(ResourceModifiedError) as e: data = self.get_random_bytes(LARGE_APPEND_BLOB_SIZE) - blob.upload_blob(data, blob_type=BlobType.AppendBlob, if_none_match=test_etag) + blob.upload_blob(data, blob_type=BlobType.AppendBlob, etag=test_etag, match_condition=MatchConditions.IfModified) self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) diff --git a/sdk/storage/azure-storage-blob/tests/test_blob_access_conditions_async.py b/sdk/storage/azure-storage-blob/tests/test_blob_access_conditions_async.py index df0fa22d4748..98d90b8871ee 100644 --- a/sdk/storage/azure-storage-blob/tests/test_blob_access_conditions_async.py +++ b/sdk/storage/azure-storage-blob/tests/test_blob_access_conditions_async.py @@ -12,6 +12,7 @@ import os import unittest +from azure.core import MatchConditions from azure.core.exceptions import HttpResponseError, ResourceNotFoundError, ResourceModifiedError from azure.core.pipeline.transport import AioHttpTransport from multidict import CIMultiDict, CIMultiDictProxy @@ -449,7 +450,7 @@ async def _test_put_blob_with_if_match_async(self): etag = (await blob.get_blob_properties()).etag # Act - resp = await blob.upload_blob(data, length=len(data), if_match=etag) + resp = await blob.upload_blob(data, length=len(data), etag=etag, match_condition=MatchConditions.IfNotModified) # Assert self.assertIsNotNone(resp.get('etag')) @@ -467,7 +468,9 @@ async def _test_put_blob_with_if_match_fail_async(self): # Act with self.assertRaises(ResourceModifiedError) as e: - await blob.upload_blob(data, length=len(data), if_match='0x111111111111111', overwrite=True) + await blob.upload_blob( + data, length=len(data), etag='0x111111111111111', + match_condition=MatchConditions.IfNotModified, overwrite=True) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -484,7 +487,7 @@ async def _test_put_blob_with_if_none_match_async(self): self.container_name, 'blob1', data) # Act - resp = await blob.upload_blob(data, length=len(data), if_none_match='0x111111111111111') + resp = await blob.upload_blob(data, length=len(data), etag='0x111111111111111', match_condition=MatchConditions.IfModified) # Assert self.assertIsNotNone(resp.get('etag')) @@ -503,7 +506,7 @@ async def _test_put_blob_with_if_none_match_fail_async(self): # Act with self.assertRaises(ResourceModifiedError) as e: - await blob.upload_blob(data, length=len(data), if_none_match=etag, overwrite=True) + await blob.upload_blob(data, length=len(data), etag=etag, match_condition=MatchConditions.IfModified, overwrite=True) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -596,7 +599,7 @@ async def _test_get_blob_with_if_match_async(self): etag = (await blob.get_blob_properties()).etag # Act - content = await blob.download_blob(if_match=etag) + content = await blob.download_blob(etag=etag, match_condition=MatchConditions.IfNotModified) content = await content.content_as_bytes() # Assert @@ -614,7 +617,7 @@ async def _test_get_blob_with_if_match_fail_async(self): # Act with self.assertRaises(ResourceModifiedError) as e: - await blob.download_blob(if_match='0x111111111111111') + await blob.download_blob(etag='0x111111111111111', match_condition=MatchConditions.IfNotModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -630,7 +633,7 @@ async def _test_get_blob_with_if_none_match_async(self): self.container_name, 'blob1', b'hello world') # Act - content = await blob.download_blob(if_none_match='0x111111111111111') + content = await blob.download_blob(etag='0x111111111111111', match_condition=MatchConditions.IfModified) content = await content.content_as_bytes() # Assert @@ -649,7 +652,7 @@ async def _test_get_blob_with_if_none_match_fail_async(self): # Act with self.assertRaises(ResourceModifiedError) as e: - await blob.download_blob(if_none_match=etag) + await blob.download_blob(etag=etag, match_condition=MatchConditions.IfModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -760,7 +763,7 @@ async def _test_set_blob_properties_with_if_match_async(self): content_settings = ContentSettings( content_language='spanish', content_disposition='inline') - await blob.set_http_headers(content_settings, if_match=etag) + await blob.set_http_headers(content_settings, etag=etag, match_condition=MatchConditions.IfNotModified) # Assert properties = await blob.get_blob_properties() @@ -783,7 +786,7 @@ async def _test_set_blob_properties_with_if_match_fail_async(self): content_language='spanish', content_disposition='inline') blob = self.bsc.get_blob_client(self.container_name, 'blob1') - await blob.set_http_headers(content_settings, if_match='0x111111111111111') + await blob.set_http_headers(content_settings, etag='0x111111111111111', match_condition=MatchConditions.IfNotModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -803,7 +806,7 @@ async def _test_set_blob_properties_with_if_none_match_async(self): content_language='spanish', content_disposition='inline') blob = self.bsc.get_blob_client(self.container_name, 'blob1') - await blob.set_http_headers(content_settings, if_none_match='0x111111111111111') + await blob.set_http_headers(content_settings, etag='0x111111111111111', match_condition=MatchConditions.IfModified) # Assert properties = await blob.get_blob_properties() @@ -827,7 +830,7 @@ async def _test_set_blob_properties_with_if_none_match_fail_async(self): content_settings = ContentSettings( content_language='spanish', content_disposition='inline') - await blob.set_http_headers(content_settings, if_none_match=etag) + await blob.set_http_headers(content_settings, etag=etag, match_condition=MatchConditions.IfModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -925,7 +928,7 @@ async def _test_get_blob_properties_with_if_match_async(self): etag = (await blob.get_blob_properties()).etag # Act - properties = await blob.get_blob_properties(if_match=etag) + properties = await blob.get_blob_properties(etag=etag, match_condition=MatchConditions.IfNotModified) # Assert self.assertIsNotNone(properties) @@ -946,7 +949,7 @@ async def _test_get_blob_properties_with_if_match_fail_async(self): # Act with self.assertRaises(ResourceModifiedError) as e: blob = self.bsc.get_blob_client(self.container_name, 'blob1') - await blob.get_blob_properties(if_match='0x111111111111111') + await blob.get_blob_properties(etag='0x111111111111111', match_condition=MatchConditions.IfNotModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -963,7 +966,7 @@ async def _test_get_blob_properties_with_if_none_match_async(self): # Act blob = self.bsc.get_blob_client(self.container_name, 'blob1') - properties = await blob.get_blob_properties(if_none_match='0x111111111111111') + properties = await blob.get_blob_properties(etag='0x111111111111111', match_condition=MatchConditions.IfModified) # Assert self.assertIsNotNone(properties) @@ -985,7 +988,7 @@ async def _test_get_blob_properties_with_if_none_match_fail_async(self): # Act with self.assertRaises(ResourceModifiedError) as e: - await blob.get_blob_properties(if_none_match=etag) + await blob.get_blob_properties(etag=etag, match_condition=MatchConditions.IfModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -1081,7 +1084,7 @@ async def _test_get_blob_metadata_with_if_match_async(self): etag = (await blob.get_blob_properties()).etag # Act - md = (await blob.get_blob_properties(if_match=etag)).metadata + md = (await blob.get_blob_properties(etag=etag, match_condition=MatchConditions.IfNotModified)).metadata # Assert self.assertIsNotNone(md) @@ -1099,7 +1102,7 @@ async def _test_get_blob_metadata_with_if_match_fail_async(self): # Act with self.assertRaises(ResourceModifiedError) as e: blob = self.bsc.get_blob_client(self.container_name, 'blob1') - await blob.get_blob_properties(if_match='0x111111111111111') + await blob.get_blob_properties(etag='0x111111111111111', match_condition=MatchConditions.IfNotModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -1116,7 +1119,7 @@ async def _test_get_blob_metadata_with_if_none_match_async(self): # Act blob = self.bsc.get_blob_client(self.container_name, 'blob1') - md = (await blob.get_blob_properties(if_none_match='0x111111111111111')).metadata + md = (await blob.get_blob_properties(etag='0x111111111111111', match_condition=MatchConditions.IfModified)).metadata # Assert self.assertIsNotNone(md) @@ -1135,7 +1138,7 @@ async def _test_get_blob_metadata_with_if_none_match_fail_async(self): # Act with self.assertRaises(ResourceModifiedError) as e: - await blob.get_blob_properties(if_none_match=etag) + await blob.get_blob_properties(etag=etag, match_condition=MatchConditions.IfModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -1238,7 +1241,7 @@ async def _test_set_blob_metadata_with_if_match_async(self): # Act metadata = {'hello': 'world', 'number': '42'} - await blob.set_blob_metadata(metadata, if_match=etag) + await blob.set_blob_metadata(metadata, etag=etag, match_condition=MatchConditions.IfNotModified) # Assert md = (await blob.get_blob_properties()).metadata @@ -1258,7 +1261,7 @@ async def _test_set_blob_metadata_with_if_match_fail_async(self): with self.assertRaises(ResourceModifiedError) as e: metadata = {'hello': 'world', 'number': '42'} blob = self.bsc.get_blob_client(self.container_name, 'blob1') - await blob.set_blob_metadata(metadata, if_match='0x111111111111111') + await blob.set_blob_metadata(metadata, etag='0x111111111111111', match_condition=MatchConditions.IfNotModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -1276,7 +1279,7 @@ async def _test_set_blob_metadata_with_if_none_match_async(self): # Act metadata = {'hello': 'world', 'number': '42'} blob = self.bsc.get_blob_client(self.container_name, 'blob1') - await blob.set_blob_metadata(metadata, if_none_match='0x111111111111111') + await blob.set_blob_metadata(metadata, etag='0x111111111111111', match_condition=MatchConditions.IfModified) # Assert md = (await blob.get_blob_properties()).metadata @@ -1297,7 +1300,7 @@ async def _test_set_blob_metadata_with_if_none_match_fail_async(self): # Act with self.assertRaises(ResourceModifiedError) as e: metadata = {'hello': 'world', 'number': '42'} - await blob.set_blob_metadata(metadata, if_none_match=etag) + await blob.set_blob_metadata(metadata, etag=etag, match_condition=MatchConditions.IfModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -1394,7 +1397,7 @@ async def _test_delete_blob_with_if_match_async(self): # Act - resp = await blob.delete_blob(if_match=etag) + resp = await blob.delete_blob(etag=etag, match_condition=MatchConditions.IfNotModified) # Assert self.assertIsNone(resp) @@ -1412,7 +1415,7 @@ async def _test_delete_blob_with_if_match_fail_async(self): # Act blob = self.bsc.get_blob_client(self.container_name, 'blob1') with self.assertRaises(ResourceModifiedError) as e: - await blob.delete_blob(if_match='0x111111111111111') + await blob.delete_blob(etag='0x111111111111111', match_condition=MatchConditions.IfNotModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -1429,7 +1432,7 @@ async def _test_delete_blob_with_if_none_match_async(self): # Act blob = self.bsc.get_blob_client(self.container_name, 'blob1') - resp = await blob.delete_blob(if_none_match='0x111111111111111') + resp = await blob.delete_blob(etag='0x111111111111111', match_condition=MatchConditions.IfModified) # Assert self.assertIsNone(resp) @@ -1448,7 +1451,7 @@ async def _test_delete_blob_with_if_none_match_fail_async(self): # Act with self.assertRaises(ResourceModifiedError) as e: - await blob.delete_blob(if_none_match=etag) + await blob.delete_blob(etag=etag, match_condition=MatchConditions.IfModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -1546,7 +1549,7 @@ async def _test_snapshot_blob_with_if_match_async(self): etag = (await blob.get_blob_properties()).etag # Act - resp = await blob.create_snapshot(if_match=etag) + resp = await blob.create_snapshot(etag=etag, match_condition=MatchConditions.IfNotModified) # Assert self.assertIsNotNone(resp) @@ -1565,7 +1568,7 @@ async def _test_snapshot_blob_with_if_match_fail_async(self): # Act with self.assertRaises(ResourceModifiedError) as e: blob = self.bsc.get_blob_client(self.container_name, 'blob1') - await blob.create_snapshot(if_match='0x111111111111111') + await blob.create_snapshot(etag='0x111111111111111', match_condition=MatchConditions.IfNotModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -1582,7 +1585,7 @@ async def _test_snapshot_blob_with_if_none_match_async(self): # Act blob = self.bsc.get_blob_client(self.container_name, 'blob1') - resp = await blob.create_snapshot(if_none_match='0x111111111111111') + resp = await blob.create_snapshot(etag='0x111111111111111', match_condition=MatchConditions.IfModified) # Assert self.assertIsNotNone(resp) @@ -1602,7 +1605,7 @@ async def _test_snapshot_blob_with_if_none_match_fail_async(self): # Act with self.assertRaises(ResourceModifiedError) as e: - await blob.create_snapshot(if_none_match=etag) + await blob.create_snapshot(etag=etag, match_condition=MatchConditions.IfModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -1713,7 +1716,7 @@ async def _test_lease_blob_with_if_match_async(self): # Act lease = await blob.acquire_lease( lease_id=test_lease_id, - if_match=etag) + etag=etag, match_condition=MatchConditions.IfNotModified) await lease.break_lease() @@ -1734,7 +1737,7 @@ async def _test_lease_blob_with_if_match_fail_async(self): # Act blob = self.bsc.get_blob_client(self.container_name, 'blob1') with self.assertRaises(ResourceModifiedError) as e: - await blob.acquire_lease(if_match='0x111111111111111') + await blob.acquire_lease(etag='0x111111111111111', match_condition=MatchConditions.IfNotModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -1754,7 +1757,8 @@ async def _test_lease_blob_with_if_none_match_async(self): blob = self.bsc.get_blob_client(self.container_name, 'blob1') lease = await blob.acquire_lease( lease_id=test_lease_id, - if_none_match='0x111111111111111') + etag='0x111111111111111', + match_condition=MatchConditions.IfModified) await lease.break_lease() @@ -1776,7 +1780,7 @@ async def _test_lease_blob_with_if_none_match_fail_async(self): # Act with self.assertRaises(ResourceModifiedError) as e: - await blob.acquire_lease(if_none_match=etag) + await blob.acquire_lease(etag=etag, match_condition=MatchConditions.IfModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -1898,7 +1902,7 @@ async def _test_put_block_list_with_if_match_async(self): # Act block_list = [BlobBlock(block_id='1'), BlobBlock(block_id='2'), BlobBlock(block_id='3')] - await blob.commit_block_list(block_list, if_match=etag) + await blob.commit_block_list(block_list, etag=etag, match_condition=MatchConditions.IfNotModified) # Assert content = await blob.download_blob() @@ -1923,7 +1927,7 @@ async def _test_put_block_list_with_if_match_fail_async(self): with self.assertRaises(ResourceModifiedError) as e: await blob.commit_block_list( [BlobBlock(block_id='1'), BlobBlock(block_id='2'), BlobBlock(block_id='3')], - if_match='0x111111111111111') + etag='0x111111111111111', match_condition=MatchConditions.IfNotModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -1944,7 +1948,7 @@ async def _test_put_block_list_with_if_none_match_async(self): # Act block_list = [BlobBlock(block_id='1'), BlobBlock(block_id='2'), BlobBlock(block_id='3')] - await blob.commit_block_list(block_list, if_none_match='0x111111111111111') + await blob.commit_block_list(block_list, etag='0x111111111111111', match_condition=MatchConditions.IfModified) # Assert content = await blob.download_blob() @@ -1969,7 +1973,7 @@ async def _test_put_block_list_with_if_none_match_fail_async(self): # Act with self.assertRaises(ResourceModifiedError) as e: block_list = [BlobBlock(block_id='1'), BlobBlock(block_id='2'), BlobBlock(block_id='3')] - await blob.commit_block_list(block_list, if_none_match=etag) + await blob.commit_block_list(block_list, etag=etag, match_condition=MatchConditions.IfModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -2068,7 +2072,7 @@ async def _test_update_page_with_if_match_async(self): etag = (await blob.get_blob_properties()).etag # Act - await blob.upload_page(data, offset=0, length=512, if_match=etag) + await blob.upload_page(data, offset=0, length=512, etag=etag, match_condition=MatchConditions.IfNotModified) # Assert @@ -2086,7 +2090,7 @@ async def _test_update_page_with_if_match_fail_async(self): # Act blob = self.bsc.get_blob_client(self.container_name, 'blob1') with self.assertRaises(ResourceModifiedError) as e: - await blob.upload_page(data, offset=0, length=512, if_match='0x111111111111111') + await blob.upload_page(data, offset=0, length=512, etag='0x111111111111111', match_condition=MatchConditions.IfNotModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -2104,7 +2108,7 @@ async def _test_update_page_with_if_none_match_async(self): # Act blob = self.bsc.get_blob_client(self.container_name, 'blob1') - await blob.upload_page(data, offset=0, length=512, if_none_match='0x111111111111111') + await blob.upload_page(data, offset=0, length=512, etag='0x111111111111111', match_condition=MatchConditions.IfModified) # Assert @@ -2123,7 +2127,7 @@ async def _test_update_page_with_if_none_match_fail_async(self): # Act with self.assertRaises(ResourceModifiedError) as e: - await blob.upload_page(data, offset=0, length=512, if_none_match=etag) + await blob.upload_page(data, offset=0, length=512, etag=etag, match_condition=MatchConditions.IfModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -2228,7 +2232,7 @@ async def _test_get_page_ranges_iter_with_if_match_async(self): etag = (await blob.get_blob_properties()).etag # Act - ranges = await blob.get_page_ranges(if_match=etag) + ranges = await blob.get_page_ranges(etag=etag, match_condition=MatchConditions.IfNotModified) # Assert self.assertEqual(len(ranges[0]), 2) @@ -2249,7 +2253,7 @@ async def _test_get_page_ranges_iter_with_if_match_fail_async(self): # Act with self.assertRaises(ResourceModifiedError) as e: - await blob.get_page_ranges(if_match='0x111111111111111') + await blob.get_page_ranges(etag='0x111111111111111', match_condition=MatchConditions.IfNotModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -2267,7 +2271,7 @@ async def _test_get_page_ranges_iter_with_if_none_match_async(self): await asyncio.gather(blob.upload_page(data, offset=0, length=512), blob.upload_page(data, offset=1024, length=512)) # Act - ranges = await blob.get_page_ranges(if_none_match='0x111111111111111') + ranges = await blob.get_page_ranges(etag='0x111111111111111', match_condition=MatchConditions.IfModified) # Assert self.assertEqual(len(ranges[0]), 2) @@ -2290,7 +2294,7 @@ async def _test_get_page_ranges_iter_with_if_none_match_fail_async(self): # Act with self.assertRaises(ResourceModifiedError) as e: - await blob.get_page_ranges(if_none_match=etag) + await blob.get_page_ranges(etag=etag, match_condition=MatchConditions.IfModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -2383,7 +2387,7 @@ async def _test_append_block_with_if_match_async(self): # Act for i in range(5): etag = (await blob.get_blob_properties()).etag - resp = await blob.append_block(u'block {0}'.format(i), if_match=etag) + resp = await blob.append_block(u'block {0}'.format(i), etag=etag, match_condition=MatchConditions.IfNotModified) self.assertIsNotNone(resp) # Assert @@ -2403,7 +2407,7 @@ async def _test_append_block_with_if_match_fail_async(self): # Act with self.assertRaises(HttpResponseError) as e: for i in range(5): - resp = await blob.append_block(u'block {0}'.format(i), if_match='0x111111111111111') + resp = await blob.append_block(u'block {0}'.format(i), etag='0x111111111111111', match_condition=MatchConditions.IfNotModified) # Assert #self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -2419,7 +2423,7 @@ async def _test_append_block_with_if_none_match_async(self): # Act for i in range(5): - resp = await blob.append_block(u'block {0}'.format(i), if_none_match='0x8D2C9167D53FC2C') + resp = await blob.append_block(u'block {0}'.format(i), etag='0x8D2C9167D53FC2C', match_condition=MatchConditions.IfModified) self.assertIsNotNone(resp) # Assert @@ -2440,7 +2444,7 @@ async def _test_append_block_with_if_none_match_fail_async(self): with self.assertRaises(ResourceModifiedError) as e: for i in range(5): etag = (await blob.get_blob_properties()).etag - resp = await blob.append_block(u'block {0}'.format(i), if_none_match=etag) + resp = await blob.append_block(u'block {0}'.format(i), etag=etag, match_condition=MatchConditions.IfModified) # Assert self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -2534,7 +2538,7 @@ async def _test_append_blob_from_bytes_with_if_match_async(self): # Act data = self.get_random_bytes(LARGE_APPEND_BLOB_SIZE) - await blob.upload_blob(data, blob_type=BlobType.AppendBlob, if_match=test_etag) + await blob.upload_blob(data, blob_type=BlobType.AppendBlob, etag=test_etag, match_condition=MatchConditions.IfNotModified) # Assert content = await blob.download_blob() @@ -2555,7 +2559,7 @@ async def _test_append_blob_from_bytes_with_if_match_fail_async(self): # Act with self.assertRaises(ResourceModifiedError) as e: data = self.get_random_bytes(LARGE_APPEND_BLOB_SIZE) - await blob.upload_blob(data, blob_type=BlobType.AppendBlob, if_match=test_etag) + await blob.upload_blob(data, blob_type=BlobType.AppendBlob, etag=test_etag, match_condition=MatchConditions.IfNotModified) self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) @@ -2572,7 +2576,7 @@ async def _test_append_blob_from_bytes_with_if_none_match_async(self): # Act data = self.get_random_bytes(LARGE_APPEND_BLOB_SIZE) - await blob.upload_blob(data, blob_type=BlobType.AppendBlob, if_none_match=test_etag) + await blob.upload_blob(data, blob_type=BlobType.AppendBlob, etag=test_etag, match_condition=MatchConditions.IfModified) # Assert content = await blob.download_blob() @@ -2593,7 +2597,7 @@ async def _test_append_blob_from_bytes_with_if_none_match_fail_async(self): # Act with self.assertRaises(ResourceModifiedError) as e: data = self.get_random_bytes(LARGE_APPEND_BLOB_SIZE) - await blob.upload_blob(data, blob_type=BlobType.AppendBlob, if_none_match=test_etag) + await blob.upload_blob(data, blob_type=BlobType.AppendBlob, etag=test_etag, match_condition=MatchConditions.IfModified) self.assertEqual(StorageErrorCode.condition_not_met, e.exception.error_code) diff --git a/sdk/storage/azure-storage-blob/tests/test_page_blob.py b/sdk/storage/azure-storage-blob/tests/test_page_blob.py index a674618102a0..d182c4c81596 100644 --- a/sdk/storage/azure-storage-blob/tests/test_page_blob.py +++ b/sdk/storage/azure-storage-blob/tests/test_page_blob.py @@ -11,6 +11,7 @@ import os import unittest from datetime import datetime, timedelta +from azure.core import MatchConditions from azure.core.exceptions import HttpResponseError, ResourceExistsError, ResourceModifiedError from azure.storage.blob import ( @@ -557,7 +558,8 @@ def test_upload_pages_from_url_with_source_if_match(self): offset=0, length=SOURCE_BLOB_SIZE, source_offset=0, - source_if_match=source_properties.get('etag')) + source_etag=source_properties.get('etag'), + source_match_condition=MatchConditions.IfNotModified) self.assertIsNotNone(resp.get('etag')) self.assertIsNotNone(resp.get('last_modified')) @@ -573,7 +575,8 @@ def test_upload_pages_from_url_with_source_if_match(self): .upload_pages_from_url(source_blob_client.url + "?" + sas, offset=0, length=SOURCE_BLOB_SIZE, source_offset=0, - source_if_match='0x111111111111111') + source_etag='0x111111111111111', + source_match_condition=MatchConditions.IfNotModified) @record def test_upload_pages_from_url_with_source_if_none_match(self): @@ -598,7 +601,8 @@ def test_upload_pages_from_url_with_source_if_none_match(self): offset=0, length=SOURCE_BLOB_SIZE, source_offset=0, - source_if_none_match='0x111111111111111') + source_etag='0x111111111111111', + source_match_condition=MatchConditions.IfModified) self.assertIsNotNone(resp.get('etag')) self.assertIsNotNone(resp.get('last_modified')) @@ -614,7 +618,8 @@ def test_upload_pages_from_url_with_source_if_none_match(self): .upload_pages_from_url(source_blob_client.url + "?" + sas, offset=0, length=SOURCE_BLOB_SIZE, source_offset=0, - source_if_none_match=source_properties.get('etag')) + source_etag=source_properties.get('etag'), + source_match_condition=MatchConditions.IfModified) @record def test_upload_pages_from_url_with_if_modified(self): @@ -719,12 +724,10 @@ def test_upload_pages_from_url_with_if_match(self): destination_blob_properties = destination_blob_client.get_blob_properties() # Act: make update page from url calls - resp = destination_blob_client \ - .upload_pages_from_url(source_blob_client.url + "?" + sas, - 0, - SOURCE_BLOB_SIZE, - 0, - if_match=destination_blob_properties.get('etag')) + resp = destination_blob_client.upload_pages_from_url( + source_blob_client.url + "?" + sas, 0, SOURCE_BLOB_SIZE, 0, + etag=destination_blob_properties.get('etag'), + match_condition=MatchConditions.IfNotModified) self.assertIsNotNone(resp.get('etag')) self.assertIsNotNone(resp.get('last_modified')) @@ -736,11 +739,10 @@ def test_upload_pages_from_url_with_if_match(self): # Act part 2: put block from url with failing condition with self.assertRaises(HttpResponseError): - destination_blob_client \ - .upload_pages_from_url(source_blob_client.url + "?" + sas, 0, - SOURCE_BLOB_SIZE, - 0, - if_match='0x111111111111111') + destination_blob_client.upload_pages_from_url( + source_blob_client.url + "?" + sas, 0, SOURCE_BLOB_SIZE, 0, + etag='0x111111111111111', + match_condition=MatchConditions.IfNotModified) @record def test_upload_pages_from_url_with_if_none_match(self): @@ -764,7 +766,8 @@ def test_upload_pages_from_url_with_if_none_match(self): 0, SOURCE_BLOB_SIZE, 0, - if_none_match='0x111111111111111') + etag='0x111111111111111', + match_condition=MatchConditions.IfModified) self.assertIsNotNone(resp.get('etag')) self.assertIsNotNone(resp.get('last_modified')) @@ -781,7 +784,8 @@ def test_upload_pages_from_url_with_if_none_match(self): .upload_pages_from_url(source_blob_client.url + "?" + sas, 0, SOURCE_BLOB_SIZE, 0, - if_none_match=blob_properties.get('etag')) + etag=blob_properties.get('etag'), + match_condition=MatchConditions.IfModified) @record def test_upload_pages_from_url_with_sequence_number_lt(self): diff --git a/sdk/storage/azure-storage-blob/tests/test_page_blob_async.py b/sdk/storage/azure-storage-blob/tests/test_page_blob_async.py index c72f075bb9c0..0099ed89029f 100644 --- a/sdk/storage/azure-storage-blob/tests/test_page_blob_async.py +++ b/sdk/storage/azure-storage-blob/tests/test_page_blob_async.py @@ -12,6 +12,7 @@ import unittest from datetime import datetime, timedelta +from azure.core import MatchConditions from azure.core.exceptions import HttpResponseError, ResourceExistsError from azure.core.pipeline.transport import AioHttpTransport from multidict import CIMultiDict, CIMultiDictProxy @@ -675,11 +676,10 @@ async def _test_upload_pages_from_url_with_source_if_match(self): destination_blob_client = await self._create_blob(SOURCE_BLOB_SIZE) # Act: make update page from url calls - resp = await destination_blob_client.upload_pages_from_url(source_blob_client.url + "?" + sas, - 0, - SOURCE_BLOB_SIZE, - 0, - source_if_match=source_properties.get('etag')) + resp = await destination_blob_client.upload_pages_from_url( + source_blob_client.url + "?" + sas, 0, SOURCE_BLOB_SIZE, 0, + source_etag=source_properties.get('etag'), + source_match_condition=MatchConditions.IfNotModified) self.assertIsNotNone(resp.get('etag')) self.assertIsNotNone(resp.get('last_modified')) @@ -691,10 +691,10 @@ async def _test_upload_pages_from_url_with_source_if_match(self): # Act part 2: put block from url with wrong md5 with self.assertRaises(HttpResponseError): - await destination_blob_client.upload_pages_from_url(source_blob_client.url + "?" + sas, 0, - SOURCE_BLOB_SIZE, - 0, - source_if_match='0x111111111111111') + await destination_blob_client.upload_pages_from_url( + source_blob_client.url + "?" + sas, 0, SOURCE_BLOB_SIZE, 0, + source_etag='0x111111111111111', + source_match_condition=MatchConditions.IfNotModified) @record def test_upload_pages_from_url_with_source_if_match_async(self): @@ -719,11 +719,9 @@ async def _test_upload_pages_from_url_with_source_if_none_match(self): destination_blob_client = await self._create_blob(SOURCE_BLOB_SIZE) # Act: make update page from url calls - resp = await destination_blob_client.upload_pages_from_url(source_blob_client.url + "?" + sas, - 0, - SOURCE_BLOB_SIZE, - 0, - source_if_none_match='0x111111111111111') + resp = await destination_blob_client.upload_pages_from_url( + source_blob_client.url + "?" + sas, 0, SOURCE_BLOB_SIZE, 0, + source_etag='0x111111111111111', source_match_condition=MatchConditions.IfModified) self.assertIsNotNone(resp.get('etag')) self.assertIsNotNone(resp.get('last_modified')) @@ -735,10 +733,9 @@ async def _test_upload_pages_from_url_with_source_if_none_match(self): # Act part 2: put block from url with wrong md5 with self.assertRaises(HttpResponseError): - await destination_blob_client.upload_pages_from_url(source_blob_client.url + "?" + sas, 0, - SOURCE_BLOB_SIZE, - 0, - source_if_none_match=source_properties.get('etag')) + await destination_blob_client.upload_pages_from_url( + source_blob_client.url + "?" + sas, 0, SOURCE_BLOB_SIZE, 0, + source_etag=source_properties.get('etag'), source_match_condition=MatchConditions.IfModified) @record def test_upload_pages_from_url_with_source_if_none_match_async(self): @@ -857,11 +854,10 @@ async def _test_upload_pages_from_url_with_if_match(self): destination_blob_properties = await destination_blob_client.get_blob_properties() # Act: make update page from url calls - resp = await destination_blob_client.upload_pages_from_url(source_blob_client.url + "?" + sas, - 0, - SOURCE_BLOB_SIZE, - 0, - if_match=destination_blob_properties.get('etag')) + resp = await destination_blob_client.upload_pages_from_url( + source_blob_client.url + "?" + sas, 0, SOURCE_BLOB_SIZE, 0, + etag=destination_blob_properties.get('etag'), + match_condition=MatchConditions.IfNotModified) self.assertIsNotNone(resp.get('etag')) self.assertIsNotNone(resp.get('last_modified')) @@ -873,10 +869,10 @@ async def _test_upload_pages_from_url_with_if_match(self): # Act part 2: put block from url with wrong md5 with self.assertRaises(HttpResponseError): - await destination_blob_client.upload_pages_from_url(source_blob_client.url + "?" + sas, 0, - SOURCE_BLOB_SIZE, - 0, - if_match='0x111111111111111') + await destination_blob_client.upload_pages_from_url( + source_blob_client.url + "?" + sas, 0, SOURCE_BLOB_SIZE, 0, + etag='0x111111111111111', + match_condition=MatchConditions.IfNotModified) @record def test_upload_pages_from_url_with_if_match_async(self): @@ -904,7 +900,8 @@ async def _test_upload_pages_from_url_with_if_none_match(self): 0, SOURCE_BLOB_SIZE, 0, - if_none_match='0x111111111111111') + etag='0x111111111111111', + match_condition=MatchConditions.IfModified) self.assertIsNotNone(resp.get('etag')) self.assertIsNotNone(resp.get('last_modified')) @@ -919,7 +916,8 @@ async def _test_upload_pages_from_url_with_if_none_match(self): await destination_blob_client.upload_pages_from_url(source_blob_client.url + "?" + sas, 0, SOURCE_BLOB_SIZE, 0, - if_none_match=blob_properties.get('etag')) + etag=blob_properties.get('etag'), + match_condition=MatchConditions.IfModified) @record def test_upload_pages_from_url_with_if_none_match_async(self):