From fcee27a0f660e5a3c6efc93bcac4b55e69835bab Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 20 Mar 2026 13:57:24 -0400 Subject: [PATCH 01/16] WIP --- .../storage/blob/_shared_access_signature.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py index 361403cd59b1..77f25436a781 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py @@ -26,19 +26,19 @@ class BlobQueryStringConstants(object): class BlobSharedAccessSignature(SharedAccessSignature): - ''' + """ Provides a factory for creating blob and container access signature tokens with a common account name and account key. Users can either use the factory or can construct the appropriate service and use the - generate_*_shared_access_signature method directly. - ''' + generate_*_sas method directly. + """ def __init__( self, account_name: str, account_key: Optional[str] = None, user_delegation_key: Optional[UserDelegationKey] = None ) -> None: - ''' + """ :param str account_name: The storage account name used to generate the shared access signatures. :param Optional[str] account_key: @@ -47,7 +47,7 @@ def __init__( Instead of an account key, the user could pass in a user delegation key. A user delegation key can be obtained from the service by authenticating with an AAD identity; this can be accomplished by calling get_user_delegation_key on any Blob service object. - ''' + """ super(BlobSharedAccessSignature, self).__init__(account_name, account_key, x_ms_version=X_MS_VERSION) self.user_delegation_key = user_delegation_key @@ -74,7 +74,7 @@ def generate_blob( sts_hook: Optional[Callable[[str], None]] = None, **kwargs: Any ) -> str: - ''' + """ Generates a shared access signature for the blob or one of its snapshots. Use the returned signature with the sas_token parameter of any BlobService. @@ -160,7 +160,7 @@ def generate_blob( :type sts_hook: Optional[Callable[[str], None]] :return: A Shared Access Signature (sas) token. :rtype: str - ''' + """ resource_path = container_name + '/' + blob_name sas = _BlobSharedAccessHelper() @@ -212,7 +212,7 @@ def generate_container( sts_hook: Optional[Callable[[str], None]] = None, **kwargs: Any ) -> str: - ''' + """ Generates a shared access signature for the container. Use the returned signature with the sas_token parameter of any BlobService. @@ -284,7 +284,7 @@ def generate_container( :type sts_hook: Optional[Callable[[str], None]] :return: A Shared Access Signature (sas) token. :rtype: str - ''' + """ sas = _BlobSharedAccessHelper() sas.add_base(permission, expiry, start, ip, protocol, self.x_ms_version) sas.add_id(policy_id) From 86e3163a31f606aedc53f17014cc321083227194 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Tue, 24 Mar 2026 15:42:15 -0400 Subject: [PATCH 02/16] Implementation --- .../azure/storage/blob/_shared_access_signature.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py index 77f25436a781..6b0d39861af4 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py @@ -170,7 +170,9 @@ def generate_blob( resource = 'bs' if snapshot else 'b' resource = 'bv' if version_id else resource - resource = 'd' if kwargs.pop("is_directory", None) else resource + if is_directory: + resource = 'd' + sas.add_directory_depth(blob_name) sas.add_resource(resource) sas.add_timestamp(snapshot or version_id) @@ -315,6 +317,12 @@ class _BlobSharedAccessHelper(_SharedAccessHelper): def add_timestamp(self, timestamp): self._add_query(BlobQueryStringConstants.SIGNED_TIMESTAMP, timestamp) + def add_directory_depth(self, blob_name): + if blob_name == "" or blob_name == "/": + self._add_query(QueryStringConstants.SIGNED_DIRECTORY_DEPTH, 0) + else: + self._add_query(QueryStringConstants.SIGNED_DIRECTORY_DEPTH, len(blob_name.strip("/").split("/"))) + def add_info_for_hns_account(self, **kwargs): self._add_query(QueryStringConstants.SIGNED_DIRECTORY_DEPTH, kwargs.pop('sdd', None)) self._add_query(QueryStringConstants.SIGNED_AUTHORIZED_OID, kwargs.pop('preauthorized_agent_object_id', None)) @@ -792,6 +800,7 @@ def generate_blob_sas( user_delegation_oid=user_delegation_oid, request_headers=request_headers, request_query_params=request_query_params, + is_directory=is_directory, sts_hook=sts_hook, **kwargs ) From a598b22cc3a3d2774b99aad8ea01c297f3f3ce28 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Tue, 24 Mar 2026 16:28:59 -0400 Subject: [PATCH 03/16] WIP --- .../storage/blob/_shared_access_signature.py | 9 +- .../tests/test_common_blob.py | 131 +++++++++++++++++- .../tests/test_directory_sas.py | 126 +++++++++++++++++ 3 files changed, 262 insertions(+), 4 deletions(-) create mode 100644 sdk/storage/azure-storage-blob/tests/test_directory_sas.py diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py index 6b0d39861af4..d7d5d1e9be66 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py @@ -319,12 +319,15 @@ def add_timestamp(self, timestamp): def add_directory_depth(self, blob_name): if blob_name == "" or blob_name == "/": - self._add_query(QueryStringConstants.SIGNED_DIRECTORY_DEPTH, 0) + depth = 0 else: - self._add_query(QueryStringConstants.SIGNED_DIRECTORY_DEPTH, len(blob_name.strip("/").split("/"))) + depth = len(blob_name.strip("/").split("/")) + self._add_query(QueryStringConstants.SIGNED_DIRECTORY_DEPTH, str(depth)) def add_info_for_hns_account(self, **kwargs): - self._add_query(QueryStringConstants.SIGNED_DIRECTORY_DEPTH, kwargs.pop('sdd', None)) + sdd = kwargs.pop('sdd', None) + if sdd is not None: + self._add_query(QueryStringConstants.SIGNED_DIRECTORY_DEPTH, str(sdd)) self._add_query(QueryStringConstants.SIGNED_AUTHORIZED_OID, kwargs.pop('preauthorized_agent_object_id', None)) self._add_query(QueryStringConstants.SIGNED_UNAUTHORIZED_OID, kwargs.pop('agent_object_id', None)) self._add_query(QueryStringConstants.SIGNED_CORRELATION_ID, kwargs.pop('correlation_id', None)) diff --git a/sdk/storage/azure-storage-blob/tests/test_common_blob.py b/sdk/storage/azure-storage-blob/tests/test_common_blob.py index 96a628d2161a..8f78b632474f 100644 --- a/sdk/storage/azure-storage-blob/tests/test_common_blob.py +++ b/sdk/storage/azure-storage-blob/tests/test_common_blob.py @@ -3830,4 +3830,133 @@ def test_smart_rehydrate(self, **kwargs): assert props is not None assert props.archive_status == "rehydrate-pending-to-smart" - # ------------------------------------------------------------------------------ \ No newline at end of file + # ------------------------------------------------------------------------------ + # Directory SAS tests (sr=d / sdd) + # ------------------------------------------------------------------------------ + + @pytest.mark.live_test_only + @BlobPreparer() + def test_directory_sas_all_permissions(self, **kwargs): + storage_account_name = kwargs.pop("storage_account_name") + storage_account_key = kwargs.pop("storage_account_key") + self._setup(storage_account_name, storage_account_key) + + expiry = datetime.utcnow() + timedelta(hours=1) + + for blob_name in ["foo", "foo/bar", "foo/bar/hello"]: + token = self.generate_sas( + generate_blob_sas, + account_name=storage_account_name, + container_name=self.container_name, + blob_name=blob_name, + account_key=storage_account_key.secret, + permission=BlobSasPermissions(read=True, write=True, delete=True, list=True, add=True, create=True), + expiry=expiry, + is_directory=True, + ) + + # Blob whose name exactly matches the SAS directory name should succeed + exact_blob = self.bsc.get_blob_client(self.container_name, blob_name) + BlobClient.from_blob_url(exact_blob.url, credential=token).upload_blob(b"data", overwrite=True) + + # Blob whose name has the SAS directory name as a prefix should also succeed + child_blob = self.bsc.get_blob_client(self.container_name, blob_name + "/test") + BlobClient.from_blob_url(child_blob.url, credential=token).upload_blob(b"data", overwrite=True) + + @pytest.mark.live_test_only + @BlobPreparer() + def test_directory_sas_all_permissions_fail(self, **kwargs): + storage_account_name = kwargs.pop("storage_account_name") + storage_account_key = kwargs.pop("storage_account_key") + self._setup(storage_account_name, storage_account_key) + + expiry = datetime.utcnow() + timedelta(hours=1) + # SAS is scoped to foo/bar/hello (depth 3) + token = self.generate_sas( + generate_blob_sas, + account_name=storage_account_name, + container_name=self.container_name, + blob_name="foo/bar/hello", + account_key=storage_account_key.secret, + permission=BlobSasPermissions(read=True, write=True, delete=True, list=True, add=True, create=True), + expiry=expiry, + is_directory=True, + ) + + # foo/bar does NOT have foo/bar/hello as a prefix — must fail + non_prefix_blob = self.bsc.get_blob_client(self.container_name, "foo/bar") + non_prefix_blob_with_sas = BlobClient.from_blob_url(non_prefix_blob.url, credential=token) + from azure.core.exceptions import HttpResponseError + with pytest.raises(HttpResponseError): + non_prefix_blob_with_sas.upload_blob(b"data", overwrite=True) + + @pytest.mark.live_test_only + @BlobPreparer() + def test_directory_identity_sas_all_permissions(self, **kwargs): + storage_account_name = kwargs.pop("storage_account_name") + + token_credential = self.get_credential(BlobServiceClient) + service = BlobServiceClient(self.account_url(storage_account_name, "blob"), credential=token_credential) + container_name = self.get_resource_name("directorysascontainer") + container = service.create_container(container_name) + + expiry = datetime.utcnow() + timedelta(hours=1) + user_delegation_key = service.get_user_delegation_key(datetime.utcnow(), expiry) + + for blob_name in ["foo", "foo/bar", "foo/bar/hello"]: + token = self.generate_sas( + generate_blob_sas, + account_name=storage_account_name, + container_name=container_name, + blob_name=blob_name, + user_delegation_key=user_delegation_key, + permission=BlobSasPermissions(read=True, write=True, delete=True, list=True, add=True, create=True), + expiry=expiry, + is_directory=True, + ) + + # Blob whose name exactly matches the SAS directory name should succeed + exact_blob = service.get_blob_client(container_name, blob_name) + BlobClient.from_blob_url(exact_blob.url, credential=token).upload_blob(b"data", overwrite=True) + + # Blob whose name has the SAS directory name as a prefix should also succeed + child_blob = service.get_blob_client(container_name, blob_name + "/test") + BlobClient.from_blob_url(child_blob.url, credential=token).upload_blob(b"data", overwrite=True) + + container.delete_container() + + @pytest.mark.live_test_only + @BlobPreparer() + def test_directory_identity_sas_all_permissions_fail(self, **kwargs): + storage_account_name = kwargs.pop("storage_account_name") + + token_credential = self.get_credential(BlobServiceClient) + service = BlobServiceClient(self.account_url(storage_account_name, "blob"), credential=token_credential) + container_name = self.get_resource_name("directorysascontainer") + service.create_container(container_name) + + expiry = datetime.utcnow() + timedelta(hours=1) + user_delegation_key = service.get_user_delegation_key(datetime.utcnow(), expiry) + + # SAS is scoped to foo/bar/hello (depth 3) + token = self.generate_sas( + generate_blob_sas, + account_name=storage_account_name, + container_name=container_name, + blob_name="foo/bar/hello", + user_delegation_key=user_delegation_key, + permission=BlobSasPermissions(read=True, write=True, delete=True, list=True, add=True, create=True), + expiry=expiry, + is_directory=True, + ) + + # foo/bar does NOT have foo/bar/hello as a prefix — must fail + non_prefix_blob = service.get_blob_client(container_name, "foo/bar") + non_prefix_blob_with_sas = BlobClient.from_blob_url(non_prefix_blob.url, credential=token) + from azure.core.exceptions import HttpResponseError + with pytest.raises(HttpResponseError): + non_prefix_blob_with_sas.upload_blob(b"data", overwrite=True) + + service.delete_container(container_name) + + # ------------------------------------------------------------------------------ diff --git a/sdk/storage/azure-storage-blob/tests/test_directory_sas.py b/sdk/storage/azure-storage-blob/tests/test_directory_sas.py new file mode 100644 index 000000000000..bb8bf1cc3a06 --- /dev/null +++ b/sdk/storage/azure-storage-blob/tests/test_directory_sas.py @@ -0,0 +1,126 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- + +"""Unit tests for Directory SAS (sr=d / sdd) token generation. + +These are pure unit tests — no live service calls, no recordings needed. +They verify that: + - `sr=d` is emitted in the query parameters when is_directory=True + - `sdd=N` is emitted with the correct depth value + - `sdd` is NOT present in the string-to-sign (stringToSign) + - Non-directory SAS produces `sr=b` and no `sdd` +""" + +from datetime import datetime, timedelta, timezone +from urllib.parse import parse_qs + +import pytest + +from azure.storage.blob import BlobSasPermissions, generate_blob_sas + +# --------------------------------------------------------------------------- +# Shared fixtures +# --------------------------------------------------------------------------- + +FAKE_ACCOUNT_NAME = "fakestorageaccount" +# 64-byte base-64-like string — just needs to be a valid base64 value for HMAC +FAKE_ACCOUNT_KEY = "dGVzdGtleXRlc3RrZXl0ZXN0a2V5dGVzdGtleXRlc3RrZXl0ZXN0a2V5dGVzdGtleXRlc3Q=" +FAKE_CONTAINER = "mycontainer" +EXPIRY = datetime(2030, 1, 1, tzinfo=timezone.utc) +PERMISSION = BlobSasPermissions(read=True, list=True) + + +def _generate(blob_name: str, is_directory: bool = False) -> tuple[str, str]: + """Return (token, string_to_sign) for a directory or blob SAS.""" + captured = [] + + token = generate_blob_sas( + account_name=FAKE_ACCOUNT_NAME, + container_name=FAKE_CONTAINER, + blob_name=blob_name, + account_key=FAKE_ACCOUNT_KEY, + permission=PERMISSION, + expiry=EXPIRY, + is_directory=is_directory, + sts_hook=captured.append, + ) + return token, captured[0] + + +# --------------------------------------------------------------------------- +# Parameterized: directory depth calculation +# Each tuple: (blob_name, expected_sdd) +# --------------------------------------------------------------------------- + +@pytest.mark.parametrize( + "blob_name, expected_sdd", + [ + ("foo/bar/hello", 3), # basic three-level path + ("foo", 1), # single level + ("foo/bar", 2), # two levels + ("/", 0), # root slash only → 0 + ("", 0), # empty string → 0 + ("foo/bar/hello/", 3), # trailing slash stripped → still 3 + ("/foo/bar", 2), # leading slash stripped → 2 (not 3) + ], +) +def test_directory_sas_depth(blob_name: str, expected_sdd: int) -> None: + """sr=d is present, sdd equals the expected depth, sdd is absent from stringToSign.""" + token, sts = _generate(blob_name, is_directory=True) + params = parse_qs(token) + + # sr must be 'd' + assert params.get("sr") == ["d"], f"Expected sr=d, got {params.get('sr')}" + + # sdd must equal expected depth + assert params.get("sdd") == [str(expected_sdd)], ( + f"blob_name={blob_name!r}: expected sdd={expected_sdd}, got {params.get('sdd')}" + ) + + # sdd must NOT appear in the string-to-sign + assert "sdd" not in sts, ( + f"blob_name={blob_name!r}: 'sdd' should not be in stringToSign, but got:\n{sts}" + ) + + # '\nd\n' must appear in the string-to-sign (resource indicator) + assert "\nd\n" in sts, ( + f"blob_name={blob_name!r}: expected '\\nd\\n' in stringToSign, but got:\n{sts}" + ) + + # sig must be present (token is properly signed) + assert "sig" in params, "Token must contain a signature" + + +def test_non_directory_sas() -> None: + """Without is_directory, sr=b and no sdd in the token or stringToSign.""" + token, sts = _generate("foo/bar/hello", is_directory=False) + params = parse_qs(token) + + assert params.get("sr") == ["b"], f"Expected sr=b, got {params.get('sr')}" + assert "sdd" not in params, f"sdd should not appear in a non-directory SAS, got {params.get('sdd')}" + assert "sdd" not in sts, "sdd should not appear in stringToSign for a blob SAS" + + +def test_hns_sdd_zero_kwarg_not_dropped() -> None: + """sdd=0 passed as an explicit kwarg (DataLake path) must not be silently dropped, + and must override the depth computed by add_directory_depth from blob_name.""" + captured = [] + # blob_name has depth 2, but sdd=0 is passed explicitly (DataLake caller pattern) + token = generate_blob_sas( + account_name=FAKE_ACCOUNT_NAME, + container_name=FAKE_CONTAINER, + blob_name="foo/bar", + account_key=FAKE_ACCOUNT_KEY, + permission=PERMISSION, + expiry=EXPIRY, + is_directory=True, + sdd=0, + sts_hook=captured.append, + ) + params = parse_qs(token) + # sdd kwarg takes precedence over the depth computed from blob_name + assert params.get("sdd") == ["0"], f"Expected sdd=0 in token, got {params.get('sdd')}" + assert "sdd" not in captured[0], "sdd must not appear in stringToSign" From 330040d79c6cdd3e29d1586356d9817b88e559b8 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 25 Mar 2026 22:57:28 -0400 Subject: [PATCH 04/16] Tests --- .../tests/test_common_blob.py | 153 ++++++------------ .../tests/test_common_blob_async.py | 84 ++++++++++ .../tests/test_directory_sas.py | 126 --------------- 3 files changed, 137 insertions(+), 226 deletions(-) delete mode 100644 sdk/storage/azure-storage-blob/tests/test_directory_sas.py diff --git a/sdk/storage/azure-storage-blob/tests/test_common_blob.py b/sdk/storage/azure-storage-blob/tests/test_common_blob.py index 8f78b632474f..a82d607b42bf 100644 --- a/sdk/storage/azure-storage-blob/tests/test_common_blob.py +++ b/sdk/storage/azure-storage-blob/tests/test_common_blob.py @@ -3830,80 +3830,68 @@ def test_smart_rehydrate(self, **kwargs): assert props is not None assert props.archive_status == "rehydrate-pending-to-smart" - # ------------------------------------------------------------------------------ - # Directory SAS tests (sr=d / sdd) - # ------------------------------------------------------------------------------ - @pytest.mark.live_test_only @BlobPreparer() - def test_directory_sas_all_permissions(self, **kwargs): + def test_blob_fns_directory(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") - storage_account_key = kwargs.pop("storage_account_key") - self._setup(storage_account_name, storage_account_key) - - expiry = datetime.utcnow() + timedelta(hours=1) - - for blob_name in ["foo", "foo/bar", "foo/bar/hello"]: - token = self.generate_sas( - generate_blob_sas, - account_name=storage_account_name, - container_name=self.container_name, - blob_name=blob_name, - account_key=storage_account_key.secret, - permission=BlobSasPermissions(read=True, write=True, delete=True, list=True, add=True, create=True), - expiry=expiry, - is_directory=True, - ) - - # Blob whose name exactly matches the SAS directory name should succeed - exact_blob = self.bsc.get_blob_client(self.container_name, blob_name) - BlobClient.from_blob_url(exact_blob.url, credential=token).upload_blob(b"data", overwrite=True) + variables = kwargs.pop("variables", {}) - # Blob whose name has the SAS directory name as a prefix should also succeed - child_blob = self.bsc.get_blob_client(self.container_name, blob_name + "/test") - BlobClient.from_blob_url(child_blob.url, credential=token).upload_blob(b"data", overwrite=True) + token_credential = self.get_credential(BlobServiceClient) + service = BlobServiceClient( + self.account_url(storage_account_name, "blob"), + credential=token_credential + ) + container_name = self.get_resource_name("directorysascontainer") - @pytest.mark.live_test_only - @BlobPreparer() - def test_directory_sas_all_permissions_fail(self, **kwargs): - storage_account_name = kwargs.pop("storage_account_name") - storage_account_key = kwargs.pop("storage_account_key") - self._setup(storage_account_name, storage_account_key) + try: + service.create_container(container_name) + + start = self.get_datetime_variable(variables, 'start', datetime.utcnow()) + expiry = self.get_datetime_variable(variables, 'expiry', datetime.utcnow() + timedelta(hours=1)) + user_delegation_key = service.get_user_delegation_key(start, expiry) + + for blob_name in ["foo", "foo/bar", "foo/bar/hello"]: + token = self.generate_sas( + generate_blob_sas, + account_name=storage_account_name, + container_name=container_name, + blob_name=blob_name, + user_delegation_key=user_delegation_key, + permission=BlobSasPermissions(read=True, write=True, delete=True, list=True, add=True, create=True), + expiry=expiry, + is_directory=True, + ) - expiry = datetime.utcnow() + timedelta(hours=1) - # SAS is scoped to foo/bar/hello (depth 3) - token = self.generate_sas( - generate_blob_sas, - account_name=storage_account_name, - container_name=self.container_name, - blob_name="foo/bar/hello", - account_key=storage_account_key.secret, - permission=BlobSasPermissions(read=True, write=True, delete=True, list=True, add=True, create=True), - expiry=expiry, - is_directory=True, - ) + exact_blob = service.get_blob_client(container_name, blob_name) + BlobClient.from_blob_url(exact_blob.url, credential=token).upload_blob(b"data", overwrite=True) - # foo/bar does NOT have foo/bar/hello as a prefix — must fail - non_prefix_blob = self.bsc.get_blob_client(self.container_name, "foo/bar") - non_prefix_blob_with_sas = BlobClient.from_blob_url(non_prefix_blob.url, credential=token) - from azure.core.exceptions import HttpResponseError - with pytest.raises(HttpResponseError): - non_prefix_blob_with_sas.upload_blob(b"data", overwrite=True) + # Blob whose name has the SAS directory name as a prefix should also succeed + child_blob = service.get_blob_client(container_name, blob_name + "/test") + BlobClient.from_blob_url(child_blob.url, credential=token).upload_blob(b"data", overwrite=True) + finally: + service.delete_container(container_name) @pytest.mark.live_test_only @BlobPreparer() - def test_directory_identity_sas_all_permissions(self, **kwargs): + def test_blob_fns_directory_fail(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") + variables = kwargs.pop("variables", {}) token_credential = self.get_credential(BlobServiceClient) - service = BlobServiceClient(self.account_url(storage_account_name, "blob"), credential=token_credential) + service = BlobServiceClient( + self.account_url(storage_account_name, "blob"), + credential=token_credential + ) container_name = self.get_resource_name("directorysascontainer") - container = service.create_container(container_name) - expiry = datetime.utcnow() + timedelta(hours=1) - user_delegation_key = service.get_user_delegation_key(datetime.utcnow(), expiry) + try: + service.create_container(container_name) - for blob_name in ["foo", "foo/bar", "foo/bar/hello"]: + start = self.get_datetime_variable(variables, 'start', datetime.utcnow()) + expiry = self.get_datetime_variable(variables, 'expiry', datetime.utcnow() + timedelta(hours=1)) + user_delegation_key = service.get_user_delegation_key(start, expiry) + + blob_name = "foo/bar/baz/" token = self.generate_sas( generate_blob_sas, account_name=storage_account_name, @@ -3915,48 +3903,13 @@ def test_directory_identity_sas_all_permissions(self, **kwargs): is_directory=True, ) - # Blob whose name exactly matches the SAS directory name should succeed - exact_blob = service.get_blob_client(container_name, blob_name) - BlobClient.from_blob_url(exact_blob.url, credential=token).upload_blob(b"data", overwrite=True) - - # Blob whose name has the SAS directory name as a prefix should also succeed - child_blob = service.get_blob_client(container_name, blob_name + "/test") - BlobClient.from_blob_url(child_blob.url, credential=token).upload_blob(b"data", overwrite=True) - - container.delete_container() - - @pytest.mark.live_test_only - @BlobPreparer() - def test_directory_identity_sas_all_permissions_fail(self, **kwargs): - storage_account_name = kwargs.pop("storage_account_name") - - token_credential = self.get_credential(BlobServiceClient) - service = BlobServiceClient(self.account_url(storage_account_name, "blob"), credential=token_credential) - container_name = self.get_resource_name("directorysascontainer") - service.create_container(container_name) - - expiry = datetime.utcnow() + timedelta(hours=1) - user_delegation_key = service.get_user_delegation_key(datetime.utcnow(), expiry) - - # SAS is scoped to foo/bar/hello (depth 3) - token = self.generate_sas( - generate_blob_sas, - account_name=storage_account_name, - container_name=container_name, - blob_name="foo/bar/hello", - user_delegation_key=user_delegation_key, - permission=BlobSasPermissions(read=True, write=True, delete=True, list=True, add=True, create=True), - expiry=expiry, - is_directory=True, - ) - - # foo/bar does NOT have foo/bar/hello as a prefix — must fail - non_prefix_blob = service.get_blob_client(container_name, "foo/bar") - non_prefix_blob_with_sas = BlobClient.from_blob_url(non_prefix_blob.url, credential=token) - from azure.core.exceptions import HttpResponseError - with pytest.raises(HttpResponseError): - non_prefix_blob_with_sas.upload_blob(b"data", overwrite=True) + non_prefix_blob = service.get_blob_client(container_name, "foo/bar") + non_prefix_blob_with_sas = BlobClient.from_blob_url(non_prefix_blob.url, credential=token) + with pytest.raises(HttpResponseError): + non_prefix_blob_with_sas.upload_blob(b"data", overwrite=True) + finally: + service.delete_container(container_name) - service.delete_container(container_name) + return variables # ------------------------------------------------------------------------------ diff --git a/sdk/storage/azure-storage-blob/tests/test_common_blob_async.py b/sdk/storage/azure-storage-blob/tests/test_common_blob_async.py index 2cc3bae41454..f103e122192c 100644 --- a/sdk/storage/azure-storage-blob/tests/test_common_blob_async.py +++ b/sdk/storage/azure-storage-blob/tests/test_common_blob_async.py @@ -3768,4 +3768,88 @@ async def test_smart_rehydrate(self, **kwargs): assert props is not None assert props.archive_status == "rehydrate-pending-to-smart" + @pytest.mark.live_test_only + @BlobPreparer() + async def test_blob_fns_directory(self, **kwargs): + storage_account_name = kwargs.pop("storage_account_name") + variables = kwargs.pop("variables", {}) + + token_credential = self.get_credential(BlobServiceClient, is_async=True) + service = BlobServiceClient( + self.account_url(storage_account_name, "blob"), + credential=token_credential + ) + container_name = self.get_resource_name("directorysascontainer") + + try: + await service.create_container(container_name) + + start = self.get_datetime_variable(variables, 'start', datetime.utcnow()) + expiry = self.get_datetime_variable(variables, 'expiry', datetime.utcnow() + timedelta(hours=1)) + user_delegation_key = await service.get_user_delegation_key(start, expiry) + + for blob_name in ["foo", "foo/bar", "foo/bar/hello"]: + token = self.generate_sas( + generate_blob_sas, + account_name=storage_account_name, + container_name=container_name, + blob_name=blob_name, + user_delegation_key=user_delegation_key, + permission=BlobSasPermissions(read=True, write=True, delete=True, list=True, add=True, create=True), + expiry=expiry, + is_directory=True, + ) + + exact_blob = service.get_blob_client(container_name, blob_name) + await BlobClient.from_blob_url( + exact_blob.url, credential=token).upload_blob(b"data", overwrite=True) + + # Blob whose name has the SAS directory name as a prefix should also succeed + child_blob = service.get_blob_client(container_name, blob_name + "/test") + await BlobClient.from_blob_url( + child_blob.url, credential=token).upload_blob(b"data", overwrite=True) + finally: + await service.delete_container(container_name) + + @pytest.mark.live_test_only + @BlobPreparer() + async def test_blob_fns_directory_fail(self, **kwargs): + storage_account_name = kwargs.pop("storage_account_name") + variables = kwargs.pop("variables", {}) + + token_credential = self.get_credential(BlobServiceClient, is_async=True) + service = BlobServiceClient( + self.account_url(storage_account_name, "blob"), + credential=token_credential + ) + container_name = self.get_resource_name("directorysascontainer") + + try: + await service.create_container(container_name) + + start = self.get_datetime_variable(variables, 'start', datetime.utcnow()) + expiry = self.get_datetime_variable(variables, 'expiry', datetime.utcnow() + timedelta(hours=1)) + user_delegation_key = await service.get_user_delegation_key(start, expiry) + + blob_name = "foo/bar/baz/" + token = self.generate_sas( + generate_blob_sas, + account_name=storage_account_name, + container_name=container_name, + blob_name=blob_name, + user_delegation_key=user_delegation_key, + permission=BlobSasPermissions(read=True, write=True, delete=True, list=True, add=True, create=True), + expiry=expiry, + is_directory=True, + ) + + non_prefix_blob = service.get_blob_client(container_name, "foo/bar") + non_prefix_blob_with_sas = BlobClient.from_blob_url(non_prefix_blob.url, credential=token) + with pytest.raises(HttpResponseError): + await non_prefix_blob_with_sas.upload_blob(b"data", overwrite=True) + finally: + await service.delete_container(container_name) + + return variables + # ------------------------------------------------------------------------------ diff --git a/sdk/storage/azure-storage-blob/tests/test_directory_sas.py b/sdk/storage/azure-storage-blob/tests/test_directory_sas.py deleted file mode 100644 index bb8bf1cc3a06..000000000000 --- a/sdk/storage/azure-storage-blob/tests/test_directory_sas.py +++ /dev/null @@ -1,126 +0,0 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- - -"""Unit tests for Directory SAS (sr=d / sdd) token generation. - -These are pure unit tests — no live service calls, no recordings needed. -They verify that: - - `sr=d` is emitted in the query parameters when is_directory=True - - `sdd=N` is emitted with the correct depth value - - `sdd` is NOT present in the string-to-sign (stringToSign) - - Non-directory SAS produces `sr=b` and no `sdd` -""" - -from datetime import datetime, timedelta, timezone -from urllib.parse import parse_qs - -import pytest - -from azure.storage.blob import BlobSasPermissions, generate_blob_sas - -# --------------------------------------------------------------------------- -# Shared fixtures -# --------------------------------------------------------------------------- - -FAKE_ACCOUNT_NAME = "fakestorageaccount" -# 64-byte base-64-like string — just needs to be a valid base64 value for HMAC -FAKE_ACCOUNT_KEY = "dGVzdGtleXRlc3RrZXl0ZXN0a2V5dGVzdGtleXRlc3RrZXl0ZXN0a2V5dGVzdGtleXRlc3Q=" -FAKE_CONTAINER = "mycontainer" -EXPIRY = datetime(2030, 1, 1, tzinfo=timezone.utc) -PERMISSION = BlobSasPermissions(read=True, list=True) - - -def _generate(blob_name: str, is_directory: bool = False) -> tuple[str, str]: - """Return (token, string_to_sign) for a directory or blob SAS.""" - captured = [] - - token = generate_blob_sas( - account_name=FAKE_ACCOUNT_NAME, - container_name=FAKE_CONTAINER, - blob_name=blob_name, - account_key=FAKE_ACCOUNT_KEY, - permission=PERMISSION, - expiry=EXPIRY, - is_directory=is_directory, - sts_hook=captured.append, - ) - return token, captured[0] - - -# --------------------------------------------------------------------------- -# Parameterized: directory depth calculation -# Each tuple: (blob_name, expected_sdd) -# --------------------------------------------------------------------------- - -@pytest.mark.parametrize( - "blob_name, expected_sdd", - [ - ("foo/bar/hello", 3), # basic three-level path - ("foo", 1), # single level - ("foo/bar", 2), # two levels - ("/", 0), # root slash only → 0 - ("", 0), # empty string → 0 - ("foo/bar/hello/", 3), # trailing slash stripped → still 3 - ("/foo/bar", 2), # leading slash stripped → 2 (not 3) - ], -) -def test_directory_sas_depth(blob_name: str, expected_sdd: int) -> None: - """sr=d is present, sdd equals the expected depth, sdd is absent from stringToSign.""" - token, sts = _generate(blob_name, is_directory=True) - params = parse_qs(token) - - # sr must be 'd' - assert params.get("sr") == ["d"], f"Expected sr=d, got {params.get('sr')}" - - # sdd must equal expected depth - assert params.get("sdd") == [str(expected_sdd)], ( - f"blob_name={blob_name!r}: expected sdd={expected_sdd}, got {params.get('sdd')}" - ) - - # sdd must NOT appear in the string-to-sign - assert "sdd" not in sts, ( - f"blob_name={blob_name!r}: 'sdd' should not be in stringToSign, but got:\n{sts}" - ) - - # '\nd\n' must appear in the string-to-sign (resource indicator) - assert "\nd\n" in sts, ( - f"blob_name={blob_name!r}: expected '\\nd\\n' in stringToSign, but got:\n{sts}" - ) - - # sig must be present (token is properly signed) - assert "sig" in params, "Token must contain a signature" - - -def test_non_directory_sas() -> None: - """Without is_directory, sr=b and no sdd in the token or stringToSign.""" - token, sts = _generate("foo/bar/hello", is_directory=False) - params = parse_qs(token) - - assert params.get("sr") == ["b"], f"Expected sr=b, got {params.get('sr')}" - assert "sdd" not in params, f"sdd should not appear in a non-directory SAS, got {params.get('sdd')}" - assert "sdd" not in sts, "sdd should not appear in stringToSign for a blob SAS" - - -def test_hns_sdd_zero_kwarg_not_dropped() -> None: - """sdd=0 passed as an explicit kwarg (DataLake path) must not be silently dropped, - and must override the depth computed by add_directory_depth from blob_name.""" - captured = [] - # blob_name has depth 2, but sdd=0 is passed explicitly (DataLake caller pattern) - token = generate_blob_sas( - account_name=FAKE_ACCOUNT_NAME, - container_name=FAKE_CONTAINER, - blob_name="foo/bar", - account_key=FAKE_ACCOUNT_KEY, - permission=PERMISSION, - expiry=EXPIRY, - is_directory=True, - sdd=0, - sts_hook=captured.append, - ) - params = parse_qs(token) - # sdd kwarg takes precedence over the depth computed from blob_name - assert params.get("sdd") == ["0"], f"Expected sdd=0 in token, got {params.get('sdd')}" - assert "sdd" not in captured[0], "sdd must not appear in stringToSign" From 0aff462a63170c73554a2473906c22a86e02ea08 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 25 Mar 2026 23:01:08 -0400 Subject: [PATCH 05/16] Changelogs --- sdk/storage/azure-storage-blob/CHANGELOG.md | 3 ++- sdk/storage/azure-storage-file-datalake/CHANGELOG.md | 2 +- sdk/storage/azure-storage-file-share/CHANGELOG.md | 2 +- sdk/storage/azure-storage-queue/CHANGELOG.md | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/sdk/storage/azure-storage-blob/CHANGELOG.md b/sdk/storage/azure-storage-blob/CHANGELOG.md index 9cf0e77f73a5..afba2e87753f 100644 --- a/sdk/storage/azure-storage-blob/CHANGELOG.md +++ b/sdk/storage/azure-storage-blob/CHANGELOG.md @@ -1,6 +1,6 @@ # Release History -## 12.30.0b1 (Unreleased) +## 12.30.0b1 (2026-03-26) ### Features Added - Added support for service version 2026-06-06. @@ -12,6 +12,7 @@ for `BlobServiceClient`, `ContainerClient`, and `BlobClient`. which is optimized to automatically determine the most cost-effective access with no performance impact. When set, `BlobProperties.smart_access_tier` will reveal the service's current access tier choice between `Hot`, `Cool`, and `Archive`. +- Added support for `is_directory` keyword in `generate_blob_sas` that generates directory-level SAS for blobs. ### Other Changes - Consolidated the behavior of `max_concurrency=None` by defaulting to the shared `DEFAULT_MAX_CONCURRENCY` constant. diff --git a/sdk/storage/azure-storage-file-datalake/CHANGELOG.md b/sdk/storage/azure-storage-file-datalake/CHANGELOG.md index 5b53709ea1f7..e0ecbb7b7767 100644 --- a/sdk/storage/azure-storage-file-datalake/CHANGELOG.md +++ b/sdk/storage/azure-storage-file-datalake/CHANGELOG.md @@ -1,6 +1,6 @@ # Release History -## 12.25.0b1 (Unreleased) +## 12.25.0b1 (2026-03-26) ### Features Added - Added support for service version 2026-06-06. diff --git a/sdk/storage/azure-storage-file-share/CHANGELOG.md b/sdk/storage/azure-storage-file-share/CHANGELOG.md index be77bd26429b..23171cb39d6c 100644 --- a/sdk/storage/azure-storage-file-share/CHANGELOG.md +++ b/sdk/storage/azure-storage-file-share/CHANGELOG.md @@ -1,6 +1,6 @@ # Release History -## 12.26.0b1 (Unreleased) +## 12.26.0b1 (2026-03-26) ### Features Added - Added support for service version 2026-06-06. diff --git a/sdk/storage/azure-storage-queue/CHANGELOG.md b/sdk/storage/azure-storage-queue/CHANGELOG.md index 5a221274b93e..9aa5c12bd37c 100644 --- a/sdk/storage/azure-storage-queue/CHANGELOG.md +++ b/sdk/storage/azure-storage-queue/CHANGELOG.md @@ -1,6 +1,6 @@ # Release History -## 12.17.0b1 (Unreleased) +## 12.17.0b1 (2026-03-26) ### Features Added - Added support for service version 2026-06-06. From efed3e9992739c57d3b1f7452ac582a2faa911d0 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 25 Mar 2026 23:07:02 -0400 Subject: [PATCH 06/16] Regenerated code --- .../azure-storage-blob/swagger/README.md | 2 +- .../_azure_data_lake_storage_restapi.py | 9 ++-- .../filedatalake/_generated/_configuration.py | 12 ++--- .../aio/_azure_data_lake_storage_restapi.py | 9 ++-- .../_generated/aio/_configuration.py | 12 ++--- .../aio/operations/_file_system_operations.py | 12 ++--- .../aio/operations/_path_operations.py | 26 +++++----- .../aio/operations/_service_operations.py | 2 +- .../_azure_data_lake_storage_restapi_enums.py | 1 - .../operations/_file_system_operations.py | 25 +++++----- .../_generated/operations/_path_operations.py | 50 +++++++++---------- .../operations/_service_operations.py | 4 +- .../swagger/README.md | 2 +- .../aio/operations/_file_operations.py | 16 +++++- .../_generated/operations/_file_operations.py | 24 ++++++++- .../swagger/README.md | 2 +- 16 files changed, 120 insertions(+), 88 deletions(-) diff --git a/sdk/storage/azure-storage-blob/swagger/README.md b/sdk/storage/azure-storage-blob/swagger/README.md index a01f9a614515..dd8889803d24 100644 --- a/sdk/storage/azure-storage-blob/swagger/README.md +++ b/sdk/storage/azure-storage-blob/swagger/README.md @@ -16,7 +16,7 @@ autorest --v3 --python ### Settings ``` yaml -input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/storage/data-plane/Microsoft.BlobStorage/stable/2026-04-06/blob.json +input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/storage/data-plane/Microsoft.BlobStorage/stable/2026-06-06/blob.json output-folder: ../azure/storage/blob/_generated namespace: azure.storage.blob no-namespace-folders: true diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/_azure_data_lake_storage_restapi.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/_azure_data_lake_storage_restapi.py index 6304ac3e09a4..ccbd94a2d0f6 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/_azure_data_lake_storage_restapi.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/_azure_data_lake_storage_restapi.py @@ -32,6 +32,8 @@ class AzureDataLakeStorageRESTAPI: # pylint: disable=client-accepts-api-version :param url: The URL of the service account, container, or blob that is the target of the desired operation. Required. :type url: str + :param version: Specifies the version of the operation to use for this request. Required. + :type version: str :param base_url: Service URL. Required. Default value is "". :type base_url: str :param x_ms_lease_duration: The lease duration is required to acquire a lease, and specifies @@ -41,16 +43,13 @@ class AzureDataLakeStorageRESTAPI: # pylint: disable=client-accepts-api-version :keyword resource: The value must be "filesystem" for all filesystem operations. Default value is "filesystem". Note that overriding this default value may result in unsupported behavior. :paramtype resource: str - :keyword version: Specifies the version of the operation to use for this request. Default value - is "2026-02-06". Note that overriding this default value may result in unsupported behavior. - :paramtype version: str """ def __init__( # pylint: disable=missing-client-constructor-parameter-credential - self, url: str, base_url: str = "", x_ms_lease_duration: Optional[int] = None, **kwargs: Any + self, url: str, version: str, base_url: str = "", x_ms_lease_duration: Optional[int] = None, **kwargs: Any ) -> None: self._config = AzureDataLakeStorageRESTAPIConfiguration( - url=url, x_ms_lease_duration=x_ms_lease_duration, **kwargs + url=url, version=version, x_ms_lease_duration=x_ms_lease_duration, **kwargs ) _policies = kwargs.pop("policies", None) diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/_configuration.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/_configuration.py index 0f8ea82cd0da..a1a941bed54f 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/_configuration.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/_configuration.py @@ -22,6 +22,8 @@ class AzureDataLakeStorageRESTAPIConfiguration: # pylint: disable=too-many-inst :param url: The URL of the service account, container, or blob that is the target of the desired operation. Required. :type url: str + :param version: Specifies the version of the operation to use for this request. Required. + :type version: str :param x_ms_lease_duration: The lease duration is required to acquire a lease, and specifies the duration of the lease in seconds. The lease duration must be between 15 and 60 seconds or -1 for infinite lease. Default value is None. @@ -29,22 +31,20 @@ class AzureDataLakeStorageRESTAPIConfiguration: # pylint: disable=too-many-inst :keyword resource: The value must be "filesystem" for all filesystem operations. Default value is "filesystem". Note that overriding this default value may result in unsupported behavior. :paramtype resource: str - :keyword version: Specifies the version of the operation to use for this request. Default value - is "2026-02-06". Note that overriding this default value may result in unsupported behavior. - :paramtype version: str """ - def __init__(self, url: str, x_ms_lease_duration: Optional[int] = None, **kwargs: Any) -> None: + def __init__(self, url: str, version: str, x_ms_lease_duration: Optional[int] = None, **kwargs: Any) -> None: resource: Literal["filesystem"] = kwargs.pop("resource", "filesystem") - version: Literal["2026-02-06"] = kwargs.pop("version", "2026-02-06") if url is None: raise ValueError("Parameter 'url' must not be None.") + if version is None: + raise ValueError("Parameter 'version' must not be None.") self.url = url + self.version = version self.x_ms_lease_duration = x_ms_lease_duration self.resource = resource - self.version = version kwargs.setdefault("sdk_moniker", "azuredatalakestoragerestapi/{}".format(VERSION)) self.polling_interval = kwargs.get("polling_interval", 30) self._configure(**kwargs) diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/aio/_azure_data_lake_storage_restapi.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/aio/_azure_data_lake_storage_restapi.py index 60f2078853b1..b15761157c8b 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/aio/_azure_data_lake_storage_restapi.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/aio/_azure_data_lake_storage_restapi.py @@ -32,6 +32,8 @@ class AzureDataLakeStorageRESTAPI: # pylint: disable=client-accepts-api-version :param url: The URL of the service account, container, or blob that is the target of the desired operation. Required. :type url: str + :param version: Specifies the version of the operation to use for this request. Required. + :type version: str :param base_url: Service URL. Required. Default value is "". :type base_url: str :param x_ms_lease_duration: The lease duration is required to acquire a lease, and specifies @@ -41,16 +43,13 @@ class AzureDataLakeStorageRESTAPI: # pylint: disable=client-accepts-api-version :keyword resource: The value must be "filesystem" for all filesystem operations. Default value is "filesystem". Note that overriding this default value may result in unsupported behavior. :paramtype resource: str - :keyword version: Specifies the version of the operation to use for this request. Default value - is "2026-02-06". Note that overriding this default value may result in unsupported behavior. - :paramtype version: str """ def __init__( # pylint: disable=missing-client-constructor-parameter-credential - self, url: str, base_url: str = "", x_ms_lease_duration: Optional[int] = None, **kwargs: Any + self, url: str, version: str, base_url: str = "", x_ms_lease_duration: Optional[int] = None, **kwargs: Any ) -> None: self._config = AzureDataLakeStorageRESTAPIConfiguration( - url=url, x_ms_lease_duration=x_ms_lease_duration, **kwargs + url=url, version=version, x_ms_lease_duration=x_ms_lease_duration, **kwargs ) _policies = kwargs.pop("policies", None) diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/aio/_configuration.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/aio/_configuration.py index 95fdeeffc2bc..944d6e735243 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/aio/_configuration.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/aio/_configuration.py @@ -22,6 +22,8 @@ class AzureDataLakeStorageRESTAPIConfiguration: # pylint: disable=too-many-inst :param url: The URL of the service account, container, or blob that is the target of the desired operation. Required. :type url: str + :param version: Specifies the version of the operation to use for this request. Required. + :type version: str :param x_ms_lease_duration: The lease duration is required to acquire a lease, and specifies the duration of the lease in seconds. The lease duration must be between 15 and 60 seconds or -1 for infinite lease. Default value is None. @@ -29,22 +31,20 @@ class AzureDataLakeStorageRESTAPIConfiguration: # pylint: disable=too-many-inst :keyword resource: The value must be "filesystem" for all filesystem operations. Default value is "filesystem". Note that overriding this default value may result in unsupported behavior. :paramtype resource: str - :keyword version: Specifies the version of the operation to use for this request. Default value - is "2026-02-06". Note that overriding this default value may result in unsupported behavior. - :paramtype version: str """ - def __init__(self, url: str, x_ms_lease_duration: Optional[int] = None, **kwargs: Any) -> None: + def __init__(self, url: str, version: str, x_ms_lease_duration: Optional[int] = None, **kwargs: Any) -> None: resource: Literal["filesystem"] = kwargs.pop("resource", "filesystem") - version: Literal["2026-02-06"] = kwargs.pop("version", "2026-02-06") if url is None: raise ValueError("Parameter 'url' must not be None.") + if version is None: + raise ValueError("Parameter 'version' must not be None.") self.url = url + self.version = version self.x_ms_lease_duration = x_ms_lease_duration self.resource = resource - self.version = version kwargs.setdefault("sdk_moniker", "azuredatalakestoragerestapi/{}".format(VERSION)) self.polling_interval = kwargs.get("polling_interval", 30) self._configure(**kwargs) diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/aio/operations/_file_system_operations.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/aio/operations/_file_system_operations.py index 3dc6fe583f50..88edb5316012 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/aio/operations/_file_system_operations.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/aio/operations/_file_system_operations.py @@ -110,11 +110,11 @@ async def create( _request = build_create_request( url=self._config.url, + version=self._config.version, request_id_parameter=request_id_parameter, timeout=timeout, properties=properties, resource=self._config.resource, - version=self._config.version, headers=_headers, params=_params, ) @@ -208,13 +208,13 @@ async def set_properties( _request = build_set_properties_request( url=self._config.url, + version=self._config.version, request_id_parameter=request_id_parameter, timeout=timeout, properties=properties, if_modified_since=_if_modified_since, if_unmodified_since=_if_unmodified_since, resource=self._config.resource, - version=self._config.version, headers=_headers, params=_params, ) @@ -281,10 +281,10 @@ async def get_properties( _request = build_get_properties_request( url=self._config.url, + version=self._config.version, request_id_parameter=request_id_parameter, timeout=timeout, resource=self._config.resource, - version=self._config.version, headers=_headers, params=_params, ) @@ -375,12 +375,12 @@ async def delete( _request = build_delete_request( url=self._config.url, + version=self._config.version, request_id_parameter=request_id_parameter, timeout=timeout, if_modified_since=_if_modified_since, if_unmodified_since=_if_unmodified_since, resource=self._config.resource, - version=self._config.version, headers=_headers, params=_params, ) @@ -485,6 +485,7 @@ async def list_paths( _request = build_list_paths_request( url=self._config.url, recursive=recursive, + version=self._config.version, request_id_parameter=request_id_parameter, timeout=timeout, continuation=continuation, @@ -493,7 +494,6 @@ async def list_paths( upn=upn, begin_from=begin_from, resource=self._config.resource, - version=self._config.version, headers=_headers, params=_params, ) @@ -599,6 +599,7 @@ async def list_blob_hierarchy_segment( _request = build_list_blob_hierarchy_segment_request( url=self._config.url, + version=self._config.version, prefix=prefix, delimiter=delimiter, marker=marker, @@ -609,7 +610,6 @@ async def list_blob_hierarchy_segment( request_id_parameter=request_id_parameter, restype=restype, comp=comp, - version=self._config.version, headers=_headers, params=_params, ) diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/aio/operations/_path_operations.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/aio/operations/_path_operations.py index bb1ce5ce7e4e..79f220bed0bd 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/aio/operations/_path_operations.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/aio/operations/_path_operations.py @@ -254,6 +254,7 @@ async def create( # pylint: disable=too-many-locals _request = build_create_request( url=self._config.url, + version=self._config.version, request_id_parameter=request_id_parameter, timeout=timeout, resource=resource, @@ -289,7 +290,6 @@ async def create( # pylint: disable=too-many-locals expiry_options=expiry_options, expires_on=expires_on, encryption_context=encryption_context, - version=self._config.version, headers=_headers, params=_params, ) @@ -522,6 +522,7 @@ async def update( # pylint: disable=too-many-locals url=self._config.url, action=action, mode=mode, + version=self._config.version, request_id_parameter=request_id_parameter, timeout=timeout, max_records=max_records, @@ -550,7 +551,6 @@ async def update( # pylint: disable=too-many-locals structured_body_type=structured_body_type, structured_content_length=structured_content_length, content_type=content_type, - version=self._config.version, content=_content, headers=_headers, params=_params, @@ -638,7 +638,7 @@ async def lease( the current lease ID in "x-ms-lease-id" and the new lease ID in "x-ms-proposed-lease-id" to change the lease ID of an active lease. Use "renew" and specify the "x-ms-lease-id" to renew an existing lease. Use "release" and specify the "x-ms-lease-id" to release a lease. Known values - are: "acquire", "break", "change", "renew", "release", and "break". Required. + are: "acquire", "break", "change", "renew", and "release". Required. :type x_ms_lease_action: str or ~azure.storage.filedatalake.models.PathLeaseAction :param request_id_parameter: Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. Default @@ -694,6 +694,7 @@ async def lease( _request = build_lease_request( url=self._config.url, x_ms_lease_action=x_ms_lease_action, + version=self._config.version, request_id_parameter=request_id_parameter, timeout=timeout, x_ms_lease_break_period=x_ms_lease_break_period, @@ -704,7 +705,6 @@ async def lease( if_modified_since=_if_modified_since, if_unmodified_since=_if_unmodified_since, x_ms_lease_duration=self._config.x_ms_lease_duration, - version=self._config.version, headers=_headers, params=_params, ) @@ -835,6 +835,7 @@ async def read( _request = build_read_request( url=self._config.url, + version=self._config.version, request_id_parameter=request_id_parameter, timeout=timeout, range=range, @@ -847,7 +848,6 @@ async def read( encryption_key=_encryption_key, encryption_key_sha256=_encryption_key_sha256, encryption_algorithm=_encryption_algorithm, # type: ignore - version=self._config.version, headers=_headers, params=_params, ) @@ -1025,6 +1025,7 @@ async def get_properties( _request = build_get_properties_request( url=self._config.url, + version=self._config.version, request_id_parameter=request_id_parameter, timeout=timeout, action=action, @@ -1034,7 +1035,6 @@ async def get_properties( if_none_match=_if_none_match, if_modified_since=_if_modified_since, if_unmodified_since=_if_unmodified_since, - version=self._config.version, headers=_headers, params=_params, ) @@ -1176,6 +1176,7 @@ async def delete( _request = build_delete_request( url=self._config.url, + version=self._config.version, request_id_parameter=request_id_parameter, timeout=timeout, recursive=recursive, @@ -1186,7 +1187,6 @@ async def delete( if_modified_since=_if_modified_since, if_unmodified_since=_if_unmodified_since, paginated=paginated, - version=self._config.version, headers=_headers, params=_params, ) @@ -1300,6 +1300,7 @@ async def set_access_control( _request = build_set_access_control_request( url=self._config.url, + version=self._config.version, timeout=timeout, lease_id=_lease_id, owner=owner, @@ -1312,7 +1313,6 @@ async def set_access_control( if_unmodified_since=_if_unmodified_since, request_id_parameter=request_id_parameter, action=action, - version=self._config.version, headers=_headers, params=_params, ) @@ -1418,6 +1418,7 @@ async def set_access_control_recursive( _request = build_set_access_control_recursive_request( url=self._config.url, mode=mode, + version=self._config.version, timeout=timeout, continuation=continuation, force_flag=force_flag, @@ -1425,7 +1426,6 @@ async def set_access_control_recursive( acl=acl, request_id_parameter=request_id_parameter, action=action, - version=self._config.version, headers=_headers, params=_params, ) @@ -1595,6 +1595,7 @@ async def flush_data( # pylint: disable=too-many-locals _request = build_flush_data_request( url=self._config.url, + version=self._config.version, timeout=timeout, position=position, retain_uncommitted_data=retain_uncommitted_data, @@ -1619,7 +1620,6 @@ async def flush_data( # pylint: disable=too-many-locals encryption_key_sha256=_encryption_key_sha256, encryption_algorithm=_encryption_algorithm, # type: ignore action=action, - version=self._config.version, headers=_headers, params=_params, ) @@ -1774,6 +1774,7 @@ async def append_data( # pylint: disable=too-many-locals _request = build_append_data_request( url=self._config.url, + version=self._config.version, position=position, timeout=timeout, content_length=content_length, @@ -1792,7 +1793,6 @@ async def append_data( # pylint: disable=too-many-locals structured_content_length=structured_content_length, action=action, content_type=content_type, - version=self._config.version, content=_content, headers=_headers, params=_params, @@ -1886,11 +1886,11 @@ async def set_expiry( _request = build_set_expiry_request( url=self._config.url, expiry_options=expiry_options, + version=self._config.version, timeout=timeout, request_id_parameter=request_id_parameter, expires_on=expires_on, comp=comp, - version=self._config.version, headers=_headers, params=_params, ) @@ -1966,11 +1966,11 @@ async def undelete( _request = build_undelete_request( url=self._config.url, + version=self._config.version, timeout=timeout, undelete_source=undelete_source, request_id_parameter=request_id_parameter, comp=comp, - version=self._config.version, headers=_headers, params=_params, ) diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/aio/operations/_service_operations.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/aio/operations/_service_operations.py index 83b9459d6ede..1f97459e2812 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/aio/operations/_service_operations.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/aio/operations/_service_operations.py @@ -113,13 +113,13 @@ def prepare_request(next_link=None): _request = build_list_file_systems_request( url=self._config.url, + version=self._config.version, prefix=prefix, continuation=continuation, max_results=max_results, request_id_parameter=request_id_parameter, timeout=timeout, resource=resource, - version=self._config.version, headers=_headers, params=_params, ) diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/models/_azure_data_lake_storage_restapi_enums.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/models/_azure_data_lake_storage_restapi_enums.py index c9bb43b5e4a0..f9fe6b949142 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/models/_azure_data_lake_storage_restapi_enums.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/models/_azure_data_lake_storage_restapi_enums.py @@ -55,7 +55,6 @@ class PathLeaseAction(str, Enum, metaclass=CaseInsensitiveEnumMeta): CHANGE = "change" RENEW = "renew" RELEASE = "release" - BREAK_ENUM = "break" class PathRenameMode(str, Enum, metaclass=CaseInsensitiveEnumMeta): diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/operations/_file_system_operations.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/operations/_file_system_operations.py index a6bd831c6b1f..abc58c7a7ba4 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/operations/_file_system_operations.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/operations/_file_system_operations.py @@ -38,6 +38,7 @@ def build_create_request( url: str, *, + version: str, request_id_parameter: Optional[str] = None, timeout: Optional[int] = None, properties: Optional[str] = None, @@ -47,7 +48,6 @@ def build_create_request( _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) resource: Literal["filesystem"] = kwargs.pop("resource", _params.pop("resource", "filesystem")) - version: Literal["2026-02-06"] = kwargs.pop("version", _headers.pop("x-ms-version", "2026-02-06")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -77,6 +77,7 @@ def build_create_request( def build_set_properties_request( url: str, *, + version: str, request_id_parameter: Optional[str] = None, timeout: Optional[int] = None, properties: Optional[str] = None, @@ -88,7 +89,6 @@ def build_set_properties_request( _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) resource: Literal["filesystem"] = kwargs.pop("resource", _params.pop("resource", "filesystem")) - version: Literal["2026-02-06"] = kwargs.pop("version", _headers.pop("x-ms-version", "2026-02-06")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -120,13 +120,12 @@ def build_set_properties_request( def build_get_properties_request( - url: str, *, request_id_parameter: Optional[str] = None, timeout: Optional[int] = None, **kwargs: Any + url: str, *, version: str, request_id_parameter: Optional[str] = None, timeout: Optional[int] = None, **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) resource: Literal["filesystem"] = kwargs.pop("resource", _params.pop("resource", "filesystem")) - version: Literal["2026-02-06"] = kwargs.pop("version", _headers.pop("x-ms-version", "2026-02-06")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -154,6 +153,7 @@ def build_get_properties_request( def build_delete_request( url: str, *, + version: str, request_id_parameter: Optional[str] = None, timeout: Optional[int] = None, if_modified_since: Optional[datetime.datetime] = None, @@ -164,7 +164,6 @@ def build_delete_request( _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) resource: Literal["filesystem"] = kwargs.pop("resource", _params.pop("resource", "filesystem")) - version: Literal["2026-02-06"] = kwargs.pop("version", _headers.pop("x-ms-version", "2026-02-06")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -197,6 +196,7 @@ def build_list_paths_request( url: str, *, recursive: bool, + version: str, request_id_parameter: Optional[str] = None, timeout: Optional[int] = None, continuation: Optional[str] = None, @@ -210,7 +210,6 @@ def build_list_paths_request( _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) resource: Literal["filesystem"] = kwargs.pop("resource", _params.pop("resource", "filesystem")) - version: Literal["2026-02-06"] = kwargs.pop("version", _headers.pop("x-ms-version", "2026-02-06")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -249,6 +248,7 @@ def build_list_paths_request( def build_list_blob_hierarchy_segment_request( # pylint: disable=name-too-long url: str, *, + version: str, prefix: Optional[str] = None, delimiter: Optional[str] = None, marker: Optional[str] = None, @@ -264,7 +264,6 @@ def build_list_blob_hierarchy_segment_request( # pylint: disable=name-too-long restype: Literal["container"] = kwargs.pop("restype", _params.pop("restype", "container")) comp: Literal["list"] = kwargs.pop("comp", _params.pop("comp", "list")) - version: Literal["2026-02-06"] = kwargs.pop("version", _headers.pop("x-ms-version", "2026-02-06")) accept = _headers.pop("Accept", "application/xml") # Construct URL @@ -373,11 +372,11 @@ def create( # pylint: disable=inconsistent-return-statements _request = build_create_request( url=self._config.url, + version=self._config.version, request_id_parameter=request_id_parameter, timeout=timeout, properties=properties, resource=self._config.resource, - version=self._config.version, headers=_headers, params=_params, ) @@ -471,13 +470,13 @@ def set_properties( # pylint: disable=inconsistent-return-statements _request = build_set_properties_request( url=self._config.url, + version=self._config.version, request_id_parameter=request_id_parameter, timeout=timeout, properties=properties, if_modified_since=_if_modified_since, if_unmodified_since=_if_unmodified_since, resource=self._config.resource, - version=self._config.version, headers=_headers, params=_params, ) @@ -544,10 +543,10 @@ def get_properties( # pylint: disable=inconsistent-return-statements _request = build_get_properties_request( url=self._config.url, + version=self._config.version, request_id_parameter=request_id_parameter, timeout=timeout, resource=self._config.resource, - version=self._config.version, headers=_headers, params=_params, ) @@ -638,12 +637,12 @@ def delete( # pylint: disable=inconsistent-return-statements _request = build_delete_request( url=self._config.url, + version=self._config.version, request_id_parameter=request_id_parameter, timeout=timeout, if_modified_since=_if_modified_since, if_unmodified_since=_if_unmodified_since, resource=self._config.resource, - version=self._config.version, headers=_headers, params=_params, ) @@ -748,6 +747,7 @@ def list_paths( _request = build_list_paths_request( url=self._config.url, recursive=recursive, + version=self._config.version, request_id_parameter=request_id_parameter, timeout=timeout, continuation=continuation, @@ -756,7 +756,6 @@ def list_paths( upn=upn, begin_from=begin_from, resource=self._config.resource, - version=self._config.version, headers=_headers, params=_params, ) @@ -862,6 +861,7 @@ def list_blob_hierarchy_segment( _request = build_list_blob_hierarchy_segment_request( url=self._config.url, + version=self._config.version, prefix=prefix, delimiter=delimiter, marker=marker, @@ -872,7 +872,6 @@ def list_blob_hierarchy_segment( request_id_parameter=request_id_parameter, restype=restype, comp=comp, - version=self._config.version, headers=_headers, params=_params, ) diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/operations/_path_operations.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/operations/_path_operations.py index ccff697bed0e..40a2b8902804 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/operations/_path_operations.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/operations/_path_operations.py @@ -40,6 +40,7 @@ def build_create_request( # pylint: disable=too-many-locals,too-many-statements,too-many-branches url: str, *, + version: str, request_id_parameter: Optional[str] = None, timeout: Optional[int] = None, resource: Optional[Union[str, _models.PathResourceType]] = None, @@ -80,7 +81,6 @@ def build_create_request( # pylint: disable=too-many-locals,too-many-statements _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - version: Literal["2026-02-06"] = kwargs.pop("version", _headers.pop("x-ms-version", "2026-02-06")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -182,6 +182,7 @@ def build_update_request( # pylint: disable=too-many-locals,too-many-statements action: Union[str, _models.PathUpdateAction], mode: Union[str, _models.PathSetAccessControlRecursiveMode], content: IO[bytes], + version: str, request_id_parameter: Optional[str] = None, timeout: Optional[int] = None, max_records: Optional[int] = None, @@ -215,7 +216,6 @@ def build_update_request( # pylint: disable=too-many-locals,too-many-statements _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - version: Literal["2026-02-06"] = kwargs.pop("version", _headers.pop("x-ms-version", "2026-02-06")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -299,6 +299,7 @@ def build_lease_request( url: str, *, x_ms_lease_action: Union[str, _models.PathLeaseAction], + version: str, request_id_parameter: Optional[str] = None, timeout: Optional[int] = None, x_ms_lease_break_period: Optional[int] = None, @@ -314,7 +315,6 @@ def build_lease_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - version: Literal["2026-02-06"] = kwargs.pop("version", _headers.pop("x-ms-version", "2026-02-06")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -360,6 +360,7 @@ def build_lease_request( def build_read_request( url: str, *, + version: str, request_id_parameter: Optional[str] = None, timeout: Optional[int] = None, range: Optional[str] = None, @@ -377,7 +378,6 @@ def build_read_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - version: Literal["2026-02-06"] = kwargs.pop("version", _headers.pop("x-ms-version", "2026-02-06")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -428,6 +428,7 @@ def build_read_request( def build_get_properties_request( url: str, *, + version: str, request_id_parameter: Optional[str] = None, timeout: Optional[int] = None, action: Optional[Union[str, _models.PathGetPropertiesAction]] = None, @@ -442,7 +443,6 @@ def build_get_properties_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - version: Literal["2026-02-06"] = kwargs.pop("version", _headers.pop("x-ms-version", "2026-02-06")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -483,6 +483,7 @@ def build_get_properties_request( def build_delete_request( url: str, *, + version: str, request_id_parameter: Optional[str] = None, timeout: Optional[int] = None, recursive: Optional[bool] = None, @@ -498,7 +499,6 @@ def build_delete_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - version: Literal["2026-02-06"] = kwargs.pop("version", _headers.pop("x-ms-version", "2026-02-06")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -541,6 +541,7 @@ def build_delete_request( def build_set_access_control_request( url: str, *, + version: str, timeout: Optional[int] = None, lease_id: Optional[str] = None, owner: Optional[str] = None, @@ -558,7 +559,6 @@ def build_set_access_control_request( _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) action: Literal["setAccessControl"] = kwargs.pop("action", _params.pop("action", "setAccessControl")) - version: Literal["2026-02-06"] = kwargs.pop("version", _headers.pop("x-ms-version", "2026-02-06")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -605,6 +605,7 @@ def build_set_access_control_recursive_request( # pylint: disable=name-too-long url: str, *, mode: Union[str, _models.PathSetAccessControlRecursiveMode], + version: str, timeout: Optional[int] = None, continuation: Optional[str] = None, force_flag: Optional[bool] = None, @@ -619,7 +620,6 @@ def build_set_access_control_recursive_request( # pylint: disable=name-too-long action: Literal["setAccessControlRecursive"] = kwargs.pop( "action", _params.pop("action", "setAccessControlRecursive") ) - version: Literal["2026-02-06"] = kwargs.pop("version", _headers.pop("x-ms-version", "2026-02-06")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -656,6 +656,7 @@ def build_set_access_control_recursive_request( # pylint: disable=name-too-long def build_flush_data_request( # pylint: disable=too-many-locals url: str, *, + version: str, timeout: Optional[int] = None, position: Optional[int] = None, retain_uncommitted_data: Optional[bool] = None, @@ -685,7 +686,6 @@ def build_flush_data_request( # pylint: disable=too-many-locals _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) action: Literal["flush"] = kwargs.pop("action", _params.pop("action", "flush")) - version: Literal["2026-02-06"] = kwargs.pop("version", _headers.pop("x-ms-version", "2026-02-06")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -758,6 +758,7 @@ def build_append_data_request( # pylint: disable=too-many-locals url: str, *, content: IO[bytes], + version: str, position: Optional[int] = None, timeout: Optional[int] = None, content_length: Optional[int] = None, @@ -781,7 +782,6 @@ def build_append_data_request( # pylint: disable=too-many-locals action: Literal["append"] = kwargs.pop("action", _params.pop("action", "append")) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - version: Literal["2026-02-06"] = kwargs.pop("version", _headers.pop("x-ms-version", "2026-02-06")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -848,6 +848,7 @@ def build_set_expiry_request( url: str, *, expiry_options: Union[str, _models.PathExpiryOptions], + version: str, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, expires_on: Optional[str] = None, @@ -857,7 +858,6 @@ def build_set_expiry_request( _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) comp: Literal["expiry"] = kwargs.pop("comp", _params.pop("comp", "expiry")) - version: Literal["2026-02-06"] = kwargs.pop("version", _headers.pop("x-ms-version", "2026-02-06")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -888,6 +888,7 @@ def build_set_expiry_request( def build_undelete_request( url: str, *, + version: str, timeout: Optional[int] = None, undelete_source: Optional[str] = None, request_id_parameter: Optional[str] = None, @@ -897,7 +898,6 @@ def build_undelete_request( _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) comp: Literal["undelete"] = kwargs.pop("comp", _params.pop("comp", "undelete")) - version: Literal["2026-02-06"] = kwargs.pop("version", _headers.pop("x-ms-version", "2026-02-06")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -1131,6 +1131,7 @@ def create( # pylint: disable=inconsistent-return-statements,too-many-locals _request = build_create_request( url=self._config.url, + version=self._config.version, request_id_parameter=request_id_parameter, timeout=timeout, resource=resource, @@ -1166,7 +1167,6 @@ def create( # pylint: disable=inconsistent-return-statements,too-many-locals expiry_options=expiry_options, expires_on=expires_on, encryption_context=encryption_context, - version=self._config.version, headers=_headers, params=_params, ) @@ -1399,6 +1399,7 @@ def update( # pylint: disable=too-many-locals url=self._config.url, action=action, mode=mode, + version=self._config.version, request_id_parameter=request_id_parameter, timeout=timeout, max_records=max_records, @@ -1427,7 +1428,6 @@ def update( # pylint: disable=too-many-locals structured_body_type=structured_body_type, structured_content_length=structured_content_length, content_type=content_type, - version=self._config.version, content=_content, headers=_headers, params=_params, @@ -1515,7 +1515,7 @@ def lease( # pylint: disable=inconsistent-return-statements the current lease ID in "x-ms-lease-id" and the new lease ID in "x-ms-proposed-lease-id" to change the lease ID of an active lease. Use "renew" and specify the "x-ms-lease-id" to renew an existing lease. Use "release" and specify the "x-ms-lease-id" to release a lease. Known values - are: "acquire", "break", "change", "renew", "release", and "break". Required. + are: "acquire", "break", "change", "renew", and "release". Required. :type x_ms_lease_action: str or ~azure.storage.filedatalake.models.PathLeaseAction :param request_id_parameter: Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. Default @@ -1571,6 +1571,7 @@ def lease( # pylint: disable=inconsistent-return-statements _request = build_lease_request( url=self._config.url, x_ms_lease_action=x_ms_lease_action, + version=self._config.version, request_id_parameter=request_id_parameter, timeout=timeout, x_ms_lease_break_period=x_ms_lease_break_period, @@ -1581,7 +1582,6 @@ def lease( # pylint: disable=inconsistent-return-statements if_modified_since=_if_modified_since, if_unmodified_since=_if_unmodified_since, x_ms_lease_duration=self._config.x_ms_lease_duration, - version=self._config.version, headers=_headers, params=_params, ) @@ -1712,6 +1712,7 @@ def read( _request = build_read_request( url=self._config.url, + version=self._config.version, request_id_parameter=request_id_parameter, timeout=timeout, range=range, @@ -1724,7 +1725,6 @@ def read( encryption_key=_encryption_key, encryption_key_sha256=_encryption_key_sha256, encryption_algorithm=_encryption_algorithm, # type: ignore - version=self._config.version, headers=_headers, params=_params, ) @@ -1902,6 +1902,7 @@ def get_properties( # pylint: disable=inconsistent-return-statements _request = build_get_properties_request( url=self._config.url, + version=self._config.version, request_id_parameter=request_id_parameter, timeout=timeout, action=action, @@ -1911,7 +1912,6 @@ def get_properties( # pylint: disable=inconsistent-return-statements if_none_match=_if_none_match, if_modified_since=_if_modified_since, if_unmodified_since=_if_unmodified_since, - version=self._config.version, headers=_headers, params=_params, ) @@ -2053,6 +2053,7 @@ def delete( # pylint: disable=inconsistent-return-statements _request = build_delete_request( url=self._config.url, + version=self._config.version, request_id_parameter=request_id_parameter, timeout=timeout, recursive=recursive, @@ -2063,7 +2064,6 @@ def delete( # pylint: disable=inconsistent-return-statements if_modified_since=_if_modified_since, if_unmodified_since=_if_unmodified_since, paginated=paginated, - version=self._config.version, headers=_headers, params=_params, ) @@ -2177,6 +2177,7 @@ def set_access_control( # pylint: disable=inconsistent-return-statements _request = build_set_access_control_request( url=self._config.url, + version=self._config.version, timeout=timeout, lease_id=_lease_id, owner=owner, @@ -2189,7 +2190,6 @@ def set_access_control( # pylint: disable=inconsistent-return-statements if_unmodified_since=_if_unmodified_since, request_id_parameter=request_id_parameter, action=action, - version=self._config.version, headers=_headers, params=_params, ) @@ -2295,6 +2295,7 @@ def set_access_control_recursive( _request = build_set_access_control_recursive_request( url=self._config.url, mode=mode, + version=self._config.version, timeout=timeout, continuation=continuation, force_flag=force_flag, @@ -2302,7 +2303,6 @@ def set_access_control_recursive( acl=acl, request_id_parameter=request_id_parameter, action=action, - version=self._config.version, headers=_headers, params=_params, ) @@ -2472,6 +2472,7 @@ def flush_data( # pylint: disable=inconsistent-return-statements,too-many-local _request = build_flush_data_request( url=self._config.url, + version=self._config.version, timeout=timeout, position=position, retain_uncommitted_data=retain_uncommitted_data, @@ -2496,7 +2497,6 @@ def flush_data( # pylint: disable=inconsistent-return-statements,too-many-local encryption_key_sha256=_encryption_key_sha256, encryption_algorithm=_encryption_algorithm, # type: ignore action=action, - version=self._config.version, headers=_headers, params=_params, ) @@ -2651,6 +2651,7 @@ def append_data( # pylint: disable=inconsistent-return-statements,too-many-loca _request = build_append_data_request( url=self._config.url, + version=self._config.version, position=position, timeout=timeout, content_length=content_length, @@ -2669,7 +2670,6 @@ def append_data( # pylint: disable=inconsistent-return-statements,too-many-loca structured_content_length=structured_content_length, action=action, content_type=content_type, - version=self._config.version, content=_content, headers=_headers, params=_params, @@ -2763,11 +2763,11 @@ def set_expiry( # pylint: disable=inconsistent-return-statements _request = build_set_expiry_request( url=self._config.url, expiry_options=expiry_options, + version=self._config.version, timeout=timeout, request_id_parameter=request_id_parameter, expires_on=expires_on, comp=comp, - version=self._config.version, headers=_headers, params=_params, ) @@ -2843,11 +2843,11 @@ def undelete( # pylint: disable=inconsistent-return-statements _request = build_undelete_request( url=self._config.url, + version=self._config.version, timeout=timeout, undelete_source=undelete_source, request_id_parameter=request_id_parameter, comp=comp, - version=self._config.version, headers=_headers, params=_params, ) diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/operations/_service_operations.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/operations/_service_operations.py index 49f604f39e94..d0f5d710b7ac 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/operations/_service_operations.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_generated/operations/_service_operations.py @@ -38,6 +38,7 @@ def build_list_file_systems_request( url: str, *, + version: str, prefix: Optional[str] = None, continuation: Optional[str] = None, max_results: Optional[int] = None, @@ -49,7 +50,6 @@ def build_list_file_systems_request( _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) resource: Literal["account"] = kwargs.pop("resource", _params.pop("resource", "account")) - version: Literal["2026-02-06"] = kwargs.pop("version", _headers.pop("x-ms-version", "2026-02-06")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -160,13 +160,13 @@ def prepare_request(next_link=None): _request = build_list_file_systems_request( url=self._config.url, + version=self._config.version, prefix=prefix, continuation=continuation, max_results=max_results, request_id_parameter=request_id_parameter, timeout=timeout, resource=resource, - version=self._config.version, headers=_headers, params=_params, ) diff --git a/sdk/storage/azure-storage-file-datalake/swagger/README.md b/sdk/storage/azure-storage-file-datalake/swagger/README.md index 006da7eae4d3..21777a2b10f6 100644 --- a/sdk/storage/azure-storage-file-datalake/swagger/README.md +++ b/sdk/storage/azure-storage-file-datalake/swagger/README.md @@ -16,7 +16,7 @@ autorest --v3 --python ### Settings ``` yaml -input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/storage/data-plane/Azure.Storage.Files.DataLake/stable/2026-02-06/DataLakeStorage.json +input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/storage/data-plane/Azure.Storage.Files.DataLake/stable/2026-06-06/DataLakeStorage.json output-folder: ../azure/storage/filedatalake/_generated namespace: azure.storage.filedatalake no-namespace-folders: true diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_generated/aio/operations/_file_operations.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_generated/aio/operations/_file_operations.py index 76311af25265..1f6bc63e53c0 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_generated/aio/operations/_file_operations.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_generated/aio/operations/_file_operations.py @@ -95,12 +95,14 @@ async def create( # pylint: disable=too-many-locals content_md5: Optional[bytes] = None, file_property_semantics: Optional[Union[str, _models.FilePropertySemantics]] = None, content_length: Optional[int] = None, + structured_body_type: Optional[str] = None, + structured_content_length: Optional[int] = None, file_http_headers: Optional[_models.FileHTTPHeaders] = None, lease_access_conditions: Optional[_models.LeaseAccessConditions] = None, optionalbody: Optional[IO[bytes]] = None, **kwargs: Any ) -> None: - """Creates a new file or replaces a file. Note it only initializes the file with no content. + """Creates a new file or replaces a file. Can also initialize the file with content. :param file_content_length: Specifies the maximum size for the file, up to 4 TB. Required. :type file_content_length: int @@ -167,6 +169,13 @@ async def create( # pylint: disable=too-many-locals When the x-ms-write header is set to clear, the value of this header must be set to zero. Default value is None. :type content_length: int + :param structured_body_type: Required if the request body is a structured message. Specifies + the message schema version and properties. Default value is None. + :type structured_body_type: str + :param structured_content_length: Required if the request body is a structured message. + Specifies the length of the blob/file content inside the message body. Will always be smaller + than Content-Length. Default value is None. + :type structured_content_length: int :param file_http_headers: Parameter group. Default value is None. :type file_http_headers: ~azure.storage.fileshare.models.FileHTTPHeaders :param lease_access_conditions: Parameter group. Default value is None. @@ -240,6 +249,8 @@ async def create( # pylint: disable=too-many-locals content_md5=content_md5, file_property_semantics=file_property_semantics, content_length=content_length, + structured_body_type=structured_body_type, + structured_content_length=structured_content_length, allow_trailing_dot=self._config.allow_trailing_dot, file_request_intent=self._config.file_request_intent, file_type_constant=file_type_constant, @@ -297,6 +308,9 @@ async def create( # pylint: disable=too-many-locals response_headers["x-ms-file-file-type"] = self._deserialize("str", response.headers.get("x-ms-file-file-type")) response_headers["Content-MD5"] = self._deserialize("bytearray", response.headers.get("Content-MD5")) response_headers["Content-Length"] = self._deserialize("int", response.headers.get("Content-Length")) + response_headers["x-ms-structured-body"] = self._deserialize( + "str", response.headers.get("x-ms-structured-body") + ) if cls: return cls(pipeline_response, None, response_headers) # type: ignore diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_generated/operations/_file_operations.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_generated/operations/_file_operations.py index 176dfe9bda33..22ca6948e8b4 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_generated/operations/_file_operations.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_generated/operations/_file_operations.py @@ -64,6 +64,8 @@ def build_create_request( # pylint: disable=too-many-locals,too-many-statements content_md5: Optional[bytes] = None, file_property_semantics: Optional[Union[str, _models.FilePropertySemantics]] = None, content_length: Optional[int] = None, + structured_body_type: Optional[str] = None, + structured_content_length: Optional[int] = None, content: Optional[IO[bytes]] = None, allow_trailing_dot: Optional[bool] = None, file_request_intent: Optional[Union[str, _models.ShareTokenIntent]] = None, @@ -146,6 +148,12 @@ def build_create_request( # pylint: disable=too-many-locals,too-many-statements ) if content_length is not None: _headers["Content-Length"] = _SERIALIZER.header("content_length", content_length, "int") + if structured_body_type is not None: + _headers["x-ms-structured-body"] = _SERIALIZER.header("structured_body_type", structured_body_type, "str") + if structured_content_length is not None: + _headers["x-ms-structured-content-length"] = _SERIALIZER.header( + "structured_content_length", structured_content_length, "int" + ) if content_type is not None: _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") @@ -1347,12 +1355,14 @@ def create( # pylint: disable=inconsistent-return-statements,too-many-locals content_md5: Optional[bytes] = None, file_property_semantics: Optional[Union[str, _models.FilePropertySemantics]] = None, content_length: Optional[int] = None, + structured_body_type: Optional[str] = None, + structured_content_length: Optional[int] = None, file_http_headers: Optional[_models.FileHTTPHeaders] = None, lease_access_conditions: Optional[_models.LeaseAccessConditions] = None, optionalbody: Optional[IO[bytes]] = None, **kwargs: Any ) -> None: - """Creates a new file or replaces a file. Note it only initializes the file with no content. + """Creates a new file or replaces a file. Can also initialize the file with content. :param file_content_length: Specifies the maximum size for the file, up to 4 TB. Required. :type file_content_length: int @@ -1419,6 +1429,13 @@ def create( # pylint: disable=inconsistent-return-statements,too-many-locals When the x-ms-write header is set to clear, the value of this header must be set to zero. Default value is None. :type content_length: int + :param structured_body_type: Required if the request body is a structured message. Specifies + the message schema version and properties. Default value is None. + :type structured_body_type: str + :param structured_content_length: Required if the request body is a structured message. + Specifies the length of the blob/file content inside the message body. Will always be smaller + than Content-Length. Default value is None. + :type structured_content_length: int :param file_http_headers: Parameter group. Default value is None. :type file_http_headers: ~azure.storage.fileshare.models.FileHTTPHeaders :param lease_access_conditions: Parameter group. Default value is None. @@ -1492,6 +1509,8 @@ def create( # pylint: disable=inconsistent-return-statements,too-many-locals content_md5=content_md5, file_property_semantics=file_property_semantics, content_length=content_length, + structured_body_type=structured_body_type, + structured_content_length=structured_content_length, allow_trailing_dot=self._config.allow_trailing_dot, file_request_intent=self._config.file_request_intent, file_type_constant=file_type_constant, @@ -1549,6 +1568,9 @@ def create( # pylint: disable=inconsistent-return-statements,too-many-locals response_headers["x-ms-file-file-type"] = self._deserialize("str", response.headers.get("x-ms-file-file-type")) response_headers["Content-MD5"] = self._deserialize("bytearray", response.headers.get("Content-MD5")) response_headers["Content-Length"] = self._deserialize("int", response.headers.get("Content-Length")) + response_headers["x-ms-structured-body"] = self._deserialize( + "str", response.headers.get("x-ms-structured-body") + ) if cls: return cls(pipeline_response, None, response_headers) # type: ignore diff --git a/sdk/storage/azure-storage-file-share/swagger/README.md b/sdk/storage/azure-storage-file-share/swagger/README.md index 6910c5517eca..b0a4352a5550 100644 --- a/sdk/storage/azure-storage-file-share/swagger/README.md +++ b/sdk/storage/azure-storage-file-share/swagger/README.md @@ -16,7 +16,7 @@ autorest --v3 --python ### Settings ``` yaml -input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/storage/data-plane/Microsoft.FileStorage/stable/2026-04-06/file.json +input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/storage/data-plane/Microsoft.FileStorage/stable/2026-06-06/file.json output-folder: ../azure/storage/fileshare/_generated namespace: azure.storage.fileshare no-namespace-folders: true From dbe120811d64a9ab583e6ca4b6e3ef29cb9c2129 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 26 Mar 2026 13:34:39 -0400 Subject: [PATCH 07/16] Fixed test failures --- .../storage/filedatalake/_data_lake_service_client.py | 9 +++++++-- .../azure/storage/filedatalake/_file_system_client.py | 3 ++- .../azure/storage/filedatalake/_path_client.py | 2 +- .../filedatalake/aio/_data_lake_service_client_async.py | 9 +++++++-- .../filedatalake/aio/_file_system_client_async.py | 3 ++- .../azure/storage/filedatalake/aio/_path_client_async.py | 2 +- 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_service_client.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_service_client.py index b30a532af67e..a8cc3d21f39f 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_service_client.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_service_client.py @@ -116,8 +116,13 @@ def __init__( # ADLS doesn't support secondary endpoint, make sure it's empty self._hosts[LocationMode.SECONDARY] = "" - self._client = AzureDataLakeStorageRESTAPI(self.url, base_url=self.url, pipeline=self._pipeline) - self._client._config.version = get_api_version(kwargs) # type: ignore [assignment] + self._api_version = get_api_version(kwargs) + self._client = AzureDataLakeStorageRESTAPI( + self.url, + version=self._api_version, + base_url=self.url, + pipeline=self._pipeline + ) def __enter__(self) -> Self: self._client.__enter__() diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py index 8a5f6d643152..2178be109500 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py @@ -157,11 +157,11 @@ def close(self) -> None: def _build_generated_client(self, url: str) -> AzureDataLakeStorageRESTAPI: client = AzureDataLakeStorageRESTAPI( url, + version=self._api_version, base_url=url, file_system=self.file_system_name, pipeline=self._pipeline ) - client._config.version = self._api_version # type: ignore [assignment] # pylint: disable=protected-access return client def _format_url(self, hostname: str) -> str: @@ -968,6 +968,7 @@ def _undelete_path( ) path_client = AzureDataLakeStorageRESTAPI( url, + version=self._api_version, filesystem=self.file_system_name, path=deleted_path_name, pipeline=pipeline diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_path_client.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_path_client.py index 3df13a6b2026..54e1ecf13492 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_path_client.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_path_client.py @@ -163,12 +163,12 @@ def close(self) -> None: def _build_generated_client(self, url: str) -> AzureDataLakeStorageRESTAPI: client = AzureDataLakeStorageRESTAPI( url, + version=self._api_version, base_url=url, file_system=self.file_system_name, path=self.path_name, pipeline=self._pipeline ) - client._config.version = self._api_version # type: ignore [assignment] # pylint: disable=protected-access return client def _format_url(self, hostname: str) -> str: diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_service_client_async.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_service_client_async.py index 5ff3b28659a3..673782455886 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_service_client_async.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_service_client_async.py @@ -121,8 +121,13 @@ def __init__( # ADLS doesn't support secondary endpoint, make sure it's empty self._hosts[LocationMode.SECONDARY] = "" - self._client = AzureDataLakeStorageRESTAPI(self.url, base_url=self.url, pipeline=self._pipeline) - self._client._config.version = get_api_version(kwargs) # type: ignore [assignment] + self._api_version = get_api_version(kwargs) + self._client = AzureDataLakeStorageRESTAPI( + self.url, + version=self._api_version, + base_url=self.url, + pipeline=self._pipeline + ) self._loop = kwargs.get('loop', None) async def __aenter__(self) -> Self: diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_file_system_client_async.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_file_system_client_async.py index 735a6d410132..64355b81c310 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_file_system_client_async.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_file_system_client_async.py @@ -165,11 +165,11 @@ async def close(self) -> None: # type: ignore def _build_generated_client(self, url: str) -> AzureDataLakeStorageRESTAPI: client = AzureDataLakeStorageRESTAPI( url, + version=self._api_version, base_url=url, file_system=self.file_system_name, pipeline=self._pipeline ) - client._config.version = self._api_version # type: ignore [assignment] # pylint: disable=protected-access return client def _format_url(self, hostname: str) -> str: @@ -972,6 +972,7 @@ async def _undelete_path( ) path_client = AzureDataLakeStorageRESTAPI( url, + version=self._api_version, filesystem=self.file_system_name, path=deleted_path_name, pipeline=pipeline diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_path_client_async.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_path_client_async.py index a20a88a5985a..210be85bbb2c 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_path_client_async.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_path_client_async.py @@ -166,12 +166,12 @@ async def close(self) -> None: # type: ignore def _build_generated_client(self, url: str) -> AzureDataLakeStorageRESTAPI: client = AzureDataLakeStorageRESTAPI( url, + version=self._api_version, base_url=url, file_system=self.file_system_name, path=self.path_name, pipeline=self._pipeline ) - client._config.version = self._api_version # type: ignore [assignment] # pylint: disable=protected-access return client def _format_url(self, hostname: str) -> str: From a0bd8f787e050994aa8e551508bfe6cd4feba836 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 26 Mar 2026 14:04:46 -0400 Subject: [PATCH 08/16] max_concurrency=None tests --- sdk/storage/azure-storage-file-share/assets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/storage/azure-storage-file-share/assets.json b/sdk/storage/azure-storage-file-share/assets.json index 992936aafc04..f8436a861d3c 100644 --- a/sdk/storage/azure-storage-file-share/assets.json +++ b/sdk/storage/azure-storage-file-share/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "python", "TagPrefix": "python/storage/azure-storage-file-share", - "Tag": "python/storage/azure-storage-file-share_b02a740ab3" + "Tag": "python/storage/azure-storage-file-share_4afd6de033" } From 9be45a34ffb6f962132d6684e4fe5edce2423ad9 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 26 Mar 2026 14:39:27 -0400 Subject: [PATCH 09/16] Fixed bug --- .../azure/storage/blob/_shared_access_signature.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py index d7d5d1e9be66..e61abc3c764e 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py @@ -170,9 +170,7 @@ def generate_blob( resource = 'bs' if snapshot else 'b' resource = 'bv' if version_id else resource - if is_directory: - resource = 'd' - sas.add_directory_depth(blob_name) + resource = 'd' if is_directory else resource sas.add_resource(resource) sas.add_timestamp(snapshot or version_id) @@ -180,6 +178,10 @@ def generate_blob( content_encoding, content_language, content_type) sas.add_encryption_scope(**kwargs) + + if is_directory: + sas.add_directory_depth(blob_name) + sas.add_info_for_hns_account(**kwargs) sas.add_resource_signature( self.account_name, From 2ec74db4da0b922aabfb14fa9f974f13b7b0524c Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 26 Mar 2026 17:04:58 -0400 Subject: [PATCH 10/16] PR Feedback --- .../storage/blob/_shared_access_signature.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py index e61abc3c764e..bfe0e5c30fb0 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py @@ -180,7 +180,7 @@ def generate_blob( sas.add_encryption_scope(**kwargs) if is_directory: - sas.add_directory_depth(blob_name) + sas.add_directory_depth(blob_name, kwargs.pop('sdd', None)) sas.add_info_for_hns_account(**kwargs) sas.add_resource_signature( @@ -319,17 +319,17 @@ class _BlobSharedAccessHelper(_SharedAccessHelper): def add_timestamp(self, timestamp): self._add_query(BlobQueryStringConstants.SIGNED_TIMESTAMP, timestamp) - def add_directory_depth(self, blob_name): - if blob_name == "" or blob_name == "/": - depth = 0 - else: - depth = len(blob_name.strip("/").split("/")) - self._add_query(QueryStringConstants.SIGNED_DIRECTORY_DEPTH, str(depth)) + def add_directory_depth(self, blob_name, sdd): + # sdd may be provided from Datalake + # If not provided, it will be manually computed from blob_name + if sdd is None: + if blob_name == "" or blob_name == "/": + sdd = 0 + else: + sdd = len(blob_name.strip("/").split("/")) + self._add_query(QueryStringConstants.SIGNED_DIRECTORY_DEPTH, str(sdd)) def add_info_for_hns_account(self, **kwargs): - sdd = kwargs.pop('sdd', None) - if sdd is not None: - self._add_query(QueryStringConstants.SIGNED_DIRECTORY_DEPTH, str(sdd)) self._add_query(QueryStringConstants.SIGNED_AUTHORIZED_OID, kwargs.pop('preauthorized_agent_object_id', None)) self._add_query(QueryStringConstants.SIGNED_UNAUTHORIZED_OID, kwargs.pop('agent_object_id', None)) self._add_query(QueryStringConstants.SIGNED_CORRELATION_ID, kwargs.pop('correlation_id', None)) From 0a0638b864e11dce8cf6c9c276f785d9a95e4120 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 26 Mar 2026 21:04:16 -0400 Subject: [PATCH 11/16] Test recordings --- sdk/storage/azure-storage-blob/assets.json | 2 +- sdk/storage/azure-storage-blob/tests/test_common_blob.py | 6 ++++-- .../azure-storage-blob/tests/test_common_blob_async.py | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/sdk/storage/azure-storage-blob/assets.json b/sdk/storage/azure-storage-blob/assets.json index fd266e619907..f7f288f51754 100644 --- a/sdk/storage/azure-storage-blob/assets.json +++ b/sdk/storage/azure-storage-blob/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "python", "TagPrefix": "python/storage/azure-storage-blob", - "Tag": "python/storage/azure-storage-blob_054396a10c" + "Tag": "python/storage/azure-storage-blob_a6eb270886" } diff --git a/sdk/storage/azure-storage-blob/tests/test_common_blob.py b/sdk/storage/azure-storage-blob/tests/test_common_blob.py index a82d607b42bf..652a5cb5a0df 100644 --- a/sdk/storage/azure-storage-blob/tests/test_common_blob.py +++ b/sdk/storage/azure-storage-blob/tests/test_common_blob.py @@ -3830,8 +3830,8 @@ def test_smart_rehydrate(self, **kwargs): assert props is not None assert props.archive_status == "rehydrate-pending-to-smart" - @pytest.mark.live_test_only @BlobPreparer() + @recorded_by_proxy def test_blob_fns_directory(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") variables = kwargs.pop("variables", {}) @@ -3871,8 +3871,10 @@ def test_blob_fns_directory(self, **kwargs): finally: service.delete_container(container_name) - @pytest.mark.live_test_only + return variables + @BlobPreparer() + @recorded_by_proxy def test_blob_fns_directory_fail(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") variables = kwargs.pop("variables", {}) diff --git a/sdk/storage/azure-storage-blob/tests/test_common_blob_async.py b/sdk/storage/azure-storage-blob/tests/test_common_blob_async.py index f103e122192c..feca11c74ee2 100644 --- a/sdk/storage/azure-storage-blob/tests/test_common_blob_async.py +++ b/sdk/storage/azure-storage-blob/tests/test_common_blob_async.py @@ -3768,8 +3768,8 @@ async def test_smart_rehydrate(self, **kwargs): assert props is not None assert props.archive_status == "rehydrate-pending-to-smart" - @pytest.mark.live_test_only @BlobPreparer() + @recorded_by_proxy_async async def test_blob_fns_directory(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") variables = kwargs.pop("variables", {}) @@ -3811,8 +3811,10 @@ async def test_blob_fns_directory(self, **kwargs): finally: await service.delete_container(container_name) - @pytest.mark.live_test_only + return variables + @BlobPreparer() + @recorded_by_proxy_async async def test_blob_fns_directory_fail(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") variables = kwargs.pop("variables", {}) From 56318df9714978d62a1d6e1289d54b8c53c925a8 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 27 Mar 2026 20:49:30 -0400 Subject: [PATCH 12/16] Black formatter --- .../azure/storage/queue/_deserialize.py | 8 +- .../azure/storage/queue/_encryption.py | 167 ++++++--- .../queue/_generated/_azure_queue_storage.py | 47 ++- .../queue/_generated/_configuration.py | 24 +- .../queue/_generated/_utils/serialization.py | 292 +++++++++++---- .../_generated/aio/_azure_queue_storage.py | 41 ++- .../queue/_generated/aio/_configuration.py | 28 +- .../aio/operations/_message_id_operations.py | 83 +++-- .../aio/operations/_messages_operations.py | 133 +++++-- .../queue/_generated/aio/operations/_patch.py | 5 +- .../aio/operations/_queue_operations.py | 184 +++++++--- .../aio/operations/_service_operations.py | 188 +++++++--- .../queue/_generated/models/_models_py3.py | 28 +- .../storage/queue/_generated/models/_patch.py | 5 +- .../operations/_message_id_operations.py | 107 ++++-- .../operations/_messages_operations.py | 197 +++++++--- .../queue/_generated/operations/_patch.py | 5 +- .../operations/_queue_operations.py | 266 ++++++++++---- .../operations/_service_operations.py | 292 +++++++++++---- .../azure/storage/queue/_message_encoding.py | 25 +- .../azure/storage/queue/_models.py | 44 ++- .../azure/storage/queue/_queue_client.py | 210 ++++++++--- .../storage/queue/_queue_client_helpers.py | 19 +- .../storage/queue/_queue_service_client.py | 92 ++++- .../queue/_queue_service_client_helpers.py | 10 +- .../azure/storage/queue/_serialize.py | 4 +- .../storage/queue/_shared/authentication.py | 21 +- .../storage/queue/_shared/base_client.py | 131 +++++-- .../queue/_shared/base_client_async.py | 85 ++++- .../azure/storage/queue/_shared/constants.py | 1 - .../azure/storage/queue/_shared/models.py | 77 +++- .../azure/storage/queue/_shared/parser.py | 5 +- .../azure/storage/queue/_shared/policies.py | 184 +++++++--- .../storage/queue/_shared/policies_async.py | 126 +++++-- .../storage/queue/_shared/request_handlers.py | 31 +- .../queue/_shared/response_handlers.py | 87 +++-- .../queue/_shared/shared_access_signature.py | 32 +- .../azure/storage/queue/_shared/uploads.py | 82 +++-- .../storage/queue/_shared/uploads_async.py | 54 ++- .../storage/queue/_shared_access_signature.py | 78 +++- .../azure/storage/queue/aio/__init__.py | 1 - .../azure/storage/queue/aio/_models.py | 16 +- .../storage/queue/aio/_queue_client_async.py | 216 ++++++++--- .../queue/aio/_queue_service_client_async.py | 94 ++++- .../samples/queue_samples_authentication.py | 27 +- .../queue_samples_authentication_async.py | 27 +- .../samples/queue_samples_hello_world.py | 8 +- .../queue_samples_hello_world_async.py | 12 +- .../samples/queue_samples_message.py | 25 +- .../samples/queue_samples_message_async.py | 59 ++- .../samples/queue_samples_service.py | 52 ++- .../samples/queue_samples_service_async.py | 51 ++- sdk/storage/azure-storage-queue/setup.py | 7 +- .../azure-storage-queue/tests/conftest.py | 21 +- .../tests/encryption_test_helper.py | 14 +- .../tests/settings/testcase.py | 16 +- .../azure-storage-queue/tests/test_queue.py | 322 ++++++++++++----- .../tests/test_queue_api_version.py | 15 +- .../tests/test_queue_api_version_async.py | 15 +- .../tests/test_queue_async.py | 340 +++++++++++++----- .../tests/test_queue_client.py | 251 +++++++++---- .../tests/test_queue_client_async.py | 240 ++++++++++--- .../tests/test_queue_encodings.py | 35 +- .../tests/test_queue_encodings_async.py | 35 +- .../tests/test_queue_encryption.py | 128 +++++-- .../tests/test_queue_encryption_async.py | 133 +++++-- .../tests/test_queue_service_properties.py | 91 +++-- .../test_queue_service_properties_async.py | 85 ++++- .../tests/test_queue_service_stats.py | 8 +- .../tests/test_queue_service_stats_async.py | 8 +- 70 files changed, 4460 insertions(+), 1390 deletions(-) diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_deserialize.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_deserialize.py index 355a0053c2dc..e46e26dc7da6 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_deserialize.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_deserialize.py @@ -16,13 +16,17 @@ from azure.core.pipeline import PipelineResponse -def deserialize_queue_properties(response: "PipelineResponse", obj: Any, headers: Dict[str, Any]) -> QueueProperties: +def deserialize_queue_properties( + response: "PipelineResponse", obj: Any, headers: Dict[str, Any] +) -> QueueProperties: metadata = deserialize_metadata(response, obj, headers) queue_properties = QueueProperties(metadata=metadata, **headers) return queue_properties -def deserialize_queue_creation(response: "PipelineResponse", obj: Any, headers: Dict[str, Any]) -> Dict[str, Any]: +def deserialize_queue_creation( + response: "PipelineResponse", obj: Any, headers: Dict[str, Any] +) -> Dict[str, Any]: response = response.http_response if response.status_code == 204: # type: ignore [attr-defined] error_code = StorageErrorCode.queue_already_exists diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_encryption.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_encryption.py index 2153d1da1da6..204f5f3319aa 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_encryption.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_encryption.py @@ -41,7 +41,11 @@ _ENCRYPTION_PROTOCOL_V1 = "1.0" _ENCRYPTION_PROTOCOL_V2 = "2.0" _ENCRYPTION_PROTOCOL_V2_1 = "2.1" -_VALID_ENCRYPTION_PROTOCOLS = [_ENCRYPTION_PROTOCOL_V1, _ENCRYPTION_PROTOCOL_V2, _ENCRYPTION_PROTOCOL_V2_1] +_VALID_ENCRYPTION_PROTOCOLS = [ + _ENCRYPTION_PROTOCOL_V1, + _ENCRYPTION_PROTOCOL_V2, + _ENCRYPTION_PROTOCOL_V2_1, +] _ENCRYPTION_V2_PROTOCOLS = [_ENCRYPTION_PROTOCOL_V2, _ENCRYPTION_PROTOCOL_V2_1] _GCM_REGION_DATA_LENGTH = 4 * 1024 * 1024 _GCM_NONCE_LENGTH = 12 @@ -49,9 +53,7 @@ _ERROR_OBJECT_INVALID = "{0} does not define a complete interface. Value of {1} is either missing or invalid." -_ERROR_UNSUPPORTED_METHOD_FOR_ENCRYPTION = ( - "The require_encryption flag is set, but encryption is not supported for this method." -) +_ERROR_UNSUPPORTED_METHOD_FOR_ENCRYPTION = "The require_encryption flag is set, but encryption is not supported for this method." class KeyEncryptionKey(Protocol): @@ -73,11 +75,19 @@ def _validate_not_none(param_name: str, param: Any): def _validate_key_encryption_key_wrap(kek: KeyEncryptionKey): # Note that None is not callable and so will fail the second clause of each check. if not hasattr(kek, "wrap_key") or not callable(kek.wrap_key): - raise AttributeError(_ERROR_OBJECT_INVALID.format("key encryption key", "wrap_key")) + raise AttributeError( + _ERROR_OBJECT_INVALID.format("key encryption key", "wrap_key") + ) if not hasattr(kek, "get_kid") or not callable(kek.get_kid): - raise AttributeError(_ERROR_OBJECT_INVALID.format("key encryption key", "get_kid")) - if not hasattr(kek, "get_key_wrap_algorithm") or not callable(kek.get_key_wrap_algorithm): - raise AttributeError(_ERROR_OBJECT_INVALID.format("key encryption key", "get_key_wrap_algorithm")) + raise AttributeError( + _ERROR_OBJECT_INVALID.format("key encryption key", "get_kid") + ) + if not hasattr(kek, "get_key_wrap_algorithm") or not callable( + kek.get_key_wrap_algorithm + ): + raise AttributeError( + _ERROR_OBJECT_INVALID.format("key encryption key", "get_key_wrap_algorithm") + ) class StorageEncryptionMixin(object): @@ -157,7 +167,9 @@ class _EncryptionAgent: It consists of the encryption protocol version and encryption algorithm used. """ - def __init__(self, encryption_algorithm: _EncryptionAlgorithm, protocol: str) -> None: + def __init__( + self, encryption_algorithm: _EncryptionAlgorithm, protocol: str + ) -> None: """ :param _EncryptionAlgorithm encryption_algorithm: The algorithm used for encrypting the message contents. @@ -269,7 +281,9 @@ def read(self, size: int = -1) -> bytes: # No more data to read break - self.current = encrypt_data_v2(data, self.nonce_counter, self.content_encryption_key) + self.current = encrypt_data_v2( + data, self.nonce_counter, self.content_encryption_key + ) # IMPORTANT: Must increment the nonce each time. self.nonce_counter += 1 @@ -304,11 +318,17 @@ def is_encryption_v2(encryption_data: Optional[_EncryptionData]) -> bool: :rtype: bool """ # If encryption_data is None, assume no encryption - return bool(encryption_data and (encryption_data.encryption_agent.protocol in _ENCRYPTION_V2_PROTOCOLS)) + return bool( + encryption_data + and (encryption_data.encryption_agent.protocol in _ENCRYPTION_V2_PROTOCOLS) + ) def modify_user_agent_for_encryption( - user_agent: str, moniker: str, encryption_version: str, request_options: Dict[str, Any] + user_agent: str, + moniker: str, + encryption_version: str, + request_options: Dict[str, Any], ) -> None: """ Modifies the request options to contain a user agent string updated with encryption information. @@ -360,7 +380,10 @@ def get_adjusted_upload_size(length: int, encryption_version: str) -> int: def get_adjusted_download_range_and_offset( - start: int, end: int, length: Optional[int], encryption_data: Optional[_EncryptionData] + start: int, + end: int, + length: Optional[int], + encryption_data: Optional[_EncryptionData], ) -> Tuple[Tuple[int, int], Tuple[int, int]]: """ Gets the new download range and offsets into the decrypted data for @@ -449,12 +472,16 @@ def parse_encryption_data(metadata: Dict[str, Any]) -> Optional[_EncryptionData] try: # Use case insensitive dict as key needs to be case-insensitive case_insensitive_metadata = CaseInsensitiveDict(metadata) - return _dict_to_encryption_data(loads(case_insensitive_metadata["encryptiondata"])) + return _dict_to_encryption_data( + loads(case_insensitive_metadata["encryptiondata"]) + ) except: # pylint: disable=bare-except return None -def adjust_blob_size_for_encryption(size: int, encryption_data: Optional[_EncryptionData]) -> int: +def adjust_blob_size_for_encryption( + size: int, encryption_data: Optional[_EncryptionData] +) -> int: """ Adjusts the given blob size for encryption by subtracting the size of the encryption data (nonce + tag). This only has an affect for encryption V2. @@ -533,7 +560,9 @@ def _generate_encryption_data_dict( encryption_data_dict["ContentEncryptionIV"] = encode_base64(iv) elif version == _ENCRYPTION_PROTOCOL_V2: encryption_data_dict["EncryptedRegionInfo"] = encrypted_region_info - encryption_data_dict["KeyWrappingMetadata"] = OrderedDict({"EncryptionLibrary": "Python " + VERSION}) + encryption_data_dict["KeyWrappingMetadata"] = OrderedDict( + {"EncryptionLibrary": "Python " + VERSION} + ) return encryption_data_dict @@ -562,7 +591,9 @@ def _dict_to_encryption_data(encryption_data_dict: Dict[str, Any]) -> _Encryptio ) encryption_agent = encryption_data_dict["EncryptionAgent"] - encryption_agent = _EncryptionAgent(encryption_agent["EncryptionAlgorithm"], encryption_agent["Protocol"]) + encryption_agent = _EncryptionAgent( + encryption_agent["EncryptionAlgorithm"], encryption_agent["Protocol"] + ) if "KeyWrappingMetadata" in encryption_data_dict: key_wrapping_metadata = encryption_data_dict["KeyWrappingMetadata"] @@ -572,18 +603,26 @@ def _dict_to_encryption_data(encryption_data_dict: Dict[str, Any]) -> _Encryptio # AES-CBC only encryption_iv = None if "ContentEncryptionIV" in encryption_data_dict: - encryption_iv = decode_base64_to_bytes(encryption_data_dict["ContentEncryptionIV"]) + encryption_iv = decode_base64_to_bytes( + encryption_data_dict["ContentEncryptionIV"] + ) # AES-GCM only region_info = None if "EncryptedRegionInfo" in encryption_data_dict: encrypted_region_info = encryption_data_dict["EncryptedRegionInfo"] region_info = _EncryptedRegionInfo( - encrypted_region_info["DataLength"], encrypted_region_info["NonceLength"], _GCM_TAG_LENGTH + encrypted_region_info["DataLength"], + encrypted_region_info["NonceLength"], + _GCM_TAG_LENGTH, ) encryption_data = _EncryptionData( - encryption_iv, region_info, encryption_agent, wrapped_content_key, key_wrapping_metadata + encryption_iv, + region_info, + encryption_agent, + wrapped_content_key, + key_wrapping_metadata, ) return encryption_data @@ -630,13 +669,19 @@ def _validate_and_unwrap_cek( :rtype: bytes """ - _validate_not_none("encrypted_key", encryption_data.wrapped_content_key.encrypted_key) + _validate_not_none( + "encrypted_key", encryption_data.wrapped_content_key.encrypted_key + ) # Validate we have the right info for the specified version if encryption_data.encryption_agent.protocol == _ENCRYPTION_PROTOCOL_V1: - _validate_not_none("content_encryption_IV", encryption_data.content_encryption_IV) + _validate_not_none( + "content_encryption_IV", encryption_data.content_encryption_IV + ) elif encryption_data.encryption_agent.protocol in _ENCRYPTION_V2_PROTOCOLS: - _validate_not_none("encrypted_region_info", encryption_data.encrypted_region_info) + _validate_not_none( + "encrypted_region_info", encryption_data.encrypted_region_info + ) else: raise ValueError("Specified encryption version is not supported.") @@ -647,25 +692,42 @@ def _validate_and_unwrap_cek( key_encryption_key = key_resolver(encryption_data.wrapped_content_key.key_id) if key_encryption_key is None: - raise ValueError("Unable to decrypt. key_resolver and key_encryption_key cannot both be None.") - if not hasattr(key_encryption_key, "get_kid") or not callable(key_encryption_key.get_kid): - raise AttributeError(_ERROR_OBJECT_INVALID.format("key encryption key", "get_kid")) - if not hasattr(key_encryption_key, "unwrap_key") or not callable(key_encryption_key.unwrap_key): - raise AttributeError(_ERROR_OBJECT_INVALID.format("key encryption key", "unwrap_key")) + raise ValueError( + "Unable to decrypt. key_resolver and key_encryption_key cannot both be None." + ) + if not hasattr(key_encryption_key, "get_kid") or not callable( + key_encryption_key.get_kid + ): + raise AttributeError( + _ERROR_OBJECT_INVALID.format("key encryption key", "get_kid") + ) + if not hasattr(key_encryption_key, "unwrap_key") or not callable( + key_encryption_key.unwrap_key + ): + raise AttributeError( + _ERROR_OBJECT_INVALID.format("key encryption key", "unwrap_key") + ) if encryption_data.wrapped_content_key.key_id != key_encryption_key.get_kid(): - raise ValueError("Provided or resolved key-encryption-key does not match the id of key used to encrypt.") + raise ValueError( + "Provided or resolved key-encryption-key does not match the id of key used to encrypt." + ) # Will throw an exception if the specified algorithm is not supported. content_encryption_key = key_encryption_key.unwrap_key( - encryption_data.wrapped_content_key.encrypted_key, encryption_data.wrapped_content_key.algorithm + encryption_data.wrapped_content_key.encrypted_key, + encryption_data.wrapped_content_key.algorithm, ) # For V2, the version is included with the cek. We need to validate it # and remove it from the actual cek. if encryption_data.encryption_agent.protocol in _ENCRYPTION_V2_PROTOCOLS: - version_2_bytes = encryption_data.encryption_agent.protocol.encode().ljust(8, b"\0") + version_2_bytes = encryption_data.encryption_agent.protocol.encode().ljust( + 8, b"\0" + ) cek_version_bytes = content_encryption_key[: len(version_2_bytes)] if cek_version_bytes != version_2_bytes: - raise ValueError("The encryption metadata is not valid and may have been modified.") + raise ValueError( + "The encryption metadata is not valid and may have been modified." + ) # Remove version from the start of the cek. content_encryption_key = content_encryption_key[len(version_2_bytes) :] @@ -705,13 +767,17 @@ def _decrypt_message( :rtype: bytes """ _validate_not_none("message", message) - content_encryption_key = _validate_and_unwrap_cek(encryption_data, key_encryption_key, resolver) + content_encryption_key = _validate_and_unwrap_cek( + encryption_data, key_encryption_key, resolver + ) if encryption_data.encryption_agent.protocol == _ENCRYPTION_PROTOCOL_V1: if not encryption_data.content_encryption_IV: raise ValueError("Missing required metadata for decryption.") - cipher = _generate_AES_CBC_cipher(content_encryption_key, encryption_data.content_encryption_IV) + cipher = _generate_AES_CBC_cipher( + content_encryption_key, encryption_data.content_encryption_IV + ) # decrypt data decryptor = cipher.decryptor() @@ -744,7 +810,9 @@ def _decrypt_message( return decrypted_data -def encrypt_blob(blob: bytes, key_encryption_key: KeyEncryptionKey, version: str) -> Tuple[str, bytes]: +def encrypt_blob( + blob: bytes, key_encryption_key: KeyEncryptionKey, version: str +) -> Tuple[str, bytes]: """ Encrypts the given blob using the given encryption protocol version. Wraps the generated content-encryption-key using the user-provided key-encryption-key (kek). @@ -878,7 +946,9 @@ def decrypt_blob( # pylint: disable=too-many-locals,too-many-statements :rtype: bytes """ try: - encryption_data = _dict_to_encryption_data(loads(response_headers["x-ms-meta-encryptiondata"])) + encryption_data = _dict_to_encryption_data( + loads(response_headers["x-ms-meta-encryptiondata"]) + ) except Exception as exc: # pylint: disable=broad-except if require_encryption: raise ValueError( @@ -889,14 +959,19 @@ def decrypt_blob( # pylint: disable=too-many-locals,too-many-statements return content algorithm = encryption_data.encryption_agent.encryption_algorithm - if algorithm not in (_EncryptionAlgorithm.AES_CBC_256, _EncryptionAlgorithm.AES_GCM_256): + if algorithm not in ( + _EncryptionAlgorithm.AES_CBC_256, + _EncryptionAlgorithm.AES_GCM_256, + ): raise ValueError("Specified encryption algorithm is not supported.") version = encryption_data.encryption_agent.protocol if version not in _VALID_ENCRYPTION_PROTOCOLS: raise ValueError("Specified encryption version is not supported.") - content_encryption_key = _validate_and_unwrap_cek(encryption_data, key_encryption_key, key_resolver) + content_encryption_key = _validate_and_unwrap_cek( + encryption_data, key_encryption_key, key_resolver + ) if version == _ENCRYPTION_PROTOCOL_V1: blob_type = response_headers["x-ms-blob-type"] @@ -993,7 +1068,9 @@ def get_blob_encryptor_and_padder( return encryptor, padder -def encrypt_queue_message(message: str, key_encryption_key: KeyEncryptionKey, version: str) -> str: +def encrypt_queue_message( + message: str, key_encryption_key: KeyEncryptionKey, version: str +) -> str: """ Encrypts the given plain text message using the given protocol version. Wraps the generated content-encryption-key using the user-provided key-encryption-key (kek). @@ -1099,8 +1176,12 @@ def decrypt_queue_message( try: deserialized_message: Dict[str, Any] = loads(message) - encryption_data = _dict_to_encryption_data(deserialized_message["EncryptionData"]) - decoded_data = decode_base64_to_bytes(deserialized_message["EncryptedMessageContents"]) + encryption_data = _dict_to_encryption_data( + deserialized_message["EncryptionData"] + ) + decoded_data = decode_base64_to_bytes( + deserialized_message["EncryptedMessageContents"] + ) except (KeyError, ValueError) as exc: # Message was not json formatted and so was not encrypted # or the user provided a json formatted message @@ -1113,7 +1194,9 @@ def decrypt_queue_message( return message try: - return _decrypt_message(decoded_data, encryption_data, key_encryption_key, resolver).decode("utf-8") + return _decrypt_message( + decoded_data, encryption_data, key_encryption_key, resolver + ).decode("utf-8") except Exception as error: raise HttpResponseError( message="Decryption failed.", response=response, error=error # type: ignore [arg-type] diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/_azure_queue_storage.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/_azure_queue_storage.py index 8ef85723b820..c2bd463fd619 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/_azure_queue_storage.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/_azure_queue_storage.py @@ -17,7 +17,12 @@ from . import models as _models from ._configuration import AzureQueueStorageConfiguration from ._utils.serialization import Deserializer, Serializer -from .operations import MessageIdOperations, MessagesOperations, QueueOperations, ServiceOperations +from .operations import ( + MessageIdOperations, + MessagesOperations, + QueueOperations, + ServiceOperations, +) class AzureQueueStorage: # pylint: disable=client-accepts-api-version-keyword @@ -43,7 +48,9 @@ class AzureQueueStorage: # pylint: disable=client-accepts-api-version-keyword def __init__( # pylint: disable=missing-client-constructor-parameter-credential self, url: str, version: str, base_url: str = "", **kwargs: Any ) -> None: - self._config = AzureQueueStorageConfiguration(url=url, version=version, **kwargs) + self._config = AzureQueueStorageConfiguration( + url=url, version=version, **kwargs + ) _policies = kwargs.pop("policies", None) if _policies is None: @@ -59,21 +66,39 @@ def __init__( # pylint: disable=missing-client-constructor-parameter-credential self._config.custom_hook_policy, self._config.logging_policy, policies.DistributedTracingPolicy(**kwargs), - policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None, + ( + policies.SensitiveHeaderCleanupPolicy(**kwargs) + if self._config.redirect_policy + else None + ), self._config.http_logging_policy, ] - self._client: PipelineClient = PipelineClient(base_url=base_url, policies=_policies, **kwargs) + self._client: PipelineClient = PipelineClient( + base_url=base_url, policies=_policies, **kwargs + ) - client_models = {k: v for k, v in _models.__dict__.items() if isinstance(v, type)} + client_models = { + k: v for k, v in _models.__dict__.items() if isinstance(v, type) + } self._serialize = Serializer(client_models) self._deserialize = Deserializer(client_models) self._serialize.client_side_validation = False - self.service = ServiceOperations(self._client, self._config, self._serialize, self._deserialize) - self.queue = QueueOperations(self._client, self._config, self._serialize, self._deserialize) - self.messages = MessagesOperations(self._client, self._config, self._serialize, self._deserialize) - self.message_id = MessageIdOperations(self._client, self._config, self._serialize, self._deserialize) - - def _send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse: + self.service = ServiceOperations( + self._client, self._config, self._serialize, self._deserialize + ) + self.queue = QueueOperations( + self._client, self._config, self._serialize, self._deserialize + ) + self.messages = MessagesOperations( + self._client, self._config, self._serialize, self._deserialize + ) + self.message_id = MessageIdOperations( + self._client, self._config, self._serialize, self._deserialize + ) + + def _send_request( + self, request: HttpRequest, *, stream: bool = False, **kwargs: Any + ) -> HttpResponse: """Runs the network request through the client's chained policies. >>> from azure.core.rest import HttpRequest diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/_configuration.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/_configuration.py index 04adef0da253..1ea4478a7f01 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/_configuration.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/_configuration.py @@ -39,12 +39,24 @@ def __init__(self, url: str, version: str, **kwargs: Any) -> None: self._configure(**kwargs) def _configure(self, **kwargs: Any) -> None: - self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs) - self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs) + self.user_agent_policy = kwargs.get( + "user_agent_policy" + ) or policies.UserAgentPolicy(**kwargs) + self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy( + **kwargs + ) self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs) - self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs) - self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs) - self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs) - self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs) + self.logging_policy = kwargs.get( + "logging_policy" + ) or policies.NetworkTraceLoggingPolicy(**kwargs) + self.http_logging_policy = kwargs.get( + "http_logging_policy" + ) or policies.HttpLoggingPolicy(**kwargs) + self.custom_hook_policy = kwargs.get( + "custom_hook_policy" + ) or policies.CustomHookPolicy(**kwargs) + self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy( + **kwargs + ) self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs) self.authentication_policy = kwargs.get("authentication_policy") diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/_utils/serialization.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/_utils/serialization.py index 6da830e0cf4a..7a2a33ce8b12 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/_utils/serialization.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/_utils/serialization.py @@ -58,7 +58,9 @@ class RawDeserializer: CONTEXT_NAME = "deserialized_data" @classmethod - def deserialize_from_text(cls, data: Optional[Union[AnyStr, IO]], content_type: Optional[str] = None) -> Any: + def deserialize_from_text( + cls, data: Optional[Union[AnyStr, IO]], content_type: Optional[str] = None + ) -> Any: """Decode data according to content-type. Accept a stream of data as well, but will be load at once in memory for now. @@ -91,7 +93,9 @@ def deserialize_from_text(cls, data: Optional[Union[AnyStr, IO]], content_type: try: return json.loads(data_as_str) except ValueError as err: - raise DeserializationError("JSON is invalid: {}".format(err), err) from err + raise DeserializationError( + "JSON is invalid: {}".format(err), err + ) from err elif "xml" in (content_type or []): try: @@ -125,10 +129,14 @@ def _json_attemp(data): raise DeserializationError("XML is invalid") from err elif content_type.startswith("text/"): return data_as_str - raise DeserializationError("Cannot deserialize content-type: {}".format(content_type)) + raise DeserializationError( + "Cannot deserialize content-type: {}".format(content_type) + ) @classmethod - def deserialize_from_http_generics(cls, body_bytes: Optional[Union[AnyStr, IO]], headers: Mapping) -> Any: + def deserialize_from_http_generics( + cls, body_bytes: Optional[Union[AnyStr, IO]], headers: Mapping + ) -> Any: """Deserialize from HTTP response. Use bytes and headers to NOT use any requests/aiohttp or whatever @@ -180,7 +188,9 @@ def attribute_transformer(key, attr_desc, value): # pylint: disable=unused-argu return (key, value) -def full_restapi_key_transformer(key, attr_desc, value): # pylint: disable=unused-argument +def full_restapi_key_transformer( + key, attr_desc, value +): # pylint: disable=unused-argument """A key transformer that returns the full RestAPI key path. :param str key: The attribute name @@ -235,9 +245,17 @@ def __init__(self, **kwargs: Any) -> None: self.additional_properties: Optional[dict[str, Any]] = {} for k in kwargs: # pylint: disable=consider-using-dict-items if k not in self._attribute_map: - _LOGGER.warning("%s is not a known attribute of class %s and will be ignored", k, self.__class__) + _LOGGER.warning( + "%s is not a known attribute of class %s and will be ignored", + k, + self.__class__, + ) elif k in self._validation and self._validation[k].get("readonly", False): - _LOGGER.warning("Readonly attribute %s will be ignored in class %s", k, self.__class__) + _LOGGER.warning( + "Readonly attribute %s will be ignored in class %s", + k, + self.__class__, + ) else: setattr(self, k, kwargs[k]) @@ -288,7 +306,11 @@ def _create_xml_node(cls): except AttributeError: xml_map = {} - return _create_xml_node(xml_map.get("name", cls.__name__), xml_map.get("prefix", None), xml_map.get("ns", None)) + return _create_xml_node( + xml_map.get("name", cls.__name__), + xml_map.get("prefix", None), + xml_map.get("ns", None), + ) def serialize(self, keep_readonly: bool = False, **kwargs: Any) -> JSON: """Return the JSON that would be sent to server from this model. @@ -309,7 +331,9 @@ def serialize(self, keep_readonly: bool = False, **kwargs: Any) -> JSON: def as_dict( self, keep_readonly: bool = True, - key_transformer: Callable[[str, dict[str, Any], Any], Any] = attribute_transformer, + key_transformer: Callable[ + [str, dict[str, Any], Any], Any + ] = attribute_transformer, **kwargs: Any ) -> JSON: """Return a dict that can be serialized using json.dump. @@ -353,7 +377,9 @@ def _infer_class_models(cls): try: str_models = cls.__module__.rsplit(".", 1)[0] models = sys.modules[str_models] - client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)} + client_models = { + k: v for k, v in models.__dict__.items() if isinstance(v, type) + } if cls.__name__ not in client_models: raise ValueError("Not Autorest generated code") except Exception: # pylint: disable=broad-exception-caught @@ -412,7 +438,9 @@ def _flatten_subtype(cls, key, objects): return {} result = dict(cls._subtype_map[key]) for valuetype in cls._subtype_map[key].values(): - result |= objects[valuetype]._flatten_subtype(key, objects) # pylint: disable=protected-access + result |= objects[valuetype]._flatten_subtype( + key, objects + ) # pylint: disable=protected-access return result @classmethod @@ -430,9 +458,13 @@ def _classify(cls, response, objects): if not isinstance(response, ET.Element): rest_api_response_key = cls._get_rest_key_parts(subtype_key)[-1] - subtype_value = response.get(rest_api_response_key, None) or response.get(subtype_key, None) + subtype_value = response.get( + rest_api_response_key, None + ) or response.get(subtype_key, None) else: - subtype_value = xml_key_extractor(subtype_key, cls._attribute_map[subtype_key], response) + subtype_value = xml_key_extractor( + subtype_key, cls._attribute_map[subtype_key], response + ) if subtype_value: # Try to match base class. Can be class name only # (bug to fix in Autorest to support x-ms-discriminator-name) @@ -449,7 +481,11 @@ def _classify(cls, response, objects): ) break else: - _LOGGER.warning("Discriminator %s is absent or null, use base class %s.", subtype_key, cls.__name__) + _LOGGER.warning( + "Discriminator %s is absent or null, use base class %s.", + subtype_key, + cls.__name__, + ) break return cls @@ -561,18 +597,25 @@ def _serialize( # pylint: disable=too-many-nested-blocks, too-many-branches, to try: is_xml_model_serialization = kwargs["is_xml"] except KeyError: - is_xml_model_serialization = kwargs.setdefault("is_xml", target_obj.is_xml_model()) + is_xml_model_serialization = kwargs.setdefault( + "is_xml", target_obj.is_xml_model() + ) serialized = {} if is_xml_model_serialization: - serialized = target_obj._create_xml_node() # pylint: disable=protected-access + serialized = ( + target_obj._create_xml_node() + ) # pylint: disable=protected-access try: attributes = target_obj._attribute_map # pylint: disable=protected-access for attr, attr_desc in attributes.items(): attr_name = attr - if not keep_readonly and target_obj._validation.get( # pylint: disable=protected-access - attr_name, {} - ).get("readonly", False): + if ( + not keep_readonly + and target_obj._validation.get( # pylint: disable=protected-access + attr_name, {} + ).get("readonly", False) + ): continue if attr_name == "additional_properties" and attr_desc["key"] == "": @@ -585,11 +628,15 @@ def _serialize( # pylint: disable=too-many-nested-blocks, too-many-branches, to if is_xml_model_serialization: pass # Don't provide "transformer" for XML for now. Keep "orig_attr" else: # JSON - keys, orig_attr = key_transformer(attr, attr_desc.copy(), orig_attr) + keys, orig_attr = key_transformer( + attr, attr_desc.copy(), orig_attr + ) keys = keys if isinstance(keys, list) else [keys] kwargs["serialization_ctxt"] = attr_desc - new_attr = self.serialize_data(orig_attr, attr_desc["type"], **kwargs) + new_attr = self.serialize_data( + orig_attr, attr_desc["type"], **kwargs + ) if is_xml_model_serialization: xml_desc = attr_desc.get("xml", {}) @@ -638,7 +685,9 @@ def _serialize( # pylint: disable=too-many-nested-blocks, too-many-branches, to raise except (AttributeError, KeyError, TypeError) as err: - msg = "Attribute {} in object {} cannot be serialized.\n{}".format(attr_name, class_name, str(target_obj)) + msg = "Attribute {} in object {} cannot be serialized.\n{}".format( + attr_name, class_name, str(target_obj) + ) raise SerializationError(msg) from err return serialized @@ -660,7 +709,9 @@ def body(self, data, data_type, **kwargs): is_xml_model_serialization = kwargs["is_xml"] except KeyError: if internal_data_type and issubclass(internal_data_type, Model): - is_xml_model_serialization = kwargs.setdefault("is_xml", internal_data_type.is_xml_model()) + is_xml_model_serialization = kwargs.setdefault( + "is_xml", internal_data_type.is_xml_model() + ) else: is_xml_model_serialization = False if internal_data_type and not isinstance(internal_data_type, Enum): @@ -679,9 +730,13 @@ def body(self, data, data_type, **kwargs): attribute_key_case_insensitive_extractor, last_rest_key_case_insensitive_extractor, ] - data = deserializer._deserialize(data_type, data) # pylint: disable=protected-access + data = deserializer._deserialize( + data_type, data + ) # pylint: disable=protected-access except DeserializationError as err: - raise SerializationError("Unable to build a model: " + str(err)) from err + raise SerializationError( + "Unable to build a model: " + str(err) + ) from err return self._serialize(data, data_type, **kwargs) @@ -726,7 +781,9 @@ def query(self, name, data, data_type, **kwargs): if data_type.startswith("["): internal_data_type = data_type[1:-1] do_quote = not kwargs.get("skip_quote", False) - return self.serialize_iter(data, internal_data_type, do_quote=do_quote, **kwargs) + return self.serialize_iter( + data, internal_data_type, do_quote=do_quote, **kwargs + ) # Not a list, regular serialization output = self.serialize_data(data, data_type, **kwargs) @@ -801,7 +858,9 @@ def serialize_data(self, data, data_type, **kwargs): return self._serialize(data, **kwargs) @classmethod - def _get_custom_serializers(cls, data_type, **kwargs): # pylint: disable=inconsistent-return-statements + def _get_custom_serializers( + cls, data_type, **kwargs + ): # pylint: disable=inconsistent-return-statements custom_serializer = kwargs.get("basic_types_serializers", {}).get(data_type) if custom_serializer: return custom_serializer @@ -891,7 +950,9 @@ def serialize_iter(self, data, iter_type, div=None, **kwargs): serialized.append(None) if kwargs.get("do_quote", False): - serialized = ["" if s is None else quote(str(s), safe="") for s in serialized] + serialized = [ + "" if s is None else quote(str(s), safe="") for s in serialized + ] if div: serialized = ["" if s is None else str(s) for s in serialized] @@ -908,7 +969,9 @@ def serialize_iter(self, data, iter_type, div=None, **kwargs): is_wrapped = xml_desc.get("wrapped", False) node_name = xml_desc.get("itemsName", xml_name) if is_wrapped: - final_result = _create_xml_node(xml_name, xml_desc.get("prefix", None), xml_desc.get("ns", None)) + final_result = _create_xml_node( + xml_name, xml_desc.get("prefix", None), xml_desc.get("ns", None) + ) else: final_result = [] # All list elements to "local_node" @@ -916,7 +979,11 @@ def serialize_iter(self, data, iter_type, div=None, **kwargs): if isinstance(el, ET.Element): el_node = el else: - el_node = _create_xml_node(node_name, xml_desc.get("prefix", None), xml_desc.get("ns", None)) + el_node = _create_xml_node( + node_name, + xml_desc.get("prefix", None), + xml_desc.get("ns", None), + ) if el is not None: # Otherwise it writes "None" :-p el_node.text = str(el) final_result.append(el_node) @@ -935,7 +1002,9 @@ def serialize_dict(self, attr, dict_type, **kwargs): serialized = {} for key, value in attr.items(): try: - serialized[self.serialize_unicode(key)] = self.serialize_data(value, dict_type, **kwargs) + serialized[self.serialize_unicode(key)] = self.serialize_data( + value, dict_type, **kwargs + ) except ValueError as err: if isinstance(err, SerializationError): raise @@ -946,14 +1015,18 @@ def serialize_dict(self, attr, dict_type, **kwargs): xml_desc = serialization_ctxt["xml"] xml_name = xml_desc["name"] - final_result = _create_xml_node(xml_name, xml_desc.get("prefix", None), xml_desc.get("ns", None)) + final_result = _create_xml_node( + xml_name, xml_desc.get("prefix", None), xml_desc.get("ns", None) + ) for key, value in serialized.items(): ET.SubElement(final_result, key).text = value return final_result return serialized - def serialize_object(self, attr, **kwargs): # pylint: disable=too-many-return-statements + def serialize_object( + self, attr, **kwargs + ): # pylint: disable=too-many-return-statements """Serialize a generic object. This will be handled as a dictionary. If object passed in is not a basic type (str, int, float, dict, list) it will simply be @@ -993,7 +1066,9 @@ def serialize_object(self, attr, **kwargs): # pylint: disable=too-many-return-s serialized = {} for key, value in attr.items(): try: - serialized[self.serialize_unicode(key)] = self.serialize_object(value, **kwargs) + serialized[self.serialize_unicode(key)] = self.serialize_object( + value, **kwargs + ) except ValueError: serialized[self.serialize_unicode(key)] = None return serialized @@ -1153,7 +1228,12 @@ def serialize_iso(attr, **kwargs): # pylint: disable=unused-argument if microseconds: microseconds = "." + microseconds date = "{:04}-{:02}-{:02}T{:02}:{:02}:{:02}".format( - utc.tm_year, utc.tm_mon, utc.tm_mday, utc.tm_hour, utc.tm_min, utc.tm_sec + utc.tm_year, + utc.tm_mon, + utc.tm_mday, + utc.tm_hour, + utc.tm_min, + utc.tm_sec, ) return date + microseconds + "Z" except (ValueError, OverflowError) as err: @@ -1216,7 +1296,9 @@ def rest_key_case_insensitive_extractor( # pylint: disable=unused-argument, inc key = _decode_attribute_map_key(dict_keys[0]) break working_key = _decode_attribute_map_key(dict_keys[0]) - working_data = attribute_key_case_insensitive_extractor(working_key, None, working_data) + working_data = attribute_key_case_insensitive_extractor( + working_key, None, working_data + ) if working_data is None: # If at any point while following flatten JSON path see None, it means # that all properties under are None as well @@ -1241,7 +1323,9 @@ def last_rest_key_extractor(attr, attr_desc, data): # pylint: disable=unused-ar return attribute_key_extractor(dict_keys[-1], None, data) -def last_rest_key_case_insensitive_extractor(attr, attr_desc, data): # pylint: disable=unused-argument +def last_rest_key_case_insensitive_extractor( + attr, attr_desc, data +): # pylint: disable=unused-argument """Extract the attribute in "data" based on the last part of the JSON path key. This is the case insensitive version of "last_rest_key_extractor" @@ -1286,7 +1370,9 @@ def _extract_name_from_internal_type(internal_type): return xml_name -def xml_key_extractor(attr, attr_desc, data): # pylint: disable=unused-argument,too-many-return-statements +def xml_key_extractor( + attr, attr_desc, data +): # pylint: disable=unused-argument,too-many-return-statements if isinstance(data, dict): return None @@ -1320,7 +1406,10 @@ def xml_key_extractor(attr, attr_desc, data): # pylint: disable=unused-argument # - Wrapped node # - Internal type is an enum (considered basic types) # - Internal type has no XML/Name node - if is_wrapped or (internal_type and (issubclass(internal_type, Enum) or "name" not in internal_type_xml_map)): + if is_wrapped or ( + internal_type + and (issubclass(internal_type, Enum) or "name" not in internal_type_xml_map) + ): children = data.findall(xml_name) # If internal type has a local name and it's not a list, I use that name elif not is_iter_type and internal_type and "name" in internal_type_xml_map: @@ -1328,7 +1417,9 @@ def xml_key_extractor(attr, attr_desc, data): # pylint: disable=unused-argument children = data.findall(xml_name) # That's an array else: - if internal_type: # Complex type, ignore itemsName and use the complex type name + if ( + internal_type + ): # Complex type, ignore itemsName and use the complex type name items_name = _extract_name_from_internal_type(internal_type) else: items_name = xml_desc.get("itemsName", xml_name) @@ -1356,7 +1447,9 @@ def xml_key_extractor(attr, attr_desc, data): # pylint: disable=unused-argument # Here it's not a itertype, we should have found one element only or empty if len(children) > 1: - raise DeserializationError("Find several XML '{}' where it was not expected".format(xml_name)) + raise DeserializationError( + "Find several XML '{}' where it was not expected".format(xml_name) + ) return children[0] @@ -1369,7 +1462,9 @@ class Deserializer: basic_types = {str: "str", int: "int", bool: "bool", float: "float"} - valid_date = re.compile(r"\d{4}[-]\d{2}[-]\d{2}T\d{2}:\d{2}:\d{2}\.?\d*Z?[-+]?[\d{2}]?:?[\d{2}]?") + valid_date = re.compile( + r"\d{4}[-]\d{2}[-]\d{2}T\d{2}:\d{2}:\d{2}\.?\d*Z?[-+]?[\d{2}]?:?[\d{2}]?" + ) def __init__(self, classes: Optional[Mapping[str, type]] = None) -> None: self.deserialize_type = { @@ -1414,7 +1509,9 @@ def __call__(self, target_obj, response_data, content_type=None): data = self._unpack_content(response_data, content_type) return self._deserialize(target_obj, data) - def _deserialize(self, target_obj, data): # pylint: disable=inconsistent-return-statements + def _deserialize( + self, target_obj, data + ): # pylint: disable=inconsistent-return-statements """Call the deserializer on a model. Data needs to be already deserialized as JSON or XML ElementTree @@ -1427,9 +1524,16 @@ def _deserialize(self, target_obj, data): # pylint: disable=inconsistent-return """ # This is already a model, go recursive just in case if hasattr(data, "_attribute_map"): - constants = [name for name, config in getattr(data, "_validation", {}).items() if config.get("constant")] + constants = [ + name + for name, config in getattr(data, "_validation", {}).items() + if config.get("constant") + ] try: - for attr, mapconfig in data._attribute_map.items(): # pylint: disable=protected-access + for ( + attr, + mapconfig, + ) in data._attribute_map.items(): # pylint: disable=protected-access if attr in constants: continue value = getattr(data, attr) @@ -1437,7 +1541,9 @@ def _deserialize(self, target_obj, data): # pylint: disable=inconsistent-return continue local_type = mapconfig["type"] internal_data_type = local_type.strip("[]{}") - if internal_data_type not in self.dependencies or isinstance(internal_data_type, Enum): + if internal_data_type not in self.dependencies or isinstance( + internal_data_type, Enum + ): continue setattr(data, attr, self._deserialize(local_type, value)) return data @@ -1490,7 +1596,10 @@ def _deserialize(self, target_obj, data): # pylint: disable=inconsistent-return def _build_additional_properties(self, attribute_map, data): if not self.additional_properties_detection: return None - if "additional_properties" in attribute_map and attribute_map.get("additional_properties", {}).get("key") != "": + if ( + "additional_properties" in attribute_map + and attribute_map.get("additional_properties", {}).get("key") != "" + ): # Check empty string. If it's not empty, someone has a real "additionalProperties" return None if isinstance(data, ET.Element): @@ -1547,7 +1656,8 @@ def failsafe_deserialize(self, target_obj, data, content_type=None): return self(target_obj, data, content_type=content_type) except: # pylint: disable=bare-except _LOGGER.debug( - "Ran into a deserialization error. Ignoring since this is failsafe deserialization", exc_info=True + "Ran into a deserialization error. Ignoring since this is failsafe deserialization", + exc_info=True, ) return None @@ -1575,15 +1685,21 @@ def _unpack_content(raw_data, content_type=None): if context: if RawDeserializer.CONTEXT_NAME in context: return context[RawDeserializer.CONTEXT_NAME] - raise ValueError("This pipeline didn't have the RawDeserializer policy; can't deserialize") + raise ValueError( + "This pipeline didn't have the RawDeserializer policy; can't deserialize" + ) # Assume this is enough to recognize universal_http.ClientResponse without importing it if hasattr(raw_data, "body"): - return RawDeserializer.deserialize_from_http_generics(raw_data.text(), raw_data.headers) + return RawDeserializer.deserialize_from_http_generics( + raw_data.text(), raw_data.headers + ) # Assume this enough to recognize requests.Response without importing it. if hasattr(raw_data, "_content_consumed"): - return RawDeserializer.deserialize_from_http_generics(raw_data.text, raw_data.headers) + return RawDeserializer.deserialize_from_http_generics( + raw_data.text, raw_data.headers + ) if isinstance(raw_data, (str, bytes)) or hasattr(raw_data, "read"): return RawDeserializer.deserialize_from_text(raw_data, content_type) # type: ignore @@ -1611,7 +1727,11 @@ def _instantiate_model(self, response, attrs, additional_properties=None): for k, v in response._validation.items() # pylint: disable=protected-access # type: ignore if v.get("constant") ] - kwargs = {k: v for k, v in attrs.items() if k not in subtype and k not in readonly + const} + kwargs = { + k: v + for k, v in attrs.items() + if k not in subtype and k not in readonly + const + } response_obj = response(**kwargs) for attr in readonly: setattr(response_obj, attr, attrs.get(attr)) @@ -1631,7 +1751,9 @@ def _instantiate_model(self, response, attrs, additional_properties=None): msg += "Type: {}, Error: {}".format(type(response), exp) raise DeserializationError(msg) from exp - def deserialize_data(self, data, data_type): # pylint: disable=too-many-return-statements + def deserialize_data( + self, data, data_type + ): # pylint: disable=too-many-return-statements """Process data for deserialization according to data type. :param str data: The response string to be deserialized. @@ -1649,15 +1771,24 @@ def deserialize_data(self, data, data_type): # pylint: disable=too-many-return- if data_type in self.basic_types.values(): return self.deserialize_basic(data, data_type) if data_type in self.deserialize_type: - if isinstance(data, self.deserialize_expected_types.get(data_type, tuple())): + if isinstance( + data, self.deserialize_expected_types.get(data_type, tuple()) + ): return data - is_a_text_parsing_type = lambda x: x not in [ # pylint: disable=unnecessary-lambda-assignment - "object", - "[]", - r"{}", - ] - if isinstance(data, ET.Element) and is_a_text_parsing_type(data_type) and not data.text: + is_a_text_parsing_type = ( + lambda x: x + not in [ # pylint: disable=unnecessary-lambda-assignment + "object", + "[]", + r"{}", + ] + ) + if ( + isinstance(data, ET.Element) + and is_a_text_parsing_type(data_type) + and not data.text + ): return None data_val = self.deserialize_type[data_type](data) return data_val @@ -1688,10 +1819,16 @@ def deserialize_iter(self, attr, iter_type): """ if attr is None: return None - if isinstance(attr, ET.Element): # If I receive an element here, get the children + if isinstance( + attr, ET.Element + ): # If I receive an element here, get the children attr = list(attr) if not isinstance(attr, (list, set)): - raise DeserializationError("Cannot deserialize as [{}] an object of type {}".format(iter_type, type(attr))) + raise DeserializationError( + "Cannot deserialize as [{}] an object of type {}".format( + iter_type, type(attr) + ) + ) return [self.deserialize_data(a, iter_type) for a in attr] def deserialize_dict(self, attr, dict_type): @@ -1704,14 +1841,18 @@ def deserialize_dict(self, attr, dict_type): :rtype: dict """ if isinstance(attr, list): - return {x["key"]: self.deserialize_data(x["value"], dict_type) for x in attr} + return { + x["key"]: self.deserialize_data(x["value"], dict_type) for x in attr + } if isinstance(attr, ET.Element): # Transform value into {"Key": "value"} attr = {el.tag: el.text for el in attr} return {k: self.deserialize_data(v, dict_type) for k, v in attr.items()} - def deserialize_object(self, attr, **kwargs): # pylint: disable=too-many-return-statements + def deserialize_object( + self, attr, **kwargs + ): # pylint: disable=too-many-return-statements """Deserialize a generic object. This will be handled as a dictionary. @@ -1754,7 +1895,9 @@ def deserialize_object(self, attr, **kwargs): # pylint: disable=too-many-return error = "Cannot deserialize generic object with type: " raise TypeError(error + str(obj_type)) - def deserialize_basic(self, attr, data_type): # pylint: disable=too-many-return-statements + def deserialize_basic( + self, attr, data_type + ): # pylint: disable=too-many-return-statements """Deserialize basic builtin data type from string. Will attempt to convert to str, int, float and bool. This function will also accept '1', '0', 'true' and 'false' as @@ -1849,7 +1992,11 @@ def deserialize_enum(data, enum_obj): if enum_value.value.lower() == str(data).lower(): return enum_value # We don't fail anymore for unknown value, we deserialize as a string - _LOGGER.warning("Deserializer is not able to find %s as valid enum in %s", data, enum_obj) + _LOGGER.warning( + "Deserializer is not able to find %s as valid enum in %s", + data, + enum_obj, + ) return Deserializer.deserialize_unicode(data) @staticmethod @@ -1941,7 +2088,9 @@ def deserialize_date(attr): if isinstance(attr, ET.Element): attr = attr.text if re.search(r"[^\W\d_]", attr, re.I + re.U): # type: ignore - raise DeserializationError("Date must have only digits and -. Received: %s" % attr) + raise DeserializationError( + "Date must have only digits and -. Received: %s" % attr + ) # This must NOT use defaultmonth/defaultday. Using None ensure this raises an exception. return isodate.parse_date(attr, defaultmonth=0, defaultday=0) @@ -1957,7 +2106,9 @@ def deserialize_time(attr): if isinstance(attr, ET.Element): attr = attr.text if re.search(r"[^\W\d_]", attr, re.I + re.U): # type: ignore - raise DeserializationError("Date must have only digits and -. Received: %s" % attr) + raise DeserializationError( + "Date must have only digits and -. Received: %s" % attr + ) return isodate.parse_time(attr) @staticmethod @@ -1974,7 +2125,10 @@ def deserialize_rfc(attr): try: parsed_date = email.utils.parsedate_tz(attr) # type: ignore date_obj = datetime.datetime( - *parsed_date[:6], tzinfo=datetime.timezone(datetime.timedelta(minutes=(parsed_date[9] or 0) / 60)) + *parsed_date[:6], + tzinfo=datetime.timezone( + datetime.timedelta(minutes=(parsed_date[9] or 0) / 60) + ) ) if not date_obj.tzinfo: date_obj = date_obj.astimezone(tz=TZ_UTC) diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/_azure_queue_storage.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/_azure_queue_storage.py index 3b6b202768e2..7c019e14596e 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/_azure_queue_storage.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/_azure_queue_storage.py @@ -17,7 +17,12 @@ from .. import models as _models from .._utils.serialization import Deserializer, Serializer from ._configuration import AzureQueueStorageConfiguration -from .operations import MessageIdOperations, MessagesOperations, QueueOperations, ServiceOperations +from .operations import ( + MessageIdOperations, + MessagesOperations, + QueueOperations, + ServiceOperations, +) class AzureQueueStorage: # pylint: disable=client-accepts-api-version-keyword @@ -43,7 +48,9 @@ class AzureQueueStorage: # pylint: disable=client-accepts-api-version-keyword def __init__( # pylint: disable=missing-client-constructor-parameter-credential self, url: str, version: str, base_url: str = "", **kwargs: Any ) -> None: - self._config = AzureQueueStorageConfiguration(url=url, version=version, **kwargs) + self._config = AzureQueueStorageConfiguration( + url=url, version=version, **kwargs + ) _policies = kwargs.pop("policies", None) if _policies is None: @@ -59,19 +66,35 @@ def __init__( # pylint: disable=missing-client-constructor-parameter-credential self._config.custom_hook_policy, self._config.logging_policy, policies.DistributedTracingPolicy(**kwargs), - policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None, + ( + policies.SensitiveHeaderCleanupPolicy(**kwargs) + if self._config.redirect_policy + else None + ), self._config.http_logging_policy, ] - self._client: AsyncPipelineClient = AsyncPipelineClient(base_url=base_url, policies=_policies, **kwargs) + self._client: AsyncPipelineClient = AsyncPipelineClient( + base_url=base_url, policies=_policies, **kwargs + ) - client_models = {k: v for k, v in _models.__dict__.items() if isinstance(v, type)} + client_models = { + k: v for k, v in _models.__dict__.items() if isinstance(v, type) + } self._serialize = Serializer(client_models) self._deserialize = Deserializer(client_models) self._serialize.client_side_validation = False - self.service = ServiceOperations(self._client, self._config, self._serialize, self._deserialize) - self.queue = QueueOperations(self._client, self._config, self._serialize, self._deserialize) - self.messages = MessagesOperations(self._client, self._config, self._serialize, self._deserialize) - self.message_id = MessageIdOperations(self._client, self._config, self._serialize, self._deserialize) + self.service = ServiceOperations( + self._client, self._config, self._serialize, self._deserialize + ) + self.queue = QueueOperations( + self._client, self._config, self._serialize, self._deserialize + ) + self.messages = MessagesOperations( + self._client, self._config, self._serialize, self._deserialize + ) + self.message_id = MessageIdOperations( + self._client, self._config, self._serialize, self._deserialize + ) def _send_request( self, request: HttpRequest, *, stream: bool = False, **kwargs: Any diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/_configuration.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/_configuration.py index 1c90497920fe..d45c53a0b020 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/_configuration.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/_configuration.py @@ -39,12 +39,26 @@ def __init__(self, url: str, version: str, **kwargs: Any) -> None: self._configure(**kwargs) def _configure(self, **kwargs: Any) -> None: - self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs) - self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs) + self.user_agent_policy = kwargs.get( + "user_agent_policy" + ) or policies.UserAgentPolicy(**kwargs) + self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy( + **kwargs + ) self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs) - self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs) - self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs) - self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs) - self.redirect_policy = kwargs.get("redirect_policy") or policies.AsyncRedirectPolicy(**kwargs) - self.retry_policy = kwargs.get("retry_policy") or policies.AsyncRetryPolicy(**kwargs) + self.logging_policy = kwargs.get( + "logging_policy" + ) or policies.NetworkTraceLoggingPolicy(**kwargs) + self.http_logging_policy = kwargs.get( + "http_logging_policy" + ) or policies.HttpLoggingPolicy(**kwargs) + self.custom_hook_policy = kwargs.get( + "custom_hook_policy" + ) or policies.CustomHookPolicy(**kwargs) + self.redirect_policy = kwargs.get( + "redirect_policy" + ) or policies.AsyncRedirectPolicy(**kwargs) + self.retry_policy = kwargs.get("retry_policy") or policies.AsyncRetryPolicy( + **kwargs + ) self.authentication_policy = kwargs.get("authentication_policy") diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_message_id_operations.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_message_id_operations.py index 997087907907..5f2a6d9e952a 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_message_id_operations.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_message_id_operations.py @@ -25,11 +25,16 @@ from ... import models as _models from ..._utils.serialization import Deserializer, Serializer -from ...operations._message_id_operations import build_delete_request, build_update_request +from ...operations._message_id_operations import ( + build_delete_request, + build_update_request, +) from .._configuration import AzureQueueStorageConfiguration T = TypeVar("T") -ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, dict[str, Any]], Any]] +ClsType = Optional[ + Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, dict[str, Any]], Any] +] class MessageIdOperations: @@ -46,10 +51,18 @@ class MessageIdOperations: def __init__(self, *args, **kwargs) -> None: input_args = list(args) - self._client: AsyncPipelineClient = input_args.pop(0) if input_args else kwargs.pop("client") - self._config: AzureQueueStorageConfiguration = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize: Serializer = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize: Deserializer = input_args.pop(0) if input_args else kwargs.pop("deserializer") + self._client: AsyncPipelineClient = ( + input_args.pop(0) if input_args else kwargs.pop("client") + ) + self._config: AzureQueueStorageConfiguration = ( + input_args.pop(0) if input_args else kwargs.pop("config") + ) + self._serialize: Serializer = ( + input_args.pop(0) if input_args else kwargs.pop("serializer") + ) + self._deserialize: Deserializer = ( + input_args.pop(0) if input_args else kwargs.pop("deserializer") + ) @distributed_trace_async async def update( @@ -101,7 +114,9 @@ async def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = kwargs.pop("params", {}) or {} - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", "application/xml")) + content_type: Optional[str] = kwargs.pop( + "content_type", _headers.pop("Content-Type", "application/xml") + ) content_type = content_type if queue_message else None cls: ClsType[None] = kwargs.pop("cls", None) @@ -125,14 +140,18 @@ async def update( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -140,10 +159,18 @@ async def update( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) - response_headers["x-ms-popreceipt"] = self._deserialize("str", response.headers.get("x-ms-popreceipt")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) + response_headers["x-ms-popreceipt"] = self._deserialize( + "str", response.headers.get("x-ms-popreceipt") + ) response_headers["x-ms-time-next-visible"] = self._deserialize( "rfc-1123", response.headers.get("x-ms-time-next-visible") ) @@ -153,7 +180,11 @@ async def update( @distributed_trace_async async def delete( - self, pop_receipt: str, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any + self, + pop_receipt: str, + timeout: Optional[int] = None, + request_id_parameter: Optional[str] = None, + **kwargs: Any ) -> None: """The Delete operation deletes the specified message. @@ -197,14 +228,18 @@ async def delete( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -212,9 +247,15 @@ async def delete( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) if cls: return cls(pipeline_response, None, response_headers) # type: ignore diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_messages_operations.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_messages_operations.py index 9fd47e1b4007..646fea1b19d8 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_messages_operations.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_messages_operations.py @@ -34,7 +34,9 @@ from .._configuration import AzureQueueStorageConfiguration T = TypeVar("T") -ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, dict[str, Any]], Any]] +ClsType = Optional[ + Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, dict[str, Any]], Any] +] class MessagesOperations: @@ -51,10 +53,18 @@ class MessagesOperations: def __init__(self, *args, **kwargs) -> None: input_args = list(args) - self._client: AsyncPipelineClient = input_args.pop(0) if input_args else kwargs.pop("client") - self._config: AzureQueueStorageConfiguration = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize: Serializer = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize: Deserializer = input_args.pop(0) if input_args else kwargs.pop("deserializer") + self._client: AsyncPipelineClient = ( + input_args.pop(0) if input_args else kwargs.pop("client") + ) + self._config: AzureQueueStorageConfiguration = ( + input_args.pop(0) if input_args else kwargs.pop("config") + ) + self._serialize: Serializer = ( + input_args.pop(0) if input_args else kwargs.pop("serializer") + ) + self._deserialize: Deserializer = ( + input_args.pop(0) if input_args else kwargs.pop("deserializer") + ) @distributed_trace_async async def dequeue( @@ -116,14 +126,18 @@ async def dequeue( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -131,11 +145,19 @@ async def dequeue( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) - deserialized = self._deserialize("[DequeuedMessageItem]", pipeline_response.http_response) + deserialized = self._deserialize( + "[DequeuedMessageItem]", pipeline_response.http_response + ) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore @@ -144,7 +166,10 @@ async def dequeue( @distributed_trace_async async def clear( - self, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any + self, + timeout: Optional[int] = None, + request_id_parameter: Optional[str] = None, + **kwargs: Any ) -> None: """The Clear operation deletes all messages from the specified queue. @@ -184,14 +209,18 @@ async def clear( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -199,9 +228,15 @@ async def clear( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) if cls: return cls(pipeline_response, None, response_headers) # type: ignore @@ -260,7 +295,9 @@ async def enqueue( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = kwargs.pop("params", {}) or {} - content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/xml")) + content_type: str = kwargs.pop( + "content_type", _headers.pop("Content-Type", "application/xml") + ) cls: ClsType[list[_models.EnqueuedMessage]] = kwargs.pop("cls", None) _content = self._serialize.body(queue_message, "QueueMessage", is_xml=True) @@ -280,14 +317,18 @@ async def enqueue( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -295,11 +336,19 @@ async def enqueue( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) - deserialized = self._deserialize("[EnqueuedMessage]", pipeline_response.http_response) + deserialized = self._deserialize( + "[EnqueuedMessage]", pipeline_response.http_response + ) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore @@ -345,7 +394,9 @@ async def peek( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - peekonly: Literal["true"] = kwargs.pop("peekonly", _params.pop("peekonly", "true")) + peekonly: Literal["true"] = kwargs.pop( + "peekonly", _params.pop("peekonly", "true") + ) cls: ClsType[list[_models.PeekedMessageItem]] = kwargs.pop("cls", None) _request = build_peek_request( @@ -361,14 +412,18 @@ async def peek( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -376,11 +431,19 @@ async def peek( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) - deserialized = self._deserialize("[PeekedMessageItem]", pipeline_response.http_response) + deserialized = self._deserialize( + "[PeekedMessageItem]", pipeline_response.http_response + ) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_patch.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_patch.py index 5755fd181b3f..0f5ec7712f5f 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_patch.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_patch.py @@ -8,9 +8,12 @@ Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize """ + from typing import List -__all__: List[str] = [] # Add all objects you want publicly available to users at this package level +__all__: List[str] = ( + [] +) # Add all objects you want publicly available to users at this package level def patch_sdk(): diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_queue_operations.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_queue_operations.py index 76787fa67345..029e6dba4796 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_queue_operations.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_queue_operations.py @@ -36,7 +36,9 @@ from .._configuration import AzureQueueStorageConfiguration T = TypeVar("T") -ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, dict[str, Any]], Any]] +ClsType = Optional[ + Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, dict[str, Any]], Any] +] class QueueOperations: @@ -53,10 +55,18 @@ class QueueOperations: def __init__(self, *args, **kwargs) -> None: input_args = list(args) - self._client: AsyncPipelineClient = input_args.pop(0) if input_args else kwargs.pop("client") - self._config: AzureQueueStorageConfiguration = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize: Serializer = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize: Deserializer = input_args.pop(0) if input_args else kwargs.pop("deserializer") + self._client: AsyncPipelineClient = ( + input_args.pop(0) if input_args else kwargs.pop("client") + ) + self._config: AzureQueueStorageConfiguration = ( + input_args.pop(0) if input_args else kwargs.pop("config") + ) + self._serialize: Serializer = ( + input_args.pop(0) if input_args else kwargs.pop("serializer") + ) + self._deserialize: Deserializer = ( + input_args.pop(0) if input_args else kwargs.pop("deserializer") + ) @distributed_trace_async async def create( @@ -111,14 +121,18 @@ async def create( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [201, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -126,16 +140,25 @@ async def create( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) if cls: return cls(pipeline_response, None, response_headers) # type: ignore @distributed_trace_async async def delete( - self, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any + self, + timeout: Optional[int] = None, + request_id_parameter: Optional[str] = None, + **kwargs: Any ) -> None: """operation permanently deletes the specified queue. @@ -175,14 +198,18 @@ async def delete( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -190,16 +217,25 @@ async def delete( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) if cls: return cls(pipeline_response, None, response_headers) # type: ignore @distributed_trace_async async def get_properties( - self, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any + self, + timeout: Optional[int] = None, + request_id_parameter: Optional[str] = None, + **kwargs: Any ) -> None: """Retrieves user-defined metadata and queue properties on the specified queue. Metadata is associated with the queue as name-values pairs. @@ -242,14 +278,18 @@ async def get_properties( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -257,13 +297,21 @@ async def get_properties( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-meta"] = self._deserialize("{str}", response.headers.get("x-ms-meta")) + response_headers["x-ms-meta"] = self._deserialize( + "{str}", response.headers.get("x-ms-meta") + ) response_headers["x-ms-approximate-messages-count"] = self._deserialize( "int", response.headers.get("x-ms-approximate-messages-count") ) - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) if cls: return cls(pipeline_response, None, response_headers) # type: ignore @@ -324,14 +372,18 @@ async def set_metadata( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -339,16 +391,25 @@ async def set_metadata( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) if cls: return cls(pipeline_response, None, response_headers) # type: ignore @distributed_trace_async async def get_access_policy( - self, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any + self, + timeout: Optional[int] = None, + request_id_parameter: Optional[str] = None, + **kwargs: Any ) -> list[_models.SignedIdentifier]: """returns details about any stored access policies specified on the queue that may be used with Shared Access Signatures. @@ -391,14 +452,18 @@ async def get_access_policy( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -406,11 +471,19 @@ async def get_access_policy( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) - deserialized = self._deserialize("[SignedIdentifier]", pipeline_response.http_response) + deserialized = self._deserialize( + "[SignedIdentifier]", pipeline_response.http_response + ) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore @@ -453,14 +526,19 @@ async def set_access_policy( _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) comp: Literal["acl"] = kwargs.pop("comp", _params.pop("comp", "acl")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", "application/xml")) + content_type: Optional[str] = kwargs.pop( + "content_type", _headers.pop("Content-Type", "application/xml") + ) content_type = content_type if queue_acl else None cls: ClsType[None] = kwargs.pop("cls", None) serialization_ctxt = {"xml": {"name": "SignedIdentifiers", "wrapped": True}} if queue_acl is not None: _content = self._serialize.body( - queue_acl, "[SignedIdentifier]", is_xml=True, serialization_ctxt=serialization_ctxt + queue_acl, + "[SignedIdentifier]", + is_xml=True, + serialization_ctxt=serialization_ctxt, ) else: _content = None @@ -479,14 +557,18 @@ async def set_access_policy( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -494,9 +576,15 @@ async def set_access_policy( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) if cls: return cls(pipeline_response, None, response_headers) # type: ignore diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_service_operations.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_service_operations.py index 54a8f75be779..094bc5626303 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_service_operations.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_service_operations.py @@ -35,7 +35,9 @@ from .._configuration import AzureQueueStorageConfiguration T = TypeVar("T") -ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, dict[str, Any]], Any]] +ClsType = Optional[ + Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, dict[str, Any]], Any] +] class ServiceOperations: @@ -52,10 +54,18 @@ class ServiceOperations: def __init__(self, *args, **kwargs) -> None: input_args = list(args) - self._client: AsyncPipelineClient = input_args.pop(0) if input_args else kwargs.pop("client") - self._config: AzureQueueStorageConfiguration = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize: Serializer = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize: Deserializer = input_args.pop(0) if input_args else kwargs.pop("deserializer") + self._client: AsyncPipelineClient = ( + input_args.pop(0) if input_args else kwargs.pop("client") + ) + self._config: AzureQueueStorageConfiguration = ( + input_args.pop(0) if input_args else kwargs.pop("config") + ) + self._serialize: Serializer = ( + input_args.pop(0) if input_args else kwargs.pop("serializer") + ) + self._deserialize: Deserializer = ( + input_args.pop(0) if input_args else kwargs.pop("deserializer") + ) @distributed_trace_async async def set_properties( @@ -93,12 +103,20 @@ async def set_properties( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - restype: Literal["service"] = kwargs.pop("restype", _params.pop("restype", "service")) - comp: Literal["properties"] = kwargs.pop("comp", _params.pop("comp", "properties")) - content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/xml")) + restype: Literal["service"] = kwargs.pop( + "restype", _params.pop("restype", "service") + ) + comp: Literal["properties"] = kwargs.pop( + "comp", _params.pop("comp", "properties") + ) + content_type: str = kwargs.pop( + "content_type", _headers.pop("Content-Type", "application/xml") + ) cls: ClsType[None] = kwargs.pop("cls", None) - _content = self._serialize.body(storage_service_properties, "StorageServiceProperties", is_xml=True) + _content = self._serialize.body( + storage_service_properties, "StorageServiceProperties", is_xml=True + ) _request = build_set_properties_request( url=self._config.url, @@ -115,14 +133,18 @@ async def set_properties( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [202]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -130,15 +152,22 @@ async def set_properties( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) if cls: return cls(pipeline_response, None, response_headers) # type: ignore @distributed_trace_async async def get_properties( - self, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any + self, + timeout: Optional[int] = None, + request_id_parameter: Optional[str] = None, + **kwargs: Any ) -> _models.StorageServiceProperties: """gets the properties of a storage account's Queue service, including properties for Storage Analytics and CORS (Cross-Origin Resource Sharing) rules. @@ -166,8 +195,12 @@ async def get_properties( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - restype: Literal["service"] = kwargs.pop("restype", _params.pop("restype", "service")) - comp: Literal["properties"] = kwargs.pop("comp", _params.pop("comp", "properties")) + restype: Literal["service"] = kwargs.pop( + "restype", _params.pop("restype", "service") + ) + comp: Literal["properties"] = kwargs.pop( + "comp", _params.pop("comp", "properties") + ) cls: ClsType[_models.StorageServiceProperties] = kwargs.pop("cls", None) _request = build_get_properties_request( @@ -183,14 +216,18 @@ async def get_properties( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -198,10 +235,16 @@ async def get_properties( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) - deserialized = self._deserialize("StorageServiceProperties", pipeline_response.http_response) + deserialized = self._deserialize( + "StorageServiceProperties", pipeline_response.http_response + ) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore @@ -210,7 +253,10 @@ async def get_properties( @distributed_trace_async async def get_statistics( - self, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any + self, + timeout: Optional[int] = None, + request_id_parameter: Optional[str] = None, + **kwargs: Any ) -> _models.StorageServiceStats: """Retrieves statistics related to replication for the Queue service. It is only available on the secondary location endpoint when read-access geo-redundant replication is enabled for the @@ -239,7 +285,9 @@ async def get_statistics( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - restype: Literal["service"] = kwargs.pop("restype", _params.pop("restype", "service")) + restype: Literal["service"] = kwargs.pop( + "restype", _params.pop("restype", "service") + ) comp: Literal["stats"] = kwargs.pop("comp", _params.pop("comp", "stats")) cls: ClsType[_models.StorageServiceStats] = kwargs.pop("cls", None) @@ -256,14 +304,18 @@ async def get_statistics( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -271,11 +323,19 @@ async def get_statistics( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) - deserialized = self._deserialize("StorageServiceStats", pipeline_response.http_response) + deserialized = self._deserialize( + "StorageServiceStats", pipeline_response.http_response + ) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore @@ -318,9 +378,15 @@ async def get_user_delegation_key( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - restype: Literal["service"] = kwargs.pop("restype", _params.pop("restype", "service")) - comp: Literal["userdelegationkey"] = kwargs.pop("comp", _params.pop("comp", "userdelegationkey")) - content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/xml")) + restype: Literal["service"] = kwargs.pop( + "restype", _params.pop("restype", "service") + ) + comp: Literal["userdelegationkey"] = kwargs.pop( + "comp", _params.pop("comp", "userdelegationkey") + ) + content_type: str = kwargs.pop( + "content_type", _headers.pop("Content-Type", "application/xml") + ) cls: ClsType[_models.UserDelegationKey] = kwargs.pop("cls", None) _content = self._serialize.body(key_info, "KeyInfo", is_xml=True) @@ -340,14 +406,18 @@ async def get_user_delegation_key( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -358,11 +428,19 @@ async def get_user_delegation_key( response_headers["x-ms-client-request-id"] = self._deserialize( "str", response.headers.get("x-ms-client-request-id") ) - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) - deserialized = self._deserialize("UserDelegationKey", pipeline_response.http_response) + deserialized = self._deserialize( + "UserDelegationKey", pipeline_response.http_response + ) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore @@ -444,14 +522,18 @@ async def list_queues_segment( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -459,11 +541,19 @@ async def list_queues_segment( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) - deserialized = self._deserialize("ListQueuesSegmentResponse", pipeline_response.http_response) + deserialized = self._deserialize( + "ListQueuesSegmentResponse", pipeline_response.http_response + ) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/models/_models_py3.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/models/_models_py3.py index 825f04418cf0..e3953134126f 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/models/_models_py3.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/models/_models_py3.py @@ -361,7 +361,12 @@ class KeyInfo(_serialization.Model): } def __init__( - self, *, expiry: str, start: Optional[str] = None, delegated_user_tid: Optional[str] = None, **kwargs: Any + self, + *, + expiry: str, + start: Optional[str] = None, + delegated_user_tid: Optional[str] = None, + **kwargs: Any ) -> None: """ :keyword start: The date-time the key is active in ISO 8601 UTC time. @@ -404,7 +409,11 @@ class ListQueuesSegmentResponse(_serialization.Model): } _attribute_map = { - "service_endpoint": {"key": "ServiceEndpoint", "type": "str", "xml": {"attr": True}}, + "service_endpoint": { + "key": "ServiceEndpoint", + "type": "str", + "xml": {"attr": True}, + }, "prefix": {"key": "Prefix", "type": "str"}, "marker": {"key": "Marker", "type": "str"}, "max_results": {"key": "MaxResults", "type": "int"}, @@ -655,7 +664,9 @@ class QueueItem(_serialization.Model): } _xml_map = {"name": "Queue"} - def __init__(self, *, name: str, metadata: Optional[dict[str, str]] = None, **kwargs: Any) -> None: + def __init__( + self, *, name: str, metadata: Optional[dict[str, str]] = None, **kwargs: Any + ) -> None: """ :keyword name: The name of the Queue. Required. :paramtype name: str @@ -716,7 +727,9 @@ class RetentionPolicy(_serialization.Model): "days": {"key": "Days", "type": "int"}, } - def __init__(self, *, enabled: bool, days: Optional[int] = None, **kwargs: Any) -> None: + def __init__( + self, *, enabled: bool, days: Optional[int] = None, **kwargs: Any + ) -> None: """ :keyword enabled: Indicates whether a retention policy is enabled for the storage service. Required. @@ -849,7 +862,12 @@ class StorageServiceStats(_serialization.Model): "geo_replication": {"key": "GeoReplication", "type": "GeoReplication"}, } - def __init__(self, *, geo_replication: Optional["_models.GeoReplication"] = None, **kwargs: Any) -> None: + def __init__( + self, + *, + geo_replication: Optional["_models.GeoReplication"] = None, + **kwargs: Any + ) -> None: """ :keyword geo_replication: Geo-Replication information for the Secondary Storage Service. :paramtype geo_replication: ~azure.storage.queue.models.GeoReplication diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/models/_patch.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/models/_patch.py index 5755fd181b3f..0f5ec7712f5f 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/models/_patch.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/models/_patch.py @@ -8,9 +8,12 @@ Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize """ + from typing import List -__all__: List[str] = [] # Add all objects you want publicly available to users at this package level +__all__: List[str] = ( + [] +) # Add all objects you want publicly available to users at this package level def patch_sdk(): diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_message_id_operations.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_message_id_operations.py index 39c22976afbe..7e2ea937fa43 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_message_id_operations.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_message_id_operations.py @@ -28,7 +28,9 @@ from .._utils.serialization import Deserializer, Serializer T = TypeVar("T") -ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, dict[str, Any]], Any]] +ClsType = Optional[ + Callable[[PipelineResponse[HttpRequest, HttpResponse], T, dict[str, Any]], Any] +] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False @@ -48,7 +50,9 @@ def build_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + content_type: Optional[str] = kwargs.pop( + "content_type", _headers.pop("Content-Type", None) + ) accept = _headers.pop("Accept", "application/xml") # Construct URL @@ -70,12 +74,23 @@ def build_update_request( # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") + _headers["x-ms-client-request-id"] = _SERIALIZER.header( + "request_id_parameter", request_id_parameter, "str" + ) if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Content-Type"] = _SERIALIZER.header( + "content_type", content_type, "str" + ) _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, content=content, **kwargs) + return HttpRequest( + method="PUT", + url=_url, + params=_params, + headers=_headers, + content=content, + **kwargs + ) def build_delete_request( @@ -108,10 +123,14 @@ def build_delete_request( # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") + _headers["x-ms-client-request-id"] = _SERIALIZER.header( + "request_id_parameter", request_id_parameter, "str" + ) _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) + return HttpRequest( + method="DELETE", url=_url, params=_params, headers=_headers, **kwargs + ) class MessageIdOperations: @@ -128,10 +147,18 @@ class MessageIdOperations: def __init__(self, *args, **kwargs) -> None: input_args = list(args) - self._client: PipelineClient = input_args.pop(0) if input_args else kwargs.pop("client") - self._config: AzureQueueStorageConfiguration = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize: Serializer = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize: Deserializer = input_args.pop(0) if input_args else kwargs.pop("deserializer") + self._client: PipelineClient = ( + input_args.pop(0) if input_args else kwargs.pop("client") + ) + self._config: AzureQueueStorageConfiguration = ( + input_args.pop(0) if input_args else kwargs.pop("config") + ) + self._serialize: Serializer = ( + input_args.pop(0) if input_args else kwargs.pop("serializer") + ) + self._deserialize: Deserializer = ( + input_args.pop(0) if input_args else kwargs.pop("deserializer") + ) @distributed_trace def update( # pylint: disable=inconsistent-return-statements @@ -183,7 +210,9 @@ def update( # pylint: disable=inconsistent-return-statements _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = kwargs.pop("params", {}) or {} - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", "application/xml")) + content_type: Optional[str] = kwargs.pop( + "content_type", _headers.pop("Content-Type", "application/xml") + ) content_type = content_type if queue_message else None cls: ClsType[None] = kwargs.pop("cls", None) @@ -207,14 +236,18 @@ def update( # pylint: disable=inconsistent-return-statements _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -222,10 +255,18 @@ def update( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) - response_headers["x-ms-popreceipt"] = self._deserialize("str", response.headers.get("x-ms-popreceipt")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) + response_headers["x-ms-popreceipt"] = self._deserialize( + "str", response.headers.get("x-ms-popreceipt") + ) response_headers["x-ms-time-next-visible"] = self._deserialize( "rfc-1123", response.headers.get("x-ms-time-next-visible") ) @@ -235,7 +276,11 @@ def update( # pylint: disable=inconsistent-return-statements @distributed_trace def delete( # pylint: disable=inconsistent-return-statements - self, pop_receipt: str, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any + self, + pop_receipt: str, + timeout: Optional[int] = None, + request_id_parameter: Optional[str] = None, + **kwargs: Any ) -> None: """The Delete operation deletes the specified message. @@ -279,14 +324,18 @@ def delete( # pylint: disable=inconsistent-return-statements _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -294,9 +343,15 @@ def delete( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) if cls: return cls(pipeline_response, None, response_headers) # type: ignore diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_messages_operations.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_messages_operations.py index 290bef2a7776..6b01ac95e89f 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_messages_operations.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_messages_operations.py @@ -28,7 +28,9 @@ from .._utils.serialization import Deserializer, Serializer T = TypeVar("T") -ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, dict[str, Any]], Any]] +ClsType = Optional[ + Callable[[PipelineResponse[HttpRequest, HttpResponse], T, dict[str, Any]], Any] +] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False @@ -59,7 +61,9 @@ def build_dequeue_request( # Construct parameters if number_of_messages is not None: - _params["numofmessages"] = _SERIALIZER.query("number_of_messages", number_of_messages, "int", minimum=1) + _params["numofmessages"] = _SERIALIZER.query( + "number_of_messages", number_of_messages, "int", minimum=1 + ) if visibilitytimeout is not None: _params["visibilitytimeout"] = _SERIALIZER.query( "visibilitytimeout", visibilitytimeout, "int", maximum=604800, minimum=0 @@ -70,14 +74,23 @@ def build_dequeue_request( # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") + _headers["x-ms-client-request-id"] = _SERIALIZER.header( + "request_id_parameter", request_id_parameter, "str" + ) _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + return HttpRequest( + method="GET", url=_url, params=_params, headers=_headers, **kwargs + ) def build_clear_request( - url: str, *, version: str, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any + url: str, + *, + version: str, + timeout: Optional[int] = None, + request_id_parameter: Optional[str] = None, + **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) @@ -99,10 +112,14 @@ def build_clear_request( # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") + _headers["x-ms-client-request-id"] = _SERIALIZER.header( + "request_id_parameter", request_id_parameter, "str" + ) _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) + return HttpRequest( + method="DELETE", url=_url, params=_params, headers=_headers, **kwargs + ) def build_enqueue_request( @@ -119,7 +136,9 @@ def build_enqueue_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + content_type: Optional[str] = kwargs.pop( + "content_type", _headers.pop("Content-Type", None) + ) accept = _headers.pop("Accept", "application/xml") # Construct URL @@ -136,19 +155,32 @@ def build_enqueue_request( "visibilitytimeout", visibilitytimeout, "int", maximum=604800, minimum=0 ) if message_time_to_live is not None: - _params["messagettl"] = _SERIALIZER.query("message_time_to_live", message_time_to_live, "int", minimum=-1) + _params["messagettl"] = _SERIALIZER.query( + "message_time_to_live", message_time_to_live, "int", minimum=-1 + ) if timeout is not None: _params["timeout"] = _SERIALIZER.query("timeout", timeout, "int", minimum=0) # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") + _headers["x-ms-client-request-id"] = _SERIALIZER.header( + "request_id_parameter", request_id_parameter, "str" + ) if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Content-Type"] = _SERIALIZER.header( + "content_type", content_type, "str" + ) _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, content=content, **kwargs) + return HttpRequest( + method="POST", + url=_url, + params=_params, + headers=_headers, + content=content, + **kwargs + ) def build_peek_request( @@ -177,17 +209,23 @@ def build_peek_request( # Construct parameters _params["peekonly"] = _SERIALIZER.query("peekonly", peekonly, "str") if number_of_messages is not None: - _params["numofmessages"] = _SERIALIZER.query("number_of_messages", number_of_messages, "int", minimum=1) + _params["numofmessages"] = _SERIALIZER.query( + "number_of_messages", number_of_messages, "int", minimum=1 + ) if timeout is not None: _params["timeout"] = _SERIALIZER.query("timeout", timeout, "int", minimum=0) # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") + _headers["x-ms-client-request-id"] = _SERIALIZER.header( + "request_id_parameter", request_id_parameter, "str" + ) _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + return HttpRequest( + method="GET", url=_url, params=_params, headers=_headers, **kwargs + ) class MessagesOperations: @@ -204,10 +242,18 @@ class MessagesOperations: def __init__(self, *args, **kwargs) -> None: input_args = list(args) - self._client: PipelineClient = input_args.pop(0) if input_args else kwargs.pop("client") - self._config: AzureQueueStorageConfiguration = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize: Serializer = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize: Deserializer = input_args.pop(0) if input_args else kwargs.pop("deserializer") + self._client: PipelineClient = ( + input_args.pop(0) if input_args else kwargs.pop("client") + ) + self._config: AzureQueueStorageConfiguration = ( + input_args.pop(0) if input_args else kwargs.pop("config") + ) + self._serialize: Serializer = ( + input_args.pop(0) if input_args else kwargs.pop("serializer") + ) + self._deserialize: Deserializer = ( + input_args.pop(0) if input_args else kwargs.pop("deserializer") + ) @distributed_trace def dequeue( @@ -269,14 +315,18 @@ def dequeue( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -284,11 +334,19 @@ def dequeue( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) - deserialized = self._deserialize("[DequeuedMessageItem]", pipeline_response.http_response) + deserialized = self._deserialize( + "[DequeuedMessageItem]", pipeline_response.http_response + ) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore @@ -297,7 +355,10 @@ def dequeue( @distributed_trace def clear( # pylint: disable=inconsistent-return-statements - self, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any + self, + timeout: Optional[int] = None, + request_id_parameter: Optional[str] = None, + **kwargs: Any ) -> None: """The Clear operation deletes all messages from the specified queue. @@ -337,14 +398,18 @@ def clear( # pylint: disable=inconsistent-return-statements _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -352,9 +417,15 @@ def clear( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) if cls: return cls(pipeline_response, None, response_headers) # type: ignore @@ -413,7 +484,9 @@ def enqueue( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = kwargs.pop("params", {}) or {} - content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/xml")) + content_type: str = kwargs.pop( + "content_type", _headers.pop("Content-Type", "application/xml") + ) cls: ClsType[list[_models.EnqueuedMessage]] = kwargs.pop("cls", None) _content = self._serialize.body(queue_message, "QueueMessage", is_xml=True) @@ -433,14 +506,18 @@ def enqueue( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -448,11 +525,19 @@ def enqueue( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) - deserialized = self._deserialize("[EnqueuedMessage]", pipeline_response.http_response) + deserialized = self._deserialize( + "[EnqueuedMessage]", pipeline_response.http_response + ) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore @@ -498,7 +583,9 @@ def peek( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - peekonly: Literal["true"] = kwargs.pop("peekonly", _params.pop("peekonly", "true")) + peekonly: Literal["true"] = kwargs.pop( + "peekonly", _params.pop("peekonly", "true") + ) cls: ClsType[list[_models.PeekedMessageItem]] = kwargs.pop("cls", None) _request = build_peek_request( @@ -514,14 +601,18 @@ def peek( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -529,11 +620,19 @@ def peek( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) - deserialized = self._deserialize("[PeekedMessageItem]", pipeline_response.http_response) + deserialized = self._deserialize( + "[PeekedMessageItem]", pipeline_response.http_response + ) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_patch.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_patch.py index 5755fd181b3f..0f5ec7712f5f 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_patch.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_patch.py @@ -8,9 +8,12 @@ Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize """ + from typing import List -__all__: List[str] = [] # Add all objects you want publicly available to users at this package level +__all__: List[str] = ( + [] +) # Add all objects you want publicly available to users at this package level def patch_sdk(): diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_queue_operations.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_queue_operations.py index fd4370c3801f..8cbdf2cc3713 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_queue_operations.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_queue_operations.py @@ -28,7 +28,9 @@ from .._utils.serialization import Deserializer, Serializer T = TypeVar("T") -ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, dict[str, Any]], Any]] +ClsType = Optional[ + Callable[[PipelineResponse[HttpRequest, HttpResponse], T, dict[str, Any]], Any] +] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False @@ -65,14 +67,23 @@ def build_create_request( _headers["x-ms-meta"] = _SERIALIZER.header("metadata", metadata, "{str}") _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") + _headers["x-ms-client-request-id"] = _SERIALIZER.header( + "request_id_parameter", request_id_parameter, "str" + ) _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + return HttpRequest( + method="PUT", url=_url, params=_params, headers=_headers, **kwargs + ) def build_delete_request( - url: str, *, version: str, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any + url: str, + *, + version: str, + timeout: Optional[int] = None, + request_id_parameter: Optional[str] = None, + **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) @@ -94,14 +105,23 @@ def build_delete_request( # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") + _headers["x-ms-client-request-id"] = _SERIALIZER.header( + "request_id_parameter", request_id_parameter, "str" + ) _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) + return HttpRequest( + method="DELETE", url=_url, params=_params, headers=_headers, **kwargs + ) def build_get_properties_request( - url: str, *, version: str, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any + url: str, + *, + version: str, + timeout: Optional[int] = None, + request_id_parameter: Optional[str] = None, + **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) @@ -125,10 +145,14 @@ def build_get_properties_request( # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") + _headers["x-ms-client-request-id"] = _SERIALIZER.header( + "request_id_parameter", request_id_parameter, "str" + ) _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + return HttpRequest( + method="GET", url=_url, params=_params, headers=_headers, **kwargs + ) def build_set_metadata_request( @@ -164,14 +188,23 @@ def build_set_metadata_request( _headers["x-ms-meta"] = _SERIALIZER.header("metadata", metadata, "{str}") _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") + _headers["x-ms-client-request-id"] = _SERIALIZER.header( + "request_id_parameter", request_id_parameter, "str" + ) _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + return HttpRequest( + method="PUT", url=_url, params=_params, headers=_headers, **kwargs + ) def build_get_access_policy_request( - url: str, *, version: str, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any + url: str, + *, + version: str, + timeout: Optional[int] = None, + request_id_parameter: Optional[str] = None, + **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) @@ -195,10 +228,14 @@ def build_get_access_policy_request( # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") + _headers["x-ms-client-request-id"] = _SERIALIZER.header( + "request_id_parameter", request_id_parameter, "str" + ) _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + return HttpRequest( + method="GET", url=_url, params=_params, headers=_headers, **kwargs + ) def build_set_access_policy_request( @@ -214,7 +251,9 @@ def build_set_access_policy_request( _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) comp: Literal["acl"] = kwargs.pop("comp", _params.pop("comp", "acl")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + content_type: Optional[str] = kwargs.pop( + "content_type", _headers.pop("Content-Type", None) + ) accept = _headers.pop("Accept", "application/xml") # Construct URL @@ -233,12 +272,23 @@ def build_set_access_policy_request( # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") + _headers["x-ms-client-request-id"] = _SERIALIZER.header( + "request_id_parameter", request_id_parameter, "str" + ) if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Content-Type"] = _SERIALIZER.header( + "content_type", content_type, "str" + ) _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, content=content, **kwargs) + return HttpRequest( + method="PUT", + url=_url, + params=_params, + headers=_headers, + content=content, + **kwargs + ) class QueueOperations: @@ -255,10 +305,18 @@ class QueueOperations: def __init__(self, *args, **kwargs) -> None: input_args = list(args) - self._client: PipelineClient = input_args.pop(0) if input_args else kwargs.pop("client") - self._config: AzureQueueStorageConfiguration = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize: Serializer = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize: Deserializer = input_args.pop(0) if input_args else kwargs.pop("deserializer") + self._client: PipelineClient = ( + input_args.pop(0) if input_args else kwargs.pop("client") + ) + self._config: AzureQueueStorageConfiguration = ( + input_args.pop(0) if input_args else kwargs.pop("config") + ) + self._serialize: Serializer = ( + input_args.pop(0) if input_args else kwargs.pop("serializer") + ) + self._deserialize: Deserializer = ( + input_args.pop(0) if input_args else kwargs.pop("deserializer") + ) @distributed_trace def create( # pylint: disable=inconsistent-return-statements @@ -313,14 +371,18 @@ def create( # pylint: disable=inconsistent-return-statements _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [201, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -328,16 +390,25 @@ def create( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) if cls: return cls(pipeline_response, None, response_headers) # type: ignore @distributed_trace def delete( # pylint: disable=inconsistent-return-statements - self, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any + self, + timeout: Optional[int] = None, + request_id_parameter: Optional[str] = None, + **kwargs: Any ) -> None: """operation permanently deletes the specified queue. @@ -377,14 +448,18 @@ def delete( # pylint: disable=inconsistent-return-statements _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -392,16 +467,25 @@ def delete( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) if cls: return cls(pipeline_response, None, response_headers) # type: ignore @distributed_trace def get_properties( # pylint: disable=inconsistent-return-statements - self, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any + self, + timeout: Optional[int] = None, + request_id_parameter: Optional[str] = None, + **kwargs: Any ) -> None: """Retrieves user-defined metadata and queue properties on the specified queue. Metadata is associated with the queue as name-values pairs. @@ -444,14 +528,18 @@ def get_properties( # pylint: disable=inconsistent-return-statements _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -459,13 +547,21 @@ def get_properties( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-meta"] = self._deserialize("{str}", response.headers.get("x-ms-meta")) + response_headers["x-ms-meta"] = self._deserialize( + "{str}", response.headers.get("x-ms-meta") + ) response_headers["x-ms-approximate-messages-count"] = self._deserialize( "int", response.headers.get("x-ms-approximate-messages-count") ) - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) if cls: return cls(pipeline_response, None, response_headers) # type: ignore @@ -526,14 +622,18 @@ def set_metadata( # pylint: disable=inconsistent-return-statements _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -541,16 +641,25 @@ def set_metadata( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) if cls: return cls(pipeline_response, None, response_headers) # type: ignore @distributed_trace def get_access_policy( - self, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any + self, + timeout: Optional[int] = None, + request_id_parameter: Optional[str] = None, + **kwargs: Any ) -> list[_models.SignedIdentifier]: """returns details about any stored access policies specified on the queue that may be used with Shared Access Signatures. @@ -593,14 +702,18 @@ def get_access_policy( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -608,11 +721,19 @@ def get_access_policy( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) - deserialized = self._deserialize("[SignedIdentifier]", pipeline_response.http_response) + deserialized = self._deserialize( + "[SignedIdentifier]", pipeline_response.http_response + ) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore @@ -655,14 +776,19 @@ def set_access_policy( # pylint: disable=inconsistent-return-statements _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) comp: Literal["acl"] = kwargs.pop("comp", _params.pop("comp", "acl")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", "application/xml")) + content_type: Optional[str] = kwargs.pop( + "content_type", _headers.pop("Content-Type", "application/xml") + ) content_type = content_type if queue_acl else None cls: ClsType[None] = kwargs.pop("cls", None) serialization_ctxt = {"xml": {"name": "SignedIdentifiers", "wrapped": True}} if queue_acl is not None: _content = self._serialize.body( - queue_acl, "[SignedIdentifier]", is_xml=True, serialization_ctxt=serialization_ctxt + queue_acl, + "[SignedIdentifier]", + is_xml=True, + serialization_ctxt=serialization_ctxt, ) else: _content = None @@ -681,14 +807,18 @@ def set_access_policy( # pylint: disable=inconsistent-return-statements _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -696,9 +826,15 @@ def set_access_policy( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) if cls: return cls(pipeline_response, None, response_headers) # type: ignore diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_service_operations.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_service_operations.py index b20f5f5d24bd..e66bf5d3bfaa 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_service_operations.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_service_operations.py @@ -28,7 +28,9 @@ from .._utils.serialization import Deserializer, Serializer T = TypeVar("T") -ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, dict[str, Any]], Any]] +ClsType = Optional[ + Callable[[PipelineResponse[HttpRequest, HttpResponse], T, dict[str, Any]], Any] +] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False @@ -46,9 +48,13 @@ def build_set_properties_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - restype: Literal["service"] = kwargs.pop("restype", _params.pop("restype", "service")) + restype: Literal["service"] = kwargs.pop( + "restype", _params.pop("restype", "service") + ) comp: Literal["properties"] = kwargs.pop("comp", _params.pop("comp", "properties")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + content_type: Optional[str] = kwargs.pop( + "content_type", _headers.pop("Content-Type", None) + ) accept = _headers.pop("Accept", "application/xml") # Construct URL @@ -68,21 +74,39 @@ def build_set_properties_request( # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") + _headers["x-ms-client-request-id"] = _SERIALIZER.header( + "request_id_parameter", request_id_parameter, "str" + ) if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Content-Type"] = _SERIALIZER.header( + "content_type", content_type, "str" + ) _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, content=content, **kwargs) + return HttpRequest( + method="PUT", + url=_url, + params=_params, + headers=_headers, + content=content, + **kwargs + ) def build_get_properties_request( - url: str, *, version: str, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any + url: str, + *, + version: str, + timeout: Optional[int] = None, + request_id_parameter: Optional[str] = None, + **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - restype: Literal["service"] = kwargs.pop("restype", _params.pop("restype", "service")) + restype: Literal["service"] = kwargs.pop( + "restype", _params.pop("restype", "service") + ) comp: Literal["properties"] = kwargs.pop("comp", _params.pop("comp", "properties")) accept = _headers.pop("Accept", "application/xml") @@ -103,19 +127,30 @@ def build_get_properties_request( # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") + _headers["x-ms-client-request-id"] = _SERIALIZER.header( + "request_id_parameter", request_id_parameter, "str" + ) _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + return HttpRequest( + method="GET", url=_url, params=_params, headers=_headers, **kwargs + ) def build_get_statistics_request( - url: str, *, version: str, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any + url: str, + *, + version: str, + timeout: Optional[int] = None, + request_id_parameter: Optional[str] = None, + **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - restype: Literal["service"] = kwargs.pop("restype", _params.pop("restype", "service")) + restype: Literal["service"] = kwargs.pop( + "restype", _params.pop("restype", "service") + ) comp: Literal["stats"] = kwargs.pop("comp", _params.pop("comp", "stats")) accept = _headers.pop("Accept", "application/xml") @@ -136,10 +171,14 @@ def build_get_statistics_request( # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") + _headers["x-ms-client-request-id"] = _SERIALIZER.header( + "request_id_parameter", request_id_parameter, "str" + ) _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + return HttpRequest( + method="GET", url=_url, params=_params, headers=_headers, **kwargs + ) def build_get_user_delegation_key_request( @@ -154,9 +193,15 @@ def build_get_user_delegation_key_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - restype: Literal["service"] = kwargs.pop("restype", _params.pop("restype", "service")) - comp: Literal["userdelegationkey"] = kwargs.pop("comp", _params.pop("comp", "userdelegationkey")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + restype: Literal["service"] = kwargs.pop( + "restype", _params.pop("restype", "service") + ) + comp: Literal["userdelegationkey"] = kwargs.pop( + "comp", _params.pop("comp", "userdelegationkey") + ) + content_type: Optional[str] = kwargs.pop( + "content_type", _headers.pop("Content-Type", None) + ) accept = _headers.pop("Accept", "application/xml") # Construct URL @@ -176,12 +221,23 @@ def build_get_user_delegation_key_request( # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") + _headers["x-ms-client-request-id"] = _SERIALIZER.header( + "request_id_parameter", request_id_parameter, "str" + ) if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Content-Type"] = _SERIALIZER.header( + "content_type", content_type, "str" + ) _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, content=content, **kwargs) + return HttpRequest( + method="POST", + url=_url, + params=_params, + headers=_headers, + content=content, + **kwargs + ) def build_list_queues_segment_request( @@ -217,7 +273,9 @@ def build_list_queues_segment_request( if marker is not None: _params["marker"] = _SERIALIZER.query("marker", marker, "str") if maxresults is not None: - _params["maxresults"] = _SERIALIZER.query("maxresults", maxresults, "int", minimum=1) + _params["maxresults"] = _SERIALIZER.query( + "maxresults", maxresults, "int", minimum=1 + ) if include is not None: _params["include"] = _SERIALIZER.query("include", include, "[str]", div=",") if timeout is not None: @@ -226,10 +284,14 @@ def build_list_queues_segment_request( # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") + _headers["x-ms-client-request-id"] = _SERIALIZER.header( + "request_id_parameter", request_id_parameter, "str" + ) _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + return HttpRequest( + method="GET", url=_url, params=_params, headers=_headers, **kwargs + ) class ServiceOperations: @@ -246,10 +308,18 @@ class ServiceOperations: def __init__(self, *args, **kwargs) -> None: input_args = list(args) - self._client: PipelineClient = input_args.pop(0) if input_args else kwargs.pop("client") - self._config: AzureQueueStorageConfiguration = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize: Serializer = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize: Deserializer = input_args.pop(0) if input_args else kwargs.pop("deserializer") + self._client: PipelineClient = ( + input_args.pop(0) if input_args else kwargs.pop("client") + ) + self._config: AzureQueueStorageConfiguration = ( + input_args.pop(0) if input_args else kwargs.pop("config") + ) + self._serialize: Serializer = ( + input_args.pop(0) if input_args else kwargs.pop("serializer") + ) + self._deserialize: Deserializer = ( + input_args.pop(0) if input_args else kwargs.pop("deserializer") + ) @distributed_trace def set_properties( # pylint: disable=inconsistent-return-statements @@ -287,12 +357,20 @@ def set_properties( # pylint: disable=inconsistent-return-statements _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - restype: Literal["service"] = kwargs.pop("restype", _params.pop("restype", "service")) - comp: Literal["properties"] = kwargs.pop("comp", _params.pop("comp", "properties")) - content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/xml")) + restype: Literal["service"] = kwargs.pop( + "restype", _params.pop("restype", "service") + ) + comp: Literal["properties"] = kwargs.pop( + "comp", _params.pop("comp", "properties") + ) + content_type: str = kwargs.pop( + "content_type", _headers.pop("Content-Type", "application/xml") + ) cls: ClsType[None] = kwargs.pop("cls", None) - _content = self._serialize.body(storage_service_properties, "StorageServiceProperties", is_xml=True) + _content = self._serialize.body( + storage_service_properties, "StorageServiceProperties", is_xml=True + ) _request = build_set_properties_request( url=self._config.url, @@ -309,14 +387,18 @@ def set_properties( # pylint: disable=inconsistent-return-statements _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [202]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -324,15 +406,22 @@ def set_properties( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) if cls: return cls(pipeline_response, None, response_headers) # type: ignore @distributed_trace def get_properties( - self, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any + self, + timeout: Optional[int] = None, + request_id_parameter: Optional[str] = None, + **kwargs: Any ) -> _models.StorageServiceProperties: """gets the properties of a storage account's Queue service, including properties for Storage Analytics and CORS (Cross-Origin Resource Sharing) rules. @@ -360,8 +449,12 @@ def get_properties( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - restype: Literal["service"] = kwargs.pop("restype", _params.pop("restype", "service")) - comp: Literal["properties"] = kwargs.pop("comp", _params.pop("comp", "properties")) + restype: Literal["service"] = kwargs.pop( + "restype", _params.pop("restype", "service") + ) + comp: Literal["properties"] = kwargs.pop( + "comp", _params.pop("comp", "properties") + ) cls: ClsType[_models.StorageServiceProperties] = kwargs.pop("cls", None) _request = build_get_properties_request( @@ -377,14 +470,18 @@ def get_properties( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -392,10 +489,16 @@ def get_properties( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) - deserialized = self._deserialize("StorageServiceProperties", pipeline_response.http_response) + deserialized = self._deserialize( + "StorageServiceProperties", pipeline_response.http_response + ) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore @@ -404,7 +507,10 @@ def get_properties( @distributed_trace def get_statistics( - self, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any + self, + timeout: Optional[int] = None, + request_id_parameter: Optional[str] = None, + **kwargs: Any ) -> _models.StorageServiceStats: """Retrieves statistics related to replication for the Queue service. It is only available on the secondary location endpoint when read-access geo-redundant replication is enabled for the @@ -433,7 +539,9 @@ def get_statistics( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - restype: Literal["service"] = kwargs.pop("restype", _params.pop("restype", "service")) + restype: Literal["service"] = kwargs.pop( + "restype", _params.pop("restype", "service") + ) comp: Literal["stats"] = kwargs.pop("comp", _params.pop("comp", "stats")) cls: ClsType[_models.StorageServiceStats] = kwargs.pop("cls", None) @@ -450,14 +558,18 @@ def get_statistics( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -465,11 +577,19 @@ def get_statistics( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) - deserialized = self._deserialize("StorageServiceStats", pipeline_response.http_response) + deserialized = self._deserialize( + "StorageServiceStats", pipeline_response.http_response + ) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore @@ -512,9 +632,15 @@ def get_user_delegation_key( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - restype: Literal["service"] = kwargs.pop("restype", _params.pop("restype", "service")) - comp: Literal["userdelegationkey"] = kwargs.pop("comp", _params.pop("comp", "userdelegationkey")) - content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/xml")) + restype: Literal["service"] = kwargs.pop( + "restype", _params.pop("restype", "service") + ) + comp: Literal["userdelegationkey"] = kwargs.pop( + "comp", _params.pop("comp", "userdelegationkey") + ) + content_type: str = kwargs.pop( + "content_type", _headers.pop("Content-Type", "application/xml") + ) cls: ClsType[_models.UserDelegationKey] = kwargs.pop("cls", None) _content = self._serialize.body(key_info, "KeyInfo", is_xml=True) @@ -534,14 +660,18 @@ def get_user_delegation_key( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -552,11 +682,19 @@ def get_user_delegation_key( response_headers["x-ms-client-request-id"] = self._deserialize( "str", response.headers.get("x-ms-client-request-id") ) - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) - deserialized = self._deserialize("UserDelegationKey", pipeline_response.http_response) + deserialized = self._deserialize( + "UserDelegationKey", pipeline_response.http_response + ) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore @@ -638,14 +776,18 @@ def list_queues_segment( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) + map_error( + status_code=response.status_code, response=response, error_map=error_map + ) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -653,11 +795,19 @@ def list_queues_segment( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) - response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-request-id"] = self._deserialize( + "str", response.headers.get("x-ms-request-id") + ) + response_headers["x-ms-version"] = self._deserialize( + "str", response.headers.get("x-ms-version") + ) + response_headers["Date"] = self._deserialize( + "rfc-1123", response.headers.get("Date") + ) - deserialized = self._deserialize("ListQueuesSegmentResponse", pipeline_response.http_response) + deserialized = self._deserialize( + "ListQueuesSegmentResponse", pipeline_response.http_response + ) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_message_encoding.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_message_encoding.py index bd62f9933338..3732dee8d497 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_message_encoding.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_message_encoding.py @@ -9,7 +9,12 @@ from azure.core.exceptions import DecodeError -from ._encryption import decrypt_queue_message, encrypt_queue_message, KeyEncryptionKey, _ENCRYPTION_PROTOCOL_V1 +from ._encryption import ( + decrypt_queue_message, + encrypt_queue_message, + KeyEncryptionKey, + _ENCRYPTION_PROTOCOL_V1, +) if TYPE_CHECKING: from azure.core.pipeline import PipelineResponse @@ -36,7 +41,9 @@ def __call__(self, content: Any) -> str: if content: content = self.encode(content) if self.key_encryption_key is not None: - content = encrypt_queue_message(content, self.key_encryption_key, self.encryption_version) + content = encrypt_queue_message( + content, self.key_encryption_key, self.encryption_version + ) return content def configure( @@ -71,14 +78,20 @@ def __init__(self) -> None: self.key_encryption_key = None self.resolver = None - def __call__(self, response: "PipelineResponse", obj: Iterable, headers: Dict[str, Any]) -> object: + def __call__( + self, response: "PipelineResponse", obj: Iterable, headers: Dict[str, Any] + ) -> object: for message in obj: if message.message_text in [None, "", b""]: continue content = message.message_text if (self.key_encryption_key is not None) or (self.resolver is not None): content = decrypt_queue_message( - content, response, self.require_encryption, self.key_encryption_key, self.resolver + content, + response, + self.require_encryption, + self.key_encryption_key, + self.resolver, ) message.message_text = self.decode(content, response) return obj @@ -164,7 +177,9 @@ class NoEncodePolicy(MessageEncodePolicy): def encode(self, content: str) -> str: if isinstance(content, bytes): - raise TypeError("Message content must not be bytes. Use the BinaryBase64EncodePolicy to send bytes.") + raise TypeError( + "Message content must not be bytes. Use the BinaryBase64EncodePolicy to send bytes." + ) return content diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_models.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_models.py index 6d7faf9e860e..ab4cd2c52f32 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_models.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_models.py @@ -9,7 +9,10 @@ from typing import Any, Callable, Dict, List, Optional, Tuple, TYPE_CHECKING, Union from azure.core.exceptions import HttpResponseError from azure.core.paging import PageIterator -from ._shared.response_handlers import process_storage_error, return_context_and_deserialized +from ._shared.response_handlers import ( + process_storage_error, + return_context_and_deserialized, +) from ._shared.models import DictMixin from ._generated.models import AccessPolicy as GenAccessPolicy from ._generated.models import CorsRule as GeneratedCorsRule @@ -190,7 +193,9 @@ class CorsRule(GeneratedCorsRule): """The comma-delimited string representation of the list of headers allowed to be part of the cross-origin request.""" - def __init__(self, allowed_origins: List[str], allowed_methods: List[str], **kwargs: Any) -> None: + def __init__( + self, allowed_origins: List[str], allowed_methods: List[str], **kwargs: Any + ) -> None: self.allowed_origins = ",".join(allowed_origins) self.allowed_methods = ",".join(allowed_methods) self.allowed_headers = ",".join(kwargs.get("allowed_headers", [])) @@ -198,7 +203,9 @@ def __init__(self, allowed_origins: List[str], allowed_methods: List[str], **kwa self.max_age_in_seconds = kwargs.get("max_age_in_seconds", 0) @staticmethod - def _to_generated(rules: Optional[List["CorsRule"]]) -> Optional[List[GeneratedCorsRule]]: + def _to_generated( + rules: Optional[List["CorsRule"]], + ) -> Optional[List[GeneratedCorsRule]]: if rules is None: return rules @@ -251,7 +258,13 @@ class QueueSasPermissions(object): process: bool = False """Get and delete messages from the queue.""" - def __init__(self, read: bool = False, add: bool = False, update: bool = False, process: bool = False) -> None: + def __init__( + self, + read: bool = False, + add: bool = False, + update: bool = False, + process: bool = False, + ) -> None: self.read = read self.add = add self.update = update @@ -450,7 +463,9 @@ def _extract_data_cb(self, messages: Any) -> Tuple[str, List[QueueMessage]]: raise StopIteration("End of paging") if self._max_messages is not None: self._max_messages = self._max_messages - len(messages) - return "TOKEN_IGNORED", [QueueMessage._from_generated(q) for q in messages] # pylint: disable=protected-access + return "TOKEN_IGNORED", [ + QueueMessage._from_generated(q) for q in messages + ] # pylint: disable=protected-access class QueueProperties(DictMixin): @@ -540,14 +555,17 @@ def _get_next_cb(self, continuation_token: Optional[str]) -> Any: except HttpResponseError as error: process_storage_error(error) - def _extract_data_cb(self, get_next_return: Any) -> Tuple[Optional[str], List[QueueProperties]]: + def _extract_data_cb( + self, get_next_return: Any + ) -> Tuple[Optional[str], List[QueueProperties]]: self.location_mode, self._response = get_next_return self.service_endpoint = self._response.service_endpoint self.prefix = self._response.prefix self.marker = self._response.marker self.results_per_page = self._response.max_results props_list = [ - QueueProperties._from_generated(q) for q in self._response.queue_items # pylint: disable=protected-access + QueueProperties._from_generated(q) + for q in self._response.queue_items # pylint: disable=protected-access ] return self._response.next_marker or None, props_list @@ -578,7 +596,13 @@ def service_properties_deserialize(generated: Any) -> Dict[str, Any]: "analytics_logging": QueueAnalyticsLogging._from_generated( # pylint: disable=protected-access generated.logging ), - "hour_metrics": Metrics._from_generated(generated.hour_metrics), # pylint: disable=protected-access - "minute_metrics": Metrics._from_generated(generated.minute_metrics), # pylint: disable=protected-access - "cors": [CorsRule._from_generated(cors) for cors in generated.cors], # pylint: disable=protected-access + "hour_metrics": Metrics._from_generated( + generated.hour_metrics + ), # pylint: disable=protected-access + "minute_metrics": Metrics._from_generated( + generated.minute_metrics + ), # pylint: disable=protected-access + "cors": [ + CorsRule._from_generated(cors) for cors in generated.cors + ], # pylint: disable=protected-access } diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_client.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_client.py index 7812bffb9602..b669da7e0161 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_client.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_client.py @@ -23,10 +23,18 @@ from ._serialize import get_api_version from ._shared.base_client import parse_connection_str, StorageAccountHostsMixin from ._shared.request_handlers import add_metadata_headers, serialize_iso -from ._shared.response_handlers import process_storage_error, return_headers_and_deserialized, return_response_headers +from ._shared.response_handlers import ( + process_storage_error, + return_headers_and_deserialized, + return_response_headers, +) if TYPE_CHECKING: - from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential, TokenCredential + from azure.core.credentials import ( + AzureNamedKeyCredential, + AzureSasCredential, + TokenCredential, + ) from ._message_encoding import ( BinaryBase64DecodePolicy, BinaryBase64EncodePolicy, @@ -96,17 +104,29 @@ def __init__( account_url: str, queue_name: str, credential: Optional[ - Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"] + Union[ + str, + Dict[str, str], + "AzureNamedKeyCredential", + "AzureSasCredential", + "TokenCredential", + ] ] = None, *, api_version: Optional[str] = None, secondary_hostname: Optional[str] = None, - message_encode_policy: Optional[Union["BinaryBase64EncodePolicy", "TextBase64EncodePolicy"]] = None, - message_decode_policy: Optional[Union["BinaryBase64DecodePolicy", "TextBase64DecodePolicy"]] = None, + message_encode_policy: Optional[ + Union["BinaryBase64EncodePolicy", "TextBase64EncodePolicy"] + ] = None, + message_decode_policy: Optional[ + Union["BinaryBase64DecodePolicy", "TextBase64DecodePolicy"] + ] = None, audience: Optional[str] = None, **kwargs: Any ) -> None: - parsed_url, sas_token = _parse_url(account_url=account_url, queue_name=queue_name, credential=credential) + parsed_url, sas_token = _parse_url( + account_url=account_url, queue_name=queue_name, credential=credential + ) self.queue_name = queue_name self._query_str, credential = self._format_query_string(sas_token, credential) super(QueueClient, self).__init__( @@ -120,7 +140,10 @@ def __init__( self._message_encode_policy = message_encode_policy or NoEncodePolicy() self._message_decode_policy = message_decode_policy or NoDecodePolicy() self._client = AzureQueueStorage( - self.url, get_api_version(api_version), base_url=self.url, pipeline=self._pipeline + self.url, + get_api_version(api_version), + base_url=self.url, + pipeline=self._pipeline, ) self._configure_encryption(kwargs) @@ -129,9 +152,14 @@ def __enter__(self) -> Self: return self def __exit__( - self, typ: Optional[type[BaseException]], exc: Optional[BaseException], tb: Optional[TracebackType] + self, + typ: Optional[type[BaseException]], + exc: Optional[BaseException], + tb: Optional[TracebackType], ) -> None: - self._client.__exit__(typ, exc, tb) # pylint: disable=specify-parameter-names-in-call + self._client.__exit__( + typ, exc, tb + ) # pylint: disable=specify-parameter-names-in-call def close(self) -> None: """This method is to close the sockets opened by the client. @@ -150,20 +178,35 @@ def _format_url(self, hostname: str) -> str: :returns: The formatted endpoint URL according to the specified location mode hostname. :rtype: str """ - return _format_url(queue_name=self.queue_name, hostname=hostname, scheme=self.scheme, query_str=self._query_str) + return _format_url( + queue_name=self.queue_name, + hostname=hostname, + scheme=self.scheme, + query_str=self._query_str, + ) @classmethod def from_queue_url( cls, queue_url: str, credential: Optional[ - Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"] + Union[ + str, + Dict[str, str], + "AzureNamedKeyCredential", + "AzureSasCredential", + "TokenCredential", + ] ] = None, *, api_version: Optional[str] = None, secondary_hostname: Optional[str] = None, - message_encode_policy: Optional[Union["BinaryBase64EncodePolicy", "TextBase64EncodePolicy"]] = None, - message_decode_policy: Optional[Union["BinaryBase64DecodePolicy", "TextBase64DecodePolicy"]] = None, + message_encode_policy: Optional[ + Union["BinaryBase64EncodePolicy", "TextBase64EncodePolicy"] + ] = None, + message_decode_policy: Optional[ + Union["BinaryBase64DecodePolicy", "TextBase64DecodePolicy"] + ] = None, audience: Optional[str] = None, **kwargs: Any ) -> Self: @@ -222,13 +265,23 @@ def from_connection_string( conn_str: str, queue_name: str, credential: Optional[ - Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"] + Union[ + str, + Dict[str, str], + "AzureNamedKeyCredential", + "AzureSasCredential", + "TokenCredential", + ] ] = None, *, api_version: Optional[str] = None, secondary_hostname: Optional[str] = None, - message_encode_policy: Optional[Union["BinaryBase64EncodePolicy", "TextBase64EncodePolicy"]] = None, - message_decode_policy: Optional[Union["BinaryBase64DecodePolicy", "TextBase64DecodePolicy"]] = None, + message_encode_policy: Optional[ + Union["BinaryBase64EncodePolicy", "TextBase64EncodePolicy"] + ] = None, + message_decode_policy: Optional[ + Union["BinaryBase64DecodePolicy", "TextBase64DecodePolicy"] + ] = None, audience: Optional[str] = None, **kwargs: Any ) -> Self: @@ -280,7 +333,9 @@ def from_connection_string( :dedent: 8 :caption: Create the queue client from connection string. """ - account_url, secondary, credential = parse_connection_str(conn_str, credential, "queue") + account_url, secondary, credential = parse_connection_str( + conn_str, credential, "queue" + ) return cls( account_url, queue_name=queue_name, @@ -295,7 +350,11 @@ def from_connection_string( @distributed_trace def create_queue( - self, *, metadata: Optional[Dict[str, str]] = None, timeout: Optional[int] = None, **kwargs: Any + self, + *, + metadata: Optional[Dict[str, str]] = None, + timeout: Optional[int] = None, + **kwargs: Any ) -> None: """Creates a new queue in the storage account. @@ -329,7 +388,11 @@ def create_queue( headers.update(add_metadata_headers(metadata)) try: return self._client.queue.create( - metadata=metadata, timeout=timeout, headers=headers, cls=deserialize_queue_creation, **kwargs + metadata=metadata, + timeout=timeout, + headers=headers, + cls=deserialize_queue_creation, + **kwargs ) except HttpResponseError as error: process_storage_error(error) @@ -369,7 +432,9 @@ def delete_queue(self, *, timeout: Optional[int] = None, **kwargs: Any) -> None: process_storage_error(error) @distributed_trace - def get_queue_properties(self, *, timeout: Optional[int] = None, **kwargs: Any) -> "QueueProperties": + def get_queue_properties( + self, *, timeout: Optional[int] = None, **kwargs: Any + ) -> "QueueProperties": """Returns all user-defined metadata for the specified queue. The data returned does not include the queue's list of messages. @@ -391,7 +456,9 @@ def get_queue_properties(self, *, timeout: Optional[int] = None, **kwargs: Any) try: response = cast( "QueueProperties", - self._client.queue.get_properties(timeout=timeout, cls=deserialize_queue_properties, **kwargs), + self._client.queue.get_properties( + timeout=timeout, cls=deserialize_queue_properties, **kwargs + ), ) except HttpResponseError as error: process_storage_error(error) @@ -400,7 +467,11 @@ def get_queue_properties(self, *, timeout: Optional[int] = None, **kwargs: Any) @distributed_trace def set_queue_metadata( - self, metadata: Optional[Dict[str, str]] = None, *, timeout: Optional[int] = None, **kwargs: Any + self, + metadata: Optional[Dict[str, str]] = None, + *, + timeout: Optional[int] = None, + **kwargs: Any ) -> Dict[str, Any]: """Sets user-defined metadata on the specified queue. @@ -437,7 +508,9 @@ def set_queue_metadata( process_storage_error(error) @distributed_trace - def get_queue_access_policy(self, *, timeout: Optional[int] = None, **kwargs: Any) -> Dict[str, AccessPolicy]: + def get_queue_access_policy( + self, *, timeout: Optional[int] = None, **kwargs: Any + ) -> Dict[str, AccessPolicy]: """Returns details about any stored access policies specified on the queue that may be used with Shared Access Signatures. @@ -453,7 +526,9 @@ def get_queue_access_policy(self, *, timeout: Optional[int] = None, **kwargs: An try: _, identifiers = cast( Tuple[Dict, List], - self._client.queue.get_access_policy(timeout=timeout, cls=return_headers_and_deserialized, **kwargs), + self._client.queue.get_access_policy( + timeout=timeout, cls=return_headers_and_deserialized, **kwargs + ), ) except HttpResponseError as error: process_storage_error(error) @@ -461,7 +536,11 @@ def get_queue_access_policy(self, *, timeout: Optional[int] = None, **kwargs: An @distributed_trace def set_queue_access_policy( - self, signed_identifiers: Dict[str, AccessPolicy], *, timeout: Optional[int] = None, **kwargs: Any + self, + signed_identifiers: Dict[str, AccessPolicy], + *, + timeout: Optional[int] = None, + **kwargs: Any ) -> None: """Sets stored access policies for the queue that may be used with Shared Access Signatures. @@ -510,7 +589,9 @@ def set_queue_access_policy( value.expiry = serialize_iso(value.expiry) identifiers.append(SignedIdentifier(id=key, access_policy=value)) try: - self._client.queue.set_access_policy(queue_acl=identifiers or None, timeout=timeout, **kwargs) + self._client.queue.set_access_policy( + queue_acl=identifiers or None, timeout=timeout, **kwargs + ) except HttpResponseError as error: process_storage_error(error) @@ -575,7 +656,10 @@ def send_message( """ if self.key_encryption_key: modify_user_agent_for_encryption( - self._config.user_agent_policy.user_agent, self._sdk_moniker, self.encryption_version, kwargs + self._config.user_agent_policy.user_agent, + self._sdk_moniker, + self.encryption_version, + kwargs, ) try: @@ -586,12 +670,10 @@ def send_message( encryption_version=self.encryption_version, ) except TypeError: - warnings.warn( - "TypeError when calling message_encode_policy.configure. \ + warnings.warn("TypeError when calling message_encode_policy.configure. \ It is likely missing the encryption_version parameter. \ Consider updating your encryption information/implementation. \ - Retrying without encryption_version." - ) + Retrying without encryption_version.") self._message_encode_policy.configure( require_encryption=self.require_encryption, key_encryption_key=self.key_encryption_key, @@ -622,7 +704,11 @@ def send_message( @distributed_trace def receive_message( - self, *, visibility_timeout: Optional[int] = None, timeout: Optional[int] = None, **kwargs: Any + self, + *, + visibility_timeout: Optional[int] = None, + timeout: Optional[int] = None, + **kwargs: Any ) -> Optional[QueueMessage]: """Removes one message from the front of the queue. @@ -663,7 +749,10 @@ def receive_message( """ if self.key_encryption_key or self.key_resolver_function: modify_user_agent_for_encryption( - self._config.user_agent_policy.user_agent, self._sdk_moniker, self.encryption_version, kwargs + self._config.user_agent_policy.user_agent, + self._sdk_moniker, + self.encryption_version, + kwargs, ) self._message_decode_policy.configure( @@ -680,7 +769,9 @@ def receive_message( **kwargs ) wrapped_message = ( - QueueMessage._from_generated(message[0]) if message != [] else None # pylint: disable=protected-access + QueueMessage._from_generated(message[0]) + if message != [] + else None # pylint: disable=protected-access ) return wrapped_message except HttpResponseError as error: @@ -756,7 +847,10 @@ def receive_messages( """ if self.key_encryption_key or self.key_resolver_function: modify_user_agent_for_encryption( - self._config.user_agent_policy.user_agent, self._sdk_moniker, self.encryption_version, kwargs + self._config.user_agent_policy.user_agent, + self._sdk_moniker, + self.encryption_version, + kwargs, ) self._message_decode_policy.configure( @@ -774,7 +868,9 @@ def receive_messages( ) if max_messages is not None and messages_per_page is not None: if max_messages < messages_per_page: - raise ValueError("max_messages must be greater or equal to messages_per_page") + raise ValueError( + "max_messages must be greater or equal to messages_per_page" + ) return ItemPaged( command, results_per_page=messages_per_page, @@ -847,7 +943,10 @@ def update_message( """ if self.key_encryption_key or self.key_resolver_function: modify_user_agent_for_encryption( - self._config.user_agent_policy.user_agent, self._sdk_moniker, self.encryption_version, kwargs + self._config.user_agent_policy.user_agent, + self._sdk_moniker, + self.encryption_version, + kwargs, ) if isinstance(message, QueueMessage): @@ -876,14 +975,14 @@ def update_message( encryption_version=self.encryption_version, ) except TypeError: - warnings.warn( - "TypeError when calling message_encode_policy.configure. \ + warnings.warn("TypeError when calling message_encode_policy.configure. \ It is likely missing the encryption_version parameter. \ Consider updating your encryption information/implementation. \ - Retrying without encryption_version." - ) + Retrying without encryption_version.") self._message_encode_policy.configure( - self.require_encryption, self.key_encryption_key, self.key_resolver_function + self.require_encryption, + self.key_encryption_key, + self.key_resolver_function, ) encoded_message_text = self._message_encode_policy(message_text) updated = GenQueueMessage(message_text=encoded_message_text) @@ -917,7 +1016,11 @@ def update_message( @distributed_trace def peek_messages( - self, max_messages: Optional[int] = None, *, timeout: Optional[int] = None, **kwargs: Any + self, + max_messages: Optional[int] = None, + *, + timeout: Optional[int] = None, + **kwargs: Any ) -> List[QueueMessage]: """Retrieves one or more messages from the front of the queue, but does not alter the visibility of the message. @@ -963,7 +1066,10 @@ def peek_messages( if self.key_encryption_key or self.key_resolver_function: modify_user_agent_for_encryption( - self._config.user_agent_policy.user_agent, self._sdk_moniker, self.encryption_version, kwargs + self._config.user_agent_policy.user_agent, + self._sdk_moniker, + self.encryption_version, + kwargs, ) self._message_decode_policy.configure( @@ -973,11 +1079,16 @@ def peek_messages( ) try: messages = self._client.messages.peek( - number_of_messages=max_messages, timeout=timeout, cls=self._message_decode_policy, **kwargs + number_of_messages=max_messages, + timeout=timeout, + cls=self._message_decode_policy, + **kwargs ) wrapped_messages = [] for peeked in messages: - wrapped_messages.append(QueueMessage._from_generated(peeked)) # pylint: disable=protected-access + wrapped_messages.append( + QueueMessage._from_generated(peeked) + ) # pylint: disable=protected-access return wrapped_messages except HttpResponseError as error: process_storage_error(error) @@ -1061,6 +1172,11 @@ def delete_message( if receipt is None: raise ValueError("pop_receipt must be present") try: - self._client.message_id.delete(pop_receipt=receipt, timeout=timeout, queue_message_id=message_id, **kwargs) + self._client.message_id.delete( + pop_receipt=receipt, + timeout=timeout, + queue_message_id=message_id, + **kwargs + ) except HttpResponseError as error: process_storage_error(error) diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_client_helpers.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_client_helpers.py index 36e1ddf3a7e7..831ac367058c 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_client_helpers.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_client_helpers.py @@ -9,7 +9,11 @@ from ._shared.base_client import parse_query if TYPE_CHECKING: - from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential, TokenCredential + from azure.core.credentials import ( + AzureNamedKeyCredential, + AzureSasCredential, + TokenCredential, + ) from azure.core.credentials_async import AsyncTokenCredential from urllib.parse import ParseResult @@ -62,12 +66,16 @@ def _parse_url( _, sas_token = parse_query(parsed_url.query) if not sas_token and not credential: - raise ValueError("You need to provide either a SAS token or an account shared key to authenticate.") + raise ValueError( + "You need to provide either a SAS token or an account shared key to authenticate." + ) return parsed_url, sas_token -def _format_url(queue_name: Union[bytes, str], hostname: str, scheme: str, query_str: str) -> str: +def _format_url( + queue_name: Union[bytes, str], hostname: str, scheme: str, query_str: str +) -> str: """Format the endpoint URL according to the current location mode hostname. :param Union[bytes, str] queue_name: The name of the queue. @@ -105,7 +113,10 @@ def _from_queue_url(queue_url: str) -> Tuple[str, str]: account_path = "" if len(queue_path) > 1: account_path = "/" + "/".join(queue_path[:-1]) - account_url = f"{parsed_url.scheme}://{parsed_url.netloc.rstrip('/')}" f"{account_path}?{parsed_url.query}" + account_url = ( + f"{parsed_url.scheme}://{parsed_url.netloc.rstrip('/')}" + f"{account_path}?{parsed_url.query}" + ) queue_name = unquote(queue_path[-1]) if not queue_name: raise ValueError("Invalid URL. Please provide a URL with a valid queue name") diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_service_client.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_service_client.py index 4c2004122960..7095051a17f4 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_service_client.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_service_client.py @@ -26,13 +26,24 @@ from ._queue_client import QueueClient from ._queue_service_client_helpers import _parse_url from ._serialize import get_api_version -from ._shared.base_client import parse_connection_str, StorageAccountHostsMixin, TransportWrapper +from ._shared.base_client import ( + parse_connection_str, + StorageAccountHostsMixin, + TransportWrapper, +) from ._shared.models import LocationMode from ._shared.parser import _to_utc_datetime -from ._shared.response_handlers import parse_to_internal_user_delegation_key, process_storage_error +from ._shared.response_handlers import ( + parse_to_internal_user_delegation_key, + process_storage_error, +) if TYPE_CHECKING: - from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential, TokenCredential + from azure.core.credentials import ( + AzureNamedKeyCredential, + AzureSasCredential, + TokenCredential, + ) from datetime import datetime from ._models import Metrics, QueueAnalyticsLogging from ._shared.models import UserDelegationKey @@ -98,7 +109,13 @@ def __init__( self, account_url: str, credential: Optional[ - Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"] + Union[ + str, + Dict[str, str], + "AzureNamedKeyCredential", + "AzureSasCredential", + "TokenCredential", + ] ] = None, *, api_version: Optional[str] = None, @@ -106,7 +123,9 @@ def __init__( audience: Optional[str] = None, **kwargs: Any, ) -> None: - parsed_url, sas_token = _parse_url(account_url=account_url, credential=credential) + parsed_url, sas_token = _parse_url( + account_url=account_url, credential=credential + ) self._query_str, credential = self._format_query_string(sas_token, credential) super(QueueServiceClient, self).__init__( parsed_url, @@ -117,7 +136,10 @@ def __init__( **kwargs, ) self._client = AzureQueueStorage( - self.url, get_api_version(api_version), base_url=self.url, pipeline=self._pipeline + self.url, + get_api_version(api_version), + base_url=self.url, + pipeline=self._pipeline, ) self._configure_encryption(kwargs) @@ -126,9 +148,14 @@ def __enter__(self) -> Self: return self def __exit__( - self, typ: Optional[type[BaseException]], exc: Optional[BaseException], tb: Optional[TracebackType] + self, + typ: Optional[type[BaseException]], + exc: Optional[BaseException], + tb: Optional[TracebackType], ) -> None: - self._client.__exit__(typ, exc, tb) # pylint: disable=specify-parameter-names-in-call + self._client.__exit__( + typ, exc, tb + ) # pylint: disable=specify-parameter-names-in-call def close(self) -> None: """This method is to close the sockets opened by the client. @@ -154,7 +181,13 @@ def from_connection_string( cls, conn_str: str, credential: Optional[ - Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"] + Union[ + str, + Dict[str, str], + "AzureNamedKeyCredential", + "AzureSasCredential", + "TokenCredential", + ] ] = None, *, api_version: Optional[str] = None, @@ -200,7 +233,9 @@ def from_connection_string( :dedent: 8 :caption: Creating the QueueServiceClient with a connection string. """ - account_url, secondary, credential = parse_connection_str(conn_str, credential, "queue") + account_url, secondary, credential = parse_connection_str( + conn_str, credential, "queue" + ) return cls( account_url, credential=credential, @@ -254,7 +289,9 @@ def get_user_delegation_key( return parse_to_internal_user_delegation_key(user_delegation_key) @distributed_trace - def get_service_stats(self, *, timeout: Optional[int] = None, **kwargs: Any) -> Dict[str, Any]: + def get_service_stats( + self, *, timeout: Optional[int] = None, **kwargs: Any + ) -> Dict[str, Any]: """Retrieves statistics related to replication for the Queue service. It is only available when read-access geo-redundant replication is enabled for @@ -279,13 +316,17 @@ def get_service_stats(self, *, timeout: Optional[int] = None, **kwargs: Any) -> :rtype: Dict[str, Any] """ try: - stats = self._client.service.get_statistics(timeout=timeout, use_location=LocationMode.SECONDARY, **kwargs) + stats = self._client.service.get_statistics( + timeout=timeout, use_location=LocationMode.SECONDARY, **kwargs + ) return service_stats_deserialize(stats) except HttpResponseError as error: process_storage_error(error) @distributed_trace - def get_service_properties(self, *, timeout: Optional[int] = None, **kwargs: Any) -> Dict[str, Any]: + def get_service_properties( + self, *, timeout: Optional[int] = None, **kwargs: Any + ) -> Dict[str, Any]: """Gets the properties of a storage account's Queue service, including Azure Storage Analytics. @@ -305,7 +346,9 @@ def get_service_properties(self, *, timeout: Optional[int] = None, **kwargs: Any :caption: Getting queue service properties. """ try: - service_props = self._client.service.get_properties(timeout=timeout, **kwargs) + service_props = self._client.service.get_properties( + timeout=timeout, **kwargs + ) return service_properties_deserialize(service_props) except HttpResponseError as error: process_storage_error(error) @@ -426,7 +469,12 @@ def list_queues( @distributed_trace def create_queue( - self, name: str, metadata: Optional[Dict[str, str]] = None, *, timeout: Optional[int] = None, **kwargs: Any + self, + name: str, + metadata: Optional[Dict[str, str]] = None, + *, + timeout: Optional[int] = None, + **kwargs: Any, ) -> QueueClient: """Creates a new queue under the specified account. @@ -459,7 +507,11 @@ def create_queue( @distributed_trace def delete_queue( - self, queue: Union["QueueProperties", str], *, timeout: Optional[int] = None, **kwargs: Any + self, + queue: Union["QueueProperties", str], + *, + timeout: Optional[int] = None, + **kwargs: Any, ) -> None: """Deletes the specified queue and any messages it contains. @@ -492,7 +544,9 @@ def delete_queue( kwargs.setdefault("merge_span", True) queue_client.delete_queue(timeout=timeout, **kwargs) - def get_queue_client(self, queue: Union["QueueProperties", str], **kwargs: Any) -> QueueClient: + def get_queue_client( + self, queue: Union["QueueProperties", str], **kwargs: Any + ) -> QueueClient: """Get a client to interact with the specified queue. The queue need not already exist. @@ -519,7 +573,9 @@ def get_queue_client(self, queue: Union["QueueProperties", str], **kwargs: Any) queue_name = queue _pipeline = Pipeline( - transport=TransportWrapper(self._pipeline._transport), # pylint: disable=protected-access + transport=TransportWrapper( + self._pipeline._transport + ), # pylint: disable=protected-access policies=self._pipeline._impl_policies, # type: ignore # pylint: disable=protected-access ) diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_service_client_helpers.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_service_client_helpers.py index 9e29d00b4dd5..d87ad2ded690 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_service_client_helpers.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_service_client_helpers.py @@ -9,7 +9,11 @@ from ._shared.base_client import parse_query if TYPE_CHECKING: - from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential, TokenCredential + from azure.core.credentials import ( + AzureNamedKeyCredential, + AzureSasCredential, + TokenCredential, + ) from azure.core.credentials_async import AsyncTokenCredential from urllib.parse import ParseResult @@ -58,6 +62,8 @@ def _parse_url( _, sas_token = parse_query(parsed_url.query) if not sas_token and not credential: - raise ValueError("You need to provide either a SAS token or an account shared key to authenticate.") + raise ValueError( + "You need to provide either a SAS token or an account shared key to authenticate." + ) return parsed_url, sas_token diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_serialize.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_serialize.py index 3a9b86f7b195..21afc3fc9c02 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_serialize.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_serialize.py @@ -41,5 +41,7 @@ def get_api_version(api_version: Optional[str]) -> str: if api_version and api_version not in _SUPPORTED_API_VERSIONS: versions = "\n".join(_SUPPORTED_API_VERSIONS) - raise ValueError(f"Unsupported API version '{api_version}'. Please select from:\n{versions}") + raise ValueError( + f"Unsupported API version '{api_version}'. Please select from:\n{versions}" + ) return api_version or _SUPPORTED_API_VERSIONS[-1] diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/authentication.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/authentication.py index f778dc71eec4..4a83361cbb1d 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/authentication.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/authentication.py @@ -16,7 +16,9 @@ pass try: - from azure.core.pipeline.transport import AioHttpTransport # pylint: disable=non-abstract-transport-import + from azure.core.pipeline.transport import ( + AioHttpTransport, + ) # pylint: disable=non-abstract-transport-import except ImportError: AioHttpTransport = None @@ -138,7 +140,11 @@ def __init__(self, account_name, account_key): @staticmethod def _get_headers(request, headers_to_sign): - headers = dict((name.lower(), value) for name, value in request.http_request.headers.items() if value) + headers = dict( + (name.lower(), value) + for name, value in request.http_request.headers.items() + if value + ) if "content-length" in headers and headers["content-length"] == "0": del headers["content-length"] return "\n".join(headers.get(x, "") for x in headers_to_sign) + "\n" @@ -152,9 +158,16 @@ def _get_canonicalized_resource(self, request): try: if ( isinstance(request.context.transport, AioHttpTransport) - or isinstance(getattr(request.context.transport, "_transport", None), AioHttpTransport) or isinstance( - getattr(getattr(request.context.transport, "_transport", None), "_transport", None), + getattr(request.context.transport, "_transport", None), + AioHttpTransport, + ) + or isinstance( + getattr( + getattr(request.context.transport, "_transport", None), + "_transport", + None, + ), AioHttpTransport, ) ): diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client.py index afd554939fcb..e5740f772937 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client.py @@ -17,7 +17,11 @@ ) from urllib.parse import parse_qs, quote -from azure.core.credentials import AzureSasCredential, AzureNamedKeyCredential, TokenCredential +from azure.core.credentials import ( + AzureSasCredential, + AzureNamedKeyCredential, + TokenCredential, +) from azure.core.exceptions import HttpResponseError from azure.core.pipeline import Pipeline from azure.core.pipeline.transport import ( # pylint: disable=non-abstract-transport-import, no-name-in-module @@ -64,7 +68,10 @@ if TYPE_CHECKING: from azure.core.credentials_async import AsyncTokenCredential - from azure.core.pipeline.transport import HttpRequest, HttpResponse # pylint: disable=C4756 + from azure.core.pipeline.transport import ( + HttpRequest, + HttpResponse, + ) # pylint: disable=C4756 _LOGGER = logging.getLogger(__name__) _SERVICE_PARAMS = { @@ -79,7 +86,7 @@ def _construct_endpoints(netloc: str, account_part: str) -> Tuple[str, str, str]: """Construct primary and secondary hostnames from a storage account URL's netloc.""" - domain_suffix = netloc[len(account_part):] + domain_suffix = netloc[len(account_part) :] secondary_idx = account_part.find(_SECONDARY_SUFFIX) # Case where customer provides secondary URL @@ -95,7 +102,9 @@ def _construct_endpoints(netloc: str, account_part: str) -> Tuple[str, str, str] account_name = account_name[: -len(suffix)] break primary_hostname = f"{account_part}{domain_suffix}" - secondary_hostname = f"{account_name}{_SECONDARY_SUFFIX}{feature_suffix}{domain_suffix}" + secondary_hostname = ( + f"{account_name}{_SECONDARY_SUFFIX}{feature_suffix}{domain_suffix}" + ) return account_name, primary_hostname, secondary_hostname @@ -142,8 +151,8 @@ def __init__( secondary_hostname = "" if len(account) > 1: - self.account_name, primary_hostname, secondary_hostname = _construct_endpoints( - parsed_url.netloc, account[0] + self.account_name, primary_hostname, secondary_hostname = ( + _construct_endpoints(parsed_url.netloc, account[0]) ) else: primary_hostname = (parsed_url.netloc + parsed_url.path).rstrip("/") @@ -162,10 +171,15 @@ def __init__( secondary_hostname = kwargs["secondary_hostname"] if not primary_hostname: primary_hostname = (parsed_url.netloc + parsed_url.path).rstrip("/") - self._hosts = {LocationMode.PRIMARY: primary_hostname, LocationMode.SECONDARY: secondary_hostname} + self._hosts = { + LocationMode.PRIMARY: primary_hostname, + LocationMode.SECONDARY: secondary_hostname, + } self._sdk_moniker = f"storage-{service}/{VERSION}" - self._config, self._pipeline = self._create_pipeline(self.credential, sdk_moniker=self._sdk_moniker, **kwargs) + self._config, self._pipeline = self._create_pipeline( + self.credential, sdk_moniker=self._sdk_moniker, **kwargs + ) @property def url(self) -> str: @@ -256,12 +270,27 @@ def _format_query_string( self, sas_token: Optional[str], credential: Optional[ - Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", TokenCredential] + Union[ + str, + Dict[str, str], + "AzureNamedKeyCredential", + "AzureSasCredential", + TokenCredential, + ] ], snapshot: Optional[str] = None, share_snapshot: Optional[str] = None, ) -> Tuple[ - str, Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", TokenCredential]] + str, + Optional[ + Union[ + str, + Dict[str, str], + "AzureNamedKeyCredential", + "AzureSasCredential", + TokenCredential, + ] + ], ]: query_str = "?" if snapshot: @@ -283,7 +312,13 @@ def _format_query_string( def _create_pipeline( self, credential: Optional[ - Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, TokenCredential] + Union[ + str, + Dict[str, str], + AzureNamedKeyCredential, + AzureSasCredential, + TokenCredential, + ] ] = None, **kwargs: Any, ) -> Tuple[StorageConfiguration, Pipeline]: @@ -293,7 +328,9 @@ def _create_pipeline( audience = str(kwargs.pop("audience")).rstrip("/") + DEFAULT_OAUTH_SCOPE else: audience = STORAGE_OAUTH_SCOPE - self._credential_policy = StorageBearerTokenCredentialPolicy(cast(TokenCredential, credential), audience) + self._credential_policy = StorageBearerTokenCredentialPolicy( + cast(TokenCredential, credential), audience + ) elif isinstance(credential, SharedKeyCredentialPolicy): self._credential_policy = credential elif isinstance(credential, AzureSasCredential): @@ -332,7 +369,9 @@ def _create_pipeline( config.transport = transport # type: ignore return config, Pipeline(transport, policies=policies) - def _batch_send(self, *reqs: "HttpRequest", **kwargs: Any) -> Iterator["HttpResponse"]: + def _batch_send( + self, *reqs: "HttpRequest", **kwargs: Any + ) -> Iterator["HttpResponse"]: """Given a series of request, do a Storage batch call. :param HttpRequest reqs: A collection of HttpRequest objects. @@ -351,7 +390,8 @@ def _batch_send(self, *reqs: "HttpRequest", **kwargs: Any) -> Iterator["HttpResp ), headers={ "x-ms-version": self.api_version, - "Content-Type": "multipart/mixed; boundary=" + _get_batch_request_delimiter(batch_id, False, False), + "Content-Type": "multipart/mixed; boundary=" + + _get_batch_request_delimiter(batch_id, False, False), }, ) @@ -361,7 +401,9 @@ def _batch_send(self, *reqs: "HttpRequest", **kwargs: Any) -> Iterator["HttpResp request.set_multipart_mixed(*reqs, policies=policies, enforce_https=False) - Pipeline._prepare_multipart_mixed_request(request) # pylint: disable=protected-access + Pipeline._prepare_multipart_mixed_request( + request + ) # pylint: disable=protected-access body = serialize_batch_body(request.multipart_mixed_info[0], batch_id) request.set_bytes_body(body) @@ -379,7 +421,9 @@ def _batch_send(self, *reqs: "HttpRequest", **kwargs: Any) -> Iterator["HttpResp parts = list(response.parts()) if any(p for p in parts if not 200 <= p.status_code < 300): error = PartialBatchErrorException( - message="There is a partial failure in the batch operation.", response=response, parts=parts + message="There is a partial failure in the batch operation.", + response=response, + parts=parts, ) raise error return iter(parts) @@ -416,12 +460,21 @@ def __exit__(self, *args): def _format_shared_key_credential( account_name: Optional[str], credential: Optional[ - Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "AsyncTokenCredential", TokenCredential] + Union[ + str, + Dict[str, str], + AzureNamedKeyCredential, + AzureSasCredential, + "AsyncTokenCredential", + TokenCredential, + ] ] = None, ) -> Any: if isinstance(credential, str): if not account_name: - raise ValueError("Unable to determine account name for shared key credential.") + raise ValueError( + "Unable to determine account name for shared key credential." + ) credential = {"account_name": account_name, "account_key": credential} if isinstance(credential, dict): if "account_name" not in credential: @@ -430,18 +483,36 @@ def _format_shared_key_credential( raise ValueError("Shared key credential missing 'account_key") return SharedKeyCredentialPolicy(**credential) if isinstance(credential, AzureNamedKeyCredential): - return SharedKeyCredentialPolicy(credential.named_key.name, credential.named_key.key) + return SharedKeyCredentialPolicy( + credential.named_key.name, credential.named_key.key + ) return credential def parse_connection_str( conn_str: str, - credential: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, TokenCredential]], + credential: Optional[ + Union[ + str, + Dict[str, str], + AzureNamedKeyCredential, + AzureSasCredential, + TokenCredential, + ] + ], service: str, ) -> Tuple[ str, Optional[str], - Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, TokenCredential]], + Optional[ + Union[ + str, + Dict[str, str], + AzureNamedKeyCredential, + AzureSasCredential, + TokenCredential, + ] + ], ]: conn_str = conn_str.rstrip(";") conn_settings_list = [s.split("=", 1) for s in conn_str.split(";")] @@ -455,7 +526,10 @@ def parse_connection_str( secondary = None if not credential: try: - credential = {"account_name": conn_settings["ACCOUNTNAME"], "account_key": conn_settings["ACCOUNTKEY"]} + credential = { + "account_name": conn_settings["ACCOUNTNAME"], + "account_key": conn_settings["ACCOUNTKEY"], + } except KeyError: credential = conn_settings.get("SHAREDACCESSSIGNATURE") if endpoints["primary"] in conn_settings: @@ -470,7 +544,10 @@ def parse_connection_str( f"{conn_settings['DEFAULTENDPOINTSPROTOCOL']}://" f"{conn_settings['ACCOUNTNAME']}.{service}.{conn_settings['ENDPOINTSUFFIX']}" ) - secondary = f"{conn_settings['ACCOUNTNAME']}-secondary." f"{service}.{conn_settings['ENDPOINTSUFFIX']}" + secondary = ( + f"{conn_settings['ACCOUNTNAME']}-secondary." + f"{service}.{conn_settings['ENDPOINTSUFFIX']}" + ) except KeyError: pass @@ -481,7 +558,9 @@ def parse_connection_str( f"{service}.{conn_settings.get('ENDPOINTSUFFIX', SERVICE_HOST_BASE)}" ) except KeyError as exc: - raise ValueError("Connection string missing required connection details.") from exc + raise ValueError( + "Connection string missing required connection details." + ) from exc if service == "dfs": primary = primary.replace(".blob.", ".dfs.") if secondary: @@ -505,7 +584,9 @@ def create_configuration(**kwargs: Any) -> StorageConfiguration: def parse_query(query_str: str) -> Tuple[Optional[str], Optional[str]]: sas_values = QueryStringConstants.to_list() parsed_query = {k: v[0] for k, v in parse_qs(query_str).items()} - sas_params = [f"{k}={quote(v, safe='')}" for k, v in parsed_query.items() if k in sas_values] + sas_params = [ + f"{k}={quote(v, safe='')}" for k, v in parsed_query.items() if k in sas_values + ] sas_token = None if sas_params: sas_token = "&".join(sas_params) diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client_async.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client_async.py index 400f7d6f6dff..4df6570f02f0 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client_async.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client_async.py @@ -41,12 +41,18 @@ StorageHosts, StorageRequestHook, ) -from .policies_async import AsyncStorageBearerTokenCredentialPolicy, AsyncStorageResponseHook +from .policies_async import ( + AsyncStorageBearerTokenCredentialPolicy, + AsyncStorageResponseHook, +) from .response_handlers import PartialBatchErrorException, process_storage_error from .._shared_access_signature import _is_credential_sastoken if TYPE_CHECKING: - from azure.core.pipeline.transport import HttpRequest, HttpResponse # pylint: disable=C4756 + from azure.core.pipeline.transport import ( + HttpRequest, + HttpResponse, + ) # pylint: disable=C4756 _LOGGER = logging.getLogger(__name__) _SERVICE_PARAMS = { @@ -63,12 +69,27 @@ def _format_query_string( self, sas_token: Optional[str], credential: Optional[ - Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", AsyncTokenCredential] + Union[ + str, + Dict[str, str], + "AzureNamedKeyCredential", + "AzureSasCredential", + AsyncTokenCredential, + ] ], snapshot: Optional[str] = None, share_snapshot: Optional[str] = None, ) -> Tuple[ - str, Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", AsyncTokenCredential]] + str, + Optional[ + Union[ + str, + Dict[str, str], + "AzureNamedKeyCredential", + "AzureSasCredential", + AsyncTokenCredential, + ] + ], ]: query_str = "?" if snapshot: @@ -89,12 +110,22 @@ def _format_query_string( def _create_pipeline( self, credential: Optional[ - Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, AsyncTokenCredential] + Union[ + str, + Dict[str, str], + AzureNamedKeyCredential, + AzureSasCredential, + AsyncTokenCredential, + ] ] = None, **kwargs: Any, ) -> Tuple[StorageConfiguration, AsyncPipeline]: self._credential_policy: Optional[ - Union[AsyncStorageBearerTokenCredentialPolicy, SharedKeyCredentialPolicy, AzureSasCredentialPolicy] + Union[ + AsyncStorageBearerTokenCredentialPolicy, + SharedKeyCredentialPolicy, + AzureSasCredentialPolicy, + ] ] = None if hasattr(credential, "get_token"): if kwargs.get("audience"): @@ -123,7 +154,9 @@ def _create_pipeline( AioHttpTransport, ) except ImportError as exc: - raise ImportError("Unable to create async transport. Please check aiohttp is installed.") from exc + raise ImportError( + "Unable to create async transport. Please check aiohttp is installed." + ) from exc transport = AioHttpTransport(**kwargs) hosts = self._hosts policies = [ @@ -148,7 +181,9 @@ def _create_pipeline( config.transport = transport # type: ignore return config, AsyncPipeline(transport, policies=policies) # type: ignore - async def _batch_send(self, *reqs: "HttpRequest", **kwargs: Any) -> AsyncList["HttpResponse"]: + async def _batch_send( + self, *reqs: "HttpRequest", **kwargs: Any + ) -> AsyncList["HttpResponse"]: """Given a series of request, do a Storage batch call. :param HttpRequest reqs: A collection of HttpRequest objects. @@ -198,12 +233,28 @@ async def _batch_send(self, *reqs: "HttpRequest", **kwargs: Any) -> AsyncList["H def parse_connection_str( conn_str: str, - credential: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, AsyncTokenCredential]], + credential: Optional[ + Union[ + str, + Dict[str, str], + AzureNamedKeyCredential, + AzureSasCredential, + AsyncTokenCredential, + ] + ], service: str, ) -> Tuple[ str, Optional[str], - Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, AsyncTokenCredential]], + Optional[ + Union[ + str, + Dict[str, str], + AzureNamedKeyCredential, + AzureSasCredential, + AsyncTokenCredential, + ] + ], ]: conn_str = conn_str.rstrip(";") conn_settings_list = [s.split("=", 1) for s in conn_str.split(";")] @@ -217,7 +268,10 @@ def parse_connection_str( secondary = None if not credential: try: - credential = {"account_name": conn_settings["ACCOUNTNAME"], "account_key": conn_settings["ACCOUNTKEY"]} + credential = { + "account_name": conn_settings["ACCOUNTNAME"], + "account_key": conn_settings["ACCOUNTKEY"], + } except KeyError: credential = conn_settings.get("SHAREDACCESSSIGNATURE") if endpoints["primary"] in conn_settings: @@ -232,7 +286,10 @@ def parse_connection_str( f"{conn_settings['DEFAULTENDPOINTSPROTOCOL']}://" f"{conn_settings['ACCOUNTNAME']}.{service}.{conn_settings['ENDPOINTSUFFIX']}" ) - secondary = f"{conn_settings['ACCOUNTNAME']}-secondary." f"{service}.{conn_settings['ENDPOINTSUFFIX']}" + secondary = ( + f"{conn_settings['ACCOUNTNAME']}-secondary." + f"{service}.{conn_settings['ENDPOINTSUFFIX']}" + ) except KeyError: pass @@ -243,7 +300,9 @@ def parse_connection_str( f"{service}.{conn_settings.get('ENDPOINTSUFFIX', SERVICE_HOST_BASE)}" ) except KeyError as exc: - raise ValueError("Connection string missing required connection details.") from exc + raise ValueError( + "Connection string missing required connection details." + ) from exc if service == "dfs": primary = primary.replace(".blob.", ".dfs.") if secondary: diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/constants.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/constants.py index 2bf865acf343..c9c2ba8f74d0 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/constants.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/constants.py @@ -6,7 +6,6 @@ from .._serialize import _SUPPORTED_API_VERSIONS - X_MS_VERSION = _SUPPORTED_API_VERSIONS[-1] # Connection defaults diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/models.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/models.py index aa900a4f404a..162132eb0537 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/models.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/models.py @@ -71,7 +71,9 @@ class StorageErrorCode(str, Enum, metaclass=CaseInsensitiveEnumMeta): # Blob values APPEND_POSITION_CONDITION_NOT_MET = "AppendPositionConditionNotMet" - BLOB_ACCESS_TIER_NOT_SUPPORTED_FOR_ACCOUNT_TYPE = "BlobAccessTierNotSupportedForAccountType" + BLOB_ACCESS_TIER_NOT_SUPPORTED_FOR_ACCOUNT_TYPE = ( + "BlobAccessTierNotSupportedForAccountType" + ) BLOB_ALREADY_EXISTS = "BlobAlreadyExists" BLOB_NOT_FOUND = "BlobNotFound" BLOB_OVERWRITTEN = "BlobOverwritten" @@ -89,11 +91,17 @@ class StorageErrorCode(str, Enum, metaclass=CaseInsensitiveEnumMeta): COPY_ID_MISMATCH = "CopyIdMismatch" FEATURE_VERSION_MISMATCH = "FeatureVersionMismatch" INCREMENTAL_COPY_BLOB_MISMATCH = "IncrementalCopyBlobMismatch" - INCREMENTAL_COPY_OF_EARLIER_SNAPSHOT_NOT_ALLOWED = "IncrementalCopyOfEarlierSnapshotNotAllowed" + INCREMENTAL_COPY_OF_EARLIER_SNAPSHOT_NOT_ALLOWED = ( + "IncrementalCopyOfEarlierSnapshotNotAllowed" + ) #: Deprecated: Please use INCREMENTAL_COPY_OF_EARLIER_SNAPSHOT_NOT_ALLOWED instead. - INCREMENTAL_COPY_OF_EARLIER_VERSION_SNAPSHOT_NOT_ALLOWED = "IncrementalCopyOfEarlierVersionSnapshotNotAllowed" + INCREMENTAL_COPY_OF_EARLIER_VERSION_SNAPSHOT_NOT_ALLOWED = ( + "IncrementalCopyOfEarlierVersionSnapshotNotAllowed" + ) #: Deprecated: Please use INCREMENTAL_COPY_OF_EARLIER_VERSION_SNAPSHOT_NOT_ALLOWED instead. - INCREMENTAL_COPY_OF_ERALIER_VERSION_SNAPSHOT_NOT_ALLOWED = "IncrementalCopyOfEarlierVersionSnapshotNotAllowed" + INCREMENTAL_COPY_OF_ERALIER_VERSION_SNAPSHOT_NOT_ALLOWED = ( + "IncrementalCopyOfEarlierVersionSnapshotNotAllowed" + ) INCREMENTAL_COPY_SOURCE_MUST_BE_SNAPSHOT = "IncrementalCopySourceMustBeSnapshot" INFINITE_LEASE_DURATION_REQUIRED = "InfiniteLeaseDurationRequired" INVALID_BLOB_OR_BLOCK = "InvalidBlobOrBlock" @@ -121,7 +129,9 @@ class StorageErrorCode(str, Enum, metaclass=CaseInsensitiveEnumMeta): LEASE_NOT_PRESENT_WITH_LEASE_OPERATION = "LeaseNotPresentWithLeaseOperation" MAX_BLOB_SIZE_CONDITION_NOT_MET = "MaxBlobSizeConditionNotMet" NO_PENDING_COPY_OPERATION = "NoPendingCopyOperation" - OPERATION_NOT_ALLOWED_ON_INCREMENTAL_COPY_BLOB = "OperationNotAllowedOnIncrementalCopyBlob" + OPERATION_NOT_ALLOWED_ON_INCREMENTAL_COPY_BLOB = ( + "OperationNotAllowedOnIncrementalCopyBlob" + ) PENDING_COPY_OPERATION = "PendingCopyOperation" PREVIOUS_SNAPSHOT_CANNOT_BE_NEWER = "PreviousSnapshotCannotBeNewer" PREVIOUS_SNAPSHOT_NOT_FOUND = "PreviousSnapshotNotFound" @@ -159,9 +169,13 @@ class StorageErrorCode(str, Enum, metaclass=CaseInsensitiveEnumMeta): DELETE_PENDING = "DeletePending" DIRECTORY_NOT_EMPTY = "DirectoryNotEmpty" FILE_LOCK_CONFLICT = "FileLockConflict" - FILE_SHARE_PROVISIONED_BANDWIDTH_DOWNGRADE_NOT_ALLOWED = "FileShareProvisionedBandwidthDowngradeNotAllowed" + FILE_SHARE_PROVISIONED_BANDWIDTH_DOWNGRADE_NOT_ALLOWED = ( + "FileShareProvisionedBandwidthDowngradeNotAllowed" + ) FILE_SHARE_PROVISIONED_BANDWIDTH_INVALID = "FileShareProvisionedBandwidthInvalid" - FILE_SHARE_PROVISIONED_IOPS_DOWNGRADE_NOT_ALLOWED = "FileShareProvisionedIopsDowngradeNotAllowed" + FILE_SHARE_PROVISIONED_IOPS_DOWNGRADE_NOT_ALLOWED = ( + "FileShareProvisionedIopsDowngradeNotAllowed" + ) FILE_SHARE_PROVISIONED_IOPS_INVALID = "FileShareProvisionedIopsInvalid" FILE_SHARE_PROVISIONED_STORAGE_INVALID = "FileShareProvisionedStorageInvalid" INVALID_FILE_OR_DIRECTORY_PATH_NAME = "InvalidFileOrDirectoryPathName" @@ -177,9 +191,15 @@ class StorageErrorCode(str, Enum, metaclass=CaseInsensitiveEnumMeta): SHARE_SNAPSHOT_NOT_FOUND = "ShareSnapshotNotFound" SHARE_SNAPSHOT_OPERATION_NOT_SUPPORTED = "ShareSnapshotOperationNotSupported" SHARE_HAS_SNAPSHOTS = "ShareHasSnapshots" - TOTAL_SHARES_PROVISIONED_CAPACITY_EXCEEDS_ACCOUNT_LIMIT = "TotalSharesProvisionedCapacityExceedsAccountLimit" - TOTAL_SHARES_PROVISIONED_IOPS_EXCEEDS_ACCOUNT_LIMIT = "TotalSharesProvisionedIopsExceedsAccountLimit" - TOTAL_SHARES_PROVISIONED_BANDWIDTH_EXCEEDS_ACCOUNT_LIMIT = "TotalSharesProvisionedBandwidthExceedsAccountLimit" + TOTAL_SHARES_PROVISIONED_CAPACITY_EXCEEDS_ACCOUNT_LIMIT = ( + "TotalSharesProvisionedCapacityExceedsAccountLimit" + ) + TOTAL_SHARES_PROVISIONED_IOPS_EXCEEDS_ACCOUNT_LIMIT = ( + "TotalSharesProvisionedIopsExceedsAccountLimit" + ) + TOTAL_SHARES_PROVISIONED_BANDWIDTH_EXCEEDS_ACCOUNT_LIMIT = ( + "TotalSharesProvisionedBandwidthExceedsAccountLimit" + ) TOTAL_SHARES_COUNT_EXCEEDS_ACCOUNT_LIMIT = "TotalSharesCountExceedsAccountLimit" # DataLake values @@ -198,7 +218,9 @@ class StorageErrorCode(str, Enum, metaclass=CaseInsensitiveEnumMeta): FILE_SYSTEM_BEING_DELETED = "FilesystemBeingDeleted" INVALID_DESTINATION_PATH = "InvalidDestinationPath" INVALID_RENAME_SOURCE_PATH = "InvalidRenameSourcePath" - INVALID_SOURCE_OR_DESTINATION_RESOURCE_TYPE = "InvalidSourceOrDestinationResourceType" + INVALID_SOURCE_OR_DESTINATION_RESOURCE_TYPE = ( + "InvalidSourceOrDestinationResourceType" + ) LEASE_IS_ALREADY_BROKEN = "LeaseIsAlreadyBroken" LEASE_NAME_MISMATCH = "LeaseNameMismatch" PATH_CONFLICT = "PathConflict" @@ -267,7 +289,9 @@ class LocationMode(object): """ PRIMARY = "primary" #: Requests should be sent to the primary location. - SECONDARY = "secondary" #: Requests should be sent to the secondary location, if possible. + SECONDARY = ( + "secondary" #: Requests should be sent to the secondary location, if possible. + ) class ResourceTypes(object): @@ -292,12 +316,19 @@ class ResourceTypes(object): _str: str def __init__( - self, service: bool = False, container: bool = False, object: bool = False # pylint: disable=redefined-builtin + self, + service: bool = False, + container: bool = False, + object: bool = False, # pylint: disable=redefined-builtin ) -> None: self.service = service self.container = container self.object = object - self._str = ("s" if self.service else "") + ("c" if self.container else "") + ("o" if self.object else "") + self._str = ( + ("s" if self.service else "") + + ("c" if self.container else "") + + ("o" if self.object else "") + ) def __str__(self): return self._str @@ -482,11 +513,17 @@ class Services(object): Access for the `~azure.storage.fileshare.ShareServiceClient`. Default is False. """ - def __init__(self, *, blob: bool = False, queue: bool = False, fileshare: bool = False) -> None: + def __init__( + self, *, blob: bool = False, queue: bool = False, fileshare: bool = False + ) -> None: self.blob = blob self.queue = queue self.fileshare = fileshare - self._str = ("b" if self.blob else "") + ("q" if self.queue else "") + ("f" if self.fileshare else "") + self._str = ( + ("b" if self.blob else "") + + ("q" if self.queue else "") + + ("f" if self.fileshare else "") + ) def __str__(self): return self._str @@ -590,10 +627,14 @@ def __init__(self, **kwargs): self.max_single_put_size = kwargs.pop("max_single_put_size", 64 * 1024 * 1024) self.copy_polling_interval = 15 self.max_block_size = kwargs.pop("max_block_size", 4 * 1024 * 1024) - self.min_large_block_upload_threshold = kwargs.get("min_large_block_upload_threshold", 4 * 1024 * 1024 + 1) + self.min_large_block_upload_threshold = kwargs.get( + "min_large_block_upload_threshold", 4 * 1024 * 1024 + 1 + ) self.use_byte_buffer = kwargs.pop("use_byte_buffer", False) self.max_page_size = kwargs.pop("max_page_size", 4 * 1024 * 1024) - self.min_large_chunk_upload_threshold = kwargs.pop("min_large_chunk_upload_threshold", 100 * 1024 * 1024 + 1) + self.min_large_chunk_upload_threshold = kwargs.pop( + "min_large_chunk_upload_threshold", 100 * 1024 * 1024 + 1 + ) self.max_single_get_size = kwargs.pop("max_single_get_size", 32 * 1024 * 1024) self.max_chunk_get_size = kwargs.pop("max_chunk_get_size", 4 * 1024 * 1024) self.max_range_size = kwargs.pop("max_range_size", 4 * 1024 * 1024) diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/parser.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/parser.py index 7755398d8090..f16230c9d702 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/parser.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/parser.py @@ -53,7 +53,10 @@ def _filetime_to_datetime(filetime: str) -> Optional[datetime]: if temp_filetime == 0: return None - return datetime.fromtimestamp((temp_filetime - EPOCH_AS_FILETIME) / HUNDREDS_OF_NANOSECONDS, tz=timezone.utc) + return datetime.fromtimestamp( + (temp_filetime - EPOCH_AS_FILETIME) / HUNDREDS_OF_NANOSECONDS, + tz=timezone.utc, + ) except ValueError: pass diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/policies.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/policies.py index b343373dfce5..cf3880d41acb 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/policies.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/policies.py @@ -55,7 +55,12 @@ def encode_base64(data): # Are we out of retries? def is_exhausted(settings): - retry_counts = (settings["total"], settings["connect"], settings["read"], settings["status"]) + retry_counts = ( + settings["total"], + settings["connect"], + settings["read"], + settings["status"], + ) retry_counts = list(filter(None, retry_counts)) if not retry_counts: return False @@ -64,7 +69,9 @@ def is_exhausted(settings): def retry_hook(settings, **kwargs): if settings["hook"]: - settings["hook"](retry_count=settings["count"] - 1, location_mode=settings["mode"], **kwargs) + settings["hook"]( + retry_count=settings["count"] - 1, location_mode=settings["mode"], **kwargs + ) # Is this method/status code retryable? (Based on allowlists and control @@ -84,7 +91,9 @@ def is_retry(response, mode): # pylint: disable=too-many-return-statements # Response code 408 is a timeout and should be retried. return True if status >= 400: - error_code = response.http_response.headers.get("x-ms-copy-source-error-code") + error_code = response.http_response.headers.get( + "x-ms-copy-source-error-code" + ) if error_code in [ StorageErrorCode.OPERATION_TIMED_OUT, StorageErrorCode.INTERNAL_ERROR, @@ -103,8 +112,12 @@ def is_retry(response, mode): # pylint: disable=too-many-return-statements def is_checksum_retry(response): # retry if invalid content md5 - if response.context.get("validate_content", False) and response.http_response.headers.get("content-md5"): - computed_md5 = response.http_request.headers.get("content-md5", None) or encode_base64( + if response.context.get( + "validate_content", False + ) and response.http_response.headers.get("content-md5"): + computed_md5 = response.http_request.headers.get( + "content-md5", None + ) or encode_base64( StorageContentValidation.get_content_md5(response.http_response.body()) ) if response.http_response.headers["content-md5"] != computed_md5: @@ -141,7 +154,9 @@ def on_request(self, request: "PipelineRequest") -> None: request.http_request.headers["x-ms-date"] = current_time custom_id = request.context.options.pop("client_request_id", None) - request.http_request.headers["x-ms-client-request-id"] = custom_id or str(uuid.uuid1()) + request.http_request.headers["x-ms-client-request-id"] = custom_id or str( + uuid.uuid1() + ) # def on_response(self, request, response): # # raise exception if the echoed client request id from the service is not identical to the one we sent @@ -181,7 +196,9 @@ def on_request(self, request: "PipelineRequest") -> None: # Lock retries to the specific location request.context.options["retry_to_secondary"] = False if use_location not in self.hosts: - raise ValueError(f"Attempting to use undefined host location {use_location}") + raise ValueError( + f"Attempting to use undefined host location {use_location}" + ) if use_location != location_mode: # Update request URL to use the specified location updated = parsed_url._replace(netloc=self.hosts[use_location]) @@ -199,7 +216,9 @@ class StorageLoggingPolicy(NetworkTraceLoggingPolicy): def __init__(self, logging_enable: bool = False, **kwargs) -> None: self.logging_body = kwargs.pop("logging_body", False) - super(StorageLoggingPolicy, self).__init__(logging_enable=logging_enable, **kwargs) + super(StorageLoggingPolicy, self).__init__( + logging_enable=logging_enable, **kwargs + ) def on_request(self, request: "PipelineRequest") -> None: http_request = request.http_request @@ -228,7 +247,16 @@ def on_request(self, request: "PipelineRequest") -> None: parsed_qs["sig"] = "*****" # the SAS needs to be put back together - value = urlunparse((scheme, netloc, path, params, urlencode(parsed_qs), fragment)) + value = urlunparse( + ( + scheme, + netloc, + path, + params, + urlencode(parsed_qs), + fragment, + ) + ) _LOGGER.debug(" %r: %r", header, value) _LOGGER.debug("Request body:") @@ -241,7 +269,9 @@ def on_request(self, request: "PipelineRequest") -> None: except Exception as err: # pylint: disable=broad-except _LOGGER.debug("Failed to log request: %r", err) - def on_response(self, request: "PipelineRequest", response: "PipelineResponse") -> None: + def on_response( + self, request: "PipelineRequest", response: "PipelineResponse" + ) -> None: if response.context.pop("logging_enable", self.enable_http_logger): if not _LOGGER.isEnabledFor(logging.DEBUG): return @@ -256,7 +286,9 @@ def on_response(self, request: "PipelineRequest", response: "PipelineResponse") _LOGGER.debug("Response content:") pattern = re.compile(r'attachment; ?filename=["\w.]+', re.IGNORECASE) header = response.http_response.headers.get("content-disposition") - resp_content_type = response.http_response.headers.get("content-type", "") + resp_content_type = response.http_response.headers.get( + "content-type", "" + ) if header and pattern.match(header): filename = header.partition("=")[2] @@ -285,7 +317,9 @@ def __init__(self, **kwargs): super(StorageRequestHook, self).__init__() def on_request(self, request: "PipelineRequest") -> None: - request_callback = request.context.options.pop("raw_request_hook", self._request_callback) + request_callback = request.context.options.pop( + "raw_request_hook", self._request_callback + ) if request_callback: request_callback(request) @@ -303,36 +337,50 @@ def send(self, request: "PipelineRequest") -> "PipelineResponse": data_stream_total = request.context.options.pop("data_stream_total", None) download_stream_current = request.context.get("download_stream_current") if download_stream_current is None: - download_stream_current = request.context.options.pop("download_stream_current", None) + download_stream_current = request.context.options.pop( + "download_stream_current", None + ) upload_stream_current = request.context.get("upload_stream_current") if upload_stream_current is None: - upload_stream_current = request.context.options.pop("upload_stream_current", None) + upload_stream_current = request.context.options.pop( + "upload_stream_current", None + ) - response_callback = request.context.get("response_callback") or request.context.options.pop( - "raw_response_hook", self._response_callback - ) + response_callback = request.context.get( + "response_callback" + ) or request.context.options.pop("raw_response_hook", self._response_callback) response = self.next.send(request) - will_retry = is_retry(response, request.context.options.get("mode")) or is_checksum_retry(response) + will_retry = is_retry( + response, request.context.options.get("mode") + ) or is_checksum_retry(response) # Auth error could come from Bearer challenge, in which case this request will be made again is_auth_error = response.http_response.status_code == 401 should_update_counts = not (will_retry or is_auth_error) if should_update_counts and download_stream_current is not None: - download_stream_current += int(response.http_response.headers.get("Content-Length", 0)) + download_stream_current += int( + response.http_response.headers.get("Content-Length", 0) + ) if data_stream_total is None: content_range = response.http_response.headers.get("Content-Range") if content_range: - data_stream_total = int(content_range.split(" ", 1)[1].split("/", 1)[1]) + data_stream_total = int( + content_range.split(" ", 1)[1].split("/", 1)[1] + ) else: data_stream_total = download_stream_current elif should_update_counts and upload_stream_current is not None: - upload_stream_current += int(response.http_request.headers.get("Content-Length", 0)) + upload_stream_current += int( + response.http_request.headers.get("Content-Length", 0) + ) for pipeline_obj in [request, response]: if hasattr(pipeline_obj, "context"): pipeline_obj.context["data_stream_total"] = data_stream_total - pipeline_obj.context["download_stream_current"] = download_stream_current + pipeline_obj.context["download_stream_current"] = ( + download_stream_current + ) pipeline_obj.context["upload_stream_current"] = upload_stream_current if response_callback: response_callback(response) @@ -371,7 +419,9 @@ def get_content_md5(data): try: data.seek(pos, SEEK_SET) except (AttributeError, IOError) as exc: - raise ValueError("Data should be bytes or a seekable file-like object.") from exc + raise ValueError( + "Data should be bytes or a seekable file-like object." + ) from exc else: raise ValueError("Data should be bytes or a seekable file-like object.") @@ -380,13 +430,19 @@ def get_content_md5(data): def on_request(self, request: "PipelineRequest") -> None: validate_content = request.context.options.pop("validate_content", False) if validate_content and request.http_request.method != "GET": - computed_md5 = encode_base64(StorageContentValidation.get_content_md5(request.http_request.data)) + computed_md5 = encode_base64( + StorageContentValidation.get_content_md5(request.http_request.data) + ) request.http_request.headers[self.header_name] = computed_md5 request.context["validate_content_md5"] = computed_md5 request.context["validate_content"] = validate_content - def on_response(self, request: "PipelineRequest", response: "PipelineResponse") -> None: - if response.context.get("validate_content", False) and response.http_response.headers.get("content-md5"): + def on_response( + self, request: "PipelineRequest", response: "PipelineResponse" + ) -> None: + if response.context.get( + "validate_content", False + ) and response.http_response.headers.get("content-md5"): computed_md5 = request.context.get("validate_content_md5") or encode_base64( StorageContentValidation.get_content_md5(response.http_response.body()) ) @@ -424,7 +480,9 @@ def __init__(self, **kwargs: Any) -> None: self.retry_to_secondary = kwargs.pop("retry_to_secondary", False) super(StorageRetryPolicy, self).__init__() - def _set_next_host_location(self, settings: Dict[str, Any], request: "PipelineRequest") -> None: + def _set_next_host_location( + self, settings: Dict[str, Any], request: "PipelineRequest" + ) -> None: """ A function which sets the next host location on the request, if applicable. @@ -463,7 +521,9 @@ def configure_retries(self, request: "PipelineRequest") -> Dict[str, Any]: "connect": options.pop("retry_connect", self.connect_retries), "read": options.pop("retry_read", self.read_retries), "status": options.pop("retry_status", self.status_retries), - "retry_secondary": options.pop("retry_to_secondary", self.retry_to_secondary), + "retry_secondary": options.pop( + "retry_to_secondary", self.retry_to_secondary + ), "mode": options.pop("location_mode", LocationMode.PRIMARY), "hosts": options.pop("hosts", None), "hook": options.pop("retry_hook", None), @@ -472,7 +532,9 @@ def configure_retries(self, request: "PipelineRequest") -> Dict[str, Any]: "history": [], } - def get_backoff_time(self, settings: Dict[str, Any]) -> float: # pylint: disable=unused-argument + def get_backoff_time( + self, settings: Dict[str, Any] + ) -> float: # pylint: disable=unused-argument """Formula for computing the current backoff. Should be calculated by child class. @@ -535,7 +597,9 @@ def increment( # status_forcelist and a the given method is in the allowlist if response: settings["status"] -= 1 - settings["history"].append(RequestHistory(request, http_response=response)) + settings["history"].append( + RequestHistory(request, http_response=response) + ) if not is_exhausted(settings): if request.method not in ["PUT"] and settings["retry_secondary"]: @@ -570,13 +634,20 @@ def send(self, request): while retries_remaining: try: response = self.next.send(request) - if is_retry(response, retry_settings["mode"]) or is_checksum_retry(response): + if is_retry(response, retry_settings["mode"]) or is_checksum_retry( + response + ): retries_remaining = self.increment( - retry_settings, request=request.http_request, response=response.http_response + retry_settings, + request=request.http_request, + response=response.http_response, ) if retries_remaining: retry_hook( - retry_settings, request=request.http_request, response=response.http_response, error=None + retry_settings, + request=request.http_request, + response=response.http_response, + error=None, ) self.sleep(retry_settings, request.context.transport) continue @@ -584,9 +655,16 @@ def send(self, request): except AzureError as err: if isinstance(err, AzureSigningError): raise - retries_remaining = self.increment(retry_settings, request=request.http_request, error=err) + retries_remaining = self.increment( + retry_settings, request=request.http_request, error=err + ) if retries_remaining: - retry_hook(retry_settings, request=request.http_request, response=None, error=err) + retry_hook( + retry_settings, + request=request.http_request, + response=None, + error=err, + ) self.sleep(retry_settings, request.context.transport) continue raise err @@ -639,7 +717,9 @@ def __init__( self.initial_backoff = initial_backoff self.increment_base = increment_base self.random_jitter_range = random_jitter_range - super(ExponentialRetry, self).__init__(retry_total=retry_total, retry_to_secondary=retry_to_secondary, **kwargs) + super(ExponentialRetry, self).__init__( + retry_total=retry_total, retry_to_secondary=retry_to_secondary, **kwargs + ) def get_backoff_time(self, settings: Dict[str, Any]) -> float: """ @@ -652,8 +732,14 @@ def get_backoff_time(self, settings: Dict[str, Any]) -> float: :rtype: float """ random_generator = random.Random() - backoff = self.initial_backoff + (0 if settings["count"] == 0 else pow(self.increment_base, settings["count"])) - random_range_start = backoff - self.random_jitter_range if backoff > self.random_jitter_range else 0 + backoff = self.initial_backoff + ( + 0 if settings["count"] == 0 else pow(self.increment_base, settings["count"]) + ) + random_range_start = ( + backoff - self.random_jitter_range + if backoff > self.random_jitter_range + else 0 + ) random_range_end = backoff + self.random_jitter_range return random_generator.uniform(random_range_start, random_range_end) @@ -691,7 +777,9 @@ def __init__( """ self.backoff = backoff self.random_jitter_range = random_jitter_range - super(LinearRetry, self).__init__(retry_total=retry_total, retry_to_secondary=retry_to_secondary, **kwargs) + super(LinearRetry, self).__init__( + retry_total=retry_total, retry_to_secondary=retry_to_secondary, **kwargs + ) def get_backoff_time(self, settings: Dict[str, Any]) -> float: """ @@ -706,7 +794,11 @@ def get_backoff_time(self, settings: Dict[str, Any]) -> float: random_generator = random.Random() # the backoff interval normally does not change, however there is the possibility # that it was modified by accessing the property directly after initializing the object - random_range_start = self.backoff - self.random_jitter_range if self.backoff > self.random_jitter_range else 0 + random_range_start = ( + self.backoff - self.random_jitter_range + if self.backoff > self.random_jitter_range + else 0 + ) random_range_end = self.backoff + self.random_jitter_range return random_generator.uniform(random_range_start, random_range_end) @@ -714,10 +806,16 @@ def get_backoff_time(self, settings: Dict[str, Any]) -> float: class StorageBearerTokenCredentialPolicy(BearerTokenCredentialPolicy): """Custom Bearer token credential policy for following Storage Bearer challenges""" - def __init__(self, credential: "TokenCredential", audience: str, **kwargs: Any) -> None: - super(StorageBearerTokenCredentialPolicy, self).__init__(credential, audience, **kwargs) + def __init__( + self, credential: "TokenCredential", audience: str, **kwargs: Any + ) -> None: + super(StorageBearerTokenCredentialPolicy, self).__init__( + credential, audience, **kwargs + ) - def on_challenge(self, request: "PipelineRequest", response: "PipelineResponse") -> bool: + def on_challenge( + self, request: "PipelineRequest", response: "PipelineResponse" + ) -> bool: """Handle the challenge from the service and authorize the request. :param request: The request object. diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/policies_async.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/policies_async.py index 4cb32f23248b..7d130217c50d 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/policies_async.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/policies_async.py @@ -11,11 +11,19 @@ from typing import Any, Dict, TYPE_CHECKING from azure.core.exceptions import AzureError, StreamClosedError, StreamConsumedError -from azure.core.pipeline.policies import AsyncBearerTokenCredentialPolicy, AsyncHTTPPolicy +from azure.core.pipeline.policies import ( + AsyncBearerTokenCredentialPolicy, + AsyncHTTPPolicy, +) from .authentication import AzureSigningError, StorageHttpChallenge from .constants import DEFAULT_OAUTH_SCOPE -from .policies import encode_base64, is_retry, StorageContentValidation, StorageRetryPolicy +from .policies import ( + encode_base64, + is_retry, + StorageContentValidation, + StorageRetryPolicy, +) if TYPE_CHECKING: from azure.core.credentials_async import AsyncTokenCredential @@ -31,20 +39,32 @@ async def retry_hook(settings, **kwargs): if settings["hook"]: if asyncio.iscoroutine(settings["hook"]): - await settings["hook"](retry_count=settings["count"] - 1, location_mode=settings["mode"], **kwargs) + await settings["hook"]( + retry_count=settings["count"] - 1, + location_mode=settings["mode"], + **kwargs + ) else: - settings["hook"](retry_count=settings["count"] - 1, location_mode=settings["mode"], **kwargs) + settings["hook"]( + retry_count=settings["count"] - 1, + location_mode=settings["mode"], + **kwargs + ) async def is_checksum_retry(response): # retry if invalid content md5 - if response.context.get("validate_content", False) and response.http_response.headers.get("content-md5"): + if response.context.get( + "validate_content", False + ) and response.http_response.headers.get("content-md5"): if hasattr(response.http_response, "load_body"): try: await response.http_response.load_body() # Load the body in memory and close the socket except (StreamClosedError, StreamConsumedError): pass - computed_md5 = response.http_request.headers.get("content-md5", None) or encode_base64( + computed_md5 = response.http_request.headers.get( + "content-md5", None + ) or encode_base64( StorageContentValidation.get_content_md5(response.http_response.body()) ) if response.http_response.headers["content-md5"] != computed_md5: @@ -65,36 +85,50 @@ async def send(self, request: "PipelineRequest") -> "PipelineResponse": data_stream_total = request.context.options.pop("data_stream_total", None) download_stream_current = request.context.get("download_stream_current") if download_stream_current is None: - download_stream_current = request.context.options.pop("download_stream_current", None) + download_stream_current = request.context.options.pop( + "download_stream_current", None + ) upload_stream_current = request.context.get("upload_stream_current") if upload_stream_current is None: - upload_stream_current = request.context.options.pop("upload_stream_current", None) + upload_stream_current = request.context.options.pop( + "upload_stream_current", None + ) - response_callback = request.context.get("response_callback") or request.context.options.pop( - "raw_response_hook", self._response_callback - ) + response_callback = request.context.get( + "response_callback" + ) or request.context.options.pop("raw_response_hook", self._response_callback) response = await self.next.send(request) - will_retry = is_retry(response, request.context.options.get("mode")) or await is_checksum_retry(response) + will_retry = is_retry( + response, request.context.options.get("mode") + ) or await is_checksum_retry(response) # Auth error could come from Bearer challenge, in which case this request will be made again is_auth_error = response.http_response.status_code == 401 should_update_counts = not (will_retry or is_auth_error) if should_update_counts and download_stream_current is not None: - download_stream_current += int(response.http_response.headers.get("Content-Length", 0)) + download_stream_current += int( + response.http_response.headers.get("Content-Length", 0) + ) if data_stream_total is None: content_range = response.http_response.headers.get("Content-Range") if content_range: - data_stream_total = int(content_range.split(" ", 1)[1].split("/", 1)[1]) + data_stream_total = int( + content_range.split(" ", 1)[1].split("/", 1)[1] + ) else: data_stream_total = download_stream_current elif should_update_counts and upload_stream_current is not None: - upload_stream_current += int(response.http_request.headers.get("Content-Length", 0)) + upload_stream_current += int( + response.http_request.headers.get("Content-Length", 0) + ) for pipeline_obj in [request, response]: if hasattr(pipeline_obj, "context"): pipeline_obj.context["data_stream_total"] = data_stream_total - pipeline_obj.context["download_stream_current"] = download_stream_current + pipeline_obj.context["download_stream_current"] = ( + download_stream_current + ) pipeline_obj.context["upload_stream_current"] = upload_stream_current if response_callback: if asyncio.iscoroutine(response_callback): @@ -123,13 +157,20 @@ async def send(self, request): while retries_remaining: try: response = await self.next.send(request) - if is_retry(response, retry_settings["mode"]) or await is_checksum_retry(response): + if is_retry( + response, retry_settings["mode"] + ) or await is_checksum_retry(response): retries_remaining = self.increment( - retry_settings, request=request.http_request, response=response.http_response + retry_settings, + request=request.http_request, + response=response.http_response, ) if retries_remaining: await retry_hook( - retry_settings, request=request.http_request, response=response.http_response, error=None + retry_settings, + request=request.http_request, + response=response.http_response, + error=None, ) await self.sleep(retry_settings, request.context.transport) continue @@ -137,9 +178,16 @@ async def send(self, request): except AzureError as err: if isinstance(err, AzureSigningError): raise - retries_remaining = self.increment(retry_settings, request=request.http_request, error=err) + retries_remaining = self.increment( + retry_settings, request=request.http_request, error=err + ) if retries_remaining: - await retry_hook(retry_settings, request=request.http_request, response=None, error=err) + await retry_hook( + retry_settings, + request=request.http_request, + response=None, + error=err, + ) await self.sleep(retry_settings, request.context.transport) continue raise err @@ -194,7 +242,9 @@ def __init__( self.initial_backoff = initial_backoff self.increment_base = increment_base self.random_jitter_range = random_jitter_range - super(ExponentialRetry, self).__init__(retry_total=retry_total, retry_to_secondary=retry_to_secondary, **kwargs) + super(ExponentialRetry, self).__init__( + retry_total=retry_total, retry_to_secondary=retry_to_secondary, **kwargs + ) def get_backoff_time(self, settings: Dict[str, Any]) -> float: """ @@ -207,8 +257,14 @@ def get_backoff_time(self, settings: Dict[str, Any]) -> float: :rtype: int or None """ random_generator = random.Random() - backoff = self.initial_backoff + (0 if settings["count"] == 0 else pow(self.increment_base, settings["count"])) - random_range_start = backoff - self.random_jitter_range if backoff > self.random_jitter_range else 0 + backoff = self.initial_backoff + ( + 0 if settings["count"] == 0 else pow(self.increment_base, settings["count"]) + ) + random_range_start = ( + backoff - self.random_jitter_range + if backoff > self.random_jitter_range + else 0 + ) random_range_end = backoff + self.random_jitter_range return random_generator.uniform(random_range_start, random_range_end) @@ -246,7 +302,9 @@ def __init__( """ self.backoff = backoff self.random_jitter_range = random_jitter_range - super(LinearRetry, self).__init__(retry_total=retry_total, retry_to_secondary=retry_to_secondary, **kwargs) + super(LinearRetry, self).__init__( + retry_total=retry_total, retry_to_secondary=retry_to_secondary, **kwargs + ) def get_backoff_time(self, settings: Dict[str, Any]) -> float: """ @@ -261,7 +319,11 @@ def get_backoff_time(self, settings: Dict[str, Any]) -> float: random_generator = random.Random() # the backoff interval normally does not change, however there is the possibility # that it was modified by accessing the property directly after initializing the object - random_range_start = self.backoff - self.random_jitter_range if self.backoff > self.random_jitter_range else 0 + random_range_start = ( + self.backoff - self.random_jitter_range + if self.backoff > self.random_jitter_range + else 0 + ) random_range_end = self.backoff + self.random_jitter_range return random_generator.uniform(random_range_start, random_range_end) @@ -269,10 +331,16 @@ def get_backoff_time(self, settings: Dict[str, Any]) -> float: class AsyncStorageBearerTokenCredentialPolicy(AsyncBearerTokenCredentialPolicy): """Custom Bearer token credential policy for following Storage Bearer challenges""" - def __init__(self, credential: "AsyncTokenCredential", audience: str, **kwargs: Any) -> None: - super(AsyncStorageBearerTokenCredentialPolicy, self).__init__(credential, audience, **kwargs) + def __init__( + self, credential: "AsyncTokenCredential", audience: str, **kwargs: Any + ) -> None: + super(AsyncStorageBearerTokenCredentialPolicy, self).__init__( + credential, audience, **kwargs + ) - async def on_challenge(self, request: "PipelineRequest", response: "PipelineResponse") -> bool: + async def on_challenge( + self, request: "PipelineRequest", response: "PipelineResponse" + ) -> bool: try: auth_header = response.http_response.headers.get("WWW-Authenticate") challenge = StorageHttpChallenge(auth_header) diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/request_handlers.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/request_handlers.py index b23f65859690..1cc701c9659e 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/request_handlers.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/request_handlers.py @@ -12,7 +12,6 @@ import isodate - _LOGGER = logging.getLogger(__name__) _REQUEST_DELIMITER_PREFIX = "batch_" @@ -118,11 +117,13 @@ def validate_and_format_range_headers( if align_to_page: if start_range is not None and start_range % 512 != 0: raise ValueError( - f"Invalid page blob start_range: {start_range}. " "The size must be aligned to a 512-byte boundary." + f"Invalid page blob start_range: {start_range}. " + "The size must be aligned to a 512-byte boundary." ) if end_range is not None and end_range % 512 != 511: raise ValueError( - f"Invalid page blob end_range: {end_range}. " "The size must be aligned to a 512-byte boundary." + f"Invalid page blob end_range: {end_range}. " + "The size must be aligned to a 512-byte boundary." ) # Format based on whether end_range is present @@ -136,9 +137,13 @@ def validate_and_format_range_headers( range_validation = None if check_content_md5: if start_range is None or end_range is None: - raise ValueError("Both start and end range required for MD5 content validation.") + raise ValueError( + "Both start and end range required for MD5 content validation." + ) if end_range - start_range > 4 * 1024 * 1024: - raise ValueError("Getting content MD5 for a range greater than 4MB is not supported.") + raise ValueError( + "Getting content MD5 for a range greater than 4MB is not supported." + ) range_validation = "true" return range_header, range_validation @@ -173,26 +178,34 @@ def serialize_batch_body(requests, batch_id): if requests is None or len(requests) == 0: raise ValueError("Please provide sub-request(s) for this batch request") - delimiter_bytes = (_get_batch_request_delimiter(batch_id, True, False) + _HTTP_LINE_ENDING).encode("utf-8") + delimiter_bytes = ( + _get_batch_request_delimiter(batch_id, True, False) + _HTTP_LINE_ENDING + ).encode("utf-8") newline_bytes = _HTTP_LINE_ENDING.encode("utf-8") batch_body = [] content_index = 0 for request in requests: - request.headers.update({"Content-ID": str(content_index), "Content-Length": str(0)}) + request.headers.update( + {"Content-ID": str(content_index), "Content-Length": str(0)} + ) batch_body.append(delimiter_bytes) batch_body.append(_make_body_from_sub_request(request)) batch_body.append(newline_bytes) content_index += 1 - batch_body.append(_get_batch_request_delimiter(batch_id, True, True).encode("utf-8")) + batch_body.append( + _get_batch_request_delimiter(batch_id, True, True).encode("utf-8") + ) # final line of body MUST have \r\n at the end, or it will not be properly read by the service batch_body.append(newline_bytes) return b"".join(batch_body) -def _get_batch_request_delimiter(batch_id, is_prepend_dashes=False, is_append_dashes=False): +def _get_batch_request_delimiter( + batch_id, is_prepend_dashes=False, is_append_dashes=False +): """ Gets the delimiter used for this batch request's mixed/multipart HTTP format. diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/response_handlers.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/response_handlers.py index 40faa840cfbf..c9ce88c58912 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/response_handlers.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/response_handlers.py @@ -21,7 +21,6 @@ from .models import get_enum_value, StorageErrorCode, UserDelegationKey from .parser import _to_utc_datetime - SV_DOCS_URL = "https://learn.microsoft.com/rest/api/storageservices/versioning-for-the-azure-storage-services" _LOGGER = logging.getLogger(__name__) @@ -36,7 +35,9 @@ class PartialBatchErrorException(HttpResponseError): def __init__(self, message, response, parts): self.parts = parts - super(PartialBatchErrorException, self).__init__(message=message, response=response) + super(PartialBatchErrorException, self).__init__( + message=message, response=response + ) # Parses the blob length from the content range header: bytes 1-3/65537 @@ -61,26 +62,43 @@ def normalize_headers(headers): def deserialize_metadata(response, obj, headers): # pylint: disable=unused-argument try: - raw_metadata = {k: v for k, v in response.http_response.headers.items() if k.lower().startswith("x-ms-meta-")} + raw_metadata = { + k: v + for k, v in response.http_response.headers.items() + if k.lower().startswith("x-ms-meta-") + } except AttributeError: - raw_metadata = {k: v for k, v in response.headers.items() if k.lower().startswith("x-ms-meta-")} + raw_metadata = { + k: v + for k, v in response.headers.items() + if k.lower().startswith("x-ms-meta-") + } return {k[10:]: v for k, v in raw_metadata.items()} -def return_response_headers(response, deserialized, response_headers): # pylint: disable=unused-argument +def return_response_headers( + response, deserialized, response_headers +): # pylint: disable=unused-argument return normalize_headers(response_headers) -def return_headers_and_deserialized(response, deserialized, response_headers): # pylint: disable=unused-argument +def return_headers_and_deserialized( + response, deserialized, response_headers +): # pylint: disable=unused-argument return normalize_headers(response_headers), deserialized -def return_context_and_deserialized(response, deserialized, response_headers): # pylint: disable=unused-argument +def return_context_and_deserialized( + response, deserialized, response_headers +): # pylint: disable=unused-argument return response.http_response.location_mode, deserialized def return_raw_deserialized(response, *_): - return response.http_response.location_mode, response.context[ContentDecodePolicy.CONTEXT_NAME] + return ( + response.http_response.location_mode, + response.context[ContentDecodePolicy.CONTEXT_NAME], + ) def process_storage_error(storage_error) -> NoReturn: # type: ignore [misc] # pylint:disable=too-many-statements, too-many-branches @@ -96,7 +114,12 @@ def process_storage_error(storage_error) -> NoReturn: # type: ignore [misc] # p # If it is one of those three then it has been serialized prior by the generated layer. if isinstance( storage_error, - (PartialBatchErrorException, ClientAuthenticationError, ResourceNotFoundError, ResourceExistsError), + ( + PartialBatchErrorException, + ClientAuthenticationError, + ResourceNotFoundError, + ResourceExistsError, + ), ): serialized = True error_code = storage_error.response.headers.get("x-ms-error-code") @@ -104,7 +127,9 @@ def process_storage_error(storage_error) -> NoReturn: # type: ignore [misc] # p additional_data = {} error_dict = {} try: - error_body = ContentDecodePolicy.deserialize_from_http_generics(storage_error.response) + error_body = ContentDecodePolicy.deserialize_from_http_generics( + storage_error.response + ) try: if error_body is None or len(error_body) == 0: error_body = storage_error.response.reason @@ -118,7 +143,8 @@ def process_storage_error(storage_error) -> NoReturn: # type: ignore [misc] # p error_dict = error_body.get("error", {}) elif not error_code: _LOGGER.warning( - "Unexpected return type %s from ContentDecodePolicy.deserialize_from_http_generics.", type(error_body) + "Unexpected return type %s from ContentDecodePolicy.deserialize_from_http_generics.", + type(error_body), ) error_dict = {"message": str(error_body)} @@ -127,7 +153,9 @@ def process_storage_error(storage_error) -> NoReturn: # type: ignore [misc] # p if error_dict and isinstance(error_dict, dict): error_code = error_dict.get("code") error_message = error_dict.get("message") - additional_data = {k: v for k, v in error_dict.items() if k not in {"code", "message"}} + additional_data = { + k: v for k, v in error_dict.items() if k not in {"code", "message"} + } except DecodeError: pass @@ -135,9 +163,15 @@ def process_storage_error(storage_error) -> NoReturn: # type: ignore [misc] # p # This check would be unnecessary if we have already serialized the error if error_code and not serialized: error_code = StorageErrorCode(error_code) - if error_code in [StorageErrorCode.condition_not_met, StorageErrorCode.blob_overwritten]: + if error_code in [ + StorageErrorCode.condition_not_met, + StorageErrorCode.blob_overwritten, + ]: raise_error = ResourceModifiedError - if error_code in [StorageErrorCode.invalid_authentication_info, StorageErrorCode.authentication_failed]: + if error_code in [ + StorageErrorCode.invalid_authentication_info, + StorageErrorCode.authentication_failed, + ]: raise_error = ClientAuthenticationError if error_code in [ StorageErrorCode.resource_not_found, @@ -175,7 +209,10 @@ def process_storage_error(storage_error) -> NoReturn: # type: ignore [misc] # p for name, info in additional_data.items(): error_message += f"\n{name}:{info}" - if additional_data.get("headername") == "x-ms-version" and error_code == StorageErrorCode.INVALID_HEADER_VALUE: + if ( + additional_data.get("headername") == "x-ms-version" + and error_code == StorageErrorCode.INVALID_HEADER_VALUE + ): error_message = ( "The provided service version is not enabled on this storage account." + f"Please see {SV_DOCS_URL} for additional information.\n" @@ -204,10 +241,20 @@ def parse_to_internal_user_delegation_key(service_user_delegation_key): internal_user_delegation_key = UserDelegationKey() internal_user_delegation_key.signed_oid = service_user_delegation_key.signed_oid internal_user_delegation_key.signed_tid = service_user_delegation_key.signed_tid - internal_user_delegation_key.signed_delegated_user_tid = service_user_delegation_key.signed_delegated_user_tid - internal_user_delegation_key.signed_start = _to_utc_datetime(service_user_delegation_key.signed_start) - internal_user_delegation_key.signed_expiry = _to_utc_datetime(service_user_delegation_key.signed_expiry) - internal_user_delegation_key.signed_service = service_user_delegation_key.signed_service - internal_user_delegation_key.signed_version = service_user_delegation_key.signed_version + internal_user_delegation_key.signed_delegated_user_tid = ( + service_user_delegation_key.signed_delegated_user_tid + ) + internal_user_delegation_key.signed_start = _to_utc_datetime( + service_user_delegation_key.signed_start + ) + internal_user_delegation_key.signed_expiry = _to_utc_datetime( + service_user_delegation_key.signed_expiry + ) + internal_user_delegation_key.signed_service = ( + service_user_delegation_key.signed_service + ) + internal_user_delegation_key.signed_version = ( + service_user_delegation_key.signed_version + ) internal_user_delegation_key.value = service_user_delegation_key.value return internal_user_delegation_key diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/shared_access_signature.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/shared_access_signature.py index b8582a8f71f4..44f4c2812d17 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/shared_access_signature.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/shared_access_signature.py @@ -219,17 +219,26 @@ def add_id(self, policy_id): self._add_query(QueryStringConstants.SIGNED_IDENTIFIER, policy_id) def add_user_delegation_oid(self, user_delegation_oid): - self._add_query(QueryStringConstants.SIGNED_DELEGATED_USER_OID, user_delegation_oid) + self._add_query( + QueryStringConstants.SIGNED_DELEGATED_USER_OID, user_delegation_oid + ) def add_account(self, services, resource_types): self._add_query(QueryStringConstants.SIGNED_SERVICES, services) self._add_query(QueryStringConstants.SIGNED_RESOURCE_TYPES, resource_types) def add_override_response_headers( - self, cache_control, content_disposition, content_encoding, content_language, content_type + self, + cache_control, + content_disposition, + content_encoding, + content_language, + content_type, ): self._add_query(QueryStringConstants.SIGNED_CACHE_CONTROL, cache_control) - self._add_query(QueryStringConstants.SIGNED_CONTENT_DISPOSITION, content_disposition) + self._add_query( + QueryStringConstants.SIGNED_CONTENT_DISPOSITION, content_disposition + ) self._add_query(QueryStringConstants.SIGNED_CONTENT_ENCODING, content_encoding) self._add_query(QueryStringConstants.SIGNED_CONTENT_LANGUAGE, content_language) self._add_query(QueryStringConstants.SIGNED_CONTENT_TYPE, content_type) @@ -239,7 +248,9 @@ def add_request_headers(self, request_headers): return # String-to-Sign (not encoded): "k1:v1\nk2:v2\n...kn:vn\n" - self._sts_srh = "\n".join([f"{k}:{v}" for k, v in request_headers.items()]) + "\n" + self._sts_srh = ( + "\n".join([f"{k}:{v}" for k, v in request_headers.items()]) + "\n" + ) # SAS query param: comma-separated list of encoded header keys only srh_keys = ",".join([url_quote(k) for k in request_headers.keys()]) @@ -250,7 +261,9 @@ def add_request_query_params(self, request_query_params): return # String-to-Sign (not encoded): "k1:v1\nk2:v2\n...kn:vn\n" - self._sts_srq = "\n" + "\n".join([f"{k}:{v}" for k, v in request_query_params.items()]) + self._sts_srq = "\n" + "\n".join( + [f"{k}:{v}" for k, v in request_query_params.items()] + ) # SAS query param: comma-separated list of encoded query-param keys only srq_keys = ",".join([url_quote(k) for k in request_query_params.keys()]) @@ -275,8 +288,13 @@ def get_value_to_append(query): + "\n" # Signed Encryption Scope - always empty for queue ) - self._add_query(QueryStringConstants.SIGNED_SIGNATURE, sign_string(account_key, string_to_sign)) + self._add_query( + QueryStringConstants.SIGNED_SIGNATURE, + sign_string(account_key, string_to_sign), + ) self.string_to_sign = string_to_sign def get_token(self) -> str: - return "&".join([f"{n}={url_quote(v)}" for n, v in self.query_dict.items() if v is not None]) + return "&".join( + [f"{n}={url_quote(v)}" for n, v in self.query_dict.items() if v is not None] + ) diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/uploads.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/uploads.py index 7a5fb3f3dc91..97641795aacd 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/uploads.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/uploads.py @@ -16,9 +16,10 @@ from .request_handlers import get_length from .response_handlers import return_response_headers - _LARGE_BLOB_UPLOAD_MAX_READ_BUFFER_SIZE = 4 * 1024 * 1024 -_ERROR_VALUE_SHOULD_BE_SEEKABLE_STREAM = "{0} should be a seekable file-like/io.IOBase type stream object." +_ERROR_VALUE_SHOULD_BE_SEEKABLE_STREAM = ( + "{0} should be a seekable file-like/io.IOBase type stream object." +) def _parallel_uploads(executor, uploader, pending, running): @@ -74,9 +75,13 @@ def upload_data_chunks( executor.submit(with_current_context(uploader.process_chunk), u) for u in islice(upload_tasks, 0, max_concurrency) ] - range_ids = _parallel_uploads(executor, uploader.process_chunk, upload_tasks, running_futures) + range_ids = _parallel_uploads( + executor, uploader.process_chunk, upload_tasks, running_futures + ) else: - range_ids = [uploader.process_chunk(result) for result in uploader.get_chunk_streams()] + range_ids = [ + uploader.process_chunk(result) for result in uploader.get_chunk_streams() + ] if any(range_ids): return [r[1] for r in sorted(range_ids, key=lambda r: r[0])] return uploader.response_headers @@ -110,12 +115,21 @@ def upload_substream_blocks( with futures.ThreadPoolExecutor(max_concurrency) as executor: upload_tasks = uploader.get_substream_blocks() running_futures = [ - executor.submit(with_current_context(uploader.process_substream_block), u) + executor.submit( + with_current_context(uploader.process_substream_block), u + ) for u in islice(upload_tasks, 0, max_concurrency) ] - range_ids = _parallel_uploads(executor, uploader.process_substream_block, upload_tasks, running_futures) + range_ids = _parallel_uploads( + executor, + uploader.process_substream_block, + upload_tasks, + running_futures, + ) else: - range_ids = [uploader.process_substream_block(b) for b in uploader.get_substream_blocks()] + range_ids = [ + uploader.process_substream_block(b) for b in uploader.get_substream_blocks() + ] if any(range_ids): return sorted(range_ids) return [] @@ -166,7 +180,10 @@ def get_chunk_streams(self): # Buffer until we either reach the end of the stream or get a whole chunk. while True: if self.total_size: - read_size = min(self.chunk_size - len(data), self.total_size - (index + len(data))) + read_size = min( + self.chunk_size - len(data), + self.total_size - (index + len(data)), + ) temp = self.stream.read(read_size) if not isinstance(temp, bytes): raise TypeError("Blob data should be of type bytes.") @@ -227,7 +244,11 @@ def get_substream_blocks(self): raise ValueError("Unable to determine content length of upload data.") blocks = int(ceil(blob_length / (self.chunk_size * 1.0))) - last_block_size = self.chunk_size if blob_length % self.chunk_size == 0 else blob_length % self.chunk_size + last_block_size = ( + self.chunk_size + if blob_length % self.chunk_size == 0 + else blob_length % self.chunk_size + ) for i in range(blocks): index = i * self.chunk_size @@ -311,8 +332,12 @@ def _upload_chunk(self, chunk_offset, chunk_data): **self.request_options, ) - if not self.parallel and self.request_options.get("modified_access_conditions"): - self.request_options["modified_access_conditions"].if_match = self.response_headers["etag"] + if not self.parallel and self.request_options.get( + "modified_access_conditions" + ): + self.request_options["modified_access_conditions"].if_match = ( + self.response_headers["etag"] + ) def _upload_substream_block(self, index, block_stream): pass @@ -336,9 +361,9 @@ def _upload_chunk(self, chunk_offset, chunk_data): ) self.current_length = int(self.response_headers["blob_append_offset"]) else: - self.request_options["append_position_access_conditions"].append_position = ( - self.current_length + chunk_offset - ) + self.request_options[ + "append_position_access_conditions" + ].append_position = (self.current_length + chunk_offset) self.response_headers = self.service.append_block( body=chunk_data, content_length=len(chunk_data), @@ -367,7 +392,9 @@ def _upload_chunk(self, chunk_offset, chunk_data): ) if not self.parallel and self.request_options.get("modified_access_conditions"): - self.request_options["modified_access_conditions"].if_match = self.response_headers["etag"] + self.request_options["modified_access_conditions"].if_match = ( + self.response_headers["etag"] + ) def _upload_substream_block(self, index, block_stream): try: @@ -426,7 +453,9 @@ def __init__(self, wrapped_stream, stream_begin_index, length, lockObj): # we must avoid buffering more than necessary, and also not use up too much memory # so the max buffer size is capped at 4MB self._max_buffer_size = ( - length if length < _LARGE_BLOB_UPLOAD_MAX_READ_BUFFER_SIZE else _LARGE_BLOB_UPLOAD_MAX_READ_BUFFER_SIZE + length + if length < _LARGE_BLOB_UPLOAD_MAX_READ_BUFFER_SIZE + else _LARGE_BLOB_UPLOAD_MAX_READ_BUFFER_SIZE ) self._current_buffer_start = 0 self._current_buffer_size = 0 @@ -474,7 +503,9 @@ def read(self, size=None): with self._buffer: # either read in the max buffer size specified on the class # or read in just enough data for the current block/sub stream - current_max_buffer_size = min(self._max_buffer_size, self._length - self._position) + current_max_buffer_size = min( + self._max_buffer_size, self._length - self._position + ) # lock is only defined if max_concurrency > 1 (parallel uploads) if self._lock: @@ -484,8 +515,12 @@ def read(self, size=None): self._wrapped_stream.seek(absolute_position, SEEK_SET) # If we can't seek to the right location, our read will be corrupted so fail fast. if self._wrapped_stream.tell() != absolute_position: - raise IOError("Stream failed to seek to the desired location.") - buffer_from_stream = self._wrapped_stream.read(current_max_buffer_size) + raise IOError( + "Stream failed to seek to the desired location." + ) + buffer_from_stream = self._wrapped_stream.read( + current_max_buffer_size + ) else: absolute_position = self._stream_begin_index + self._position # It's possible that there's connection problem during data transfer, @@ -494,7 +529,9 @@ def read(self, size=None): if self._wrapped_stream.tell() != absolute_position: self._wrapped_stream.seek(absolute_position, SEEK_SET) - buffer_from_stream = self._wrapped_stream.read(current_max_buffer_size) + buffer_from_stream = self._wrapped_stream.read( + current_max_buffer_size + ) if buffer_from_stream: # update the buffer with new data from the wrapped stream @@ -536,7 +573,10 @@ def seek(self, offset, whence=0): # check if buffer is still valid # if not, drop buffer - if pos < self._current_buffer_start or pos >= self._current_buffer_start + self._current_buffer_size: + if ( + pos < self._current_buffer_start + or pos >= self._current_buffer_start + self._current_buffer_size + ): self._buffer.close() self._buffer = BytesIO() else: # if yes seek to correct position diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/uploads_async.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/uploads_async.py index 6ed5ba1d0f91..678d6e2c7074 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/uploads_async.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/uploads_async.py @@ -90,11 +90,15 @@ async def upload_data_chunks( for _ in range(max_concurrency): try: chunk = await upload_tasks.__anext__() - running_futures.append(asyncio.ensure_future(uploader.process_chunk(chunk))) + running_futures.append( + asyncio.ensure_future(uploader.process_chunk(chunk)) + ) except StopAsyncIteration: break - range_ids = await _async_parallel_uploads(uploader.process_chunk, upload_tasks, running_futures) + range_ids = await _async_parallel_uploads( + uploader.process_chunk, upload_tasks, running_futures + ) else: range_ids = [] async for chunk in uploader.get_chunk_streams(): @@ -132,9 +136,12 @@ async def upload_substream_blocks( if parallel: upload_tasks = uploader.get_substream_blocks() running_futures = [ - asyncio.ensure_future(uploader.process_substream_block(u)) for u in islice(upload_tasks, 0, max_concurrency) + asyncio.ensure_future(uploader.process_substream_block(u)) + for u in islice(upload_tasks, 0, max_concurrency) ] - range_ids = await _parallel_uploads(uploader.process_substream_block, upload_tasks, running_futures) + range_ids = await _parallel_uploads( + uploader.process_substream_block, upload_tasks, running_futures + ) else: range_ids = [] for block in uploader.get_substream_blocks(): @@ -189,7 +196,10 @@ async def get_chunk_streams(self): # Buffer until we either reach the end of the stream or get a whole chunk. while True: if self.total_size: - read_size = min(self.chunk_size - len(data), self.total_size - (index + len(data))) + read_size = min( + self.chunk_size - len(data), + self.total_size - (index + len(data)), + ) temp = self.stream.read(read_size) if inspect.isawaitable(temp): temp = await temp @@ -252,7 +262,11 @@ def get_substream_blocks(self): raise ValueError("Unable to determine content length of upload data.") blocks = int(ceil(blob_length / (self.chunk_size * 1.0))) - last_block_size = self.chunk_size if blob_length % self.chunk_size == 0 else blob_length % self.chunk_size + last_block_size = ( + self.chunk_size + if blob_length % self.chunk_size == 0 + else blob_length % self.chunk_size + ) for i in range(blocks): index = i * self.chunk_size @@ -260,7 +274,9 @@ def get_substream_blocks(self): yield index, SubStream(self.stream, index, length, lock) async def process_substream_block(self, block_data): - return await self._upload_substream_block_with_progress(block_data[0], block_data[1]) + return await self._upload_substream_block_with_progress( + block_data[0], block_data[1] + ) async def _upload_substream_block(self, index, block_stream): raise NotImplementedError("Must be implemented by child class.") @@ -339,8 +355,12 @@ async def _upload_chunk(self, chunk_offset, chunk_data): **self.request_options, ) - if not self.parallel and self.request_options.get("modified_access_conditions"): - self.request_options["modified_access_conditions"].if_match = self.response_headers["etag"] + if not self.parallel and self.request_options.get( + "modified_access_conditions" + ): + self.request_options["modified_access_conditions"].if_match = ( + self.response_headers["etag"] + ) async def _upload_substream_block(self, index, block_stream): pass @@ -364,9 +384,9 @@ async def _upload_chunk(self, chunk_offset, chunk_data): ) self.current_length = int(self.response_headers["blob_append_offset"]) else: - self.request_options["append_position_access_conditions"].append_position = ( - self.current_length + chunk_offset - ) + self.request_options[ + "append_position_access_conditions" + ].append_position = (self.current_length + chunk_offset) self.response_headers = await self.service.append_block( body=chunk_data, content_length=len(chunk_data), @@ -394,7 +414,9 @@ async def _upload_chunk(self, chunk_offset, chunk_data): ) if not self.parallel and self.request_options.get("modified_access_conditions"): - self.request_options["modified_access_conditions"].if_match = self.response_headers["etag"] + self.request_options["modified_access_conditions"].if_match = ( + self.response_headers["etag"] + ) async def _upload_substream_block(self, index, block_stream): try: @@ -437,7 +459,11 @@ class AsyncIterStreamer: File-like streaming object for AsyncGenerators. """ - def __init__(self, generator: AsyncGenerator[Union[bytes, str], None], encoding: str = "UTF-8"): + def __init__( + self, + generator: AsyncGenerator[Union[bytes, str], None], + encoding: str = "UTF-8", + ): self.iterator = generator.__aiter__() self.leftover = b"" self.encoding = encoding diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared_access_signature.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared_access_signature.py index 465835d6ad69..de5de8ff3c08 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared_access_signature.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared_access_signature.py @@ -18,7 +18,11 @@ ) if TYPE_CHECKING: - from azure.storage.queue import AccountSasPermissions, QueueSasPermissions, ResourceTypes + from azure.storage.queue import ( + AccountSasPermissions, + QueueSasPermissions, + ResourceTypes, + ) from datetime import datetime @@ -46,7 +50,9 @@ def __init__( A user delegation key can be obtained from the service by authenticating with an AAD identity; this can be accomplished by calling get_user_delegation_key on any Queue service object. """ - super(QueueSharedAccessSignature, self).__init__(account_name, account_key, x_ms_version=X_MS_VERSION) + super(QueueSharedAccessSignature, self).__init__( + account_name, account_key, x_ms_version=X_MS_VERSION + ) self.user_delegation_key = user_delegation_key def generate_queue( @@ -116,7 +122,10 @@ def generate_queue( sas.add_id(policy_id) sas.add_user_delegation_oid(user_delegation_oid) sas.add_resource_signature( - self.account_name, self.account_key, queue_name, user_delegation_key=self.user_delegation_key + self.account_name, + self.account_key, + queue_name, + user_delegation_key=self.user_delegation_key, ) if sts_hook is not None: @@ -127,7 +136,9 @@ def generate_queue( class _QueueSharedAccessHelper(_SharedAccessHelper): - def add_resource_signature(self, account_name: str, account_key: str, path: str, user_delegation_key=None): + def add_resource_signature( + self, account_name: str, account_key: str, path: str, user_delegation_key=None + ): def get_value_to_append(query): return_value = self.query_dict.get(query) or "" return return_value + "\n" @@ -147,14 +158,30 @@ def get_value_to_append(query): ) if user_delegation_key is not None: - self._add_query(QueryStringConstants.SIGNED_OID, user_delegation_key.signed_oid) - self._add_query(QueryStringConstants.SIGNED_TID, user_delegation_key.signed_tid) - self._add_query(QueryStringConstants.SIGNED_KEY_START, user_delegation_key.signed_start) - self._add_query(QueryStringConstants.SIGNED_KEY_EXPIRY, user_delegation_key.signed_expiry) - self._add_query(QueryStringConstants.SIGNED_KEY_SERVICE, user_delegation_key.signed_service) - self._add_query(QueryStringConstants.SIGNED_KEY_VERSION, user_delegation_key.signed_version) self._add_query( - QueryStringConstants.SIGNED_KEY_DELEGATED_USER_TID, user_delegation_key.signed_delegated_user_tid + QueryStringConstants.SIGNED_OID, user_delegation_key.signed_oid + ) + self._add_query( + QueryStringConstants.SIGNED_TID, user_delegation_key.signed_tid + ) + self._add_query( + QueryStringConstants.SIGNED_KEY_START, user_delegation_key.signed_start + ) + self._add_query( + QueryStringConstants.SIGNED_KEY_EXPIRY, + user_delegation_key.signed_expiry, + ) + self._add_query( + QueryStringConstants.SIGNED_KEY_SERVICE, + user_delegation_key.signed_service, + ) + self._add_query( + QueryStringConstants.SIGNED_KEY_VERSION, + user_delegation_key.signed_version, + ) + self._add_query( + QueryStringConstants.SIGNED_KEY_DELEGATED_USER_TID, + user_delegation_key.signed_delegated_user_tid, ) string_to_sign += ( @@ -164,11 +191,15 @@ def get_value_to_append(query): + get_value_to_append(QueryStringConstants.SIGNED_KEY_EXPIRY) + get_value_to_append(QueryStringConstants.SIGNED_KEY_SERVICE) + get_value_to_append(QueryStringConstants.SIGNED_KEY_VERSION) - + get_value_to_append(QueryStringConstants.SIGNED_KEY_DELEGATED_USER_TID) + + get_value_to_append( + QueryStringConstants.SIGNED_KEY_DELEGATED_USER_TID + ) + get_value_to_append(QueryStringConstants.SIGNED_DELEGATED_USER_OID) ) else: - string_to_sign += get_value_to_append(QueryStringConstants.SIGNED_IDENTIFIER) + string_to_sign += get_value_to_append( + QueryStringConstants.SIGNED_IDENTIFIER + ) string_to_sign += ( get_value_to_append(QueryStringConstants.SIGNED_IP) @@ -182,7 +213,14 @@ def get_value_to_append(query): self._add_query( QueryStringConstants.SIGNED_SIGNATURE, - sign_string(account_key if user_delegation_key is None else user_delegation_key.value, string_to_sign), + sign_string( + ( + account_key + if user_delegation_key is None + else user_delegation_key.value + ), + string_to_sign, + ), ) self.string_to_sign = string_to_sign @@ -340,12 +378,18 @@ def generate_queue_sas( """ if not policy_id: if not expiry: - raise ValueError("'expiry' parameter must be provided when not using a stored access policy.") + raise ValueError( + "'expiry' parameter must be provided when not using a stored access policy." + ) if not permission: - raise ValueError("'permission' parameter must be provided when not using a stored access policy.") + raise ValueError( + "'permission' parameter must be provided when not using a stored access policy." + ) if not user_delegation_key and not account_key: raise ValueError("Either user_delegation_key or account_key must be provided.") - sas = QueueSharedAccessSignature(account_name, account_key=account_key, user_delegation_key=user_delegation_key) + sas = QueueSharedAccessSignature( + account_name, account_key=account_key, user_delegation_key=user_delegation_key + ) return sas.generate_queue( queue_name, permission=permission, diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/aio/__init__.py b/sdk/storage/azure-storage-queue/azure/storage/queue/aio/__init__.py index 434d5fe99bba..114731165ee8 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/aio/__init__.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/aio/__init__.py @@ -7,7 +7,6 @@ from ._queue_client_async import QueueClient from ._queue_service_client_async import QueueServiceClient - __all__ = [ "QueueClient", "QueueServiceClient", diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_models.py b/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_models.py index 5a1dfba70bde..fa59de55c652 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_models.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_models.py @@ -10,7 +10,10 @@ from azure.core.async_paging import AsyncPageIterator from azure.core.exceptions import HttpResponseError from .._models import QueueMessage, QueueProperties -from .._shared.response_handlers import process_storage_error, return_context_and_deserialized +from .._shared.response_handlers import ( + process_storage_error, + return_context_and_deserialized, +) class MessagesPaged(AsyncPageIterator): @@ -66,7 +69,9 @@ async def _extract_data_cb(self, messages: Any) -> Tuple[str, List[QueueMessage] raise StopAsyncIteration("End of paging") if self._max_messages is not None: self._max_messages = self._max_messages - len(messages) - return "TOKEN_IGNORED", [QueueMessage._from_generated(q) for q in messages] # pylint: disable=protected-access + return "TOKEN_IGNORED", [ + QueueMessage._from_generated(q) for q in messages + ] # pylint: disable=protected-access class QueuePropertiesPaged(AsyncPageIterator): @@ -127,14 +132,17 @@ async def _get_next_cb(self, continuation_token: Optional[str]) -> Any: except HttpResponseError as error: process_storage_error(error) - async def _extract_data_cb(self, get_next_return: Any) -> Tuple[Optional[str], List[QueueProperties]]: + async def _extract_data_cb( + self, get_next_return: Any + ) -> Tuple[Optional[str], List[QueueProperties]]: self.location_mode, self._response = get_next_return self.service_endpoint = self._response.service_endpoint self.prefix = self._response.prefix self.marker = self._response.marker self.results_per_page = self._response.max_results props_list = [ - QueueProperties._from_generated(q) for q in self._response.queue_items # pylint: disable=protected-access + QueueProperties._from_generated(q) + for q in self._response.queue_items # pylint: disable=protected-access ] next_marker = self._response.next_marker return next_marker or None, props_list diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_queue_client_async.py b/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_queue_client_async.py index 5134ea26a5ad..d106a17431f3 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_queue_client_async.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_queue_client_async.py @@ -24,10 +24,17 @@ from .._queue_client_helpers import _format_url, _from_queue_url, _parse_url from .._serialize import get_api_version from .._shared.base_client import StorageAccountHostsMixin -from .._shared.base_client_async import AsyncStorageAccountHostsMixin, parse_connection_str +from .._shared.base_client_async import ( + AsyncStorageAccountHostsMixin, + parse_connection_str, +) from .._shared.policies_async import ExponentialRetry from .._shared.request_handlers import add_metadata_headers, serialize_iso -from .._shared.response_handlers import process_storage_error, return_headers_and_deserialized, return_response_headers +from .._shared.response_handlers import ( + process_storage_error, + return_headers_and_deserialized, + return_response_headers, +) if TYPE_CHECKING: from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential @@ -106,19 +113,33 @@ def __init__( account_url: str, queue_name: str, credential: Optional[ - Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "AsyncTokenCredential"] + Union[ + str, + Dict[str, str], + "AzureNamedKeyCredential", + "AzureSasCredential", + "AsyncTokenCredential", + ] ] = None, *, api_version: Optional[str] = None, secondary_hostname: Optional[str] = None, - message_encode_policy: Optional[Union["BinaryBase64EncodePolicy", "TextBase64EncodePolicy"]] = None, - message_decode_policy: Optional[Union["BinaryBase64DecodePolicy", "TextBase64DecodePolicy"]] = None, + message_encode_policy: Optional[ + Union["BinaryBase64EncodePolicy", "TextBase64EncodePolicy"] + ] = None, + message_decode_policy: Optional[ + Union["BinaryBase64DecodePolicy", "TextBase64DecodePolicy"] + ] = None, audience: Optional[str] = None, **kwargs: Any ) -> None: - kwargs["retry_policy"] = kwargs.get("retry_policy") or ExponentialRetry(**kwargs) + kwargs["retry_policy"] = kwargs.get("retry_policy") or ExponentialRetry( + **kwargs + ) loop = kwargs.pop("loop", None) - parsed_url, sas_token = _parse_url(account_url=account_url, queue_name=queue_name, credential=credential) + parsed_url, sas_token = _parse_url( + account_url=account_url, queue_name=queue_name, credential=credential + ) self.queue_name = queue_name self._query_str, credential = self._format_query_string(sas_token, credential) super(QueueClient, self).__init__( @@ -133,7 +154,11 @@ def __init__( self._message_encode_policy = message_encode_policy or NoEncodePolicy() self._message_decode_policy = message_decode_policy or NoDecodePolicy() self._client = AzureQueueStorage( - self.url, get_api_version(api_version), base_url=self.url, pipeline=self._pipeline, loop=loop + self.url, + get_api_version(api_version), + base_url=self.url, + pipeline=self._pipeline, + loop=loop, ) self._loop = loop self._configure_encryption(kwargs) @@ -143,9 +168,14 @@ async def __aenter__(self) -> Self: return self async def __aexit__( - self, typ: Optional[type[BaseException]], exc: Optional[BaseException], tb: Optional[TracebackType] + self, + typ: Optional[type[BaseException]], + exc: Optional[BaseException], + tb: Optional[TracebackType], ) -> None: - await self._client.__aexit__(typ, exc, tb) # pylint: disable=specify-parameter-names-in-call + await self._client.__aexit__( + typ, exc, tb + ) # pylint: disable=specify-parameter-names-in-call async def close(self) -> None: """This method is to close the sockets opened by the client. @@ -164,20 +194,35 @@ def _format_url(self, hostname: str) -> str: :returns: The formatted endpoint URL according to the specified location mode hostname. :rtype: str """ - return _format_url(queue_name=self.queue_name, hostname=hostname, scheme=self.scheme, query_str=self._query_str) + return _format_url( + queue_name=self.queue_name, + hostname=hostname, + scheme=self.scheme, + query_str=self._query_str, + ) @classmethod def from_queue_url( cls, queue_url: str, credential: Optional[ - Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "AsyncTokenCredential"] + Union[ + str, + Dict[str, str], + "AzureNamedKeyCredential", + "AzureSasCredential", + "AsyncTokenCredential", + ] ] = None, *, api_version: Optional[str] = None, secondary_hostname: Optional[str] = None, - message_encode_policy: Optional[Union["BinaryBase64EncodePolicy", "TextBase64EncodePolicy"]] = None, - message_decode_policy: Optional[Union["BinaryBase64DecodePolicy", "TextBase64DecodePolicy"]] = None, + message_encode_policy: Optional[ + Union["BinaryBase64EncodePolicy", "TextBase64EncodePolicy"] + ] = None, + message_decode_policy: Optional[ + Union["BinaryBase64DecodePolicy", "TextBase64DecodePolicy"] + ] = None, audience: Optional[str] = None, **kwargs: Any ) -> Self: @@ -236,13 +281,23 @@ def from_connection_string( conn_str: str, queue_name: str, credential: Optional[ - Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "AsyncTokenCredential"] + Union[ + str, + Dict[str, str], + "AzureNamedKeyCredential", + "AzureSasCredential", + "AsyncTokenCredential", + ] ] = None, *, api_version: Optional[str] = None, secondary_hostname: Optional[str] = None, - message_encode_policy: Optional[Union["BinaryBase64EncodePolicy", "TextBase64EncodePolicy"]] = None, - message_decode_policy: Optional[Union["BinaryBase64DecodePolicy", "TextBase64DecodePolicy"]] = None, + message_encode_policy: Optional[ + Union["BinaryBase64EncodePolicy", "TextBase64EncodePolicy"] + ] = None, + message_decode_policy: Optional[ + Union["BinaryBase64DecodePolicy", "TextBase64DecodePolicy"] + ] = None, audience: Optional[str] = None, **kwargs: Any ) -> Self: @@ -294,7 +349,9 @@ def from_connection_string( :dedent: 8 :caption: Create the queue client from connection string. """ - account_url, secondary, credential = parse_connection_str(conn_str, credential, "queue") + account_url, secondary, credential = parse_connection_str( + conn_str, credential, "queue" + ) return cls( account_url, queue_name=queue_name, @@ -309,7 +366,11 @@ def from_connection_string( @distributed_trace_async async def create_queue( - self, *, metadata: Optional[Dict[str, str]] = None, timeout: Optional[int] = None, **kwargs: Any + self, + *, + metadata: Optional[Dict[str, str]] = None, + timeout: Optional[int] = None, + **kwargs: Any ) -> None: """Creates a new queue in the storage account. @@ -343,13 +404,19 @@ async def create_queue( headers.update(add_metadata_headers(metadata)) try: return await self._client.queue.create( - metadata=metadata, timeout=timeout, headers=headers, cls=deserialize_queue_creation, **kwargs + metadata=metadata, + timeout=timeout, + headers=headers, + cls=deserialize_queue_creation, + **kwargs ) except HttpResponseError as error: process_storage_error(error) @distributed_trace_async - async def delete_queue(self, *, timeout: Optional[int] = None, **kwargs: Any) -> None: + async def delete_queue( + self, *, timeout: Optional[int] = None, **kwargs: Any + ) -> None: """Deletes the specified queue and any messages it contains. When a queue is successfully deleted, it is immediately marked for deletion @@ -383,7 +450,9 @@ async def delete_queue(self, *, timeout: Optional[int] = None, **kwargs: Any) -> process_storage_error(error) @distributed_trace_async - async def get_queue_properties(self, *, timeout: Optional[int] = None, **kwargs: Any) -> "QueueProperties": + async def get_queue_properties( + self, *, timeout: Optional[int] = None, **kwargs: Any + ) -> "QueueProperties": """Returns all user-defined metadata for the specified queue. The data returned does not include the queue's list of messages. @@ -405,7 +474,9 @@ async def get_queue_properties(self, *, timeout: Optional[int] = None, **kwargs: try: response = cast( "QueueProperties", - await self._client.queue.get_properties(timeout=timeout, cls=deserialize_queue_properties, **kwargs), + await self._client.queue.get_properties( + timeout=timeout, cls=deserialize_queue_properties, **kwargs + ), ) except HttpResponseError as error: process_storage_error(error) @@ -414,7 +485,11 @@ async def get_queue_properties(self, *, timeout: Optional[int] = None, **kwargs: @distributed_trace_async async def set_queue_metadata( - self, metadata: Optional[Dict[str, str]] = None, *, timeout: Optional[int] = None, **kwargs: Any + self, + metadata: Optional[Dict[str, str]] = None, + *, + timeout: Optional[int] = None, + **kwargs: Any ) -> Dict[str, Any]: """Sets user-defined metadata on the specified queue. @@ -451,7 +526,9 @@ async def set_queue_metadata( process_storage_error(error) @distributed_trace_async - async def get_queue_access_policy(self, *, timeout: Optional[int] = None, **kwargs: Any) -> Dict[str, AccessPolicy]: + async def get_queue_access_policy( + self, *, timeout: Optional[int] = None, **kwargs: Any + ) -> Dict[str, AccessPolicy]: """Returns details about any stored access policies specified on the queue that may be used with Shared Access Signatures. @@ -477,7 +554,11 @@ async def get_queue_access_policy(self, *, timeout: Optional[int] = None, **kwar @distributed_trace_async async def set_queue_access_policy( - self, signed_identifiers: Dict[str, AccessPolicy], *, timeout: Optional[int] = None, **kwargs: Any + self, + signed_identifiers: Dict[str, AccessPolicy], + *, + timeout: Optional[int] = None, + **kwargs: Any ) -> None: """Sets stored access policies for the queue that may be used with Shared Access Signatures. @@ -526,7 +607,9 @@ async def set_queue_access_policy( value.expiry = serialize_iso(value.expiry) identifiers.append(SignedIdentifier(id=key, access_policy=value)) try: - await self._client.queue.set_access_policy(queue_acl=identifiers or None, timeout=timeout, **kwargs) + await self._client.queue.set_access_policy( + queue_acl=identifiers or None, timeout=timeout, **kwargs + ) except HttpResponseError as error: process_storage_error(error) @@ -591,7 +674,10 @@ async def send_message( """ if self.key_encryption_key: modify_user_agent_for_encryption( - self._config.user_agent_policy.user_agent, self._sdk_moniker, self.encryption_version, kwargs + self._config.user_agent_policy.user_agent, + self._sdk_moniker, + self.encryption_version, + kwargs, ) try: @@ -602,12 +688,10 @@ async def send_message( encryption_version=self.encryption_version, ) except TypeError: - warnings.warn( - "TypeError when calling message_encode_policy.configure. \ + warnings.warn("TypeError when calling message_encode_policy.configure. \ It is likely missing the encryption_version parameter. \ Consider updating your encryption information/implementation. \ - Retrying without encryption_version." - ) + Retrying without encryption_version.") self._message_encode_policy.configure( require_encryption=self.require_encryption, key_encryption_key=self.key_encryption_key, @@ -638,7 +722,11 @@ async def send_message( @distributed_trace_async async def receive_message( - self, *, visibility_timeout: Optional[int] = None, timeout: Optional[int] = None, **kwargs: Any + self, + *, + visibility_timeout: Optional[int] = None, + timeout: Optional[int] = None, + **kwargs: Any ) -> Optional[QueueMessage]: """Removes one message from the front of the queue. @@ -679,7 +767,10 @@ async def receive_message( """ if self.key_encryption_key or self.key_resolver_function: modify_user_agent_for_encryption( - self._config.user_agent_policy.user_agent, self._sdk_moniker, self.encryption_version, kwargs + self._config.user_agent_policy.user_agent, + self._sdk_moniker, + self.encryption_version, + kwargs, ) self._message_decode_policy.configure( @@ -696,7 +787,9 @@ async def receive_message( **kwargs ) wrapped_message = ( - QueueMessage._from_generated(message[0]) if message != [] else None # pylint: disable=protected-access + QueueMessage._from_generated(message[0]) + if message != [] + else None # pylint: disable=protected-access ) return wrapped_message except HttpResponseError as error: @@ -762,7 +855,10 @@ def receive_messages( """ if self.key_encryption_key or self.key_resolver_function: modify_user_agent_for_encryption( - self._config.user_agent_policy.user_agent, self._sdk_moniker, self.encryption_version, kwargs + self._config.user_agent_policy.user_agent, + self._sdk_moniker, + self.encryption_version, + kwargs, ) self._message_decode_policy.configure( @@ -780,7 +876,9 @@ def receive_messages( ) if max_messages is not None and messages_per_page is not None: if max_messages < messages_per_page: - raise ValueError("max_messages must be greater or equal to messages_per_page") + raise ValueError( + "max_messages must be greater or equal to messages_per_page" + ) return AsyncItemPaged( command, results_per_page=messages_per_page, @@ -853,7 +951,10 @@ async def update_message( """ if self.key_encryption_key or self.key_resolver_function: modify_user_agent_for_encryption( - self._config.user_agent_policy.user_agent, self._sdk_moniker, self.encryption_version, kwargs + self._config.user_agent_policy.user_agent, + self._sdk_moniker, + self.encryption_version, + kwargs, ) if isinstance(message, QueueMessage): @@ -882,14 +983,14 @@ async def update_message( encryption_version=self.encryption_version, ) except TypeError: - warnings.warn( - "TypeError when calling message_encode_policy.configure. \ + warnings.warn("TypeError when calling message_encode_policy.configure. \ It is likely missing the encryption_version parameter. \ Consider updating your encryption information/implementation. \ - Retrying without encryption_version." - ) + Retrying without encryption_version.") self._message_encode_policy.configure( - self.require_encryption, self.key_encryption_key, self.key_resolver_function + self.require_encryption, + self.key_encryption_key, + self.key_resolver_function, ) encoded_message_text = self._message_encode_policy(message_text) updated = GenQueueMessage(message_text=encoded_message_text) @@ -923,7 +1024,11 @@ async def update_message( @distributed_trace_async async def peek_messages( - self, max_messages: Optional[int] = None, *, timeout: Optional[int] = None, **kwargs: Any + self, + max_messages: Optional[int] = None, + *, + timeout: Optional[int] = None, + **kwargs: Any ) -> List[QueueMessage]: """Retrieves one or more messages from the front of the queue, but does not alter the visibility of the message. @@ -969,7 +1074,10 @@ async def peek_messages( if self.key_encryption_key or self.key_resolver_function: modify_user_agent_for_encryption( - self._config.user_agent_policy.user_agent, self._sdk_moniker, self.encryption_version, kwargs + self._config.user_agent_policy.user_agent, + self._sdk_moniker, + self.encryption_version, + kwargs, ) self._message_decode_policy.configure( @@ -979,17 +1087,24 @@ async def peek_messages( ) try: messages = await self._client.messages.peek( - number_of_messages=max_messages, timeout=timeout, cls=self._message_decode_policy, **kwargs + number_of_messages=max_messages, + timeout=timeout, + cls=self._message_decode_policy, + **kwargs ) wrapped_messages = [] for peeked in messages: - wrapped_messages.append(QueueMessage._from_generated(peeked)) # pylint: disable=protected-access + wrapped_messages.append( + QueueMessage._from_generated(peeked) + ) # pylint: disable=protected-access return wrapped_messages except HttpResponseError as error: process_storage_error(error) @distributed_trace_async - async def clear_messages(self, *, timeout: Optional[int] = None, **kwargs: Any) -> None: + async def clear_messages( + self, *, timeout: Optional[int] = None, **kwargs: Any + ) -> None: """Deletes all messages from the specified queue. :keyword int timeout: @@ -1068,7 +1183,10 @@ async def delete_message( raise ValueError("pop_receipt must be present") try: await self._client.message_id.delete( - pop_receipt=receipt, timeout=timeout, queue_message_id=message_id, **kwargs + pop_receipt=receipt, + timeout=timeout, + queue_message_id=message_id, + **kwargs ) except HttpResponseError as error: process_storage_error(error) diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_queue_service_client_async.py b/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_queue_service_client_async.py index dfb65bfccd3a..39f7c9e930bf 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_queue_service_client_async.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_queue_service_client_async.py @@ -19,15 +19,27 @@ from .._encryption import StorageEncryptionMixin from .._generated.aio import AzureQueueStorage from .._generated.models import KeyInfo, StorageServiceProperties -from .._models import CorsRule, QueueProperties, service_properties_deserialize, service_stats_deserialize +from .._models import ( + CorsRule, + QueueProperties, + service_properties_deserialize, + service_stats_deserialize, +) from .._queue_service_client_helpers import _parse_url from .._serialize import get_api_version from .._shared.base_client import StorageAccountHostsMixin -from .._shared.base_client_async import AsyncStorageAccountHostsMixin, AsyncTransportWrapper, parse_connection_str +from .._shared.base_client_async import ( + AsyncStorageAccountHostsMixin, + AsyncTransportWrapper, + parse_connection_str, +) from .._shared.models import LocationMode from .._shared.parser import _to_utc_datetime from .._shared.policies_async import ExponentialRetry -from .._shared.response_handlers import parse_to_internal_user_delegation_key, process_storage_error +from .._shared.response_handlers import ( + parse_to_internal_user_delegation_key, + process_storage_error, +) if TYPE_CHECKING: from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential @@ -95,7 +107,13 @@ def __init__( self, account_url: str, credential: Optional[ - Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "AsyncTokenCredential"] + Union[ + str, + Dict[str, str], + "AzureNamedKeyCredential", + "AzureSasCredential", + "AsyncTokenCredential", + ] ] = None, *, api_version: Optional[str] = None, @@ -103,9 +121,13 @@ def __init__( audience: Optional[str] = None, **kwargs: Any, ) -> None: - kwargs["retry_policy"] = kwargs.get("retry_policy") or ExponentialRetry(**kwargs) + kwargs["retry_policy"] = kwargs.get("retry_policy") or ExponentialRetry( + **kwargs + ) loop = kwargs.pop("loop", None) - parsed_url, sas_token = _parse_url(account_url=account_url, credential=credential) + parsed_url, sas_token = _parse_url( + account_url=account_url, credential=credential + ) self._query_str, credential = self._format_query_string(sas_token, credential) super(QueueServiceClient, self).__init__( parsed_url, @@ -116,7 +138,11 @@ def __init__( **kwargs, ) self._client = AzureQueueStorage( - self.url, get_api_version(api_version), base_url=self.url, pipeline=self._pipeline, loop=loop + self.url, + get_api_version(api_version), + base_url=self.url, + pipeline=self._pipeline, + loop=loop, ) self._loop = loop self._configure_encryption(kwargs) @@ -126,9 +152,14 @@ async def __aenter__(self) -> Self: return self async def __aexit__( - self, typ: Optional[type[BaseException]], exc: Optional[BaseException], tb: Optional[TracebackType] + self, + typ: Optional[type[BaseException]], + exc: Optional[BaseException], + tb: Optional[TracebackType], ) -> None: - await self._client.__aexit__(typ, exc, tb) # pylint: disable=specify-parameter-names-in-call + await self._client.__aexit__( + typ, exc, tb + ) # pylint: disable=specify-parameter-names-in-call async def close(self) -> None: """This method is to close the sockets opened by the client. @@ -154,7 +185,13 @@ def from_connection_string( cls, conn_str: str, credential: Optional[ - Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "AsyncTokenCredential"] + Union[ + str, + Dict[str, str], + "AzureNamedKeyCredential", + "AzureSasCredential", + "AsyncTokenCredential", + ] ] = None, *, api_version: Optional[str] = None, @@ -197,7 +234,9 @@ def from_connection_string( :dedent: 8 :caption: Creating the QueueServiceClient with a connection string. """ - account_url, secondary, credential = parse_connection_str(conn_str, credential, "queue") + account_url, secondary, credential = parse_connection_str( + conn_str, credential, "queue" + ) return cls( account_url, credential=credential, @@ -251,7 +290,9 @@ async def get_user_delegation_key( return parse_to_internal_user_delegation_key(user_delegation_key) @distributed_trace_async - async def get_service_stats(self, *, timeout: Optional[int] = None, **kwargs: Any) -> Dict[str, Any]: + async def get_service_stats( + self, *, timeout: Optional[int] = None, **kwargs: Any + ) -> Dict[str, Any]: """Retrieves statistics related to replication for the Queue service. It is only available when read-access geo-redundant replication is enabled for @@ -284,7 +325,9 @@ async def get_service_stats(self, *, timeout: Optional[int] = None, **kwargs: An process_storage_error(error) @distributed_trace_async - async def get_service_properties(self, *, timeout: Optional[int] = None, **kwargs: Any) -> Dict[str, Any]: + async def get_service_properties( + self, *, timeout: Optional[int] = None, **kwargs: Any + ) -> Dict[str, Any]: """Gets the properties of a storage account's Queue service, including Azure Storage Analytics. @@ -304,7 +347,9 @@ async def get_service_properties(self, *, timeout: Optional[int] = None, **kwarg :caption: Getting queue service properties. """ try: - service_props = await self._client.service.get_properties(timeout=timeout, **kwargs) + service_props = await self._client.service.get_properties( + timeout=timeout, **kwargs + ) return service_properties_deserialize(service_props) except HttpResponseError as error: process_storage_error(error) @@ -425,7 +470,12 @@ def list_queues( @distributed_trace_async async def create_queue( - self, name: str, metadata: Optional[Dict[str, str]] = None, *, timeout: Optional[int] = None, **kwargs: Any + self, + name: str, + metadata: Optional[Dict[str, str]] = None, + *, + timeout: Optional[int] = None, + **kwargs: Any, ) -> QueueClient: """Creates a new queue under the specified account. @@ -458,7 +508,11 @@ async def create_queue( @distributed_trace_async async def delete_queue( - self, queue: Union["QueueProperties", str], *, timeout: Optional[int] = None, **kwargs: Any + self, + queue: Union["QueueProperties", str], + *, + timeout: Optional[int] = None, + **kwargs: Any, ) -> None: """Deletes the specified queue and any messages it contains. @@ -491,7 +545,9 @@ async def delete_queue( kwargs.setdefault("merge_span", True) await queue_client.delete_queue(timeout=timeout, **kwargs) - def get_queue_client(self, queue: Union["QueueProperties", str], **kwargs: Any) -> QueueClient: + def get_queue_client( + self, queue: Union["QueueProperties", str], **kwargs: Any + ) -> QueueClient: """Get a client to interact with the specified queue. The queue need not already exist. @@ -518,7 +574,9 @@ def get_queue_client(self, queue: Union["QueueProperties", str], **kwargs: Any) queue_name = queue _pipeline = AsyncPipeline( - transport=AsyncTransportWrapper(self._pipeline._transport), # pylint: disable=protected-access + transport=AsyncTransportWrapper( + self._pipeline._transport + ), # pylint: disable=protected-access policies=self._pipeline._impl_policies, # type: ignore # pylint: disable=protected-access ) diff --git a/sdk/storage/azure-storage-queue/samples/queue_samples_authentication.py b/sdk/storage/azure-storage-queue/samples/queue_samples_authentication.py index 6219caf5436b..4103b979677d 100644 --- a/sdk/storage/azure-storage-queue/samples/queue_samples_authentication.py +++ b/sdk/storage/azure-storage-queue/samples/queue_samples_authentication.py @@ -25,7 +25,6 @@ 4) STORAGE_ACCOUNT_KEY - the storage account access key """ - from datetime import datetime, timedelta import os import sys @@ -51,7 +50,9 @@ def authentication_by_connection_string(self): # [START auth_from_connection_string] from azure.storage.queue import QueueServiceClient - queue_service = QueueServiceClient.from_connection_string(conn_str=self.connection_string) + queue_service = QueueServiceClient.from_connection_string( + conn_str=self.connection_string + ) # [END auth_from_connection_string] # Get information for the Queue Service @@ -70,7 +71,9 @@ def authentication_by_shared_key(self): # [START create_queue_service_client] from azure.storage.queue import QueueServiceClient - queue_service = QueueServiceClient(account_url=self.account_url, credential=self.access_key) + queue_service = QueueServiceClient( + account_url=self.account_url, credential=self.access_key + ) # [END create_queue_service_client] # Get information for the Queue Service @@ -93,7 +96,9 @@ def authentication_by_oauth(self): # Instantiate a QueueServiceClient using a token credential from azure.storage.queue import QueueServiceClient - queue_service = QueueServiceClient(account_url=self.account_url, credential=token_credential) + queue_service = QueueServiceClient( + account_url=self.account_url, credential=token_credential + ) # [END create_queue_service_client_oauth] # Get information for the Queue Service @@ -116,10 +121,16 @@ def authentication_by_shared_access_signature(self): # Instantiate a QueueServiceClient using a connection string from azure.storage.queue import QueueServiceClient - queue_service = QueueServiceClient.from_connection_string(conn_str=self.connection_string) + queue_service = QueueServiceClient.from_connection_string( + conn_str=self.connection_string + ) # Create a SAS token to use for authentication of a client - from azure.storage.queue import generate_account_sas, ResourceTypes, AccountSasPermissions + from azure.storage.queue import ( + generate_account_sas, + ResourceTypes, + AccountSasPermissions, + ) sas_token = generate_account_sas( self.account_name, @@ -129,7 +140,9 @@ def authentication_by_shared_access_signature(self): expiry=datetime.utcnow() + timedelta(hours=1), ) - token_auth_queue_service = QueueServiceClient(account_url=self.account_url, credential=sas_token) + token_auth_queue_service = QueueServiceClient( + account_url=self.account_url, credential=sas_token + ) # Get information for the Queue Service properties = token_auth_queue_service.get_service_properties() diff --git a/sdk/storage/azure-storage-queue/samples/queue_samples_authentication_async.py b/sdk/storage/azure-storage-queue/samples/queue_samples_authentication_async.py index c109df896b73..848552d0bff7 100644 --- a/sdk/storage/azure-storage-queue/samples/queue_samples_authentication_async.py +++ b/sdk/storage/azure-storage-queue/samples/queue_samples_authentication_async.py @@ -25,7 +25,6 @@ 4) STORAGE_ACCOUNT_KEY - the storage account access key """ - from datetime import datetime, timedelta import asyncio import os @@ -52,7 +51,9 @@ async def authentication_by_connection_string_async(self): # [START async_auth_from_connection_string] from azure.storage.queue.aio import QueueServiceClient - queue_service = QueueServiceClient.from_connection_string(conn_str=self.connection_string) + queue_service = QueueServiceClient.from_connection_string( + conn_str=self.connection_string + ) # [END async_auth_from_connection_string] # Get information for the Queue Service @@ -72,7 +73,9 @@ async def authentication_by_shared_key_async(self): # [START async_create_queue_service_client] from azure.storage.queue.aio import QueueServiceClient - queue_service = QueueServiceClient(account_url=self.account_url, credential=self.access_key) + queue_service = QueueServiceClient( + account_url=self.account_url, credential=self.access_key + ) # [END async_create_queue_service_client] # Get information for the Queue Service async with queue_service: @@ -95,7 +98,9 @@ async def authentication_by_oauth_async(self): # Instantiate a QueueServiceClient using a token credential from azure.storage.queue.aio import QueueServiceClient - queue_service = QueueServiceClient(account_url=self.account_url, credential=token_credential) + queue_service = QueueServiceClient( + account_url=self.account_url, credential=token_credential + ) # [END async_create_queue_service_client_oauth] # Get information for the Queue Service @@ -119,10 +124,16 @@ async def authentication_by_shared_access_signature_async(self): # Instantiate a QueueServiceClient using a connection string from azure.storage.queue.aio import QueueServiceClient - queue_service = QueueServiceClient.from_connection_string(conn_str=self.connection_string) + queue_service = QueueServiceClient.from_connection_string( + conn_str=self.connection_string + ) # Create a SAS token to use for authentication of a client - from azure.storage.queue import generate_account_sas, ResourceTypes, AccountSasPermissions + from azure.storage.queue import ( + generate_account_sas, + ResourceTypes, + AccountSasPermissions, + ) sas_token = generate_account_sas( self.account_name, @@ -131,7 +142,9 @@ async def authentication_by_shared_access_signature_async(self): permission=AccountSasPermissions(read=True), expiry=datetime.utcnow() + timedelta(hours=1), ) - token_auth_queue_service = QueueServiceClient(account_url=self.account_url, credential=sas_token) + token_auth_queue_service = QueueServiceClient( + account_url=self.account_url, credential=sas_token + ) # Get information for the Queue Service async with token_auth_queue_service: diff --git a/sdk/storage/azure-storage-queue/samples/queue_samples_hello_world.py b/sdk/storage/azure-storage-queue/samples/queue_samples_hello_world.py index 03969be87f7d..f82108505bc7 100644 --- a/sdk/storage/azure-storage-queue/samples/queue_samples_hello_world.py +++ b/sdk/storage/azure-storage-queue/samples/queue_samples_hello_world.py @@ -40,7 +40,9 @@ def create_client_with_connection_string(self): # Instantiate the QueueServiceClient from a connection string from azure.storage.queue import QueueServiceClient - queue_service = QueueServiceClient.from_connection_string(conn_str=self.connection_string) + queue_service = QueueServiceClient.from_connection_string( + conn_str=self.connection_string + ) # Get queue service properties properties = queue_service.get_service_properties() @@ -57,7 +59,9 @@ def queue_and_messages_example(self): # Instantiate the QueueClient from a connection string from azure.storage.queue import QueueClient - queue = QueueClient.from_connection_string(conn_str=self.connection_string, queue_name="myqueue") + queue = QueueClient.from_connection_string( + conn_str=self.connection_string, queue_name="myqueue" + ) # Create the queue # [START create_queue] diff --git a/sdk/storage/azure-storage-queue/samples/queue_samples_hello_world_async.py b/sdk/storage/azure-storage-queue/samples/queue_samples_hello_world_async.py index 46803f90cda5..05f7f2096272 100644 --- a/sdk/storage/azure-storage-queue/samples/queue_samples_hello_world_async.py +++ b/sdk/storage/azure-storage-queue/samples/queue_samples_hello_world_async.py @@ -20,7 +20,6 @@ 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ - import asyncio import os import sys @@ -42,7 +41,9 @@ async def create_client_with_connection_string_async(self): # Instantiate the QueueServiceClient from a connection string from azure.storage.queue.aio import QueueServiceClient - queue_service = QueueServiceClient.from_connection_string(conn_str=self.connection_string) + queue_service = QueueServiceClient.from_connection_string( + conn_str=self.connection_string + ) # Get queue service properties async with queue_service: @@ -60,7 +61,9 @@ async def queue_and_messages_example_async(self): # Instantiate the QueueClient from a connection string from azure.storage.queue.aio import QueueClient - queue = QueueClient.from_connection_string(conn_str=self.connection_string, queue_name="asyncmyqueue") + queue = QueueClient.from_connection_string( + conn_str=self.connection_string, queue_name="asyncmyqueue" + ) async with queue: # Create the queue @@ -71,7 +74,8 @@ async def queue_and_messages_example_async(self): try: # Send messages await asyncio.gather( - queue.send_message("I'm using queues!"), queue.send_message("This is my second message") + queue.send_message("I'm using queues!"), + queue.send_message("This is my second message"), ) # Receive the messages diff --git a/sdk/storage/azure-storage-queue/samples/queue_samples_message.py b/sdk/storage/azure-storage-queue/samples/queue_samples_message.py index 1320ab463224..e216ee981ccd 100644 --- a/sdk/storage/azure-storage-queue/samples/queue_samples_message.py +++ b/sdk/storage/azure-storage-queue/samples/queue_samples_message.py @@ -22,7 +22,6 @@ 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ - from datetime import datetime, timedelta import os import sys @@ -42,7 +41,11 @@ def set_access_policy(self): queue = QueueClient.from_connection_string(self.connection_string, "myqueue1") if queue.account_name is None: - print("Connection string did not provide an account name." + "\n" + "Test: set_access_policy") + print( + "Connection string did not provide an account name." + + "\n" + + "Test: set_access_policy" + ) sys.exit(1) # [END create_queue_client_from_connection_string] @@ -72,13 +75,18 @@ def set_access_policy(self): from azure.storage.queue import generate_queue_sas sas_token = generate_queue_sas( - queue.account_name, queue.queue_name, queue.credential.account_key, policy_id="my-access-policy-id" + queue.account_name, + queue.queue_name, + queue.credential.account_key, + policy_id="my-access-policy-id", ) # [END queue_client_sas_token] # Authenticate with the sas token # [START create_queue_client] - token_auth_queue = QueueClient.from_queue_url(queue_url=queue.url, credential=sas_token) + token_auth_queue = QueueClient.from_queue_url( + queue_url=queue.url, credential=sas_token + ) # [END create_queue_client] # Use the newly authenticated client to receive messages @@ -131,7 +139,9 @@ def send_and_receive_messages(self): try: # [START send_messages] queue.send_message("message1") - queue.send_message("message2", visibility_timeout=30) # wait 30s before becoming visible + queue.send_message( + "message2", visibility_timeout=30 + ) # wait 30s before becoming visible queue.send_message("message3") queue.send_message("message4") queue.send_message("message5") @@ -333,7 +343,10 @@ def update_message(self): # Update the message list_result = next(messages) message = queue.update_message( - list_result.id, pop_receipt=list_result.pop_receipt, visibility_timeout=0, content="updated" + list_result.id, + pop_receipt=list_result.pop_receipt, + visibility_timeout=0, + content="updated", ) # [END update_message] diff --git a/sdk/storage/azure-storage-queue/samples/queue_samples_message_async.py b/sdk/storage/azure-storage-queue/samples/queue_samples_message_async.py index 1fa4ac924b99..861e640cca96 100644 --- a/sdk/storage/azure-storage-queue/samples/queue_samples_message_async.py +++ b/sdk/storage/azure-storage-queue/samples/queue_samples_message_async.py @@ -40,9 +40,15 @@ async def set_access_policy_async(self): # [START async_create_queue_client_from_connection_string] from azure.storage.queue.aio import QueueClient - queue = QueueClient.from_connection_string(self.connection_string, "myqueueasync1") + queue = QueueClient.from_connection_string( + self.connection_string, "myqueueasync1" + ) if queue.account_name is None: - print("Connection string did not provide an account name." + "\n" + "Test: set_access_policy_async") + print( + "Connection string did not provide an account name." + + "\n" + + "Test: set_access_policy_async" + ) sys.exit(1) # [END async_create_queue_client_from_connection_string] @@ -72,12 +78,17 @@ async def set_access_policy_async(self): from azure.storage.queue import generate_queue_sas sas_token = generate_queue_sas( - queue.account_name, queue.queue_name, queue.credential.account_key, policy_id="my-access-policy-id" + queue.account_name, + queue.queue_name, + queue.credential.account_key, + policy_id="my-access-policy-id", ) # Authenticate with the sas token # [START async_create_queue_client] - token_auth_queue = QueueClient.from_queue_url(queue_url=queue.url, credential=sas_token) + token_auth_queue = QueueClient.from_queue_url( + queue_url=queue.url, credential=sas_token + ) # [END async_create_queue_client] # Use the newly authenticated client to receive messages @@ -95,7 +106,9 @@ async def queue_metadata_async(self): # Instantiate a queue client from azure.storage.queue.aio import QueueClient - queue = QueueClient.from_connection_string(self.connection_string, "myqueueasync2") + queue = QueueClient.from_connection_string( + self.connection_string, "myqueueasync2" + ) # Create the queue async with queue: @@ -123,7 +136,9 @@ async def send_and_receive_messages_async(self): # Instantiate a queue client from azure.storage.queue.aio import QueueClient - queue = QueueClient.from_connection_string(self.connection_string, "myqueueasync3") + queue = QueueClient.from_connection_string( + self.connection_string, "myqueueasync3" + ) # Create the queue async with queue: @@ -133,7 +148,9 @@ async def send_and_receive_messages_async(self): # [START async_send_messages] await asyncio.gather( queue.send_message("message1"), - queue.send_message("message2", visibility_timeout=30), # wait 30s before becoming visible + queue.send_message( + "message2", visibility_timeout=30 + ), # wait 30s before becoming visible queue.send_message("message3"), queue.send_message("message4"), queue.send_message("message5"), @@ -172,7 +189,9 @@ async def receive_one_message_from_queue(self): # Instantiate a queue client from azure.storage.queue.aio import QueueClient - queue = QueueClient.from_connection_string(self.connection_string, "myqueueasync4") + queue = QueueClient.from_connection_string( + self.connection_string, "myqueueasync4" + ) # Create the queue async with queue: @@ -180,7 +199,9 @@ async def receive_one_message_from_queue(self): try: await asyncio.gather( - queue.send_message("message1"), queue.send_message("message2"), queue.send_message("message3") + queue.send_message("message1"), + queue.send_message("message2"), + queue.send_message("message3"), ) # [START receive_one_message] @@ -209,7 +230,9 @@ async def delete_and_clear_messages_async(self): # Instantiate a queue client from azure.storage.queue.aio import QueueClient - queue = QueueClient.from_connection_string(self.connection_string, "myqueueasync5") + queue = QueueClient.from_connection_string( + self.connection_string, "myqueueasync5" + ) # Create the queue async with queue: @@ -250,7 +273,9 @@ async def peek_messages_async(self): # Instantiate a queue client from azure.storage.queue.aio import QueueClient - queue = QueueClient.from_connection_string(self.connection_string, "myqueueasync6") + queue = QueueClient.from_connection_string( + self.connection_string, "myqueueasync6" + ) # Create the queue async with queue: @@ -290,7 +315,9 @@ async def update_message_async(self): # Instantiate a queue client from azure.storage.queue.aio import QueueClient - queue = QueueClient.from_connection_string(self.connection_string, "myqueueasync7") + queue = QueueClient.from_connection_string( + self.connection_string, "myqueueasync7" + ) # Create the queue async with queue: @@ -306,7 +333,9 @@ async def update_message_async(self): # Update the message async for message in messages: - message = await queue.update_message(message, visibility_timeout=0, content="updated") + message = await queue.update_message( + message, visibility_timeout=0, content="updated" + ) # [END async_update_message] break @@ -322,7 +351,9 @@ async def receive_messages_with_max_messages(self): # Instantiate a queue client from azure.storage.queue.aio import QueueClient - queue = QueueClient.from_connection_string(self.connection_string, "myqueueasync8") + queue = QueueClient.from_connection_string( + self.connection_string, "myqueueasync8" + ) # Create the queue async with queue: diff --git a/sdk/storage/azure-storage-queue/samples/queue_samples_service.py b/sdk/storage/azure-storage-queue/samples/queue_samples_service.py index b537470edb93..25acaa9a8e6c 100644 --- a/sdk/storage/azure-storage-queue/samples/queue_samples_service.py +++ b/sdk/storage/azure-storage-queue/samples/queue_samples_service.py @@ -36,21 +36,37 @@ def queue_service_properties(self): # Instantiate the QueueServiceClient from a connection string from azure.storage.queue import QueueServiceClient - queue_service = QueueServiceClient.from_connection_string(conn_str=self.connection_string) + queue_service = QueueServiceClient.from_connection_string( + conn_str=self.connection_string + ) # [START set_queue_service_properties] # Create service properties - from azure.storage.queue import QueueAnalyticsLogging, Metrics, CorsRule, RetentionPolicy + from azure.storage.queue import ( + QueueAnalyticsLogging, + Metrics, + CorsRule, + RetentionPolicy, + ) # Create logging settings logging = QueueAnalyticsLogging( - read=True, write=True, delete=True, retention_policy=RetentionPolicy(enabled=True, days=5) + read=True, + write=True, + delete=True, + retention_policy=RetentionPolicy(enabled=True, days=5), ) # Create metrics for requests statistics - hour_metrics = Metrics(enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5)) + hour_metrics = Metrics( + enabled=True, + include_apis=True, + retention_policy=RetentionPolicy(enabled=True, days=5), + ) minute_metrics = Metrics( - enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5) + enabled=True, + include_apis=True, + retention_policy=RetentionPolicy(enabled=True, days=5), ) # Create CORS rules @@ -58,8 +74,18 @@ def queue_service_properties(self): allowed_origins = ["www.xyz.com", "www.ab.com", "www.bc.com"] allowed_methods = ["GET", "PUT"] max_age_in_seconds = 500 - exposed_headers = ["x-ms-meta-data*", "x-ms-meta-source*", "x-ms-meta-abc", "x-ms-meta-bcd"] - allowed_headers = ["x-ms-meta-data*", "x-ms-meta-target*", "x-ms-meta-xyz", "x-ms-meta-foo"] + exposed_headers = [ + "x-ms-meta-data*", + "x-ms-meta-source*", + "x-ms-meta-abc", + "x-ms-meta-bcd", + ] + allowed_headers = [ + "x-ms-meta-data*", + "x-ms-meta-target*", + "x-ms-meta-xyz", + "x-ms-meta-foo", + ] cors_rule2 = CorsRule( allowed_origins, allowed_methods, @@ -71,7 +97,9 @@ def queue_service_properties(self): cors = [cors_rule1, cors_rule2] # Set the service properties - queue_service.set_service_properties(logging, hour_metrics, minute_metrics, cors) + queue_service.set_service_properties( + logging, hour_metrics, minute_metrics, cors + ) # [END set_queue_service_properties] # [START get_queue_service_properties] @@ -86,7 +114,9 @@ def queues_in_account(self): # Instantiate the QueueServiceClient from a connection string from azure.storage.queue import QueueServiceClient - queue_service = QueueServiceClient.from_connection_string(conn_str=self.connection_string) + queue_service = QueueServiceClient.from_connection_string( + conn_str=self.connection_string + ) # [START qsc_create_queue] queue_service.create_queue("myqueueservice1") @@ -118,7 +148,9 @@ def get_queue_client(self): # Instantiate the QueueServiceClient from a connection string from azure.storage.queue import QueueServiceClient, QueueClient - queue_service = QueueServiceClient.from_connection_string(conn_str=self.connection_string) + queue_service = QueueServiceClient.from_connection_string( + conn_str=self.connection_string + ) # [START get_queue_client] # Get the queue client to interact with a specific queue diff --git a/sdk/storage/azure-storage-queue/samples/queue_samples_service_async.py b/sdk/storage/azure-storage-queue/samples/queue_samples_service_async.py index 7b6d669fa6f5..eab448d09aa2 100644 --- a/sdk/storage/azure-storage-queue/samples/queue_samples_service_async.py +++ b/sdk/storage/azure-storage-queue/samples/queue_samples_service_async.py @@ -20,7 +20,6 @@ 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ - import asyncio import os import sys @@ -38,24 +37,38 @@ async def queue_service_properties_async(self): # Instantiate the QueueServiceClient from a connection string from azure.storage.queue.aio import QueueServiceClient - queue_service = QueueServiceClient.from_connection_string(conn_str=self.connection_string) + queue_service = QueueServiceClient.from_connection_string( + conn_str=self.connection_string + ) async with queue_service: # [START async_set_queue_service_properties] # Create service properties - from azure.storage.queue import QueueAnalyticsLogging, Metrics, CorsRule, RetentionPolicy + from azure.storage.queue import ( + QueueAnalyticsLogging, + Metrics, + CorsRule, + RetentionPolicy, + ) # Create logging settings logging = QueueAnalyticsLogging( - read=True, write=True, delete=True, retention_policy=RetentionPolicy(enabled=True, days=5) + read=True, + write=True, + delete=True, + retention_policy=RetentionPolicy(enabled=True, days=5), ) # Create metrics for requests statistics hour_metrics = Metrics( - enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5) + enabled=True, + include_apis=True, + retention_policy=RetentionPolicy(enabled=True, days=5), ) minute_metrics = Metrics( - enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5) + enabled=True, + include_apis=True, + retention_policy=RetentionPolicy(enabled=True, days=5), ) # Create CORS rules @@ -63,8 +76,18 @@ async def queue_service_properties_async(self): allowed_origins = ["www.xyz.com", "www.ab.com", "www.bc.com"] allowed_methods = ["GET", "PUT"] max_age_in_seconds = 500 - exposed_headers = ["x-ms-meta-data*", "x-ms-meta-source*", "x-ms-meta-abc", "x-ms-meta-bcd"] - allowed_headers = ["x-ms-meta-data*", "x-ms-meta-target*", "x-ms-meta-xyz", "x-ms-meta-foo"] + exposed_headers = [ + "x-ms-meta-data*", + "x-ms-meta-source*", + "x-ms-meta-abc", + "x-ms-meta-bcd", + ] + allowed_headers = [ + "x-ms-meta-data*", + "x-ms-meta-target*", + "x-ms-meta-xyz", + "x-ms-meta-foo", + ] cors_rule2 = CorsRule( allowed_origins, allowed_methods, @@ -76,7 +99,9 @@ async def queue_service_properties_async(self): cors = [cors_rule1, cors_rule2] # Set the service properties - await queue_service.set_service_properties(logging, hour_metrics, minute_metrics, cors) + await queue_service.set_service_properties( + logging, hour_metrics, minute_metrics, cors + ) # [END async_set_queue_service_properties] # [START async_get_queue_service_properties] @@ -91,7 +116,9 @@ async def queues_in_account_async(self): # Instantiate the QueueServiceClient from a connection string from azure.storage.queue.aio import QueueServiceClient - queue_service = QueueServiceClient.from_connection_string(conn_str=self.connection_string) + queue_service = QueueServiceClient.from_connection_string( + conn_str=self.connection_string + ) async with queue_service: # [START async_qsc_create_queue] @@ -124,7 +151,9 @@ async def get_queue_client_async(self): # Instantiate the QueueServiceClient from a connection string from azure.storage.queue.aio import QueueServiceClient, QueueClient - queue_service = QueueServiceClient.from_connection_string(conn_str=self.connection_string) + queue_service = QueueServiceClient.from_connection_string( + conn_str=self.connection_string + ) # [START async_get_queue_client] # Get the queue client to interact with a specific queue diff --git a/sdk/storage/azure-storage-queue/setup.py b/sdk/storage/azure-storage-queue/setup.py index ac028b43a7a5..a3791f2a8895 100644 --- a/sdk/storage/azure-storage-queue/setup.py +++ b/sdk/storage/azure-storage-queue/setup.py @@ -69,7 +69,12 @@ ] ), python_requires=">=3.9", - install_requires=["azure-core>=1.37.0", "cryptography>=2.1.4", "typing-extensions>=4.6.0", "isodate>=0.6.1"], + install_requires=[ + "azure-core>=1.37.0", + "cryptography>=2.1.4", + "typing-extensions>=4.6.0", + "isodate>=0.6.1", + ], extras_require={ "aio": [ "azure-core[aio]>=1.37.0", diff --git a/sdk/storage/azure-storage-queue/tests/conftest.py b/sdk/storage/azure-storage-queue/tests/conftest.py index 2dd5fe8af6e4..44b62a8ba46f 100644 --- a/sdk/storage/azure-storage-queue/tests/conftest.py +++ b/sdk/storage/azure-storage-queue/tests/conftest.py @@ -21,17 +21,28 @@ @pytest.fixture(scope="session", autouse=True) def add_sanitizers(test_proxy): - subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") - tenant_id = os.environ.get("STORAGE_TENANT_ID", "00000000-0000-0000-0000-000000000000") - add_general_regex_sanitizer(regex=subscription_id, value="00000000-0000-0000-0000-000000000000") - add_general_regex_sanitizer(regex=tenant_id, value="00000000-0000-0000-0000-000000000000") + subscription_id = os.environ.get( + "AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000" + ) + tenant_id = os.environ.get( + "STORAGE_TENANT_ID", "00000000-0000-0000-0000-000000000000" + ) + add_general_regex_sanitizer( + regex=subscription_id, value="00000000-0000-0000-0000-000000000000" + ) + add_general_regex_sanitizer( + regex=tenant_id, value="00000000-0000-0000-0000-000000000000" + ) add_header_regex_sanitizer(key="Set-Cookie", value="[set-cookie;]") add_header_regex_sanitizer(key="Cookie", value="cookie;") add_oauth_response_sanitizer() add_header_regex_sanitizer(key="x-ms-copy-source-authorization", value="Sanitized") add_header_regex_sanitizer(key="x-ms-encryption-key", value="Sanitized") - add_general_regex_sanitizer(regex=r'"EncryptionLibrary": "Python .*?"', value='"EncryptionLibrary": "Python x.x.x"') + add_general_regex_sanitizer( + regex=r'"EncryptionLibrary": "Python .*?"', + value='"EncryptionLibrary": "Python x.x.x"', + ) add_uri_string_sanitizer(target=".preprod.", value=".") add_uri_regex_sanitizer( diff --git a/sdk/storage/azure-storage-queue/tests/encryption_test_helper.py b/sdk/storage/azure-storage-queue/tests/encryption_test_helper.py index d54df3de963b..07f3e4896872 100644 --- a/sdk/storage/azure-storage-queue/tests/encryption_test_helper.py +++ b/sdk/storage/azure-storage-queue/tests/encryption_test_helper.py @@ -55,14 +55,19 @@ def resolve_key(self, kid): class RSAKeyWrapper: def __init__(self, kid="local:key2"): - self.private_key = generate_private_key(public_exponent=65537, key_size=2048, backend=default_backend()) + self.private_key = generate_private_key( + public_exponent=65537, key_size=2048, backend=default_backend() + ) self.public_key = self.private_key.public_key() self.kid = kid def wrap_key(self, key, algorithm="RSA"): if algorithm == "RSA": return self.public_key.encrypt( - key, OAEP(mgf=MGF1(algorithm=SHA1()), algorithm=SHA1(), label=None) # nosec # nosec + key, + OAEP( + mgf=MGF1(algorithm=SHA1()), algorithm=SHA1(), label=None + ), # nosec # nosec ) raise ValueError(_ERROR_UNKNOWN_KEY_WRAP_ALGORITHM) @@ -70,7 +75,10 @@ def wrap_key(self, key, algorithm="RSA"): def unwrap_key(self, key, algorithm): if algorithm == "RSA": return self.private_key.decrypt( - key, OAEP(mgf=MGF1(algorithm=SHA1()), algorithm=SHA1(), label=None) # nosec # nosec + key, + OAEP( + mgf=MGF1(algorithm=SHA1()), algorithm=SHA1(), label=None + ), # nosec # nosec ) raise ValueError(_ERROR_UNKNOWN_KEY_WRAP_ALGORITHM) diff --git a/sdk/storage/azure-storage-queue/tests/settings/testcase.py b/sdk/storage/azure-storage-queue/tests/settings/testcase.py index 5598f9302918..562121a4772c 100644 --- a/sdk/storage/azure-storage-queue/tests/settings/testcase.py +++ b/sdk/storage/azure-storage-queue/tests/settings/testcase.py @@ -28,11 +28,19 @@ LOGGING_FORMAT = "%(asctime)s %(name)-20s %(levelname)-5s %(message)s" -os.environ["STORAGE_ACCOUNT_NAME"] = os.environ.get("STORAGE_ACCOUNT_NAME", None) or STORAGE_ACCOUNT_NAME -os.environ["STORAGE_ACCOUNT_KEY"] = os.environ.get("STORAGE_ACCOUNT_KEY", None) or STORAGE_ACCOUNT_KEY +os.environ["STORAGE_ACCOUNT_NAME"] = ( + os.environ.get("STORAGE_ACCOUNT_NAME", None) or STORAGE_ACCOUNT_NAME +) +os.environ["STORAGE_ACCOUNT_KEY"] = ( + os.environ.get("STORAGE_ACCOUNT_KEY", None) or STORAGE_ACCOUNT_KEY +) -os.environ["AZURE_TEST_RUN_LIVE"] = os.environ.get("AZURE_TEST_RUN_LIVE", None) or RUN_IN_LIVE -os.environ["AZURE_SKIP_LIVE_RECORDING"] = os.environ.get("AZURE_SKIP_LIVE_RECORDING", None) or SKIP_LIVE_RECORDING +os.environ["AZURE_TEST_RUN_LIVE"] = ( + os.environ.get("AZURE_TEST_RUN_LIVE", None) or RUN_IN_LIVE +) +os.environ["AZURE_SKIP_LIVE_RECORDING"] = ( + os.environ.get("AZURE_SKIP_LIVE_RECORDING", None) or SKIP_LIVE_RECORDING +) os.environ["PROTOCOL"] = PROTOCOL os.environ["ACCOUNT_URL_SUFFIX"] = ACCOUNT_URL_SUFFIX diff --git a/sdk/storage/azure-storage-queue/tests/test_queue.py b/sdk/storage/azure-storage-queue/tests/test_queue.py index b010159d7490..ab88a435a127 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue.py @@ -62,7 +62,9 @@ def test_create_queue(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) created = queue_client.create_queue() @@ -76,7 +78,9 @@ def test_create_queue_fail_on_exist(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) created = queue_client.create_queue() with pytest.raises(ResourceExistsError): @@ -128,7 +132,9 @@ def test_delete_non_existing_queue(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) # Asserts @@ -142,7 +148,9 @@ def test_delete_existing_queue_fail_not_exist(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) created = queue_client.create_queue() @@ -158,7 +166,9 @@ def test_list_queues(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queues = list(qsc.list_queues()) @@ -175,18 +185,22 @@ def test_list_queues_with_options(self, **kwargs): # Arrange prefix = "listqueue" - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_list = [] for i in range(0, 4): self._create_queue(qsc, prefix + str(i), queue_list) # Action - generator1 = qsc.list_queues(name_starts_with=prefix, results_per_page=3).by_page() + generator1 = qsc.list_queues( + name_starts_with=prefix, results_per_page=3 + ).by_page() queues1 = list(next(generator1)) - generator2 = qsc.list_queues(name_starts_with=prefix, include_metadata=True).by_page( - generator1.continuation_token - ) + generator2 = qsc.list_queues( + name_starts_with=prefix, include_metadata=True + ).by_page(generator1.continuation_token) queues2 = list(next(generator2)) # Asserts @@ -209,13 +223,19 @@ def test_list_queues_with_metadata(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = self._get_queue_reference(qsc) queue.create_queue() queue.set_queue_metadata(metadata={"val1": "test", "val2": "blah"}) listed_queue = list( - qsc.list_queues(name_starts_with=queue.queue_name, results_per_page=1, include_metadata=True) + qsc.list_queues( + name_starts_with=queue.queue_name, + results_per_page=1, + include_metadata=True, + ) )[0] # Asserts @@ -232,7 +252,9 @@ def test_list_queues_account_sas(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() sas_token = self.generate_sas( @@ -245,7 +267,9 @@ def test_list_queues_account_sas(self, **kwargs): ) # Act - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), credential=sas_token) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), credential=sas_token + ) queues = list(qsc.list_queues()) # Assert @@ -259,7 +283,9 @@ def test_set_queue_metadata(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = self._get_queue_reference(qsc) metadata = {"hello": "world", "number": "43"} queue.create_queue() @@ -277,7 +303,9 @@ def test_get_queue_metadata_message_count(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() sent_message = queue_client.send_message("message1") @@ -295,7 +323,9 @@ def test_queue_exists(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = self._get_queue_reference(qsc) queue.create_queue() @@ -312,7 +342,9 @@ def test_queue_not_exists(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = qsc.get_queue_client(self.get_resource_name("missing")) # Act with pytest.raises(ResourceNotFoundError): @@ -327,7 +359,9 @@ def test_put_message(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action. No exception means pass. No asserts needed. - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -350,7 +384,9 @@ def test_put_message_large_time_to_live(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() # There should be no upper bound on a queue message's time to live @@ -360,7 +396,9 @@ def test_put_message_large_time_to_live(self, **kwargs): messages = queue_client.peek_messages() # Assert - assert messages[0].expires_on >= (messages[0].inserted_on + timedelta(seconds=1024 * 1024 * 1024 - 3600)) + assert messages[0].expires_on >= ( + messages[0].inserted_on + timedelta(seconds=1024 * 1024 * 1024 - 3600) + ) @QueuePreparer() @recorded_by_proxy @@ -369,7 +407,9 @@ def test_put_message_infinite_time_to_live(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1", time_to_live=-1) @@ -387,7 +427,9 @@ def test_get_messages(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -415,7 +457,9 @@ def test_receive_one_message(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() assert queue_client.receive_message() is None @@ -451,14 +495,18 @@ def test_get_messages_with_options(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") queue_client.send_message("message2") queue_client.send_message("message3") queue_client.send_message("message4") - pager = queue_client.receive_messages(messages_per_page=4, visibility_timeout=20) + pager = queue_client.receive_messages( + messages_per_page=4, visibility_timeout=20 + ) result = list(pager) # Asserts @@ -482,7 +530,9 @@ def test_get_messages_with_max_messages(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -519,7 +569,9 @@ def test_get_messages_with_too_little_messages(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -551,7 +603,9 @@ def test_get_messages_with_page_bigger_than_max(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -571,7 +625,9 @@ def test_get_messages_with_remainder(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -627,7 +683,9 @@ def test_peek_messages(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -656,7 +714,9 @@ def test_peek_messages_with_options(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -685,7 +745,9 @@ def test_clear_messages(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -706,7 +768,9 @@ def test_delete_message(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -730,7 +794,9 @@ def test_update_message(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -767,7 +833,9 @@ def test_update_message_content(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -775,7 +843,10 @@ def test_update_message_content(self, **kwargs): messages = queue_client.receive_messages() list_result1 = next(messages) message = queue_client.update_message( - list_result1.id, pop_receipt=list_result1.pop_receipt, visibility_timeout=0, content="new text" + list_result1.id, + pop_receipt=list_result1.pop_receipt, + visibility_timeout=0, + content="new text", ) list_result2 = next(messages) @@ -806,7 +877,9 @@ def test_account_sas(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -844,8 +917,12 @@ def test_azure_named_key_credential_access(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - named_key = AzureNamedKeyCredential(storage_account_name, storage_account_key.secret) - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), named_key) + named_key = AzureNamedKeyCredential( + storage_account_name, storage_account_key.secret + ) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), named_key + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -863,7 +940,8 @@ def test_account_sas_raises_if_sas_already_in_uri(self, **kwargs): with pytest.raises(ValueError): QueueServiceClient( - self.account_url(storage_account_name, "queue") + "?sig=foo", credential=AzureSasCredential("?foo=bar") + self.account_url(storage_account_name, "queue") + "?sig=foo", + credential=AzureSasCredential("?foo=bar"), ) @pytest.mark.live_test_only @@ -875,18 +953,24 @@ def test_token_credential(self, **kwargs): token_credential = self.get_credential(QueueServiceClient) # Action 1: make sure token works - service = QueueServiceClient(self.account_url(storage_account_name, "queue"), credential=token_credential) + service = QueueServiceClient( + self.account_url(storage_account_name, "queue"), credential=token_credential + ) queues = service.get_service_properties() assert queues is not None # Action 2: change token value to make request fail fake_credential = FakeTokenCredential() - service = QueueServiceClient(self.account_url(storage_account_name, "queue"), credential=fake_credential) + service = QueueServiceClient( + self.account_url(storage_account_name, "queue"), credential=fake_credential + ) with pytest.raises(ClientAuthenticationError): list(service.list_queues()) # Action 3: update token to make it working again - service = QueueServiceClient(self.account_url(storage_account_name, "queue"), credential=token_credential) + service = QueueServiceClient( + self.account_url(storage_account_name, "queue"), credential=token_credential + ) queues = list(service.list_queues()) assert queues is not None @@ -897,7 +981,9 @@ def test_sas_read(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -933,7 +1019,9 @@ def test_sas_add(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() token = self.generate_sas( @@ -963,7 +1051,9 @@ def test_sas_update(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -1001,7 +1091,9 @@ def test_sas_process(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -1035,15 +1127,21 @@ def test_sas_signed_identifier(self, **kwargs): # Arrange access_policy = AccessPolicy() - start_time = self.get_datetime_variable(variables, "start_time", datetime.utcnow() - timedelta(hours=1)) - expiry_time = self.get_datetime_variable(variables, "expiry_time", datetime.utcnow() + timedelta(hours=1)) + start_time = self.get_datetime_variable( + variables, "start_time", datetime.utcnow() - timedelta(hours=1) + ) + expiry_time = self.get_datetime_variable( + variables, "expiry_time", datetime.utcnow() + timedelta(hours=1) + ) access_policy.start = start_time access_policy.expiry = expiry_time access_policy.permission = QueueSasPermissions(read=True) identifiers = {"testid": access_policy} - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() resp = queue_client.set_queue_access_policy(identifiers) @@ -1082,7 +1180,9 @@ def test_get_queue_acl(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() @@ -1100,7 +1200,9 @@ def test_get_queue_acl_iter(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() @@ -1120,7 +1222,9 @@ def test_get_queue_acl_with_non_existing_queue(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) # Act @@ -1136,7 +1240,9 @@ def test_set_queue_acl(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() @@ -1155,7 +1261,9 @@ def test_set_queue_acl_with_empty_signed_identifiers(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() @@ -1174,7 +1282,9 @@ def test_set_queue_acl_with_empty_signed_identifier(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() @@ -1198,14 +1308,24 @@ def test_set_queue_acl_with_signed_identifiers(self, **kwargs): variables = kwargs.pop("variables", {}) # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() # Act - expiry_time = self.get_datetime_variable(variables, "expiry_time", datetime.utcnow() + timedelta(hours=1)) - start_time = self.get_datetime_variable(variables, "start_time", datetime.utcnow() - timedelta(minutes=5)) - access_policy = AccessPolicy(permission=QueueSasPermissions(read=True), expiry=expiry_time, start=start_time) + expiry_time = self.get_datetime_variable( + variables, "expiry_time", datetime.utcnow() + timedelta(hours=1) + ) + start_time = self.get_datetime_variable( + variables, "start_time", datetime.utcnow() - timedelta(minutes=5) + ) + access_policy = AccessPolicy( + permission=QueueSasPermissions(read=True), + expiry=expiry_time, + start=start_time, + ) identifiers = {"testid": access_policy} resp = queue_client.set_queue_access_policy(signed_identifiers=identifiers) @@ -1226,7 +1346,9 @@ def test_set_queue_acl_too_many_ids(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() @@ -1246,7 +1368,9 @@ def test_set_queue_acl_with_non_existing_queue(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) # Act @@ -1262,7 +1386,9 @@ def test_unicode_create_queue_unicode_name(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_name = "啊齄丂狛狜" with pytest.raises(HttpResponseError): @@ -1279,7 +1405,9 @@ def test_unicode_get_messages_unicode_data(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1㚈") @@ -1302,7 +1430,9 @@ def test_unicode_update_message_unicode_data(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -1333,7 +1463,9 @@ def test_transport_closed_only_once(self, **kwargs): prefix = TEST_QUEUE_PREFIX queue_name = self.get_resource_name(prefix) with QueueServiceClient( - self.account_url(storage_account_name, "queue"), credential=storage_account_key.secret, transport=transport + self.account_url(storage_account_name, "queue"), + credential=storage_account_key.secret, + transport=transport, ) as qsc: qsc.get_service_properties() assert transport.session is not None @@ -1349,7 +1481,9 @@ def test_storage_account_audience_queue_service_client(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) qsc.get_service_properties() # Act @@ -1371,7 +1505,9 @@ def test_bad_audience_queue_service_client(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) qsc.get_service_properties() # Act @@ -1392,7 +1528,11 @@ def test_storage_account_audience_queue_client(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - queue = QueueClient(self.account_url(storage_account_name, "queue"), "testqueue1", storage_account_key.secret) + queue = QueueClient( + self.account_url(storage_account_name, "queue"), + "testqueue1", + storage_account_key.secret, + ) queue.create_queue() # Act @@ -1415,7 +1555,11 @@ def test_bad_audience_queue_client(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - queue = QueueClient(self.account_url(storage_account_name, "queue"), "testqueue2", storage_account_key.secret) + queue = QueueClient( + self.account_url(storage_account_name, "queue"), + "testqueue2", + storage_account_key.secret, + ) queue.create_queue() # Act @@ -1437,11 +1581,19 @@ def test_get_user_delegation_sas(self, **kwargs): variables = kwargs.pop("variables", {}) token_credential = self.get_credential(QueueServiceClient) - service = QueueServiceClient(self.account_url(storage_account_name, "queue"), credential=token_credential) + service = QueueServiceClient( + self.account_url(storage_account_name, "queue"), credential=token_credential + ) start = self.get_datetime_variable(variables, "start", datetime.utcnow()) - expiry = self.get_datetime_variable(variables, "expiry", datetime.utcnow() + timedelta(hours=1)) - user_delegation_key_1 = service.get_user_delegation_key(start=start, expiry=expiry) - user_delegation_key_2 = service.get_user_delegation_key(start=start, expiry=expiry) + expiry = self.get_datetime_variable( + variables, "expiry", datetime.utcnow() + timedelta(hours=1) + ) + user_delegation_key_1 = service.get_user_delegation_key( + start=start, expiry=expiry + ) + user_delegation_key_2 = service.get_user_delegation_key( + start=start, expiry=expiry + ) # Assert key1 is valid assert user_delegation_key_1.signed_oid is not None @@ -1456,9 +1608,15 @@ def test_get_user_delegation_sas(self, **kwargs): assert user_delegation_key_1.signed_oid == user_delegation_key_2.signed_oid assert user_delegation_key_1.signed_tid == user_delegation_key_2.signed_tid assert user_delegation_key_1.signed_start == user_delegation_key_2.signed_start - assert user_delegation_key_1.signed_expiry == user_delegation_key_2.signed_expiry - assert user_delegation_key_1.signed_version == user_delegation_key_2.signed_version - assert user_delegation_key_1.signed_service == user_delegation_key_2.signed_service + assert ( + user_delegation_key_1.signed_expiry == user_delegation_key_2.signed_expiry + ) + assert ( + user_delegation_key_1.signed_version == user_delegation_key_2.signed_version + ) + assert ( + user_delegation_key_1.signed_service == user_delegation_key_2.signed_service + ) assert user_delegation_key_1.value == user_delegation_key_2.value return variables @@ -1470,7 +1628,9 @@ def test_queue_cross_tenant_sas(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") token_credential = self.get_credential(QueueServiceClient) - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), credential=token_credential) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), credential=token_credential + ) start = datetime.utcnow() expiry = datetime.utcnow() + timedelta(hours=1) token = token_credential.get_token("https://storage.azure.com/.default") @@ -1502,7 +1662,9 @@ def test_queue_cross_tenant_sas(self, **kwargs): assert "sduoid=" + user_delegation_oid in queue_token assert "skdutid=" + delegated_user_tid in queue_token - queue_client = QueueClient.from_queue_url(queue_url=f"{queue.url}?{queue_token}", credential=token_credential) + queue_client = QueueClient.from_queue_url( + queue_url=f"{queue.url}?{queue_token}", credential=token_credential + ) message = "addedmessage" queue_msg = queue_client.send_message(message) assert queue_msg is not None diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_api_version.py b/sdk/storage/azure-storage-queue/tests/test_queue_api_version.py index 2afdab424c7c..37fbd7cc3de9 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_api_version.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_api_version.py @@ -10,7 +10,6 @@ from devtools_testutils.storage import StorageRecordedTestCase - # ------------------------------------------------------------------------------ @@ -23,7 +22,9 @@ def setUp(self): def test_service_client_api_version_property(self): self.setUp() - service_client = QueueServiceClient("https://foo.queue.core.windows.net/account", credential="fake_key") + service_client = QueueServiceClient( + "https://foo.queue.core.windows.net/account", credential="fake_key" + ) assert service_client.api_version == self.api_version_2 assert service_client._client._config.version == self.api_version_2 @@ -31,7 +32,9 @@ def test_service_client_api_version_property(self): service_client.api_version = "foo" service_client = QueueServiceClient( - "https://foo.queue.core.windows.net/account", credential="fake_key", api_version=self.api_version_1 + "https://foo.queue.core.windows.net/account", + credential="fake_key", + api_version=self.api_version_1, ) assert service_client.api_version == self.api_version_1 assert service_client._client._config.version == self.api_version_1 @@ -51,7 +54,11 @@ def test_queue_client_api_version_property(self): assert queue_client.api_version == self.api_version_1 assert queue_client._client._config.version == self.api_version_1 - queue_client = QueueClient("https://foo.queue.core.windows.net/account", "queue_name", credential="fake_key") + queue_client = QueueClient( + "https://foo.queue.core.windows.net/account", + "queue_name", + credential="fake_key", + ) assert queue_client.api_version == self.api_version_2 assert queue_client._client._config.version == self.api_version_2 diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_api_version_async.py b/sdk/storage/azure-storage-queue/tests/test_queue_api_version_async.py index 3f3dc8ad6a5a..7350ca87f7fa 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_api_version_async.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_api_version_async.py @@ -10,7 +10,6 @@ from devtools_testutils.storage.aio import AsyncStorageRecordedTestCase - # ------------------------------------------------------------------------------ @@ -23,7 +22,9 @@ def setUp(self): def test_service_client_api_version_property(self): self.setUp() - service_client = QueueServiceClient("https://foo.queue.core.windows.net/account", credential="fake_key") + service_client = QueueServiceClient( + "https://foo.queue.core.windows.net/account", credential="fake_key" + ) assert service_client.api_version == self.api_version_2 assert service_client._client._config.version == self.api_version_2 @@ -31,7 +32,9 @@ def test_service_client_api_version_property(self): service_client.api_version = "foo" service_client = QueueServiceClient( - "https://foo.queue.core.windows.net/account", credential="fake_key", api_version=self.api_version_1 + "https://foo.queue.core.windows.net/account", + credential="fake_key", + api_version=self.api_version_1, ) assert service_client.api_version == self.api_version_1 assert service_client._client._config.version == self.api_version_1 @@ -51,7 +54,11 @@ def test_queue_client_api_version_property(self): assert queue_client.api_version == self.api_version_1 assert queue_client._client._config.version == self.api_version_1 - queue_client = QueueClient("https://foo.queue.core.windows.net/account", "queue_name", credential="fake_key") + queue_client = QueueClient( + "https://foo.queue.core.windows.net/account", + "queue_name", + credential="fake_key", + ) assert queue_client.api_version == self.api_version_2 assert queue_client._client._config.version == self.api_version_2 diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_async.py b/sdk/storage/azure-storage-queue/tests/test_queue_async.py index c79124c5ab6f..b3171ea7074c 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_async.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_async.py @@ -60,7 +60,9 @@ async def test_create_queue(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) created = await queue_client.create_queue() @@ -74,7 +76,9 @@ async def test_create_queue_fail_on_exist(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) created = await queue_client.create_queue() with pytest.raises(ResourceExistsError): @@ -90,7 +94,9 @@ async def test_create_queue_fail_on_exist_different_metadata(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) created = await queue_client.create_queue() with pytest.raises(ResourceExistsError): @@ -106,7 +112,9 @@ async def test_create_queue_with_options(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) await queue_client.create_queue(metadata={"val1": "test", "val2": "blah"}) props = await queue_client.get_queue_properties() @@ -124,7 +132,9 @@ async def test_get_messages_with_max_messages(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) await queue_client.create_queue() await queue_client.send_message("message1") @@ -162,7 +172,9 @@ async def test_get_messages_with_too_little_messages(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) await queue_client.create_queue() await queue_client.send_message("message1") @@ -195,7 +207,9 @@ async def test_get_messages_with_page_bigger_than_max(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) await queue_client.create_queue() await queue_client.send_message("message1") @@ -215,7 +229,9 @@ async def test_get_messages_with_remainder(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) await queue_client.create_queue() await queue_client.send_message("message1") @@ -232,7 +248,9 @@ async def test_get_messages_with_remainder(self, **kwargs): await queue_client.send_message("message12") result = [] - async for m in queue_client.receive_messages(messages_per_page=3, max_messages=10): + async for m in queue_client.receive_messages( + messages_per_page=3, max_messages=10 + ): result.append(m) remainder = [] @@ -273,7 +291,9 @@ async def test_delete_non_existing_queue(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) # Asserts @@ -287,7 +307,9 @@ async def test_delete_existing_queue_fail_not_exist(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) created = await queue_client.create_queue() @@ -303,7 +325,9 @@ async def test_list_queues(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) await queue_client.create_queue() queues = [] @@ -321,21 +345,25 @@ async def test_list_queues_with_options(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_list = [] prefix = "listqueue" for i in range(0, 4): await self._create_queue(qsc, prefix + str(i), queue_list) # Action - generator1 = qsc.list_queues(name_starts_with=prefix, results_per_page=3).by_page() + generator1 = qsc.list_queues( + name_starts_with=prefix, results_per_page=3 + ).by_page() queues1 = [] async for el in await generator1.__anext__(): queues1.append(el) - generator2 = qsc.list_queues(name_starts_with=prefix, include_metadata=True).by_page( - generator1.continuation_token - ) + generator2 = qsc.list_queues( + name_starts_with=prefix, include_metadata=True + ).by_page(generator1.continuation_token) queues2 = [] async for el in await generator2.__anext__(): queues2.append(el) @@ -359,12 +387,16 @@ async def test_list_queues_with_metadata(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = await self._create_queue(qsc) await queue.set_queue_metadata(metadata={"val1": "test", "val2": "blah"}) listed_queue = [] - async for q in qsc.list_queues(name_starts_with=queue.queue_name, results_per_page=1, include_metadata=True): + async for q in qsc.list_queues( + name_starts_with=queue.queue_name, results_per_page=1, include_metadata=True + ): listed_queue.append(q) listed_queue = listed_queue[0] @@ -382,7 +414,9 @@ async def test_list_queues_account_sas(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) await queue_client.create_queue() sas_token = self.generate_sas( @@ -395,7 +429,9 @@ async def test_list_queues_account_sas(self, **kwargs): ) # Act - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), credential=sas_token) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), credential=sas_token + ) queues = [] async for q in qsc.list_queues(): queues.append(q) @@ -411,7 +447,9 @@ async def test_set_queue_metadata(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) metadata = {"hello": "world", "number": "43"} queue = await self._create_queue(qsc) @@ -429,7 +467,9 @@ async def test_get_queue_metadata_message_count(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = await self._create_queue(qsc) await queue_client.send_message("message1") props = await queue_client.get_queue_properties() @@ -445,7 +485,9 @@ async def test_queue_exists(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = await self._create_queue(qsc) # Act @@ -461,7 +503,9 @@ async def test_queue_not_exists(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = qsc.get_queue_client(self.get_resource_name("missing")) # Act with pytest.raises(ResourceNotFoundError): @@ -476,7 +520,9 @@ async def test_put_message(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action. No exception means pass. No asserts needed. - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = await self._create_queue(qsc) await queue_client.send_message("message1") await queue_client.send_message("message2") @@ -498,7 +544,9 @@ async def test_put_message_large_time_to_live(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = await self._create_queue(qsc) # There should be no upper bound on a queue message's time to live await queue_client.send_message("message1", time_to_live=1024 * 1024 * 1024) @@ -507,7 +555,9 @@ async def test_put_message_large_time_to_live(self, **kwargs): messages = await queue_client.peek_messages() # Assert - assert messages[0].expires_on >= (messages[0].inserted_on + timedelta(seconds=1024 * 1024 * 1024 - 3600)) + assert messages[0].expires_on >= ( + messages[0].inserted_on + timedelta(seconds=1024 * 1024 * 1024 - 3600) + ) @QueuePreparer() @recorded_by_proxy_async @@ -516,7 +566,9 @@ async def test_put_message_infinite_time_to_live(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = await self._create_queue(qsc) await queue_client.send_message("message1", time_to_live=-1) @@ -533,7 +585,9 @@ async def test_get_messages(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = await self._create_queue(qsc) await queue_client.send_message("message1") await queue_client.send_message("message2") @@ -564,7 +618,9 @@ async def test_receive_one_message(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = await self._create_queue(qsc) assert await queue_client.receive_message() is None @@ -599,13 +655,17 @@ async def test_get_messages_with_options(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = await self._create_queue(qsc) await queue_client.send_message("message1") await queue_client.send_message("message2") await queue_client.send_message("message3") await queue_client.send_message("message4") - pager = queue_client.receive_messages(messages_per_page=4, visibility_timeout=20) + pager = queue_client.receive_messages( + messages_per_page=4, visibility_timeout=20 + ) result = [] async for el in pager: result.append(el) @@ -631,7 +691,9 @@ async def test_peek_messages(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = await self._create_queue(qsc) await queue_client.send_message("message1") await queue_client.send_message("message2") @@ -659,7 +721,9 @@ async def test_peek_messages_with_options(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = await self._create_queue(qsc) await queue_client.send_message("message1") await queue_client.send_message("message2") @@ -687,7 +751,9 @@ async def test_clear_messages(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = await self._create_queue(qsc) await queue_client.send_message("message1") await queue_client.send_message("message2") @@ -707,7 +773,9 @@ async def test_delete_message(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = await self._create_queue(qsc) await queue_client.send_message("message1") await queue_client.send_message("message2") @@ -730,7 +798,9 @@ async def test_update_message(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = await self._create_queue(qsc) await queue_client.send_message("message1") messages = [] @@ -771,7 +841,9 @@ async def test_update_message_content(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = await self._create_queue(qsc) await queue_client.send_message("message1") @@ -780,7 +852,10 @@ async def test_update_message_content(self, **kwargs): messages.append(m) list_result1 = messages[0] message = await queue_client.update_message( - list_result1.id, pop_receipt=list_result1.pop_receipt, visibility_timeout=0, content="new text" + list_result1.id, + pop_receipt=list_result1.pop_receipt, + visibility_timeout=0, + content="new text", ) assert "new text" == message.content @@ -814,7 +889,9 @@ async def test_account_sas(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Arrange queue_client = await self._create_queue(qsc) @@ -853,8 +930,12 @@ async def test_azure_named_key_credential_access(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - named_key = AzureNamedKeyCredential(storage_account_name, storage_account_key.secret) - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), named_key) + named_key = AzureNamedKeyCredential( + storage_account_name, storage_account_key.secret + ) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), named_key + ) queue_client = self._get_queue_reference(qsc) await queue_client.create_queue() await queue_client.send_message("message1") @@ -872,7 +953,8 @@ async def test_account_sas_raises_if_sas_already_in_uri(self, **kwargs): with pytest.raises(ValueError): QueueServiceClient( - self.account_url(storage_account_name, "queue") + "?sig=foo", credential=AzureSasCredential("?foo=bar") + self.account_url(storage_account_name, "queue") + "?sig=foo", + credential=AzureSasCredential("?foo=bar"), ) @pytest.mark.live_test_only @@ -881,22 +963,30 @@ async def test_token_credential(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) token_credential = self.get_credential(QueueServiceClient, is_async=True) # Action 1: make sure token works - service = QueueServiceClient(self.account_url(storage_account_name, "queue"), credential=token_credential) + service = QueueServiceClient( + self.account_url(storage_account_name, "queue"), credential=token_credential + ) queues = await service.get_service_properties() assert queues is not None # Action 2: change token value to make request fail fake_credential = AsyncFakeCredential() - service = QueueServiceClient(self.account_url(storage_account_name, "queue"), credential=fake_credential) + service = QueueServiceClient( + self.account_url(storage_account_name, "queue"), credential=fake_credential + ) with pytest.raises(ClientAuthenticationError): await service.get_service_properties() # Action 3: update token to make it working again - service = QueueServiceClient(self.account_url(storage_account_name, "queue"), credential=token_credential) + service = QueueServiceClient( + self.account_url(storage_account_name, "queue"), credential=token_credential + ) queues = await service.get_service_properties() # Not raise means success assert queues is not None @@ -906,7 +996,9 @@ async def test_sas_read(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Arrange queue_client = await self._create_queue(qsc) @@ -942,7 +1034,9 @@ async def test_sas_add(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Arrange queue_client = await self._create_queue(qsc) @@ -976,7 +1070,9 @@ async def test_sas_update(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Arrange queue_client = await self._create_queue(qsc) @@ -1019,7 +1115,9 @@ async def test_sas_process(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Arrange queue_client = await self._create_queue(qsc) @@ -1055,12 +1153,18 @@ async def test_sas_signed_identifier(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") variables = kwargs.pop("variables", {}) - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Arrange access_policy = AccessPolicy() - start_time = self.get_datetime_variable(variables, "start_time", datetime.utcnow() - timedelta(hours=1)) - expiry_time = self.get_datetime_variable(variables, "expiry_time", datetime.utcnow() + timedelta(hours=1)) + start_time = self.get_datetime_variable( + variables, "start_time", datetime.utcnow() - timedelta(hours=1) + ) + expiry_time = self.get_datetime_variable( + variables, "expiry_time", datetime.utcnow() + timedelta(hours=1) + ) access_policy.start = start_time access_policy.expiry = expiry_time access_policy.permission = QueueSasPermissions(read=True) @@ -1103,7 +1207,9 @@ async def test_get_queue_acl(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Arrange queue_client = await self._create_queue(qsc) @@ -1120,7 +1226,9 @@ async def test_get_queue_acl_iter(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Arrange queue_client = await self._create_queue(qsc) @@ -1139,7 +1247,9 @@ async def test_get_queue_acl_with_non_existing_queue(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Arrange queue_client = self._get_queue_reference(qsc) @@ -1155,7 +1265,9 @@ async def test_set_queue_acl(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Arrange queue_client = await self._create_queue(qsc) @@ -1173,7 +1285,9 @@ async def test_set_queue_acl_with_empty_signed_identifiers(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Arrange queue_client = await self._create_queue(qsc) @@ -1191,7 +1305,9 @@ async def test_set_queue_acl_with_empty_signed_identifier(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Arrange queue_client = await self._create_queue(qsc) @@ -1215,16 +1331,28 @@ async def test_set_queue_acl_with_signed_identifiers(self, **kwargs): variables = kwargs.pop("variables", {}) # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = await self._create_queue(qsc) # Act - expiry_time = self.get_datetime_variable(variables, "expiry_time", datetime.utcnow() + timedelta(hours=1)) - start_time = self.get_datetime_variable(variables, "start_time", datetime.utcnow() - timedelta(minutes=5)) - access_policy = AccessPolicy(permission=QueueSasPermissions(read=True), expiry=expiry_time, start=start_time) + expiry_time = self.get_datetime_variable( + variables, "expiry_time", datetime.utcnow() + timedelta(hours=1) + ) + start_time = self.get_datetime_variable( + variables, "start_time", datetime.utcnow() - timedelta(minutes=5) + ) + access_policy = AccessPolicy( + permission=QueueSasPermissions(read=True), + expiry=expiry_time, + start=start_time, + ) identifiers = {"testid": access_policy} - resp = await queue_client.set_queue_access_policy(signed_identifiers=identifiers) + resp = await queue_client.set_queue_access_policy( + signed_identifiers=identifiers + ) # Assert assert resp is None @@ -1242,7 +1370,9 @@ async def test_set_queue_acl_too_many_ids(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = await self._create_queue(qsc) # Act @@ -1261,7 +1391,9 @@ async def test_set_queue_acl_with_non_existing_queue(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = self._get_queue_reference(qsc) # Act @@ -1275,7 +1407,9 @@ async def test_unicode_create_queue_unicode_name(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_name = "啊齄丂狛狜" with pytest.raises(HttpResponseError): @@ -1292,7 +1426,9 @@ async def test_unicode_get_messages_unicode_data(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = await self._create_queue(qsc) await queue_client.send_message("message1㚈") message = None @@ -1315,7 +1451,9 @@ async def test_unicode_update_message_unicode_data(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue_client = await self._create_queue(qsc) await queue_client.send_message("message1") messages = [] @@ -1349,7 +1487,9 @@ async def test_transport_closed_only_once(self, **kwargs): prefix = TEST_QUEUE_PREFIX queue_name = self.get_resource_name(prefix) async with QueueServiceClient( - self.account_url(storage_account_name, "queue"), credential=storage_account_key.secret, transport=transport + self.account_url(storage_account_name, "queue"), + credential=storage_account_key.secret, + transport=transport, ) as qsc: await qsc.get_service_properties() assert transport.session is not None @@ -1365,7 +1505,9 @@ async def test_storage_account_audience_queue_service_client(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) await qsc.get_service_properties() # Act @@ -1387,7 +1529,9 @@ async def test_bad_audience_queue_service_client(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) await qsc.get_service_properties() # Act @@ -1409,7 +1553,11 @@ async def test_storage_account_audience_queue_client(self, **kwargs): # Arrange queue_name = self.get_resource_name(TEST_QUEUE_PREFIX) - queue = QueueClient(self.account_url(storage_account_name, "queue"), queue_name, storage_account_key.secret) + queue = QueueClient( + self.account_url(storage_account_name, "queue"), + queue_name, + storage_account_key.secret, + ) await queue.create_queue() # Act @@ -1433,7 +1581,11 @@ async def test_bad_audience_queue_client(self, **kwargs): # Arrange queue_name = self.get_resource_name(TEST_QUEUE_PREFIX) - queue = QueueClient(self.account_url(storage_account_name, "queue"), queue_name, storage_account_key.secret) + queue = QueueClient( + self.account_url(storage_account_name, "queue"), + queue_name, + storage_account_key.secret, + ) await queue.create_queue() # Act @@ -1455,11 +1607,19 @@ async def test_get_user_delegation_sas(self, **kwargs): variables = kwargs.pop("variables", {}) token_credential = self.get_credential(QueueServiceClient, is_async=True) - service = QueueServiceClient(self.account_url(storage_account_name, "queue"), credential=token_credential) + service = QueueServiceClient( + self.account_url(storage_account_name, "queue"), credential=token_credential + ) start = self.get_datetime_variable(variables, "start", datetime.utcnow()) - expiry = self.get_datetime_variable(variables, "expiry", datetime.utcnow() + timedelta(hours=1)) - user_delegation_key_1 = await service.get_user_delegation_key(start=start, expiry=expiry) - user_delegation_key_2 = await service.get_user_delegation_key(start=start, expiry=expiry) + expiry = self.get_datetime_variable( + variables, "expiry", datetime.utcnow() + timedelta(hours=1) + ) + user_delegation_key_1 = await service.get_user_delegation_key( + start=start, expiry=expiry + ) + user_delegation_key_2 = await service.get_user_delegation_key( + start=start, expiry=expiry + ) # Assert key1 is valid assert user_delegation_key_1.signed_oid is not None @@ -1474,9 +1634,15 @@ async def test_get_user_delegation_sas(self, **kwargs): assert user_delegation_key_1.signed_oid == user_delegation_key_2.signed_oid assert user_delegation_key_1.signed_tid == user_delegation_key_2.signed_tid assert user_delegation_key_1.signed_start == user_delegation_key_2.signed_start - assert user_delegation_key_1.signed_expiry == user_delegation_key_2.signed_expiry - assert user_delegation_key_1.signed_version == user_delegation_key_2.signed_version - assert user_delegation_key_1.signed_service == user_delegation_key_2.signed_service + assert ( + user_delegation_key_1.signed_expiry == user_delegation_key_2.signed_expiry + ) + assert ( + user_delegation_key_1.signed_version == user_delegation_key_2.signed_version + ) + assert ( + user_delegation_key_1.signed_service == user_delegation_key_2.signed_service + ) assert user_delegation_key_1.value == user_delegation_key_2.value return variables @@ -1488,7 +1654,9 @@ async def test_queue_cross_tenant_sas(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") token_credential = self.get_credential(QueueServiceClient, is_async=True) - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), credential=token_credential) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), credential=token_credential + ) start = datetime.utcnow() expiry = datetime.utcnow() + timedelta(hours=1) token = await token_credential.get_token("https://storage.azure.com/.default") @@ -1520,7 +1688,9 @@ async def test_queue_cross_tenant_sas(self, **kwargs): assert "sduoid=" + user_delegation_oid in queue_token assert "skdutid=" + delegated_user_tid in queue_token - queue_client = QueueClient.from_queue_url(queue_url=f"{queue.url}?{queue_token}", credential=token_credential) + queue_client = QueueClient.from_queue_url( + queue_url=f"{queue.url}?{queue_token}", credential=token_credential + ) message = "addedmessage" queue_msg = await queue_client.send_message(message) assert queue_msg is not None diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_client.py b/sdk/storage/azure-storage-queue/tests/test_queue_client.py index 69d65899b545..42d242327437 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_client.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_client.py @@ -17,7 +17,10 @@ ResourceTypes, VERSION, ) -from azure.storage.queue._shared.parser import DEVSTORE_ACCOUNT_KEY, DEVSTORE_ACCOUNT_NAME +from azure.storage.queue._shared.parser import ( + DEVSTORE_ACCOUNT_KEY, + DEVSTORE_ACCOUNT_NAME, +) from devtools_testutils import recorded_by_proxy from devtools_testutils.storage import StorageRecordedTestCase @@ -40,15 +43,22 @@ def setUp(self): self.token_credential = self.get_credential(QueueServiceClient) # --Helpers----------------------------------------------------------------- - def validate_standard_account_endpoints(self, service, url_type, account_name, account_key): + def validate_standard_account_endpoints( + self, service, url_type, account_name, account_key + ): assert service is not None assert service.account_name == account_name assert service.credential.account_name == account_name assert service.credential.account_key == account_key.secret assert f"{account_name}.{url_type}.core.windows.net" in service.url - assert f"{account_name}-secondary.{url_type}.core.windows.net" in service.secondary_endpoint + assert ( + f"{account_name}-secondary.{url_type}.core.windows.net" + in service.secondary_endpoint + ) - def validate_ipv6_account_endpoints(self, service, account_name, account_key, primary_endpoint, secondary_endpoint): + def validate_ipv6_account_endpoints( + self, service, account_name, account_key, primary_endpoint, secondary_endpoint + ): assert service is not None assert service.scheme == "https" assert service.account_name == account_name @@ -80,11 +90,15 @@ def test_create_service_with_key(self, **kwargs): for client, url in SERVICES.items(): # Act service = client( - self.account_url(storage_account_name, "queue"), credential=storage_account_key.secret, queue_name="foo" + self.account_url(storage_account_name, "queue"), + credential=storage_account_key.secret, + queue_name="foo", ) # Assert - self.validate_standard_account_endpoints(service, url, storage_account_name, storage_account_key) + self.validate_standard_account_endpoints( + service, url, storage_account_name, storage_account_key + ) assert service.scheme == "https" @QueuePreparer() @@ -95,7 +109,10 @@ def test_create_service_with_connection_string(self, **kwargs): for service_type in SERVICES.items(): # Act service = service_type[0].from_connection_string( - self.connection_string(storage_account_name, storage_account_key.secret), queue_name="test" + self.connection_string( + storage_account_name, storage_account_key.secret + ), + queue_name="test", ) # Assert @@ -114,13 +131,17 @@ def test_create_service_with_sas(self, **kwargs): for service_type in SERVICES: # Act service = service_type( - self.account_url(storage_account_name, "queue"), credential=self.sas_token, queue_name="foo" + self.account_url(storage_account_name, "queue"), + credential=self.sas_token, + queue_name="foo", ) # Assert assert service is not None assert service.account_name == storage_account_name - assert service.url.startswith("https://" + storage_account_name + ".queue.core.windows.net") + assert service.url.startswith( + "https://" + storage_account_name + ".queue.core.windows.net" + ) assert service.url.endswith(self.sas_token) assert service.credential is None @@ -133,13 +154,17 @@ def test_create_service_with_token(self, **kwargs): for service_type in SERVICES: # Act service = service_type( - self.account_url(storage_account_name, "queue"), credential=self.token_credential, queue_name="foo" + self.account_url(storage_account_name, "queue"), + credential=self.token_credential, + queue_name="foo", ) # Assert assert service is not None assert service.account_name == storage_account_name - assert service.url.startswith("https://" + storage_account_name + ".queue.core.windows.net") + assert service.url.startswith( + "https://" + storage_account_name + ".queue.core.windows.net" + ) assert service.credential == self.token_credential assert not hasattr(service.credential, "account_key") assert hasattr(service.credential, "get_token") @@ -153,7 +178,9 @@ def test_create_service_with_token_and_http(self, **kwargs): for service_type in SERVICES: # Act with pytest.raises(ValueError): - url = self.account_url(storage_account_name, "queue").replace("https", "http") + url = self.account_url(storage_account_name, "queue").replace( + "https", "http" + ) service_type(url, credential=self.token_credential, queue_name="foo") @QueuePreparer() @@ -165,8 +192,12 @@ def test_create_service_china(self, **kwargs): for service_type in SERVICES.items(): # Act - url = self.account_url(storage_account_name, "queue").replace("core.windows.net", "core.chinacloudapi.cn") - service = service_type[0](url, credential=storage_account_key.secret, queue_name="foo") + url = self.account_url(storage_account_name, "queue").replace( + "core.windows.net", "core.chinacloudapi.cn" + ) + service = service_type[0]( + url, credential=storage_account_key.secret, queue_name="foo" + ) # Assert assert service is not None @@ -195,8 +226,12 @@ def test_create_service_protocol(self, **kwargs): for service_type in SERVICES.items(): # Act - url = self.account_url(storage_account_name, "queue").replace("https", "http") - service = service_type[0](url, credential=storage_account_key.secret, queue_name="foo") + url = self.account_url(storage_account_name, "queue").replace( + "https", "http" + ) + service = service_type[0]( + url, credential=storage_account_key.secret, queue_name="foo" + ) # Assert self.validate_standard_account_endpoints( @@ -215,9 +250,14 @@ def test_create_service_empty_key(self, **kwargs): for service_type in QUEUE_SERVICES: # Act with pytest.raises(ValueError) as e: - test_service = service_type("testaccount", credential="", queue_name="foo") + test_service = service_type( + "testaccount", credential="", queue_name="foo" + ) - assert str(e.value) == "You need to provide either a SAS token or an account shared key to authenticate." + assert ( + str(e.value) + == "You need to provide either a SAS token or an account shared key to authenticate." + ) @QueuePreparer() def test_create_service_with_socket_timeout(self, **kwargs): @@ -229,7 +269,9 @@ def test_create_service_with_socket_timeout(self, **kwargs): for service_type in SERVICES.items(): # Act default_service = service_type[0]( - self.account_url(storage_account_name, "queue"), credential=storage_account_key.secret, queue_name="foo" + self.account_url(storage_account_name, "queue"), + credential=storage_account_key.secret, + queue_name="foo", ) service = service_type[0]( self.account_url(storage_account_name, "queue"), @@ -242,8 +284,14 @@ def test_create_service_with_socket_timeout(self, **kwargs): self.validate_standard_account_endpoints( service, service_type[1], storage_account_name, storage_account_key ) - assert service._client._client._pipeline._transport.connection_config.timeout == 22 - assert default_service._client._client._pipeline._transport.connection_config.timeout in [20, (20, 2000)] + assert ( + service._client._client._pipeline._transport.connection_config.timeout + == 22 + ) + assert ( + default_service._client._client._pipeline._transport.connection_config.timeout + in [20, (20, 2000)] + ) @pytest.mark.parametrize( "account_url, expected_primary, expected_secondary", @@ -281,16 +329,26 @@ def test_create_service_with_socket_timeout(self, **kwargs): ], ) @QueuePreparer() - def test_create_service_ipv6(self, account_url, expected_primary, expected_secondary, **kwargs): + def test_create_service_ipv6( + self, account_url, expected_primary, expected_secondary, **kwargs + ): storage_account_name = "myaccount" storage_account_key = kwargs.pop("storage_account_key") queue_name = "queue" for service_type in SERVICES.keys(): - service = service_type(account_url, credential=storage_account_key.secret, queue_name=queue_name) + service = service_type( + account_url, + credential=storage_account_key.secret, + queue_name=queue_name, + ) self.validate_ipv6_account_endpoints( - service, storage_account_name, storage_account_key.secret, expected_primary, expected_secondary + service, + storage_account_name, + storage_account_key.secret, + expected_primary, + expected_secondary, ) conn_str = ( @@ -303,14 +361,23 @@ def test_create_service_ipv6(self, account_url, expected_primary, expected_secon conn_str, credential=storage_account_key.secret, queue_name=queue_name ) self.validate_ipv6_account_endpoints( - service, storage_account_name, storage_account_key.secret, expected_primary, expected_secondary + service, + storage_account_name, + storage_account_key.secret, + expected_primary, + expected_secondary, ) service = QueueClient.from_queue_url( - queue_url=f"{account_url}/{queue_name}-secondary", credential=storage_account_key.secret + queue_url=f"{account_url}/{queue_name}-secondary", + credential=storage_account_key.secret, ) self.validate_ipv6_account_endpoints( - service, storage_account_name, storage_account_key.secret, expected_primary, expected_secondary + service, + storage_account_name, + storage_account_key.secret, + expected_primary, + expected_secondary, ) @QueuePreparer() @@ -321,9 +388,7 @@ def test_create_service_ipv6_custom_domain(self): account_url = f"https://{hostname}" for service_type in SERVICES.keys(): service = service_type( - account_url, - credential=token_credential, - queue_name="foo" + account_url, credential=token_credential, queue_name="foo" ) assert service is not None assert service.scheme == "https" @@ -343,7 +408,9 @@ def test_create_service_with_connection_string_key(self, **kwargs): for service_type in SERVICES.items(): # Act - service = service_type[0].from_connection_string(conn_string, queue_name="foo") + service = service_type[0].from_connection_string( + conn_string, queue_name="foo" + ) # Assert self.validate_standard_account_endpoints( @@ -366,7 +433,9 @@ def test_create_service_with_connection_string_sas(self, **kwargs): # Assert assert service is not None assert service.account_name == storage_account_name - assert service.url.startswith("https://" + storage_account_name + ".queue.core.windows.net") + assert service.url.startswith( + "https://" + storage_account_name + ".queue.core.windows.net" + ) assert service.url.endswith(self.sas_token) assert service.credential is None @@ -385,7 +454,9 @@ def test_create_service_with_connection_string_endpoint_protocol(self, **kwargs) for service_type in SERVICES.items(): # Act - service = service_type[0].from_connection_string(conn_string, queue_name="foo") + service = service_type[0].from_connection_string( + conn_string, queue_name="foo" + ) # Assert assert service is not None @@ -410,7 +481,9 @@ def test_create_service_with_connection_string_endpoint_protocol(self, **kwargs) def test_create_service_use_development_storage(self): for service_type in SERVICES.items(): # Act - service = service_type[0].from_connection_string("UseDevelopmentStorage=true;", queue_name="test") + service = service_type[0].from_connection_string( + "UseDevelopmentStorage=true;", queue_name="test" + ) # Assert assert service is not None @@ -434,7 +507,9 @@ def test_create_service_with_connection_string_custom_domain(self, **kwargs): ) # Act - service = service_type[0].from_connection_string(conn_string, queue_name="foo") + service = service_type[0].from_connection_string( + conn_string, queue_name="foo" + ) # Assert assert service is not None @@ -462,7 +537,9 @@ def test_create_service_with_conn_str_custom_domain_trailing_slash(self, **kwarg "QueueEndpoint=www.mydomain.com/;" ) # Act - service = service_type[0].from_connection_string(conn_string, queue_name="foo") + service = service_type[0].from_connection_string( + conn_string, queue_name="foo" + ) # Assert assert service is not None @@ -500,7 +577,9 @@ def test_create_service_with_conn_str_custom_domain_sec_override(self, **kwargs) assert service.credential.account_name == storage_account_name assert service.credential.account_key == storage_account_key.secret assert service.primary_endpoint.startswith("https://www.mydomain.com/") - assert service.secondary_endpoint.startswith("https://www-sec.mydomain.com/") + assert service.secondary_endpoint.startswith( + "https://www-sec.mydomain.com/" + ) @QueuePreparer() def test_create_service_with_conn_str_fails_if_sec_without_primary(self, **kwargs): @@ -518,7 +597,9 @@ def test_create_service_with_conn_str_fails_if_sec_without_primary(self, **kwarg # Fails if primary excluded with pytest.raises(ValueError): - service = service_type[0].from_connection_string(conn_string, queue_name="foo") + service = service_type[0].from_connection_string( + conn_string, queue_name="foo" + ) @QueuePreparer() def test_create_service_with_conn_str_succeeds_if_sec_with_primary(self, **kwargs): @@ -534,7 +615,9 @@ def test_create_service_with_conn_str_succeeds_if_sec_with_primary(self, **kwarg f"{_CONNECTION_ENDPOINTS_SECONDARY.get(service_type[1])}=www-sec.mydomain.com;" ) # Act - service = service_type[0].from_connection_string(conn_string, queue_name="foo") + service = service_type[0].from_connection_string( + conn_string, queue_name="foo" + ) # Assert assert service is not None @@ -542,14 +625,18 @@ def test_create_service_with_conn_str_succeeds_if_sec_with_primary(self, **kwarg assert service.credential.account_name == storage_account_name assert service.credential.account_key == storage_account_key.secret assert service.primary_endpoint.startswith("https://www.mydomain.com/") - assert service.secondary_endpoint.startswith("https://www-sec.mydomain.com/") + assert service.secondary_endpoint.startswith( + "https://www-sec.mydomain.com/" + ) @QueuePreparer() def test_create_service_with_custom_account_endpoint_path(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - custom_account_url = "http://local-machine:11002/custom/account/path/" + self.sas_token + custom_account_url = ( + "http://local-machine:11002/custom/account/path/" + self.sas_token + ) for service_type in SERVICES.items(): conn_string = ( f"DefaultEndpointsProtocol=http;" @@ -558,7 +645,9 @@ def test_create_service_with_custom_account_endpoint_path(self, **kwargs): f"QueueEndpoint={custom_account_url};" ) # Act - service = service_type[0].from_connection_string(conn_string, queue_name="foo") + service = service_type[0].from_connection_string( + conn_string, queue_name="foo" + ) # Assert assert service.account_name == storage_account_name @@ -570,21 +659,29 @@ def test_create_service_with_custom_account_endpoint_path(self, **kwargs): assert service.account_name == None assert service.credential == None assert service.primary_hostname == "local-machine:11002/custom/account/path" - assert service.url.startswith("http://local-machine:11002/custom/account/path/?") + assert service.url.startswith( + "http://local-machine:11002/custom/account/path/?" + ) service = QueueClient(account_url=custom_account_url, queue_name="foo") assert service.account_name == None assert service.queue_name == "foo" assert service.credential == None assert service.primary_hostname == "local-machine:11002/custom/account/path" - assert service.url.startswith("http://local-machine:11002/custom/account/path/foo?") + assert service.url.startswith( + "http://local-machine:11002/custom/account/path/foo?" + ) - service = QueueClient.from_queue_url("http://local-machine:11002/custom/account/path/foo" + self.sas_token) + service = QueueClient.from_queue_url( + "http://local-machine:11002/custom/account/path/foo" + self.sas_token + ) assert service.account_name == None assert service.queue_name == "foo" assert service.credential == None assert service.primary_hostname == "local-machine:11002/custom/account/path" - assert service.url.startswith("http://local-machine:11002/custom/account/path/foo?") + assert service.url.startswith( + "http://local-machine:11002/custom/account/path/foo?" + ) @QueuePreparer() @recorded_by_proxy @@ -594,7 +691,8 @@ def test_request_callback_signed_header(self, **kwargs): # Arrange service = QueueServiceClient( - self.account_url(storage_account_name, "queue"), credential=storage_account_key.secret + self.account_url(storage_account_name, "queue"), + credential=storage_account_key.secret, ) name = self.get_resource_name("cont") @@ -617,7 +715,8 @@ def test_response_callback(self, **kwargs): # Arrange service = QueueServiceClient( - self.account_url(storage_account_name, "queue"), credential=storage_account_key.secret + self.account_url(storage_account_name, "queue"), + credential=storage_account_key.secret, ) name = self.get_resource_name("cont") queue = service.get_queue_client(name) @@ -638,12 +737,16 @@ def test_user_agent_default(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") service = QueueServiceClient( - self.account_url(storage_account_name, "queue"), credential=storage_account_key.secret + self.account_url(storage_account_name, "queue"), + credential=storage_account_key.secret, ) def callback(response): assert "User-Agent" in response.http_request.headers - assert f"azsdk-python-storage-queue/{VERSION}" in response.http_request.headers["User-Agent"] + assert ( + f"azsdk-python-storage-queue/{VERSION}" + in response.http_request.headers["User-Agent"] + ) service.get_service_properties(raw_response_hook=callback) @@ -677,7 +780,9 @@ def callback(response): f"Python/{platform.python_version()} ({platform.platform()})" ) in response.http_request.headers["User-Agent"] - service.get_service_properties(raw_response_hook=callback, user_agent="TestApp/v2.0") + service.get_service_properties( + raw_response_hook=callback, user_agent="TestApp/v2.0" + ) @QueuePreparer() @recorded_by_proxy @@ -686,7 +791,8 @@ def test_user_agent_append(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") service = QueueServiceClient( - self.account_url(storage_account_name, "queue"), credential=storage_account_key.secret + self.account_url(storage_account_name, "queue"), + credential=storage_account_key.secret, ) def callback(response): @@ -696,7 +802,9 @@ def callback(response): f"Python/{platform.python_version()} ({platform.platform()})" ) in response.http_request.headers["User-Agent"] - service.get_service_properties(raw_response_hook=callback, user_agent="customer_user_agent") + service.get_service_properties( + raw_response_hook=callback, user_agent="customer_user_agent" + ) @QueuePreparer() def test_create_queue_client_with_complete_queue_url(self, **kwargs): @@ -705,7 +813,9 @@ def test_create_queue_client_with_complete_queue_url(self, **kwargs): # Arrange queue_url = self.account_url(storage_account_name, "queue") + "/foo" - service = QueueClient(queue_url, queue_name="bar", credential=storage_account_key.secret) + service = QueueClient( + queue_url, queue_name="bar", credential=storage_account_key.secret + ) # Assert assert service.scheme == "https" @@ -714,16 +824,33 @@ def test_create_queue_client_with_complete_queue_url(self, **kwargs): def test_error_with_malformed_conn_str(self): # Arrange - for conn_str in ["", "foobar", "foobar=baz=foo", "foo;bar;baz", "foo=;bar=;", "=", ";", "=;=="]: + for conn_str in [ + "", + "foobar", + "foobar=baz=foo", + "foo;bar;baz", + "foo=;bar=;", + "=", + ";", + "=;==", + ]: for service_type in SERVICES.items(): # Act with pytest.raises(ValueError) as e: - service = service_type[0].from_connection_string(conn_str, queue_name="test") + service = service_type[0].from_connection_string( + conn_str, queue_name="test" + ) if conn_str in ("", "foobar", "foo;bar;baz", ";"): - assert str(e.value) == "Connection string is either blank or malformed." + assert ( + str(e.value) + == "Connection string is either blank or malformed." + ) elif conn_str in ("foobar=baz=foo", "foo=;bar=;", "=", "=;=="): - assert str(e.value) == "Connection string missing required connection details." + assert ( + str(e.value) + == "Connection string missing required connection details." + ) @QueuePreparer() def test_closing_pipeline_client(self, **kwargs): @@ -766,8 +893,12 @@ def test_get_and_set_queue_access_policy_oauth(self, **kwargs): self.setUp() # Arrange - service_client = QueueServiceClient(self.account_url(storage_account_name, "queue"), self.token_credential) - queue_client = service_client.get_queue_client(self.get_resource_name("pyqueuesync")) + service_client = QueueServiceClient( + self.account_url(storage_account_name, "queue"), self.token_credential + ) + queue_client = service_client.get_queue_client( + self.get_resource_name("pyqueuesync") + ) queue_client.create_queue() # Act / Assert diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_client_async.py b/sdk/storage/azure-storage-queue/tests/test_queue_client_async.py index 5b89846c7d5f..43d38fb2da67 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_client_async.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_client_async.py @@ -8,8 +8,17 @@ from datetime import datetime, timedelta import pytest -from azure.storage.queue import AccountSasPermissions, generate_account_sas, LocationMode, ResourceTypes, VERSION -from azure.storage.queue._shared.parser import DEVSTORE_ACCOUNT_KEY, DEVSTORE_ACCOUNT_NAME +from azure.storage.queue import ( + AccountSasPermissions, + generate_account_sas, + LocationMode, + ResourceTypes, + VERSION, +) +from azure.storage.queue._shared.parser import ( + DEVSTORE_ACCOUNT_KEY, + DEVSTORE_ACCOUNT_NAME, +) from azure.storage.queue.aio import QueueClient, QueueServiceClient from devtools_testutils.aio import recorded_by_proxy_async @@ -32,15 +41,22 @@ def setUp(self): self.token_credential = self.get_credential(QueueServiceClient, is_async=True) # --Helpers----------------------------------------------------------------- - def validate_standard_account_endpoints(self, service, url_type, storage_account_name, storage_account_key): + def validate_standard_account_endpoints( + self, service, url_type, storage_account_name, storage_account_key + ): assert service is not None assert service.account_name == storage_account_name assert service.credential.account_name == storage_account_name assert service.credential.account_key == storage_account_key.secret assert f"{storage_account_name}.{url_type}.core.windows.net" in service.url - assert f"{storage_account_name}-secondary.{url_type}.core.windows.net" in service.secondary_endpoint + assert ( + f"{storage_account_name}-secondary.{url_type}.core.windows.net" + in service.secondary_endpoint + ) - def validate_ipv6_account_endpoints(self, service, account_name, account_key, primary_endpoint, secondary_endpoint): + def validate_ipv6_account_endpoints( + self, service, account_name, account_key, primary_endpoint, secondary_endpoint + ): assert service is not None assert service.scheme == "https" assert service.account_name == account_name @@ -72,11 +88,15 @@ def test_create_service_with_key(self, **kwargs): for client, url in SERVICES.items(): # Act service = client( - self.account_url(storage_account_name, "queue"), credential=storage_account_key.secret, queue_name="foo" + self.account_url(storage_account_name, "queue"), + credential=storage_account_key.secret, + queue_name="foo", ) # Assert - self.validate_standard_account_endpoints(service, url, storage_account_name, storage_account_key) + self.validate_standard_account_endpoints( + service, url, storage_account_name, storage_account_key + ) assert service.scheme == "https" @QueuePreparer() @@ -87,7 +107,10 @@ def test_create_service_with_connection_string(self, **kwargs): for service_type in SERVICES.items(): # Act service = service_type[0].from_connection_string( - self.connection_string(storage_account_name, storage_account_key.secret), queue_name="test" + self.connection_string( + storage_account_name, storage_account_key.secret + ), + queue_name="test", ) # Assert @@ -106,13 +129,17 @@ def test_create_service_with_sas(self, **kwargs): for service_type in SERVICES: # Act service = service_type( - self.account_url(storage_account_name, "queue"), credential=self.sas_token, queue_name="foo" + self.account_url(storage_account_name, "queue"), + credential=self.sas_token, + queue_name="foo", ) # Assert assert service is not None assert service.account_name == storage_account_name - assert service.url.startswith("https://" + storage_account_name + ".queue.core.windows.net") + assert service.url.startswith( + "https://" + storage_account_name + ".queue.core.windows.net" + ) assert service.url.endswith(self.sas_token) assert service.credential is None @@ -124,13 +151,17 @@ async def test_create_service_with_token(self, **kwargs): for service_type in SERVICES: # Act service = service_type( - self.account_url(storage_account_name, "queue"), credential=self.token_credential, queue_name="foo" + self.account_url(storage_account_name, "queue"), + credential=self.token_credential, + queue_name="foo", ) # Assert assert service is not None assert service.account_name == storage_account_name - assert service.url.startswith("https://" + storage_account_name + ".queue.core.windows.net") + assert service.url.startswith( + "https://" + storage_account_name + ".queue.core.windows.net" + ) assert service.credential == self.token_credential assert not hasattr(service.credential, "account_key") assert hasattr(service.credential, "get_token") @@ -143,7 +174,9 @@ async def test_create_service_with_token_and_http(self, **kwargs): for service_type in SERVICES: # Act with pytest.raises(ValueError): - url = self.account_url(storage_account_name, "queue").replace("https", "http") + url = self.account_url(storage_account_name, "queue").replace( + "https", "http" + ) service_type(url, credential=self.token_credential, queue_name="foo") @QueuePreparer() @@ -155,8 +188,12 @@ def test_create_service_china(self, **kwargs): for service_type in SERVICES.items(): # Act - url = self.account_url(storage_account_name, "queue").replace("core.windows.net", "core.chinacloudapi.cn") - service = service_type[0](url, credential=storage_account_key.secret, queue_name="foo") + url = self.account_url(storage_account_name, "queue").replace( + "core.windows.net", "core.chinacloudapi.cn" + ) + service = service_type[0]( + url, credential=storage_account_key.secret, queue_name="foo" + ) # Assert assert service is not None @@ -185,8 +222,12 @@ def test_create_service_protocol(self, **kwargs): for service_type in SERVICES.items(): # Act - url = self.account_url(storage_account_name, "queue").replace("https", "http") - service = service_type[0](url, credential=storage_account_key.secret, queue_name="foo") + url = self.account_url(storage_account_name, "queue").replace( + "https", "http" + ) + service = service_type[0]( + url, credential=storage_account_key.secret, queue_name="foo" + ) # Assert self.validate_standard_account_endpoints( @@ -205,9 +246,14 @@ def test_create_service_empty_key(self, **kwargs): for service_type in QUEUE_SERVICES: # Act with pytest.raises(ValueError) as e: - test_service = service_type("testaccount", credential="", queue_name="foo") + test_service = service_type( + "testaccount", credential="", queue_name="foo" + ) - assert str(e.value) == "You need to provide either a SAS token or an account shared key to authenticate." + assert ( + str(e.value) + == "You need to provide either a SAS token or an account shared key to authenticate." + ) @QueuePreparer() def test_create_service_with_socket_timeout(self, **kwargs): @@ -219,7 +265,9 @@ def test_create_service_with_socket_timeout(self, **kwargs): for service_type in SERVICES.items(): # Act default_service = service_type[0]( - self.account_url(storage_account_name, "queue"), credential=storage_account_key.secret, queue_name="foo" + self.account_url(storage_account_name, "queue"), + credential=storage_account_key.secret, + queue_name="foo", ) service = service_type[0]( self.account_url(storage_account_name, "queue"), @@ -232,8 +280,14 @@ def test_create_service_with_socket_timeout(self, **kwargs): self.validate_standard_account_endpoints( service, service_type[1], storage_account_name, storage_account_key ) - assert service._client._client._pipeline._transport.connection_config.timeout == 22 - assert default_service._client._client._pipeline._transport.connection_config.timeout in [20, (20, 2000)] + assert ( + service._client._client._pipeline._transport.connection_config.timeout + == 22 + ) + assert ( + default_service._client._client._pipeline._transport.connection_config.timeout + in [20, (20, 2000)] + ) @pytest.mark.parametrize( "account_url, expected_primary, expected_secondary", @@ -271,16 +325,26 @@ def test_create_service_with_socket_timeout(self, **kwargs): ], ) @QueuePreparer() - def test_create_service_ipv6(self, account_url, expected_primary, expected_secondary, **kwargs): + def test_create_service_ipv6( + self, account_url, expected_primary, expected_secondary, **kwargs + ): storage_account_name = "myaccount" storage_account_key = kwargs.pop("storage_account_key") queue_name = "queue" for service_type in SERVICES.keys(): - service = service_type(account_url, credential=storage_account_key.secret, queue_name=queue_name) + service = service_type( + account_url, + credential=storage_account_key.secret, + queue_name=queue_name, + ) self.validate_ipv6_account_endpoints( - service, storage_account_name, storage_account_key.secret, expected_primary, expected_secondary + service, + storage_account_name, + storage_account_key.secret, + expected_primary, + expected_secondary, ) conn_str = ( @@ -293,14 +357,23 @@ def test_create_service_ipv6(self, account_url, expected_primary, expected_secon conn_str, credential=storage_account_key.secret, queue_name=queue_name ) self.validate_ipv6_account_endpoints( - service, storage_account_name, storage_account_key.secret, expected_primary, expected_secondary + service, + storage_account_name, + storage_account_key.secret, + expected_primary, + expected_secondary, ) service = QueueClient.from_queue_url( - queue_url=f"{account_url}/{queue_name}-secondary", credential=storage_account_key.secret + queue_url=f"{account_url}/{queue_name}-secondary", + credential=storage_account_key.secret, ) self.validate_ipv6_account_endpoints( - service, storage_account_name, storage_account_key.secret, expected_primary, expected_secondary + service, + storage_account_name, + storage_account_key.secret, + expected_primary, + expected_secondary, ) @QueuePreparer() @@ -311,9 +384,7 @@ def test_create_service_ipv6_custom_domain(self): account_url = f"https://{hostname}" for service_type in SERVICES.keys(): service = service_type( - account_url, - credential=token_credential, - queue_name="foo" + account_url, credential=token_credential, queue_name="foo" ) assert service is not None assert service.scheme == "https" @@ -329,10 +400,15 @@ def test_create_service_with_connection_string_key(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - conn_string = f"AccountName={storage_account_name};" f"AccountKey={storage_account_key.secret};" + conn_string = ( + f"AccountName={storage_account_name};" + f"AccountKey={storage_account_key.secret};" + ) for service_type in SERVICES.items(): # Act - service = service_type[0].from_connection_string(conn_string, queue_name="foo") + service = service_type[0].from_connection_string( + conn_string, queue_name="foo" + ) # Assert self.validate_standard_account_endpoints( @@ -346,7 +422,10 @@ def test_create_service_with_connection_string_sas(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - conn_string = f"AccountName={storage_account_name};" f"SharedAccessSignature={self.sas_token};" + conn_string = ( + f"AccountName={storage_account_name};" + f"SharedAccessSignature={self.sas_token};" + ) for service_type in SERVICES: # Act @@ -355,7 +434,9 @@ def test_create_service_with_connection_string_sas(self, **kwargs): # Assert assert service is not None assert service.account_name == storage_account_name - assert service.url.startswith("https://" + storage_account_name + ".queue.core.windows.net") + assert service.url.startswith( + "https://" + storage_account_name + ".queue.core.windows.net" + ) assert service.url.endswith(self.sas_token) assert service.credential is None @@ -373,7 +454,9 @@ def test_create_service_with_conn_str_endpoint_protocol(self, **kwargs): for service_type in SERVICES.items(): # Act - service = service_type[0].from_connection_string(conn_string, queue_name="foo") + service = service_type[0].from_connection_string( + conn_string, queue_name="foo" + ) # Assert assert service is not None @@ -398,7 +481,9 @@ def test_create_service_with_conn_str_endpoint_protocol(self, **kwargs): def test_create_service_use_development_storage(self): for service_type in SERVICES.items(): # Act - service = service_type[0].from_connection_string("UseDevelopmentStorage=true;", queue_name="test") + service = service_type[0].from_connection_string( + "UseDevelopmentStorage=true;", queue_name="test" + ) # Assert assert service is not None @@ -422,7 +507,9 @@ def test_create_service_with_connection_string_custom_domain(self, **kwargs): ) # Act - service = service_type[0].from_connection_string(conn_string, queue_name="foo") + service = service_type[0].from_connection_string( + conn_string, queue_name="foo" + ) # Assert assert service is not None @@ -448,7 +535,9 @@ def test_create_serv_with_cs_custom_dmn_trlng_slash(self, **kwargs): ) # Act - service = service_type[0].from_connection_string(conn_string, queue_name="foo") + service = service_type[0].from_connection_string( + conn_string, queue_name="foo" + ) # Assert assert service is not None @@ -484,7 +573,9 @@ def test_create_service_with_cs_custom_dmn_sec_override(self, **kwargs): assert service.credential.account_name == storage_account_name assert service.credential.account_key == storage_account_key.secret assert service.primary_endpoint.startswith("https://www.mydomain.com/") - assert service.secondary_endpoint.startswith("https://www-sec.mydomain.com/") + assert service.secondary_endpoint.startswith( + "https://www-sec.mydomain.com/" + ) @QueuePreparer() def test_create_service_with_cs_fails_if_sec_without_prim(self, **kwargs): @@ -503,7 +594,9 @@ def test_create_service_with_cs_fails_if_sec_without_prim(self, **kwargs): # Fails if primary excluded with pytest.raises(ValueError): - service = service_type[0].from_connection_string(conn_string, queue_name="foo") + service = service_type[0].from_connection_string( + conn_string, queue_name="foo" + ) @QueuePreparer() def test_create_service_with_cs_succeeds_if_sec_with_prim(self, **kwargs): @@ -520,7 +613,9 @@ def test_create_service_with_cs_succeeds_if_sec_with_prim(self, **kwargs): ) # Act - service = service_type[0].from_connection_string(conn_string, queue_name="foo") + service = service_type[0].from_connection_string( + conn_string, queue_name="foo" + ) # Assert assert service is not None @@ -528,14 +623,18 @@ def test_create_service_with_cs_succeeds_if_sec_with_prim(self, **kwargs): assert service.credential.account_name == storage_account_name assert service.credential.account_key == storage_account_key.secret assert service.primary_endpoint.startswith("https://www.mydomain.com/") - assert service.secondary_endpoint.startswith("https://www-sec.mydomain.com/") + assert service.secondary_endpoint.startswith( + "https://www-sec.mydomain.com/" + ) @QueuePreparer() def test_create_service_with_custom_account_endpoint_path(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - custom_account_url = "http://local-machine:11002/custom/account/path/" + self.sas_token + custom_account_url = ( + "http://local-machine:11002/custom/account/path/" + self.sas_token + ) for service_type in SERVICES.items(): conn_string = ( f"DefaultEndpointsProtocol=http;AccountName={storage_account_name};" @@ -544,7 +643,9 @@ def test_create_service_with_custom_account_endpoint_path(self, **kwargs): ) # Act - service = service_type[0].from_connection_string(conn_string, queue_name="foo") + service = service_type[0].from_connection_string( + conn_string, queue_name="foo" + ) # Assert assert service.account_name == storage_account_name @@ -556,21 +657,29 @@ def test_create_service_with_custom_account_endpoint_path(self, **kwargs): assert service.account_name == None assert service.credential == None assert service.primary_hostname == "local-machine:11002/custom/account/path" - assert service.url.startswith("http://local-machine:11002/custom/account/path/?") + assert service.url.startswith( + "http://local-machine:11002/custom/account/path/?" + ) service = QueueClient(account_url=custom_account_url, queue_name="foo") assert service.account_name == None assert service.queue_name == "foo" assert service.credential == None assert service.primary_hostname == "local-machine:11002/custom/account/path" - assert service.url.startswith("http://local-machine:11002/custom/account/path/foo?") + assert service.url.startswith( + "http://local-machine:11002/custom/account/path/foo?" + ) - service = QueueClient.from_queue_url("http://local-machine:11002/custom/account/path/foo" + self.sas_token) + service = QueueClient.from_queue_url( + "http://local-machine:11002/custom/account/path/foo" + self.sas_token + ) assert service.account_name == None assert service.queue_name == "foo" assert service.credential == None assert service.primary_hostname == "local-machine:11002/custom/account/path" - assert service.url.startswith("http://local-machine:11002/custom/account/path/foo?") + assert service.url.startswith( + "http://local-machine:11002/custom/account/path/foo?" + ) @QueuePreparer() @recorded_by_proxy_async @@ -580,7 +689,8 @@ async def test_request_callback_signed_header(self, **kwargs): # Arrange service = QueueServiceClient( - self.account_url(storage_account_name, "queue"), credential=storage_account_key.secret + self.account_url(storage_account_name, "queue"), + credential=storage_account_key.secret, ) name = self.get_resource_name("cont") @@ -604,7 +714,8 @@ async def test_response_callback(self, **kwargs): # Arrange service = QueueServiceClient( - self.account_url(storage_account_name, "queue"), credential=storage_account_key.secret + self.account_url(storage_account_name, "queue"), + credential=storage_account_key.secret, ) name = self.get_resource_name("cont") queue = service.get_queue_client(name) @@ -624,12 +735,16 @@ async def test_user_agent_default(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") service = QueueServiceClient( - self.account_url(storage_account_name, "queue"), credential=storage_account_key.secret + self.account_url(storage_account_name, "queue"), + credential=storage_account_key.secret, ) def callback(response): assert "User-Agent" in response.http_request.headers - assert f"azsdk-python-storage-queue/{VERSION}" in response.http_request.headers["User-Agent"] + assert ( + f"azsdk-python-storage-queue/{VERSION}" + in response.http_request.headers["User-Agent"] + ) await service.get_service_properties(raw_response_hook=callback) @@ -663,7 +778,9 @@ def callback(response): f"Python/{platform.python_version()} ({platform.platform()})" ) in response.http_request.headers["User-Agent"] - await service.get_service_properties(raw_response_hook=callback, user_agent="TestApp/v2.0") + await service.get_service_properties( + raw_response_hook=callback, user_agent="TestApp/v2.0" + ) @QueuePreparer() @recorded_by_proxy_async @@ -672,7 +789,8 @@ async def test_user_agent_append(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") service = QueueServiceClient( - self.account_url(storage_account_name, "queue"), credential=storage_account_key.secret + self.account_url(storage_account_name, "queue"), + credential=storage_account_key.secret, ) def callback(response): @@ -682,7 +800,9 @@ def callback(response): f"Python/{platform.python_version()} ({platform.platform()})" ) in response.http_request.headers["User-Agent"] - await service.get_service_properties(raw_response_hook=callback, user_agent="customer_user_agent") + await service.get_service_properties( + raw_response_hook=callback, user_agent="customer_user_agent" + ) @QueuePreparer() async def test_closing_pipeline_client(self, **kwargs): @@ -725,8 +845,12 @@ async def test_get_and_set_queue_access_policy_oauth(self, **kwargs): self.setUp() # Arrange - service_client = QueueServiceClient(self.account_url(storage_account_name, "queue"), self.token_credential) - queue_client = service_client.get_queue_client(self.get_resource_name("pyqueueasync")) + service_client = QueueServiceClient( + self.account_url(storage_account_name, "queue"), self.token_credential + ) + queue_client = service_client.get_queue_client( + self.get_resource_name("pyqueueasync") + ) await queue_client.create_queue() # Act / Assert diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_encodings.py b/sdk/storage/azure-storage-queue/tests/test_queue_encodings.py index ac704c1b2bd8..989c6d256a55 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_encodings.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_encodings.py @@ -66,7 +66,9 @@ def test_message_text_xml(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange. - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) message = "" queue = qsc.get_queue_client(self.get_resource_name(TEST_QUEUE_PREFIX)) @@ -82,7 +84,9 @@ def test_message_text_xml_whitespace(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange. - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) message = " mess\t age1\n" queue = qsc.get_queue_client(self.get_resource_name(TEST_QUEUE_PREFIX)) @@ -96,7 +100,9 @@ def test_message_text_xml_invalid_chars(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action. - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = self._get_queue_reference(qsc) message = "\u0001" @@ -111,7 +117,9 @@ def test_message_text_base64(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange. - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = QueueClient( account_url=self.account_url(storage_account_name, "queue"), queue_name=self.get_resource_name(TEST_QUEUE_PREFIX), @@ -132,7 +140,9 @@ def test_message_bytes_base64(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange. - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = QueueClient( account_url=self.account_url(storage_account_name, "queue"), queue_name=self.get_resource_name(TEST_QUEUE_PREFIX), @@ -153,7 +163,9 @@ def test_message_bytes_fails(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = qsc.get_queue_client(self.get_resource_name("failqueue")) queue.create_queue() @@ -165,7 +177,8 @@ def test_message_bytes_fails(self, **kwargs): # Asserts assert str( e.exception.startswith( - "Message content must not be bytes. " "Use the BinaryBase64EncodePolicy to send bytes." + "Message content must not be bytes. " + "Use the BinaryBase64EncodePolicy to send bytes." ) ) @@ -175,7 +188,9 @@ def test_message_text_fails(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = QueueClient( account_url=self.account_url(storage_account_name, "queue"), queue_name=self.get_resource_name(TEST_QUEUE_PREFIX), @@ -199,7 +214,9 @@ def test_message_base64_decode_fails(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = QueueClient( account_url=self.account_url(storage_account_name, "queue"), queue_name=self.get_resource_name(TEST_QUEUE_PREFIX), diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_encodings_async.py b/sdk/storage/azure-storage-queue/tests/test_queue_encodings_async.py index 90951d298e72..795e4fb18795 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_encodings_async.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_encodings_async.py @@ -64,7 +64,9 @@ async def test_message_text_xml(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange. - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) message = "" queue = qsc.get_queue_client(self.get_resource_name(TEST_QUEUE_PREFIX)) @@ -78,7 +80,9 @@ async def test_message_text_xml_whitespace(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange. - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) message = " mess\t age1\n" queue = qsc.get_queue_client(self.get_resource_name(TEST_QUEUE_PREFIX)) @@ -92,7 +96,9 @@ async def test_message_text_xml_invalid_chars(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action. - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = self._get_queue_reference(qsc) message = "\u0001" @@ -107,7 +113,9 @@ async def test_message_text_base64(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange. - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = QueueClient( account_url=self.account_url(storage_account_name, "queue"), queue_name=self.get_resource_name(TEST_QUEUE_PREFIX), @@ -128,7 +136,9 @@ async def test_message_bytes_base64(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange. - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = QueueClient( account_url=self.account_url(storage_account_name, "queue"), queue_name=self.get_resource_name(TEST_QUEUE_PREFIX), @@ -149,7 +159,9 @@ async def test_message_bytes_fails(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = await self._create_queue(qsc) # Action. with pytest.raises(TypeError) as e: @@ -159,7 +171,8 @@ async def test_message_bytes_fails(self, **kwargs): # Asserts assert str( e.exception.startswith( - "Message content must not be bytes. " "Use the BinaryBase64EncodePolicy to send bytes." + "Message content must not be bytes. " + "Use the BinaryBase64EncodePolicy to send bytes." ) ) @@ -169,7 +182,9 @@ async def test_message_text_fails(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = QueueClient( account_url=self.account_url(storage_account_name, "queue"), queue_name=self.get_resource_name(TEST_QUEUE_PREFIX), @@ -193,7 +208,9 @@ async def test_message_base64_decode_fails(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = QueueClient( account_url=self.account_url(storage_account_name, "queue"), queue_name=self.get_resource_name(TEST_QUEUE_PREFIX), diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_encryption.py b/sdk/storage/azure-storage-queue/tests/test_queue_encryption.py index 9aab6293c2f7..97c52230381b 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_encryption.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_encryption.py @@ -41,7 +41,6 @@ from encryption_test_helper import KeyResolver, KeyWrapper, mock_urandom, RSAKeyWrapper from settings.testcase import QueuePreparer - # ------------------------------------------------------------------------------ TEST_QUEUE_PREFIX = "encryptionqueue" # ------------------------------------------------------------------------------ @@ -78,7 +77,9 @@ def test_get_messages_encrypted_kek(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) qsc.key_encryption_key = KeyWrapper("key1") queue = self._create_queue(qsc) queue.send_message("encrypted_message_2") @@ -96,7 +97,9 @@ def test_get_messages_encrypted_resolver(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) qsc.key_encryption_key = KeyWrapper("key1") queue = self._create_queue(qsc) queue.send_message("encrypted_message_2") @@ -118,7 +121,9 @@ def test_peek_messages_encrypted_kek(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) qsc.key_encryption_key = KeyWrapper("key1") queue = self._create_queue(qsc) queue.send_message("encrypted_message_3") @@ -136,7 +141,9 @@ def test_peek_messages_encrypted_resolver(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) qsc.key_encryption_key = KeyWrapper("key1") queue = self._create_queue(qsc) queue.send_message("encrypted_message_4") @@ -161,7 +168,9 @@ def test_peek_messages_encrypted_kek_RSA(self, **kwargs): # the playback test will fail due to a change in kek values. # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) qsc.key_encryption_key = RSAKeyWrapper("key2") queue = self._create_queue(qsc) queue.send_message("encrypted_message_3") @@ -179,7 +188,9 @@ def test_update_encrypted_message(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = self._create_queue(qsc) queue.key_encryption_key = KeyWrapper("key1") queue.send_message("Update Me") @@ -202,9 +213,13 @@ def test_update_encrypted_binary_message(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = self._create_queue( - qsc, message_encode_policy=BinaryBase64EncodePolicy(), message_decode_policy=BinaryBase64DecodePolicy() + qsc, + message_encode_policy=BinaryBase64EncodePolicy(), + message_decode_policy=BinaryBase64DecodePolicy(), ) queue.key_encryption_key = KeyWrapper("key1") @@ -234,8 +249,12 @@ def test_update_encrypted_raw_text_message(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) - queue = self._create_queue(qsc, message_encode_policy=None, message_decode_policy=None) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) + queue = self._create_queue( + qsc, message_encode_policy=None, message_decode_policy=None + ) queue.key_encryption_key = KeyWrapper("key1") raw_text = "Update Me" @@ -260,8 +279,12 @@ def test_update_encrypted_json_message(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) - queue = self._create_queue(qsc, message_encode_policy=None, message_decode_policy=None) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) + queue = self._create_queue( + qsc, message_encode_policy=None, message_decode_policy=None + ) queue.key_encryption_key = KeyWrapper("key1") message_dict = {"val1": 1, "val2": "2"} @@ -289,7 +312,9 @@ def test_invalid_value_kek_wrap(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = self._create_queue(qsc) queue.key_encryption_key = KeyWrapper("key1") queue.key_encryption_key.get_kid = None @@ -297,7 +322,9 @@ def test_invalid_value_kek_wrap(self, **kwargs): with pytest.raises(AttributeError) as e: queue.send_message("message") - assert str(e.value.args[0]), _ERROR_OBJECT_INVALID.format("key encryption key" == "get_kid") + assert str(e.value.args[0]), _ERROR_OBJECT_INVALID.format( + "key encryption key" == "get_kid" + ) queue.key_encryption_key = KeyWrapper("key1") queue.key_encryption_key.get_kid = None @@ -316,13 +343,17 @@ def test_missing_attribute_kek_wrap(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = self._create_queue(qsc) valid_key = KeyWrapper("key1") # Act - invalid_key_1 = lambda: None # functions are objects, so this effectively creates an empty object + invalid_key_1 = ( + lambda: None + ) # functions are objects, so this effectively creates an empty object invalid_key_1.get_key_wrap_algorithm = valid_key.get_key_wrap_algorithm invalid_key_1.get_kid = valid_key.get_kid # No attribute wrap_key @@ -330,7 +361,9 @@ def test_missing_attribute_kek_wrap(self, **kwargs): with pytest.raises(AttributeError): queue.send_message("message") - invalid_key_2 = lambda: None # functions are objects, so this effectively creates an empty object + invalid_key_2 = ( + lambda: None + ) # functions are objects, so this effectively creates an empty object invalid_key_2.wrap_key = valid_key.wrap_key invalid_key_2.get_kid = valid_key.get_kid # No attribute get_key_wrap_algorithm @@ -338,7 +371,9 @@ def test_missing_attribute_kek_wrap(self, **kwargs): with pytest.raises(AttributeError): queue.send_message("message") - invalid_key_3 = lambda: None # functions are objects, so this effectively creates an empty object + invalid_key_3 = ( + lambda: None + ) # functions are objects, so this effectively creates an empty object invalid_key_3.get_key_wrap_algorithm = valid_key.get_key_wrap_algorithm invalid_key_3.wrap_key = valid_key.wrap_key # No attribute get_kid @@ -353,7 +388,9 @@ def test_invalid_value_kek_unwrap(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = self._create_queue(qsc) queue.key_encryption_key = KeyWrapper("key1") queue.send_message("message") @@ -374,14 +411,18 @@ def test_missing_attribute_kek_unwrap(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = self._create_queue(qsc) queue.key_encryption_key = KeyWrapper("key1") queue.send_message("message") # Act valid_key = KeyWrapper("key1") - invalid_key_1 = lambda: None # functions are objects, so this effectively creates an empty object + invalid_key_1 = ( + lambda: None + ) # functions are objects, so this effectively creates an empty object invalid_key_1.unwrap_key = valid_key.unwrap_key # No attribute get_kid queue.key_encryption_key = invalid_key_1 @@ -390,7 +431,9 @@ def test_missing_attribute_kek_unwrap(self, **kwargs): assert "Decryption failed." in str(e.value.args[0]) - invalid_key_2 = lambda: None # functions are objects, so this effectively creates an empty object + invalid_key_2 = ( + lambda: None + ) # functions are objects, so this effectively creates an empty object invalid_key_2.get_kid = valid_key.get_kid # No attribute unwrap_key queue.key_encryption_key = invalid_key_2 @@ -404,7 +447,9 @@ def test_validate_encryption(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = self._create_queue(qsc) kek = KeyWrapper("key1") queue.key_encryption_key = kek @@ -426,7 +471,9 @@ def test_validate_encryption(self, **kwargs): ) encryption_agent = encryption_data["EncryptionAgent"] - encryption_agent = _EncryptionAgent(encryption_agent["EncryptionAlgorithm"], encryption_agent["Protocol"]) + encryption_agent = _EncryptionAgent( + encryption_agent["EncryptionAlgorithm"], encryption_agent["Protocol"] + ) encryption_data = _EncryptionData( b64decode(encryption_data["ContentEncryptionIV"].encode(encoding="utf-8")), @@ -438,7 +485,8 @@ def test_validate_encryption(self, **kwargs): message = message["EncryptedMessageContents"] content_encryption_key = kek.unwrap_key( - encryption_data.wrapped_content_key.encrypted_key, encryption_data.wrapped_content_key.algorithm + encryption_data.wrapped_content_key.encrypted_key, + encryption_data.wrapped_content_key.algorithm, ) # Create decryption cipher @@ -468,7 +516,9 @@ def test_put_with_strict_mode(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = self._create_queue(qsc) kek = KeyWrapper("key1") queue.key_encryption_key = kek @@ -490,7 +540,9 @@ def test_get_with_strict_mode(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = self._create_queue(qsc) queue.send_message("message") @@ -499,7 +551,9 @@ def test_get_with_strict_mode(self, **kwargs): with pytest.raises(ValueError) as e: next(queue.receive_messages()) - assert "Message was either not encrypted or metadata was incorrect." in str(e.value.args[0]) + assert "Message was either not encrypted or metadata was incorrect." in str( + e.value.args[0] + ) @QueuePreparer() @recorded_by_proxy @@ -508,7 +562,9 @@ def test_encryption_add_encrypted_64k_message(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = self._create_queue(qsc) message = "a" * 1024 * 64 @@ -527,7 +583,9 @@ def test_encryption_nonmatching_kid(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) queue = self._create_queue(qsc) queue.key_encryption_key = KeyWrapper("key1") queue.send_message("message") @@ -664,7 +722,9 @@ def test_update_encrypted_binary_message_v2(self, **kwargs): key_encryption_key=KeyWrapper("key1"), ) queue = self._create_queue( - qsc, message_encode_policy=BinaryBase64EncodePolicy(), message_decode_policy=BinaryBase64DecodePolicy() + qsc, + message_encode_policy=BinaryBase64EncodePolicy(), + message_decode_policy=BinaryBase64DecodePolicy(), ) queue.key_encryption_key = KeyWrapper("key1") @@ -801,7 +861,9 @@ def assert_user_agent(request): key_encryption_key=kek, ) queue = self._create_queue(qsc) - queue.send_message(content, raw_request_hook=assert_user_agent, user_agent=app_id) + queue.send_message( + content, raw_request_hook=assert_user_agent, user_agent=app_id + ) # Test client constructor level keyword qsc = QueueServiceClient( diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_encryption_async.py b/sdk/storage/azure-storage-queue/tests/test_queue_encryption_async.py index 05b881c686d8..02177d3375b4 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_encryption_async.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_encryption_async.py @@ -12,7 +12,11 @@ import pytest from azure.core.exceptions import HttpResponseError, ResourceExistsError -from azure.storage.queue import BinaryBase64DecodePolicy, BinaryBase64EncodePolicy, VERSION +from azure.storage.queue import ( + BinaryBase64DecodePolicy, + BinaryBase64EncodePolicy, + VERSION, +) from azure.storage.queue.aio import QueueServiceClient from azure.storage.queue._encryption import ( _dict_to_encryption_data, @@ -72,7 +76,9 @@ async def test_get_messages_encrypted_kek(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) qsc.key_encryption_key = KeyWrapper("key1") queue = await self._create_queue(qsc) await queue.send_message("encrypted_message_2") @@ -92,7 +98,9 @@ async def test_get_messages_encrypted_resolver(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) qsc.key_encryption_key = KeyWrapper("key1") queue = await self._create_queue(qsc) await queue.send_message("encrypted_message_2") @@ -115,7 +123,9 @@ async def test_peek_messages_encrypted_kek(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Arrange qsc.key_encryption_key = KeyWrapper("key1") queue = await self._create_queue(qsc) @@ -133,7 +143,9 @@ async def test_peek_messages_encrypted_resolver(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Arrange qsc.key_encryption_key = KeyWrapper("key1") queue = await self._create_queue(qsc) @@ -155,7 +167,9 @@ async def test_peek_messages_encrypted_kek_RSA(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # We can only generate random RSA keys, so this must be run live or # the playback test will fail due to a change in kek values. @@ -176,7 +190,9 @@ async def test_update_encrypted_message(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Arrange queue = await self._create_queue(qsc) queue.key_encryption_key = KeyWrapper("key1") @@ -203,10 +219,14 @@ async def test_update_encrypted_binary_message(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Arrange queue = await self._create_queue( - qsc, message_encode_policy=BinaryBase64EncodePolicy(), message_decode_policy=BinaryBase64DecodePolicy() + qsc, + message_encode_policy=BinaryBase64EncodePolicy(), + message_decode_policy=BinaryBase64DecodePolicy(), ) queue.key_encryption_key = KeyWrapper("key1") @@ -235,9 +255,13 @@ async def test_update_encrypted_raw_text_message(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Arrange - queue = await self._create_queue(qsc, message_encode_policy=None, message_decode_policy=None) + queue = await self._create_queue( + qsc, message_encode_policy=None, message_decode_policy=None + ) queue.key_encryption_key = KeyWrapper("key1") raw_text = "Update Me" @@ -263,9 +287,13 @@ async def test_update_encrypted_json_message(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Arrange - queue = await self._create_queue(qsc, message_encode_policy=None, message_decode_policy=None) + queue = await self._create_queue( + qsc, message_encode_policy=None, message_decode_policy=None + ) queue.key_encryption_key = KeyWrapper("key1") message_dict = {"val1": 1, "val2": "2"} @@ -296,7 +324,9 @@ async def test_invalid_value_kek_wrap(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Arrange queue = await self._create_queue(qsc) queue.key_encryption_key = KeyWrapper("key1") @@ -305,7 +335,9 @@ async def test_invalid_value_kek_wrap(self, **kwargs): with pytest.raises(AttributeError) as e: await queue.send_message("message") - assert str(e.value.args[0]), _ERROR_OBJECT_INVALID.format("key encryption key" == "get_kid") + assert str(e.value.args[0]), _ERROR_OBJECT_INVALID.format( + "key encryption key" == "get_kid" + ) queue.key_encryption_key = KeyWrapper("key1") queue.key_encryption_key.get_kid = None @@ -323,14 +355,18 @@ async def test_missing_attribute_kek_wrap(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Arrange queue = await self._create_queue(qsc) valid_key = KeyWrapper("key1") # Act - invalid_key_1 = lambda: None # functions are objects, so this effectively creates an empty object + invalid_key_1 = ( + lambda: None + ) # functions are objects, so this effectively creates an empty object invalid_key_1.get_key_wrap_algorithm = valid_key.get_key_wrap_algorithm invalid_key_1.get_kid = valid_key.get_kid # No attribute wrap_key @@ -338,7 +374,9 @@ async def test_missing_attribute_kek_wrap(self, **kwargs): with pytest.raises(AttributeError): await queue.send_message("message") - invalid_key_2 = lambda: None # functions are objects, so this effectively creates an empty object + invalid_key_2 = ( + lambda: None + ) # functions are objects, so this effectively creates an empty object invalid_key_2.wrap_key = valid_key.wrap_key invalid_key_2.get_kid = valid_key.get_kid # No attribute get_key_wrap_algorithm @@ -346,7 +384,9 @@ async def test_missing_attribute_kek_wrap(self, **kwargs): with pytest.raises(AttributeError): await queue.send_message("message") - invalid_key_3 = lambda: None # functions are objects, so this effectively creates an empty object + invalid_key_3 = ( + lambda: None + ) # functions are objects, so this effectively creates an empty object invalid_key_3.get_key_wrap_algorithm = valid_key.get_key_wrap_algorithm invalid_key_3.wrap_key = valid_key.wrap_key # No attribute get_kid @@ -360,7 +400,9 @@ async def test_invalid_value_kek_unwrap(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Arrange queue = await self._create_queue(qsc) queue.key_encryption_key = KeyWrapper("key1") @@ -381,7 +423,9 @@ async def test_missing_attribute_kek_unwrap(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Arrange queue = await self._create_queue(qsc) queue.key_encryption_key = KeyWrapper("key1") @@ -389,7 +433,9 @@ async def test_missing_attribute_kek_unwrap(self, **kwargs): # Act valid_key = KeyWrapper("key1") - invalid_key_1 = lambda: None # functions are objects, so this effectively creates an empty object + invalid_key_1 = ( + lambda: None + ) # functions are objects, so this effectively creates an empty object invalid_key_1.unwrap_key = valid_key.unwrap_key # No attribute get_kid queue.key_encryption_key = invalid_key_1 @@ -398,7 +444,9 @@ async def test_missing_attribute_kek_unwrap(self, **kwargs): assert "Decryption failed." in str(e.value.args[0]) - invalid_key_2 = lambda: None # functions are objects, so this effectively creates an empty object + invalid_key_2 = ( + lambda: None + ) # functions are objects, so this effectively creates an empty object invalid_key_2.get_kid = valid_key.get_kid # No attribute unwrap_key queue.key_encryption_key = invalid_key_2 @@ -411,7 +459,9 @@ async def test_validate_encryption(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Arrange queue = await self._create_queue(qsc) kek = KeyWrapper("key1") @@ -434,7 +484,9 @@ async def test_validate_encryption(self, **kwargs): ) encryption_agent = encryption_data["EncryptionAgent"] - encryption_agent = _EncryptionAgent(encryption_agent["EncryptionAlgorithm"], encryption_agent["Protocol"]) + encryption_agent = _EncryptionAgent( + encryption_agent["EncryptionAlgorithm"], encryption_agent["Protocol"] + ) encryption_data = _EncryptionData( b64decode(encryption_data["ContentEncryptionIV"].encode(encoding="utf-8")), @@ -446,7 +498,8 @@ async def test_validate_encryption(self, **kwargs): message = message["EncryptedMessageContents"] content_encryption_key = kek.unwrap_key( - encryption_data.wrapped_content_key.encrypted_key, encryption_data.wrapped_content_key.algorithm + encryption_data.wrapped_content_key.encrypted_key, + encryption_data.wrapped_content_key.algorithm, ) # Create decryption cipher @@ -475,7 +528,9 @@ async def test_put_with_strict_mode(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Arrange queue = await self._create_queue(qsc) kek = KeyWrapper("key1") @@ -497,7 +552,9 @@ async def test_get_with_strict_mode(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Arrange queue = await self._create_queue(qsc) await queue.send_message("message") @@ -509,7 +566,9 @@ async def test_get_with_strict_mode(self, **kwargs): async for m in queue.receive_messages(): messages.append(m) _ = messages[0] - assert "Message was either not encrypted or metadata was incorrect." in str(e.value.args[0]) + assert "Message was either not encrypted or metadata was incorrect." in str( + e.value.args[0] + ) @QueuePreparer() @recorded_by_proxy_async @@ -517,7 +576,9 @@ async def test_encryption_add_encrypted_64k_message(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Arrange queue = await self._create_queue(qsc) message = "a" * 1024 * 64 @@ -536,7 +597,9 @@ async def test_encryption_nonmatching_kid(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Arrange queue = await self._create_queue(qsc) queue.key_encryption_key = KeyWrapper("key1") @@ -676,7 +739,9 @@ async def test_update_encrypted_binary_message_v2(self, **kwargs): key_encryption_key=KeyWrapper("key1"), ) queue = await self._create_queue( - qsc, message_encode_policy=BinaryBase64EncodePolicy(), message_decode_policy=BinaryBase64DecodePolicy() + qsc, + message_encode_policy=BinaryBase64EncodePolicy(), + message_decode_policy=BinaryBase64DecodePolicy(), ) queue.key_encryption_key = KeyWrapper("key1") @@ -813,7 +878,9 @@ def assert_user_agent(request): key_encryption_key=kek, ) queue = await self._create_queue(qsc) - await queue.send_message(content, raw_request_hook=assert_user_agent, user_agent=app_id) + await queue.send_message( + content, raw_request_hook=assert_user_agent, user_agent=app_id + ) # Test client constructor level keyword qsc = QueueServiceClient( diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_service_properties.py b/sdk/storage/azure-storage-queue/tests/test_queue_service_properties.py index 6d154ecf46a2..e3deba34540d 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_service_properties.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_service_properties.py @@ -9,13 +9,18 @@ import pytest from azure.core.exceptions import HttpResponseError -from azure.storage.queue import CorsRule, Metrics, QueueAnalyticsLogging, QueueServiceClient, RetentionPolicy +from azure.storage.queue import ( + CorsRule, + Metrics, + QueueAnalyticsLogging, + QueueServiceClient, + RetentionPolicy, +) from devtools_testutils import recorded_by_proxy from devtools_testutils.storage import StorageRecordedTestCase from settings.testcase import QueuePreparer - # ------------------------------------------------------------------------------ @@ -62,7 +67,9 @@ def _assert_delete_retention_policy_not_equal(self, policy1, policy2): assert policy1 != policy2 return - assert (policy1.enabled == policy2.enabled) is False or (policy1.days == policy2.days) is False + assert (policy1.enabled == policy2.enabled) is False or ( + policy1.days == policy2.days + ) is False def _assert_metrics_equal(self, metrics1, metrics2): if metrics1 is None or metrics2 is None: @@ -72,7 +79,9 @@ def _assert_metrics_equal(self, metrics1, metrics2): assert metrics1.version == metrics2.version assert metrics1.enabled == metrics2.enabled assert metrics1.include_apis == metrics2.include_apis - self._assert_retention_equal(metrics1.retention_policy, metrics2.retention_policy) + self._assert_retention_equal( + metrics1.retention_policy, metrics2.retention_policy + ) def _assert_cors_equal(self, cors1, cors2): if cors1 is None or cors2 is None: @@ -103,10 +112,15 @@ def test_queue_service_properties(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Act resp = qsc.set_service_properties( - analytics_logging=QueueAnalyticsLogging(), hour_metrics=Metrics(), minute_metrics=Metrics(), cors=[] + analytics_logging=QueueAnalyticsLogging(), + hour_metrics=Metrics(), + minute_metrics=Metrics(), + cors=[], ) # Assert @@ -122,9 +136,14 @@ def test_set_logging(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) logging = QueueAnalyticsLogging( - read=True, write=True, delete=True, retention_policy=RetentionPolicy(enabled=True, days=5) + read=True, + write=True, + delete=True, + retention_policy=RetentionPolicy(enabled=True, days=5), ) # Act @@ -141,8 +160,14 @@ def test_set_hour_metrics(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) - hour_metrics = Metrics(enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5)) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) + hour_metrics = Metrics( + enabled=True, + include_apis=True, + retention_policy=RetentionPolicy(enabled=True, days=5), + ) # Act qsc.set_service_properties(hour_metrics=hour_metrics) @@ -158,9 +183,13 @@ def test_set_minute_metrics(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) minute_metrics = Metrics( - enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5) + enabled=True, + include_apis=True, + retention_policy=RetentionPolicy(enabled=True, days=5), ) # Act @@ -177,14 +206,26 @@ def test_set_cors(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) cors_rule1 = CorsRule(["www.xyz.com"], ["GET"]) allowed_origins = ["www.xyz.com", "www.ab.com", "www.bc.com"] allowed_methods = ["GET", "PUT"] max_age_in_seconds = 500 - exposed_headers = ["x-ms-meta-data*", "x-ms-meta-source*", "x-ms-meta-abc", "x-ms-meta-bcd"] - allowed_headers = ["x-ms-meta-data*", "x-ms-meta-target*", "x-ms-meta-xyz", "x-ms-meta-foo"] + exposed_headers = [ + "x-ms-meta-data*", + "x-ms-meta-source*", + "x-ms-meta-abc", + "x-ms-meta-bcd", + ] + allowed_headers = [ + "x-ms-meta-data*", + "x-ms-meta-target*", + "x-ms-meta-xyz", + "x-ms-meta-foo", + ] cors_rule2 = CorsRule( allowed_origins, allowed_methods, @@ -218,13 +259,17 @@ def test_too_many_cors_rules(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) cors = [] for i in range(0, 6): cors.append(CorsRule(["www.xyz.com"], ["GET"])) # Assert - pytest.raises(HttpResponseError, qsc.set_service_properties, None, None, None, cors) + pytest.raises( + HttpResponseError, qsc.set_service_properties, None, None, None, cors + ) @QueuePreparer() @recorded_by_proxy @@ -233,13 +278,19 @@ def test_retention_too_long(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) minute_metrics = Metrics( - enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=366) + enabled=True, + include_apis=True, + retention_policy=RetentionPolicy(enabled=True, days=366), ) # Assert - pytest.raises(HttpResponseError, qsc.set_service_properties, None, None, minute_metrics) + pytest.raises( + HttpResponseError, qsc.set_service_properties, None, None, minute_metrics + ) # ------------------------------------------------------------------------------ diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_service_properties_async.py b/sdk/storage/azure-storage-queue/tests/test_queue_service_properties_async.py index f8bb7e39231e..19f966488406 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_service_properties_async.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_service_properties_async.py @@ -7,7 +7,12 @@ import pytest from azure.core.exceptions import HttpResponseError -from azure.storage.queue import CorsRule, Metrics, QueueAnalyticsLogging, RetentionPolicy +from azure.storage.queue import ( + CorsRule, + Metrics, + QueueAnalyticsLogging, + RetentionPolicy, +) from azure.storage.queue.aio import QueueServiceClient from devtools_testutils.aio import recorded_by_proxy_async @@ -58,7 +63,9 @@ def _assert_delete_retention_policy_not_equal(self, policy1, policy2): assert policy1 != policy2 return - assert (policy1.enabled == policy2.enabled) is False or (policy1.days == policy2.days) is False + assert (policy1.enabled == policy2.enabled) is False or ( + policy1.days == policy2.days + ) is False def _assert_metrics_equal(self, metrics1, metrics2): if metrics1 is None or metrics2 is None: @@ -68,7 +75,9 @@ def _assert_metrics_equal(self, metrics1, metrics2): assert metrics1.version == metrics2.version assert metrics1.enabled == metrics2.enabled assert metrics1.include_apis == metrics2.include_apis - self._assert_retention_equal(metrics1.retention_policy, metrics2.retention_policy) + self._assert_retention_equal( + metrics1.retention_policy, metrics2.retention_policy + ) def _assert_cors_equal(self, cors1, cors2): if cors1 is None or cors2 is None: @@ -99,11 +108,16 @@ async def test_queue_service_properties(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Act resp = await qsc.set_service_properties( - analytics_logging=QueueAnalyticsLogging(), hour_metrics=Metrics(), minute_metrics=Metrics(), cors=[] + analytics_logging=QueueAnalyticsLogging(), + hour_metrics=Metrics(), + minute_metrics=Metrics(), + cors=[], ) # Assert @@ -119,9 +133,14 @@ async def test_set_logging(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) logging = QueueAnalyticsLogging( - read=True, write=True, delete=True, retention_policy=RetentionPolicy(enabled=True, days=5) + read=True, + write=True, + delete=True, + retention_policy=RetentionPolicy(enabled=True, days=5), ) # Act @@ -138,8 +157,14 @@ async def test_set_hour_metrics(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) - hour_metrics = Metrics(enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5)) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) + hour_metrics = Metrics( + enabled=True, + include_apis=True, + retention_policy=RetentionPolicy(enabled=True, days=5), + ) # Act await qsc.set_service_properties(hour_metrics=hour_metrics) @@ -155,9 +180,13 @@ async def test_set_minute_metrics(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) minute_metrics = Metrics( - enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5) + enabled=True, + include_apis=True, + retention_policy=RetentionPolicy(enabled=True, days=5), ) # Act @@ -174,14 +203,26 @@ async def test_set_cors(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) cors_rule1 = CorsRule(["www.xyz.com"], ["GET"]) allowed_origins = ["www.xyz.com", "www.ab.com", "www.bc.com"] allowed_methods = ["GET", "PUT"] max_age_in_seconds = 500 - exposed_headers = ["x-ms-meta-data*", "x-ms-meta-source*", "x-ms-meta-abc", "x-ms-meta-bcd"] - allowed_headers = ["x-ms-meta-data*", "x-ms-meta-target*", "x-ms-meta-xyz", "x-ms-meta-foo"] + exposed_headers = [ + "x-ms-meta-data*", + "x-ms-meta-source*", + "x-ms-meta-abc", + "x-ms-meta-bcd", + ] + allowed_headers = [ + "x-ms-meta-data*", + "x-ms-meta-target*", + "x-ms-meta-xyz", + "x-ms-meta-foo", + ] cors_rule2 = CorsRule( allowed_origins, allowed_methods, @@ -207,7 +248,9 @@ async def test_retention_no_days(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Assert - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) pytest.raises(ValueError, RetentionPolicy, True, None) @QueuePreparer() @@ -217,7 +260,9 @@ async def test_too_many_cors_rules(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) cors = [] for _ in range(0, 6): cors.append(CorsRule(["www.xyz.com"], ["GET"])) @@ -233,9 +278,13 @@ async def test_retention_too_long(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) minute_metrics = Metrics( - enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=366) + enabled=True, + include_apis=True, + retention_policy=RetentionPolicy(enabled=True, days=366), ) # Assert diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_service_stats.py b/sdk/storage/azure-storage-queue/tests/test_queue_service_stats.py index 6c07b58a264c..aa818fb53473 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_service_stats.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_service_stats.py @@ -40,7 +40,9 @@ def test_queue_service_stats(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Act stats = qsc.get_service_stats() @@ -55,7 +57,9 @@ def test_queue_service_stats_when_unavailable(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Act stats = qsc.get_service_stats() diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_service_stats_async.py b/sdk/storage/azure-storage-queue/tests/test_queue_service_stats_async.py index 23a0f0ade37e..2c7ca3b097ec 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_service_stats_async.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_service_stats_async.py @@ -40,7 +40,9 @@ async def test_queue_service_stats(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Act stats = await qsc.get_service_stats() @@ -55,7 +57,9 @@ async def test_queue_service_stats_when_unavailable(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + qsc = QueueServiceClient( + self.account_url(storage_account_name, "queue"), storage_account_key.secret + ) # Act stats = await qsc.get_service_stats() From baf0cc317163804a50b635ce888451deba181f1a Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 27 Mar 2026 20:55:45 -0400 Subject: [PATCH 13/16] Resolved pylint errors --- .../azure/storage/blob/_shared/base_client.py | 9 ++++++++- .../azure/storage/blob/_shared_access_signature.py | 4 ++-- .../azure/storage/filedatalake/_shared/base_client.py | 9 ++++++++- .../azure/storage/fileshare/_shared/base_client.py | 9 ++++++++- .../azure/storage/queue/_shared/base_client.py | 9 ++++++++- 5 files changed, 34 insertions(+), 6 deletions(-) diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_shared/base_client.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_shared/base_client.py index 9a8a595336d3..9674127b7952 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_shared/base_client.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_shared/base_client.py @@ -78,7 +78,14 @@ def _construct_endpoints(netloc: str, account_part: str) -> Tuple[str, str, str]: - """Construct primary and secondary hostnames from a storage account URL's netloc.""" + """ + Construct primary and secondary hostnames from a storage account URL's netloc. + + :param str netloc: The network location in a URL. + :param account_part: The account part after parsing the URL. + :return: The account name, primary hostname, and secondary hostname. + :rtype: Tuple[str, str, str] + """ domain_suffix = netloc[len(account_part):] secondary_idx = account_part.find(_SECONDARY_SUFFIX) diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py index bfe0e5c30fb0..866b6ea51ef2 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py @@ -150,7 +150,7 @@ def generate_blob( :param Dict[str, str] request_query_params: Specifies a set of query parameters and their corresponding values that must be present in the request when using this SAS. - :keyword Optional[bool] is_directory: + :param Optional[bool] is_directory: Specifies whether the `blob_name` is a virtual directory. If set, the `blob_name` is treated to be a virtual directory name for a Directory SAS. When set, do not prefix or suffix the `blob_name` with `/`. If not set, the `blob_name` is assumed to be a blob name for a Blob SAS. @@ -323,7 +323,7 @@ def add_directory_depth(self, blob_name, sdd): # sdd may be provided from Datalake # If not provided, it will be manually computed from blob_name if sdd is None: - if blob_name == "" or blob_name == "/": + if blob_name in ["", "/"]: sdd = 0 else: sdd = len(blob_name.strip("/").split("/")) diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared/base_client.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared/base_client.py index 60aa8e43aa58..ea3ceefded6f 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared/base_client.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared/base_client.py @@ -78,7 +78,14 @@ def _construct_endpoints(netloc: str, account_part: str) -> Tuple[str, str, str]: - """Construct primary and secondary hostnames from a storage account URL's netloc.""" + """ + Construct primary and secondary hostnames from a storage account URL's netloc. + + :param str netloc: The network location in a URL. + :param account_part: The account part after parsing the URL. + :return: The account name, primary hostname, and secondary hostname. + :rtype: Tuple[str, str, str] + """ domain_suffix = netloc[len(account_part):] secondary_idx = account_part.find(_SECONDARY_SUFFIX) diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/base_client.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/base_client.py index 60aa8e43aa58..ea3ceefded6f 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/base_client.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/base_client.py @@ -78,7 +78,14 @@ def _construct_endpoints(netloc: str, account_part: str) -> Tuple[str, str, str]: - """Construct primary and secondary hostnames from a storage account URL's netloc.""" + """ + Construct primary and secondary hostnames from a storage account URL's netloc. + + :param str netloc: The network location in a URL. + :param account_part: The account part after parsing the URL. + :return: The account name, primary hostname, and secondary hostname. + :rtype: Tuple[str, str, str] + """ domain_suffix = netloc[len(account_part):] secondary_idx = account_part.find(_SECONDARY_SUFFIX) diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client.py index e5740f772937..a2ec8f687c09 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client.py @@ -85,7 +85,14 @@ def _construct_endpoints(netloc: str, account_part: str) -> Tuple[str, str, str]: - """Construct primary and secondary hostnames from a storage account URL's netloc.""" + """ + Construct primary and secondary hostnames from a storage account URL's netloc. + + :param str netloc: The network location in a URL. + :param account_part: The account part after parsing the URL. + :return: The account name, primary hostname, and secondary hostname. + :rtype: Tuple[str, str, str] + """ domain_suffix = netloc[len(account_part) :] secondary_idx = account_part.find(_SECONDARY_SUFFIX) From 0f515b3f1a05083381f0dfcead850af428bb0958 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 27 Mar 2026 21:55:10 -0400 Subject: [PATCH 14/16] More pylint problems --- .../azure/storage/queue/_deserialize.py | 8 +- .../azure/storage/queue/_encryption.py | 133 ++------ .../queue/_generated/_azure_queue_storage.py | 40 +-- .../queue/_generated/_configuration.py | 24 +- .../queue/_generated/_utils/serialization.py | 241 ++++---------- .../_generated/aio/_azure_queue_storage.py | 34 +- .../queue/_generated/aio/_configuration.py | 28 +- .../aio/operations/_message_id_operations.py | 78 ++--- .../aio/operations/_messages_operations.py | 133 ++------ .../queue/_generated/aio/operations/_patch.py | 4 +- .../aio/operations/_queue_operations.py | 179 +++------- .../aio/operations/_service_operations.py | 188 +++-------- .../queue/_generated/models/_models_py3.py | 22 +- .../storage/queue/_generated/models/_patch.py | 4 +- .../operations/_message_id_operations.py | 107 ++---- .../operations/_messages_operations.py | 197 +++-------- .../queue/_generated/operations/_patch.py | 4 +- .../operations/_queue_operations.py | 261 ++++----------- .../operations/_service_operations.py | 292 ++++------------- .../azure/storage/queue/_message_encoding.py | 12 +- .../azure/storage/queue/_models.py | 27 +- .../azure/storage/queue/_queue_client.py | 128 ++------ .../storage/queue/_queue_client_helpers.py | 13 +- .../storage/queue/_queue_service_client.py | 36 +- .../queue/_queue_service_client_helpers.py | 4 +- .../azure/storage/queue/_serialize.py | 4 +- .../storage/queue/_shared/authentication.py | 6 +- .../storage/queue/_shared/base_client.py | 50 +-- .../queue/_shared/base_client_async.py | 17 +- .../azure/storage/queue/_shared/models.py | 72 +--- .../azure/storage/queue/_shared/policies.py | 150 +++------ .../storage/queue/_shared/policies_async.py | 98 ++---- .../storage/queue/_shared/request_handlers.py | 30 +- .../queue/_shared/response_handlers.py | 61 +--- .../queue/_shared/shared_access_signature.py | 20 +- .../azure/storage/queue/_shared/uploads.py | 69 +--- .../storage/queue/_shared/uploads_async.py | 43 +-- .../storage/queue/_shared_access_signature.py | 46 +-- .../azure/storage/queue/aio/_models.py | 11 +- .../storage/queue/aio/_queue_client_async.py | 134 ++------ .../queue/aio/_queue_service_client_async.py | 36 +- .../samples/queue_samples_authentication.py | 20 +- .../queue_samples_authentication_async.py | 20 +- .../samples/queue_samples_hello_world.py | 8 +- .../queue_samples_hello_world_async.py | 8 +- .../samples/queue_samples_message.py | 14 +- .../samples/queue_samples_message_async.py | 50 +-- .../samples/queue_samples_service.py | 16 +- .../samples/queue_samples_service_async.py | 16 +- .../azure-storage-queue/tests/conftest.py | 16 +- .../tests/encryption_test_helper.py | 12 +- .../tests/settings/testcase.py | 16 +- .../azure-storage-queue/tests/test_queue.py | 286 +++++----------- .../tests/test_queue_api_version.py | 4 +- .../tests/test_queue_api_version_async.py | 4 +- .../tests/test_queue_async.py | 310 +++++------------- .../tests/test_queue_client.py | 179 +++------- .../tests/test_queue_client_async.py | 171 +++------- .../tests/test_queue_encodings.py | 35 +- .../tests/test_queue_encodings_async.py | 35 +- .../tests/test_queue_encryption.py | 116 ++----- .../tests/test_queue_encryption_async.py | 116 ++----- .../tests/test_queue_service_properties.py | 44 +-- .../test_queue_service_properties_async.py | 40 +-- .../tests/test_queue_service_stats.py | 8 +- .../tests/test_queue_service_stats_async.py | 8 +- 66 files changed, 1153 insertions(+), 3443 deletions(-) diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_deserialize.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_deserialize.py index e46e26dc7da6..355a0053c2dc 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_deserialize.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_deserialize.py @@ -16,17 +16,13 @@ from azure.core.pipeline import PipelineResponse -def deserialize_queue_properties( - response: "PipelineResponse", obj: Any, headers: Dict[str, Any] -) -> QueueProperties: +def deserialize_queue_properties(response: "PipelineResponse", obj: Any, headers: Dict[str, Any]) -> QueueProperties: metadata = deserialize_metadata(response, obj, headers) queue_properties = QueueProperties(metadata=metadata, **headers) return queue_properties -def deserialize_queue_creation( - response: "PipelineResponse", obj: Any, headers: Dict[str, Any] -) -> Dict[str, Any]: +def deserialize_queue_creation(response: "PipelineResponse", obj: Any, headers: Dict[str, Any]) -> Dict[str, Any]: response = response.http_response if response.status_code == 204: # type: ignore [attr-defined] error_code = StorageErrorCode.queue_already_exists diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_encryption.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_encryption.py index 204f5f3319aa..5d9fcb187987 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_encryption.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_encryption.py @@ -53,7 +53,9 @@ _ERROR_OBJECT_INVALID = "{0} does not define a complete interface. Value of {1} is either missing or invalid." -_ERROR_UNSUPPORTED_METHOD_FOR_ENCRYPTION = "The require_encryption flag is set, but encryption is not supported for this method." +_ERROR_UNSUPPORTED_METHOD_FOR_ENCRYPTION = ( + "The require_encryption flag is set, but encryption is not supported for this method." +) class KeyEncryptionKey(Protocol): @@ -75,19 +77,11 @@ def _validate_not_none(param_name: str, param: Any): def _validate_key_encryption_key_wrap(kek: KeyEncryptionKey): # Note that None is not callable and so will fail the second clause of each check. if not hasattr(kek, "wrap_key") or not callable(kek.wrap_key): - raise AttributeError( - _ERROR_OBJECT_INVALID.format("key encryption key", "wrap_key") - ) + raise AttributeError(_ERROR_OBJECT_INVALID.format("key encryption key", "wrap_key")) if not hasattr(kek, "get_kid") or not callable(kek.get_kid): - raise AttributeError( - _ERROR_OBJECT_INVALID.format("key encryption key", "get_kid") - ) - if not hasattr(kek, "get_key_wrap_algorithm") or not callable( - kek.get_key_wrap_algorithm - ): - raise AttributeError( - _ERROR_OBJECT_INVALID.format("key encryption key", "get_key_wrap_algorithm") - ) + raise AttributeError(_ERROR_OBJECT_INVALID.format("key encryption key", "get_kid")) + if not hasattr(kek, "get_key_wrap_algorithm") or not callable(kek.get_key_wrap_algorithm): + raise AttributeError(_ERROR_OBJECT_INVALID.format("key encryption key", "get_key_wrap_algorithm")) class StorageEncryptionMixin(object): @@ -167,9 +161,7 @@ class _EncryptionAgent: It consists of the encryption protocol version and encryption algorithm used. """ - def __init__( - self, encryption_algorithm: _EncryptionAlgorithm, protocol: str - ) -> None: + def __init__(self, encryption_algorithm: _EncryptionAlgorithm, protocol: str) -> None: """ :param _EncryptionAlgorithm encryption_algorithm: The algorithm used for encrypting the message contents. @@ -281,9 +273,7 @@ def read(self, size: int = -1) -> bytes: # No more data to read break - self.current = encrypt_data_v2( - data, self.nonce_counter, self.content_encryption_key - ) + self.current = encrypt_data_v2(data, self.nonce_counter, self.content_encryption_key) # IMPORTANT: Must increment the nonce each time. self.nonce_counter += 1 @@ -318,10 +308,7 @@ def is_encryption_v2(encryption_data: Optional[_EncryptionData]) -> bool: :rtype: bool """ # If encryption_data is None, assume no encryption - return bool( - encryption_data - and (encryption_data.encryption_agent.protocol in _ENCRYPTION_V2_PROTOCOLS) - ) + return bool(encryption_data and (encryption_data.encryption_agent.protocol in _ENCRYPTION_V2_PROTOCOLS)) def modify_user_agent_for_encryption( @@ -472,16 +459,12 @@ def parse_encryption_data(metadata: Dict[str, Any]) -> Optional[_EncryptionData] try: # Use case insensitive dict as key needs to be case-insensitive case_insensitive_metadata = CaseInsensitiveDict(metadata) - return _dict_to_encryption_data( - loads(case_insensitive_metadata["encryptiondata"]) - ) + return _dict_to_encryption_data(loads(case_insensitive_metadata["encryptiondata"])) except: # pylint: disable=bare-except return None -def adjust_blob_size_for_encryption( - size: int, encryption_data: Optional[_EncryptionData] -) -> int: +def adjust_blob_size_for_encryption(size: int, encryption_data: Optional[_EncryptionData]) -> int: """ Adjusts the given blob size for encryption by subtracting the size of the encryption data (nonce + tag). This only has an affect for encryption V2. @@ -560,9 +543,7 @@ def _generate_encryption_data_dict( encryption_data_dict["ContentEncryptionIV"] = encode_base64(iv) elif version == _ENCRYPTION_PROTOCOL_V2: encryption_data_dict["EncryptedRegionInfo"] = encrypted_region_info - encryption_data_dict["KeyWrappingMetadata"] = OrderedDict( - {"EncryptionLibrary": "Python " + VERSION} - ) + encryption_data_dict["KeyWrappingMetadata"] = OrderedDict({"EncryptionLibrary": "Python " + VERSION}) return encryption_data_dict @@ -591,9 +572,7 @@ def _dict_to_encryption_data(encryption_data_dict: Dict[str, Any]) -> _Encryptio ) encryption_agent = encryption_data_dict["EncryptionAgent"] - encryption_agent = _EncryptionAgent( - encryption_agent["EncryptionAlgorithm"], encryption_agent["Protocol"] - ) + encryption_agent = _EncryptionAgent(encryption_agent["EncryptionAlgorithm"], encryption_agent["Protocol"]) if "KeyWrappingMetadata" in encryption_data_dict: key_wrapping_metadata = encryption_data_dict["KeyWrappingMetadata"] @@ -603,9 +582,7 @@ def _dict_to_encryption_data(encryption_data_dict: Dict[str, Any]) -> _Encryptio # AES-CBC only encryption_iv = None if "ContentEncryptionIV" in encryption_data_dict: - encryption_iv = decode_base64_to_bytes( - encryption_data_dict["ContentEncryptionIV"] - ) + encryption_iv = decode_base64_to_bytes(encryption_data_dict["ContentEncryptionIV"]) # AES-GCM only region_info = None @@ -669,19 +646,13 @@ def _validate_and_unwrap_cek( :rtype: bytes """ - _validate_not_none( - "encrypted_key", encryption_data.wrapped_content_key.encrypted_key - ) + _validate_not_none("encrypted_key", encryption_data.wrapped_content_key.encrypted_key) # Validate we have the right info for the specified version if encryption_data.encryption_agent.protocol == _ENCRYPTION_PROTOCOL_V1: - _validate_not_none( - "content_encryption_IV", encryption_data.content_encryption_IV - ) + _validate_not_none("content_encryption_IV", encryption_data.content_encryption_IV) elif encryption_data.encryption_agent.protocol in _ENCRYPTION_V2_PROTOCOLS: - _validate_not_none( - "encrypted_region_info", encryption_data.encrypted_region_info - ) + _validate_not_none("encrypted_region_info", encryption_data.encrypted_region_info) else: raise ValueError("Specified encryption version is not supported.") @@ -692,25 +663,13 @@ def _validate_and_unwrap_cek( key_encryption_key = key_resolver(encryption_data.wrapped_content_key.key_id) if key_encryption_key is None: - raise ValueError( - "Unable to decrypt. key_resolver and key_encryption_key cannot both be None." - ) - if not hasattr(key_encryption_key, "get_kid") or not callable( - key_encryption_key.get_kid - ): - raise AttributeError( - _ERROR_OBJECT_INVALID.format("key encryption key", "get_kid") - ) - if not hasattr(key_encryption_key, "unwrap_key") or not callable( - key_encryption_key.unwrap_key - ): - raise AttributeError( - _ERROR_OBJECT_INVALID.format("key encryption key", "unwrap_key") - ) + raise ValueError("Unable to decrypt. key_resolver and key_encryption_key cannot both be None.") + if not hasattr(key_encryption_key, "get_kid") or not callable(key_encryption_key.get_kid): + raise AttributeError(_ERROR_OBJECT_INVALID.format("key encryption key", "get_kid")) + if not hasattr(key_encryption_key, "unwrap_key") or not callable(key_encryption_key.unwrap_key): + raise AttributeError(_ERROR_OBJECT_INVALID.format("key encryption key", "unwrap_key")) if encryption_data.wrapped_content_key.key_id != key_encryption_key.get_kid(): - raise ValueError( - "Provided or resolved key-encryption-key does not match the id of key used to encrypt." - ) + raise ValueError("Provided or resolved key-encryption-key does not match the id of key used to encrypt.") # Will throw an exception if the specified algorithm is not supported. content_encryption_key = key_encryption_key.unwrap_key( encryption_data.wrapped_content_key.encrypted_key, @@ -720,14 +679,10 @@ def _validate_and_unwrap_cek( # For V2, the version is included with the cek. We need to validate it # and remove it from the actual cek. if encryption_data.encryption_agent.protocol in _ENCRYPTION_V2_PROTOCOLS: - version_2_bytes = encryption_data.encryption_agent.protocol.encode().ljust( - 8, b"\0" - ) + version_2_bytes = encryption_data.encryption_agent.protocol.encode().ljust(8, b"\0") cek_version_bytes = content_encryption_key[: len(version_2_bytes)] if cek_version_bytes != version_2_bytes: - raise ValueError( - "The encryption metadata is not valid and may have been modified." - ) + raise ValueError("The encryption metadata is not valid and may have been modified.") # Remove version from the start of the cek. content_encryption_key = content_encryption_key[len(version_2_bytes) :] @@ -767,17 +722,13 @@ def _decrypt_message( :rtype: bytes """ _validate_not_none("message", message) - content_encryption_key = _validate_and_unwrap_cek( - encryption_data, key_encryption_key, resolver - ) + content_encryption_key = _validate_and_unwrap_cek(encryption_data, key_encryption_key, resolver) if encryption_data.encryption_agent.protocol == _ENCRYPTION_PROTOCOL_V1: if not encryption_data.content_encryption_IV: raise ValueError("Missing required metadata for decryption.") - cipher = _generate_AES_CBC_cipher( - content_encryption_key, encryption_data.content_encryption_IV - ) + cipher = _generate_AES_CBC_cipher(content_encryption_key, encryption_data.content_encryption_IV) # decrypt data decryptor = cipher.decryptor() @@ -810,9 +761,7 @@ def _decrypt_message( return decrypted_data -def encrypt_blob( - blob: bytes, key_encryption_key: KeyEncryptionKey, version: str -) -> Tuple[str, bytes]: +def encrypt_blob(blob: bytes, key_encryption_key: KeyEncryptionKey, version: str) -> Tuple[str, bytes]: """ Encrypts the given blob using the given encryption protocol version. Wraps the generated content-encryption-key using the user-provided key-encryption-key (kek). @@ -946,9 +895,7 @@ def decrypt_blob( # pylint: disable=too-many-locals,too-many-statements :rtype: bytes """ try: - encryption_data = _dict_to_encryption_data( - loads(response_headers["x-ms-meta-encryptiondata"]) - ) + encryption_data = _dict_to_encryption_data(loads(response_headers["x-ms-meta-encryptiondata"])) except Exception as exc: # pylint: disable=broad-except if require_encryption: raise ValueError( @@ -969,9 +916,7 @@ def decrypt_blob( # pylint: disable=too-many-locals,too-many-statements if version not in _VALID_ENCRYPTION_PROTOCOLS: raise ValueError("Specified encryption version is not supported.") - content_encryption_key = _validate_and_unwrap_cek( - encryption_data, key_encryption_key, key_resolver - ) + content_encryption_key = _validate_and_unwrap_cek(encryption_data, key_encryption_key, key_resolver) if version == _ENCRYPTION_PROTOCOL_V1: blob_type = response_headers["x-ms-blob-type"] @@ -1068,9 +1013,7 @@ def get_blob_encryptor_and_padder( return encryptor, padder -def encrypt_queue_message( - message: str, key_encryption_key: KeyEncryptionKey, version: str -) -> str: +def encrypt_queue_message(message: str, key_encryption_key: KeyEncryptionKey, version: str) -> str: """ Encrypts the given plain text message using the given protocol version. Wraps the generated content-encryption-key using the user-provided key-encryption-key (kek). @@ -1176,12 +1119,8 @@ def decrypt_queue_message( try: deserialized_message: Dict[str, Any] = loads(message) - encryption_data = _dict_to_encryption_data( - deserialized_message["EncryptionData"] - ) - decoded_data = decode_base64_to_bytes( - deserialized_message["EncryptedMessageContents"] - ) + encryption_data = _dict_to_encryption_data(deserialized_message["EncryptionData"]) + decoded_data = decode_base64_to_bytes(deserialized_message["EncryptedMessageContents"]) except (KeyError, ValueError) as exc: # Message was not json formatted and so was not encrypted # or the user provided a json formatted message @@ -1194,9 +1133,7 @@ def decrypt_queue_message( return message try: - return _decrypt_message( - decoded_data, encryption_data, key_encryption_key, resolver - ).decode("utf-8") + return _decrypt_message(decoded_data, encryption_data, key_encryption_key, resolver).decode("utf-8") except Exception as error: raise HttpResponseError( message="Decryption failed.", response=response, error=error # type: ignore [arg-type] diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/_azure_queue_storage.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/_azure_queue_storage.py index c2bd463fd619..688769fac8c3 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/_azure_queue_storage.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/_azure_queue_storage.py @@ -48,9 +48,7 @@ class AzureQueueStorage: # pylint: disable=client-accepts-api-version-keyword def __init__( # pylint: disable=missing-client-constructor-parameter-credential self, url: str, version: str, base_url: str = "", **kwargs: Any ) -> None: - self._config = AzureQueueStorageConfiguration( - url=url, version=version, **kwargs - ) + self._config = AzureQueueStorageConfiguration(url=url, version=version, **kwargs) _policies = kwargs.pop("policies", None) if _policies is None: @@ -66,39 +64,21 @@ def __init__( # pylint: disable=missing-client-constructor-parameter-credential self._config.custom_hook_policy, self._config.logging_policy, policies.DistributedTracingPolicy(**kwargs), - ( - policies.SensitiveHeaderCleanupPolicy(**kwargs) - if self._config.redirect_policy - else None - ), + (policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None), self._config.http_logging_policy, ] - self._client: PipelineClient = PipelineClient( - base_url=base_url, policies=_policies, **kwargs - ) + self._client: PipelineClient = PipelineClient(base_url=base_url, policies=_policies, **kwargs) - client_models = { - k: v for k, v in _models.__dict__.items() if isinstance(v, type) - } + client_models = {k: v for k, v in _models.__dict__.items() if isinstance(v, type)} self._serialize = Serializer(client_models) self._deserialize = Deserializer(client_models) self._serialize.client_side_validation = False - self.service = ServiceOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.queue = QueueOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.messages = MessagesOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.message_id = MessageIdOperations( - self._client, self._config, self._serialize, self._deserialize - ) - - def _send_request( - self, request: HttpRequest, *, stream: bool = False, **kwargs: Any - ) -> HttpResponse: + self.service = ServiceOperations(self._client, self._config, self._serialize, self._deserialize) + self.queue = QueueOperations(self._client, self._config, self._serialize, self._deserialize) + self.messages = MessagesOperations(self._client, self._config, self._serialize, self._deserialize) + self.message_id = MessageIdOperations(self._client, self._config, self._serialize, self._deserialize) + + def _send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse: """Runs the network request through the client's chained policies. >>> from azure.core.rest import HttpRequest diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/_configuration.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/_configuration.py index 1ea4478a7f01..04adef0da253 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/_configuration.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/_configuration.py @@ -39,24 +39,12 @@ def __init__(self, url: str, version: str, **kwargs: Any) -> None: self._configure(**kwargs) def _configure(self, **kwargs: Any) -> None: - self.user_agent_policy = kwargs.get( - "user_agent_policy" - ) or policies.UserAgentPolicy(**kwargs) - self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy( - **kwargs - ) + self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs) + self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs) self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs) - self.logging_policy = kwargs.get( - "logging_policy" - ) or policies.NetworkTraceLoggingPolicy(**kwargs) - self.http_logging_policy = kwargs.get( - "http_logging_policy" - ) or policies.HttpLoggingPolicy(**kwargs) - self.custom_hook_policy = kwargs.get( - "custom_hook_policy" - ) or policies.CustomHookPolicy(**kwargs) - self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy( - **kwargs - ) + self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs) + self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs) + self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs) + self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs) self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs) self.authentication_policy = kwargs.get("authentication_policy") diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/_utils/serialization.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/_utils/serialization.py index 7a2a33ce8b12..adacf7b3e18a 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/_utils/serialization.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/_utils/serialization.py @@ -58,9 +58,7 @@ class RawDeserializer: CONTEXT_NAME = "deserialized_data" @classmethod - def deserialize_from_text( - cls, data: Optional[Union[AnyStr, IO]], content_type: Optional[str] = None - ) -> Any: + def deserialize_from_text(cls, data: Optional[Union[AnyStr, IO]], content_type: Optional[str] = None) -> Any: """Decode data according to content-type. Accept a stream of data as well, but will be load at once in memory for now. @@ -93,9 +91,7 @@ def deserialize_from_text( try: return json.loads(data_as_str) except ValueError as err: - raise DeserializationError( - "JSON is invalid: {}".format(err), err - ) from err + raise DeserializationError("JSON is invalid: {}".format(err), err) from err elif "xml" in (content_type or []): try: @@ -129,14 +125,10 @@ def _json_attemp(data): raise DeserializationError("XML is invalid") from err elif content_type.startswith("text/"): return data_as_str - raise DeserializationError( - "Cannot deserialize content-type: {}".format(content_type) - ) + raise DeserializationError("Cannot deserialize content-type: {}".format(content_type)) @classmethod - def deserialize_from_http_generics( - cls, body_bytes: Optional[Union[AnyStr, IO]], headers: Mapping - ) -> Any: + def deserialize_from_http_generics(cls, body_bytes: Optional[Union[AnyStr, IO]], headers: Mapping) -> Any: """Deserialize from HTTP response. Use bytes and headers to NOT use any requests/aiohttp or whatever @@ -188,9 +180,7 @@ def attribute_transformer(key, attr_desc, value): # pylint: disable=unused-argu return (key, value) -def full_restapi_key_transformer( - key, attr_desc, value -): # pylint: disable=unused-argument +def full_restapi_key_transformer(key, attr_desc, value): # pylint: disable=unused-argument """A key transformer that returns the full RestAPI key path. :param str key: The attribute name @@ -331,9 +321,7 @@ def serialize(self, keep_readonly: bool = False, **kwargs: Any) -> JSON: def as_dict( self, keep_readonly: bool = True, - key_transformer: Callable[ - [str, dict[str, Any], Any], Any - ] = attribute_transformer, + key_transformer: Callable[[str, dict[str, Any], Any], Any] = attribute_transformer, **kwargs: Any ) -> JSON: """Return a dict that can be serialized using json.dump. @@ -377,9 +365,7 @@ def _infer_class_models(cls): try: str_models = cls.__module__.rsplit(".", 1)[0] models = sys.modules[str_models] - client_models = { - k: v for k, v in models.__dict__.items() if isinstance(v, type) - } + client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)} if cls.__name__ not in client_models: raise ValueError("Not Autorest generated code") except Exception: # pylint: disable=broad-exception-caught @@ -438,9 +424,7 @@ def _flatten_subtype(cls, key, objects): return {} result = dict(cls._subtype_map[key]) for valuetype in cls._subtype_map[key].values(): - result |= objects[valuetype]._flatten_subtype( - key, objects - ) # pylint: disable=protected-access + result |= objects[valuetype]._flatten_subtype(key, objects) # pylint: disable=protected-access return result @classmethod @@ -458,13 +442,9 @@ def _classify(cls, response, objects): if not isinstance(response, ET.Element): rest_api_response_key = cls._get_rest_key_parts(subtype_key)[-1] - subtype_value = response.get( - rest_api_response_key, None - ) or response.get(subtype_key, None) + subtype_value = response.get(rest_api_response_key, None) or response.get(subtype_key, None) else: - subtype_value = xml_key_extractor( - subtype_key, cls._attribute_map[subtype_key], response - ) + subtype_value = xml_key_extractor(subtype_key, cls._attribute_map[subtype_key], response) if subtype_value: # Try to match base class. Can be class name only # (bug to fix in Autorest to support x-ms-discriminator-name) @@ -597,25 +577,18 @@ def _serialize( # pylint: disable=too-many-nested-blocks, too-many-branches, to try: is_xml_model_serialization = kwargs["is_xml"] except KeyError: - is_xml_model_serialization = kwargs.setdefault( - "is_xml", target_obj.is_xml_model() - ) + is_xml_model_serialization = kwargs.setdefault("is_xml", target_obj.is_xml_model()) serialized = {} if is_xml_model_serialization: - serialized = ( - target_obj._create_xml_node() - ) # pylint: disable=protected-access + serialized = target_obj._create_xml_node() # pylint: disable=protected-access try: attributes = target_obj._attribute_map # pylint: disable=protected-access for attr, attr_desc in attributes.items(): attr_name = attr - if ( - not keep_readonly - and target_obj._validation.get( # pylint: disable=protected-access - attr_name, {} - ).get("readonly", False) - ): + if not keep_readonly and target_obj._validation.get( # pylint: disable=protected-access + attr_name, {} + ).get("readonly", False): continue if attr_name == "additional_properties" and attr_desc["key"] == "": @@ -628,15 +601,11 @@ def _serialize( # pylint: disable=too-many-nested-blocks, too-many-branches, to if is_xml_model_serialization: pass # Don't provide "transformer" for XML for now. Keep "orig_attr" else: # JSON - keys, orig_attr = key_transformer( - attr, attr_desc.copy(), orig_attr - ) + keys, orig_attr = key_transformer(attr, attr_desc.copy(), orig_attr) keys = keys if isinstance(keys, list) else [keys] kwargs["serialization_ctxt"] = attr_desc - new_attr = self.serialize_data( - orig_attr, attr_desc["type"], **kwargs - ) + new_attr = self.serialize_data(orig_attr, attr_desc["type"], **kwargs) if is_xml_model_serialization: xml_desc = attr_desc.get("xml", {}) @@ -685,9 +654,7 @@ def _serialize( # pylint: disable=too-many-nested-blocks, too-many-branches, to raise except (AttributeError, KeyError, TypeError) as err: - msg = "Attribute {} in object {} cannot be serialized.\n{}".format( - attr_name, class_name, str(target_obj) - ) + msg = "Attribute {} in object {} cannot be serialized.\n{}".format(attr_name, class_name, str(target_obj)) raise SerializationError(msg) from err return serialized @@ -709,9 +676,7 @@ def body(self, data, data_type, **kwargs): is_xml_model_serialization = kwargs["is_xml"] except KeyError: if internal_data_type and issubclass(internal_data_type, Model): - is_xml_model_serialization = kwargs.setdefault( - "is_xml", internal_data_type.is_xml_model() - ) + is_xml_model_serialization = kwargs.setdefault("is_xml", internal_data_type.is_xml_model()) else: is_xml_model_serialization = False if internal_data_type and not isinstance(internal_data_type, Enum): @@ -730,13 +695,9 @@ def body(self, data, data_type, **kwargs): attribute_key_case_insensitive_extractor, last_rest_key_case_insensitive_extractor, ] - data = deserializer._deserialize( - data_type, data - ) # pylint: disable=protected-access + data = deserializer._deserialize(data_type, data) # pylint: disable=protected-access except DeserializationError as err: - raise SerializationError( - "Unable to build a model: " + str(err) - ) from err + raise SerializationError("Unable to build a model: " + str(err)) from err return self._serialize(data, data_type, **kwargs) @@ -781,9 +742,7 @@ def query(self, name, data, data_type, **kwargs): if data_type.startswith("["): internal_data_type = data_type[1:-1] do_quote = not kwargs.get("skip_quote", False) - return self.serialize_iter( - data, internal_data_type, do_quote=do_quote, **kwargs - ) + return self.serialize_iter(data, internal_data_type, do_quote=do_quote, **kwargs) # Not a list, regular serialization output = self.serialize_data(data, data_type, **kwargs) @@ -858,9 +817,7 @@ def serialize_data(self, data, data_type, **kwargs): return self._serialize(data, **kwargs) @classmethod - def _get_custom_serializers( - cls, data_type, **kwargs - ): # pylint: disable=inconsistent-return-statements + def _get_custom_serializers(cls, data_type, **kwargs): # pylint: disable=inconsistent-return-statements custom_serializer = kwargs.get("basic_types_serializers", {}).get(data_type) if custom_serializer: return custom_serializer @@ -950,9 +907,7 @@ def serialize_iter(self, data, iter_type, div=None, **kwargs): serialized.append(None) if kwargs.get("do_quote", False): - serialized = [ - "" if s is None else quote(str(s), safe="") for s in serialized - ] + serialized = ["" if s is None else quote(str(s), safe="") for s in serialized] if div: serialized = ["" if s is None else str(s) for s in serialized] @@ -969,9 +924,7 @@ def serialize_iter(self, data, iter_type, div=None, **kwargs): is_wrapped = xml_desc.get("wrapped", False) node_name = xml_desc.get("itemsName", xml_name) if is_wrapped: - final_result = _create_xml_node( - xml_name, xml_desc.get("prefix", None), xml_desc.get("ns", None) - ) + final_result = _create_xml_node(xml_name, xml_desc.get("prefix", None), xml_desc.get("ns", None)) else: final_result = [] # All list elements to "local_node" @@ -1002,9 +955,7 @@ def serialize_dict(self, attr, dict_type, **kwargs): serialized = {} for key, value in attr.items(): try: - serialized[self.serialize_unicode(key)] = self.serialize_data( - value, dict_type, **kwargs - ) + serialized[self.serialize_unicode(key)] = self.serialize_data(value, dict_type, **kwargs) except ValueError as err: if isinstance(err, SerializationError): raise @@ -1015,18 +966,14 @@ def serialize_dict(self, attr, dict_type, **kwargs): xml_desc = serialization_ctxt["xml"] xml_name = xml_desc["name"] - final_result = _create_xml_node( - xml_name, xml_desc.get("prefix", None), xml_desc.get("ns", None) - ) + final_result = _create_xml_node(xml_name, xml_desc.get("prefix", None), xml_desc.get("ns", None)) for key, value in serialized.items(): ET.SubElement(final_result, key).text = value return final_result return serialized - def serialize_object( - self, attr, **kwargs - ): # pylint: disable=too-many-return-statements + def serialize_object(self, attr, **kwargs): # pylint: disable=too-many-return-statements """Serialize a generic object. This will be handled as a dictionary. If object passed in is not a basic type (str, int, float, dict, list) it will simply be @@ -1066,9 +1013,7 @@ def serialize_object( serialized = {} for key, value in attr.items(): try: - serialized[self.serialize_unicode(key)] = self.serialize_object( - value, **kwargs - ) + serialized[self.serialize_unicode(key)] = self.serialize_object(value, **kwargs) except ValueError: serialized[self.serialize_unicode(key)] = None return serialized @@ -1296,9 +1241,7 @@ def rest_key_case_insensitive_extractor( # pylint: disable=unused-argument, inc key = _decode_attribute_map_key(dict_keys[0]) break working_key = _decode_attribute_map_key(dict_keys[0]) - working_data = attribute_key_case_insensitive_extractor( - working_key, None, working_data - ) + working_data = attribute_key_case_insensitive_extractor(working_key, None, working_data) if working_data is None: # If at any point while following flatten JSON path see None, it means # that all properties under are None as well @@ -1323,9 +1266,7 @@ def last_rest_key_extractor(attr, attr_desc, data): # pylint: disable=unused-ar return attribute_key_extractor(dict_keys[-1], None, data) -def last_rest_key_case_insensitive_extractor( - attr, attr_desc, data -): # pylint: disable=unused-argument +def last_rest_key_case_insensitive_extractor(attr, attr_desc, data): # pylint: disable=unused-argument """Extract the attribute in "data" based on the last part of the JSON path key. This is the case insensitive version of "last_rest_key_extractor" @@ -1370,9 +1311,7 @@ def _extract_name_from_internal_type(internal_type): return xml_name -def xml_key_extractor( - attr, attr_desc, data -): # pylint: disable=unused-argument,too-many-return-statements +def xml_key_extractor(attr, attr_desc, data): # pylint: disable=unused-argument,too-many-return-statements if isinstance(data, dict): return None @@ -1406,10 +1345,7 @@ def xml_key_extractor( # - Wrapped node # - Internal type is an enum (considered basic types) # - Internal type has no XML/Name node - if is_wrapped or ( - internal_type - and (issubclass(internal_type, Enum) or "name" not in internal_type_xml_map) - ): + if is_wrapped or (internal_type and (issubclass(internal_type, Enum) or "name" not in internal_type_xml_map)): children = data.findall(xml_name) # If internal type has a local name and it's not a list, I use that name elif not is_iter_type and internal_type and "name" in internal_type_xml_map: @@ -1417,9 +1353,7 @@ def xml_key_extractor( children = data.findall(xml_name) # That's an array else: - if ( - internal_type - ): # Complex type, ignore itemsName and use the complex type name + if internal_type: # Complex type, ignore itemsName and use the complex type name items_name = _extract_name_from_internal_type(internal_type) else: items_name = xml_desc.get("itemsName", xml_name) @@ -1447,9 +1381,7 @@ def xml_key_extractor( # Here it's not a itertype, we should have found one element only or empty if len(children) > 1: - raise DeserializationError( - "Find several XML '{}' where it was not expected".format(xml_name) - ) + raise DeserializationError("Find several XML '{}' where it was not expected".format(xml_name)) return children[0] @@ -1462,9 +1394,7 @@ class Deserializer: basic_types = {str: "str", int: "int", bool: "bool", float: "float"} - valid_date = re.compile( - r"\d{4}[-]\d{2}[-]\d{2}T\d{2}:\d{2}:\d{2}\.?\d*Z?[-+]?[\d{2}]?:?[\d{2}]?" - ) + valid_date = re.compile(r"\d{4}[-]\d{2}[-]\d{2}T\d{2}:\d{2}:\d{2}\.?\d*Z?[-+]?[\d{2}]?:?[\d{2}]?") def __init__(self, classes: Optional[Mapping[str, type]] = None) -> None: self.deserialize_type = { @@ -1509,9 +1439,7 @@ def __call__(self, target_obj, response_data, content_type=None): data = self._unpack_content(response_data, content_type) return self._deserialize(target_obj, data) - def _deserialize( - self, target_obj, data - ): # pylint: disable=inconsistent-return-statements + def _deserialize(self, target_obj, data): # pylint: disable=inconsistent-return-statements """Call the deserializer on a model. Data needs to be already deserialized as JSON or XML ElementTree @@ -1524,11 +1452,7 @@ def _deserialize( """ # This is already a model, go recursive just in case if hasattr(data, "_attribute_map"): - constants = [ - name - for name, config in getattr(data, "_validation", {}).items() - if config.get("constant") - ] + constants = [name for name, config in getattr(data, "_validation", {}).items() if config.get("constant")] try: for ( attr, @@ -1541,9 +1465,7 @@ def _deserialize( continue local_type = mapconfig["type"] internal_data_type = local_type.strip("[]{}") - if internal_data_type not in self.dependencies or isinstance( - internal_data_type, Enum - ): + if internal_data_type not in self.dependencies or isinstance(internal_data_type, Enum): continue setattr(data, attr, self._deserialize(local_type, value)) return data @@ -1596,10 +1518,7 @@ def _deserialize( def _build_additional_properties(self, attribute_map, data): if not self.additional_properties_detection: return None - if ( - "additional_properties" in attribute_map - and attribute_map.get("additional_properties", {}).get("key") != "" - ): + if "additional_properties" in attribute_map and attribute_map.get("additional_properties", {}).get("key") != "": # Check empty string. If it's not empty, someone has a real "additionalProperties" return None if isinstance(data, ET.Element): @@ -1685,21 +1604,15 @@ def _unpack_content(raw_data, content_type=None): if context: if RawDeserializer.CONTEXT_NAME in context: return context[RawDeserializer.CONTEXT_NAME] - raise ValueError( - "This pipeline didn't have the RawDeserializer policy; can't deserialize" - ) + raise ValueError("This pipeline didn't have the RawDeserializer policy; can't deserialize") # Assume this is enough to recognize universal_http.ClientResponse without importing it if hasattr(raw_data, "body"): - return RawDeserializer.deserialize_from_http_generics( - raw_data.text(), raw_data.headers - ) + return RawDeserializer.deserialize_from_http_generics(raw_data.text(), raw_data.headers) # Assume this enough to recognize requests.Response without importing it. if hasattr(raw_data, "_content_consumed"): - return RawDeserializer.deserialize_from_http_generics( - raw_data.text, raw_data.headers - ) + return RawDeserializer.deserialize_from_http_generics(raw_data.text, raw_data.headers) if isinstance(raw_data, (str, bytes)) or hasattr(raw_data, "read"): return RawDeserializer.deserialize_from_text(raw_data, content_type) # type: ignore @@ -1727,11 +1640,7 @@ def _instantiate_model(self, response, attrs, additional_properties=None): for k, v in response._validation.items() # pylint: disable=protected-access # type: ignore if v.get("constant") ] - kwargs = { - k: v - for k, v in attrs.items() - if k not in subtype and k not in readonly + const - } + kwargs = {k: v for k, v in attrs.items() if k not in subtype and k not in readonly + const} response_obj = response(**kwargs) for attr in readonly: setattr(response_obj, attr, attrs.get(attr)) @@ -1751,9 +1660,7 @@ def _instantiate_model(self, response, attrs, additional_properties=None): msg += "Type: {}, Error: {}".format(type(response), exp) raise DeserializationError(msg) from exp - def deserialize_data( - self, data, data_type - ): # pylint: disable=too-many-return-statements + def deserialize_data(self, data, data_type): # pylint: disable=too-many-return-statements """Process data for deserialization according to data type. :param str data: The response string to be deserialized. @@ -1771,24 +1678,15 @@ def deserialize_data( if data_type in self.basic_types.values(): return self.deserialize_basic(data, data_type) if data_type in self.deserialize_type: - if isinstance( - data, self.deserialize_expected_types.get(data_type, tuple()) - ): + if isinstance(data, self.deserialize_expected_types.get(data_type, tuple())): return data - is_a_text_parsing_type = ( - lambda x: x - not in [ # pylint: disable=unnecessary-lambda-assignment - "object", - "[]", - r"{}", - ] - ) - if ( - isinstance(data, ET.Element) - and is_a_text_parsing_type(data_type) - and not data.text - ): + is_a_text_parsing_type = lambda x: x not in [ # pylint: disable=unnecessary-lambda-assignment + "object", + "[]", + r"{}", + ] + if isinstance(data, ET.Element) and is_a_text_parsing_type(data_type) and not data.text: return None data_val = self.deserialize_type[data_type](data) return data_val @@ -1819,16 +1717,10 @@ def deserialize_iter(self, attr, iter_type): """ if attr is None: return None - if isinstance( - attr, ET.Element - ): # If I receive an element here, get the children + if isinstance(attr, ET.Element): # If I receive an element here, get the children attr = list(attr) if not isinstance(attr, (list, set)): - raise DeserializationError( - "Cannot deserialize as [{}] an object of type {}".format( - iter_type, type(attr) - ) - ) + raise DeserializationError("Cannot deserialize as [{}] an object of type {}".format(iter_type, type(attr))) return [self.deserialize_data(a, iter_type) for a in attr] def deserialize_dict(self, attr, dict_type): @@ -1841,18 +1733,14 @@ def deserialize_dict(self, attr, dict_type): :rtype: dict """ if isinstance(attr, list): - return { - x["key"]: self.deserialize_data(x["value"], dict_type) for x in attr - } + return {x["key"]: self.deserialize_data(x["value"], dict_type) for x in attr} if isinstance(attr, ET.Element): # Transform value into {"Key": "value"} attr = {el.tag: el.text for el in attr} return {k: self.deserialize_data(v, dict_type) for k, v in attr.items()} - def deserialize_object( - self, attr, **kwargs - ): # pylint: disable=too-many-return-statements + def deserialize_object(self, attr, **kwargs): # pylint: disable=too-many-return-statements """Deserialize a generic object. This will be handled as a dictionary. @@ -1895,9 +1783,7 @@ def deserialize_object( error = "Cannot deserialize generic object with type: " raise TypeError(error + str(obj_type)) - def deserialize_basic( - self, attr, data_type - ): # pylint: disable=too-many-return-statements + def deserialize_basic(self, attr, data_type): # pylint: disable=too-many-return-statements """Deserialize basic builtin data type from string. Will attempt to convert to str, int, float and bool. This function will also accept '1', '0', 'true' and 'false' as @@ -2088,9 +1974,7 @@ def deserialize_date(attr): if isinstance(attr, ET.Element): attr = attr.text if re.search(r"[^\W\d_]", attr, re.I + re.U): # type: ignore - raise DeserializationError( - "Date must have only digits and -. Received: %s" % attr - ) + raise DeserializationError("Date must have only digits and -. Received: %s" % attr) # This must NOT use defaultmonth/defaultday. Using None ensure this raises an exception. return isodate.parse_date(attr, defaultmonth=0, defaultday=0) @@ -2106,9 +1990,7 @@ def deserialize_time(attr): if isinstance(attr, ET.Element): attr = attr.text if re.search(r"[^\W\d_]", attr, re.I + re.U): # type: ignore - raise DeserializationError( - "Date must have only digits and -. Received: %s" % attr - ) + raise DeserializationError("Date must have only digits and -. Received: %s" % attr) return isodate.parse_time(attr) @staticmethod @@ -2125,10 +2007,7 @@ def deserialize_rfc(attr): try: parsed_date = email.utils.parsedate_tz(attr) # type: ignore date_obj = datetime.datetime( - *parsed_date[:6], - tzinfo=datetime.timezone( - datetime.timedelta(minutes=(parsed_date[9] or 0) / 60) - ) + *parsed_date[:6], tzinfo=datetime.timezone(datetime.timedelta(minutes=(parsed_date[9] or 0) / 60)) ) if not date_obj.tzinfo: date_obj = date_obj.astimezone(tz=TZ_UTC) diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/_azure_queue_storage.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/_azure_queue_storage.py index 7c019e14596e..5a2ba62e4064 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/_azure_queue_storage.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/_azure_queue_storage.py @@ -48,9 +48,7 @@ class AzureQueueStorage: # pylint: disable=client-accepts-api-version-keyword def __init__( # pylint: disable=missing-client-constructor-parameter-credential self, url: str, version: str, base_url: str = "", **kwargs: Any ) -> None: - self._config = AzureQueueStorageConfiguration( - url=url, version=version, **kwargs - ) + self._config = AzureQueueStorageConfiguration(url=url, version=version, **kwargs) _policies = kwargs.pop("policies", None) if _policies is None: @@ -66,35 +64,19 @@ def __init__( # pylint: disable=missing-client-constructor-parameter-credential self._config.custom_hook_policy, self._config.logging_policy, policies.DistributedTracingPolicy(**kwargs), - ( - policies.SensitiveHeaderCleanupPolicy(**kwargs) - if self._config.redirect_policy - else None - ), + (policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None), self._config.http_logging_policy, ] - self._client: AsyncPipelineClient = AsyncPipelineClient( - base_url=base_url, policies=_policies, **kwargs - ) + self._client: AsyncPipelineClient = AsyncPipelineClient(base_url=base_url, policies=_policies, **kwargs) - client_models = { - k: v for k, v in _models.__dict__.items() if isinstance(v, type) - } + client_models = {k: v for k, v in _models.__dict__.items() if isinstance(v, type)} self._serialize = Serializer(client_models) self._deserialize = Deserializer(client_models) self._serialize.client_side_validation = False - self.service = ServiceOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.queue = QueueOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.messages = MessagesOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.message_id = MessageIdOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.service = ServiceOperations(self._client, self._config, self._serialize, self._deserialize) + self.queue = QueueOperations(self._client, self._config, self._serialize, self._deserialize) + self.messages = MessagesOperations(self._client, self._config, self._serialize, self._deserialize) + self.message_id = MessageIdOperations(self._client, self._config, self._serialize, self._deserialize) def _send_request( self, request: HttpRequest, *, stream: bool = False, **kwargs: Any diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/_configuration.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/_configuration.py index d45c53a0b020..1c90497920fe 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/_configuration.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/_configuration.py @@ -39,26 +39,12 @@ def __init__(self, url: str, version: str, **kwargs: Any) -> None: self._configure(**kwargs) def _configure(self, **kwargs: Any) -> None: - self.user_agent_policy = kwargs.get( - "user_agent_policy" - ) or policies.UserAgentPolicy(**kwargs) - self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy( - **kwargs - ) + self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs) + self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs) self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs) - self.logging_policy = kwargs.get( - "logging_policy" - ) or policies.NetworkTraceLoggingPolicy(**kwargs) - self.http_logging_policy = kwargs.get( - "http_logging_policy" - ) or policies.HttpLoggingPolicy(**kwargs) - self.custom_hook_policy = kwargs.get( - "custom_hook_policy" - ) or policies.CustomHookPolicy(**kwargs) - self.redirect_policy = kwargs.get( - "redirect_policy" - ) or policies.AsyncRedirectPolicy(**kwargs) - self.retry_policy = kwargs.get("retry_policy") or policies.AsyncRetryPolicy( - **kwargs - ) + self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs) + self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs) + self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs) + self.redirect_policy = kwargs.get("redirect_policy") or policies.AsyncRedirectPolicy(**kwargs) + self.retry_policy = kwargs.get("retry_policy") or policies.AsyncRetryPolicy(**kwargs) self.authentication_policy = kwargs.get("authentication_policy") diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_message_id_operations.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_message_id_operations.py index 5f2a6d9e952a..bc26d91d2d9d 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_message_id_operations.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_message_id_operations.py @@ -32,9 +32,7 @@ from .._configuration import AzureQueueStorageConfiguration T = TypeVar("T") -ClsType = Optional[ - Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, dict[str, Any]], Any] -] +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, dict[str, Any]], Any]] class MessageIdOperations: @@ -51,18 +49,10 @@ class MessageIdOperations: def __init__(self, *args, **kwargs) -> None: input_args = list(args) - self._client: AsyncPipelineClient = ( - input_args.pop(0) if input_args else kwargs.pop("client") - ) - self._config: AzureQueueStorageConfiguration = ( - input_args.pop(0) if input_args else kwargs.pop("config") - ) - self._serialize: Serializer = ( - input_args.pop(0) if input_args else kwargs.pop("serializer") - ) - self._deserialize: Deserializer = ( - input_args.pop(0) if input_args else kwargs.pop("deserializer") - ) + self._client: AsyncPipelineClient = input_args.pop(0) if input_args else kwargs.pop("client") + self._config: AzureQueueStorageConfiguration = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize: Serializer = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize: Deserializer = input_args.pop(0) if input_args else kwargs.pop("deserializer") @distributed_trace_async async def update( @@ -114,9 +104,7 @@ async def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = kwargs.pop("params", {}) or {} - content_type: Optional[str] = kwargs.pop( - "content_type", _headers.pop("Content-Type", "application/xml") - ) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", "application/xml")) content_type = content_type if queue_message else None cls: ClsType[None] = kwargs.pop("cls", None) @@ -140,18 +128,14 @@ async def update( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [204]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -159,18 +143,10 @@ async def update( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) - response_headers["x-ms-popreceipt"] = self._deserialize( - "str", response.headers.get("x-ms-popreceipt") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-popreceipt"] = self._deserialize("str", response.headers.get("x-ms-popreceipt")) response_headers["x-ms-time-next-visible"] = self._deserialize( "rfc-1123", response.headers.get("x-ms-time-next-visible") ) @@ -180,11 +156,7 @@ async def update( @distributed_trace_async async def delete( - self, - pop_receipt: str, - timeout: Optional[int] = None, - request_id_parameter: Optional[str] = None, - **kwargs: Any + self, pop_receipt: str, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any ) -> None: """The Delete operation deletes the specified message. @@ -228,18 +200,14 @@ async def delete( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [204]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -247,15 +215,9 @@ async def delete( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) if cls: return cls(pipeline_response, None, response_headers) # type: ignore diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_messages_operations.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_messages_operations.py index 646fea1b19d8..9fd47e1b4007 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_messages_operations.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_messages_operations.py @@ -34,9 +34,7 @@ from .._configuration import AzureQueueStorageConfiguration T = TypeVar("T") -ClsType = Optional[ - Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, dict[str, Any]], Any] -] +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, dict[str, Any]], Any]] class MessagesOperations: @@ -53,18 +51,10 @@ class MessagesOperations: def __init__(self, *args, **kwargs) -> None: input_args = list(args) - self._client: AsyncPipelineClient = ( - input_args.pop(0) if input_args else kwargs.pop("client") - ) - self._config: AzureQueueStorageConfiguration = ( - input_args.pop(0) if input_args else kwargs.pop("config") - ) - self._serialize: Serializer = ( - input_args.pop(0) if input_args else kwargs.pop("serializer") - ) - self._deserialize: Deserializer = ( - input_args.pop(0) if input_args else kwargs.pop("deserializer") - ) + self._client: AsyncPipelineClient = input_args.pop(0) if input_args else kwargs.pop("client") + self._config: AzureQueueStorageConfiguration = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize: Serializer = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize: Deserializer = input_args.pop(0) if input_args else kwargs.pop("deserializer") @distributed_trace_async async def dequeue( @@ -126,18 +116,14 @@ async def dequeue( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -145,19 +131,11 @@ async def dequeue( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) - deserialized = self._deserialize( - "[DequeuedMessageItem]", pipeline_response.http_response - ) + deserialized = self._deserialize("[DequeuedMessageItem]", pipeline_response.http_response) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore @@ -166,10 +144,7 @@ async def dequeue( @distributed_trace_async async def clear( - self, - timeout: Optional[int] = None, - request_id_parameter: Optional[str] = None, - **kwargs: Any + self, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any ) -> None: """The Clear operation deletes all messages from the specified queue. @@ -209,18 +184,14 @@ async def clear( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [204]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -228,15 +199,9 @@ async def clear( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) if cls: return cls(pipeline_response, None, response_headers) # type: ignore @@ -295,9 +260,7 @@ async def enqueue( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = kwargs.pop("params", {}) or {} - content_type: str = kwargs.pop( - "content_type", _headers.pop("Content-Type", "application/xml") - ) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/xml")) cls: ClsType[list[_models.EnqueuedMessage]] = kwargs.pop("cls", None) _content = self._serialize.body(queue_message, "QueueMessage", is_xml=True) @@ -317,18 +280,14 @@ async def enqueue( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [201]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -336,19 +295,11 @@ async def enqueue( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) - deserialized = self._deserialize( - "[EnqueuedMessage]", pipeline_response.http_response - ) + deserialized = self._deserialize("[EnqueuedMessage]", pipeline_response.http_response) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore @@ -394,9 +345,7 @@ async def peek( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - peekonly: Literal["true"] = kwargs.pop( - "peekonly", _params.pop("peekonly", "true") - ) + peekonly: Literal["true"] = kwargs.pop("peekonly", _params.pop("peekonly", "true")) cls: ClsType[list[_models.PeekedMessageItem]] = kwargs.pop("cls", None) _request = build_peek_request( @@ -412,18 +361,14 @@ async def peek( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -431,19 +376,11 @@ async def peek( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) - deserialized = self._deserialize( - "[PeekedMessageItem]", pipeline_response.http_response - ) + deserialized = self._deserialize("[PeekedMessageItem]", pipeline_response.http_response) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_patch.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_patch.py index 0f5ec7712f5f..2e25743cab74 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_patch.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_patch.py @@ -11,9 +11,7 @@ from typing import List -__all__: List[str] = ( - [] -) # Add all objects you want publicly available to users at this package level +__all__: List[str] = [] # Add all objects you want publicly available to users at this package level def patch_sdk(): diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_queue_operations.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_queue_operations.py index 029e6dba4796..252b7d54f4c5 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_queue_operations.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_queue_operations.py @@ -36,9 +36,7 @@ from .._configuration import AzureQueueStorageConfiguration T = TypeVar("T") -ClsType = Optional[ - Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, dict[str, Any]], Any] -] +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, dict[str, Any]], Any]] class QueueOperations: @@ -55,18 +53,10 @@ class QueueOperations: def __init__(self, *args, **kwargs) -> None: input_args = list(args) - self._client: AsyncPipelineClient = ( - input_args.pop(0) if input_args else kwargs.pop("client") - ) - self._config: AzureQueueStorageConfiguration = ( - input_args.pop(0) if input_args else kwargs.pop("config") - ) - self._serialize: Serializer = ( - input_args.pop(0) if input_args else kwargs.pop("serializer") - ) - self._deserialize: Deserializer = ( - input_args.pop(0) if input_args else kwargs.pop("deserializer") - ) + self._client: AsyncPipelineClient = input_args.pop(0) if input_args else kwargs.pop("client") + self._config: AzureQueueStorageConfiguration = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize: Serializer = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize: Deserializer = input_args.pop(0) if input_args else kwargs.pop("deserializer") @distributed_trace_async async def create( @@ -121,18 +111,14 @@ async def create( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [201, 204]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -140,25 +126,16 @@ async def create( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) if cls: return cls(pipeline_response, None, response_headers) # type: ignore @distributed_trace_async async def delete( - self, - timeout: Optional[int] = None, - request_id_parameter: Optional[str] = None, - **kwargs: Any + self, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any ) -> None: """operation permanently deletes the specified queue. @@ -198,18 +175,14 @@ async def delete( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [204]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -217,25 +190,16 @@ async def delete( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) if cls: return cls(pipeline_response, None, response_headers) # type: ignore @distributed_trace_async async def get_properties( - self, - timeout: Optional[int] = None, - request_id_parameter: Optional[str] = None, - **kwargs: Any + self, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any ) -> None: """Retrieves user-defined metadata and queue properties on the specified queue. Metadata is associated with the queue as name-values pairs. @@ -278,18 +242,14 @@ async def get_properties( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -297,21 +257,13 @@ async def get_properties( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-meta"] = self._deserialize( - "{str}", response.headers.get("x-ms-meta") - ) + response_headers["x-ms-meta"] = self._deserialize("{str}", response.headers.get("x-ms-meta")) response_headers["x-ms-approximate-messages-count"] = self._deserialize( "int", response.headers.get("x-ms-approximate-messages-count") ) - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) if cls: return cls(pipeline_response, None, response_headers) # type: ignore @@ -372,18 +324,14 @@ async def set_metadata( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [204]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -391,25 +339,16 @@ async def set_metadata( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) if cls: return cls(pipeline_response, None, response_headers) # type: ignore @distributed_trace_async async def get_access_policy( - self, - timeout: Optional[int] = None, - request_id_parameter: Optional[str] = None, - **kwargs: Any + self, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any ) -> list[_models.SignedIdentifier]: """returns details about any stored access policies specified on the queue that may be used with Shared Access Signatures. @@ -452,18 +391,14 @@ async def get_access_policy( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -471,19 +406,11 @@ async def get_access_policy( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) - deserialized = self._deserialize( - "[SignedIdentifier]", pipeline_response.http_response - ) + deserialized = self._deserialize("[SignedIdentifier]", pipeline_response.http_response) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore @@ -526,9 +453,7 @@ async def set_access_policy( _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) comp: Literal["acl"] = kwargs.pop("comp", _params.pop("comp", "acl")) - content_type: Optional[str] = kwargs.pop( - "content_type", _headers.pop("Content-Type", "application/xml") - ) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", "application/xml")) content_type = content_type if queue_acl else None cls: ClsType[None] = kwargs.pop("cls", None) @@ -557,18 +482,14 @@ async def set_access_policy( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [204]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -576,15 +497,9 @@ async def set_access_policy( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) if cls: return cls(pipeline_response, None, response_headers) # type: ignore diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_service_operations.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_service_operations.py index 094bc5626303..54a8f75be779 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_service_operations.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/aio/operations/_service_operations.py @@ -35,9 +35,7 @@ from .._configuration import AzureQueueStorageConfiguration T = TypeVar("T") -ClsType = Optional[ - Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, dict[str, Any]], Any] -] +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, dict[str, Any]], Any]] class ServiceOperations: @@ -54,18 +52,10 @@ class ServiceOperations: def __init__(self, *args, **kwargs) -> None: input_args = list(args) - self._client: AsyncPipelineClient = ( - input_args.pop(0) if input_args else kwargs.pop("client") - ) - self._config: AzureQueueStorageConfiguration = ( - input_args.pop(0) if input_args else kwargs.pop("config") - ) - self._serialize: Serializer = ( - input_args.pop(0) if input_args else kwargs.pop("serializer") - ) - self._deserialize: Deserializer = ( - input_args.pop(0) if input_args else kwargs.pop("deserializer") - ) + self._client: AsyncPipelineClient = input_args.pop(0) if input_args else kwargs.pop("client") + self._config: AzureQueueStorageConfiguration = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize: Serializer = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize: Deserializer = input_args.pop(0) if input_args else kwargs.pop("deserializer") @distributed_trace_async async def set_properties( @@ -103,20 +93,12 @@ async def set_properties( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - restype: Literal["service"] = kwargs.pop( - "restype", _params.pop("restype", "service") - ) - comp: Literal["properties"] = kwargs.pop( - "comp", _params.pop("comp", "properties") - ) - content_type: str = kwargs.pop( - "content_type", _headers.pop("Content-Type", "application/xml") - ) + restype: Literal["service"] = kwargs.pop("restype", _params.pop("restype", "service")) + comp: Literal["properties"] = kwargs.pop("comp", _params.pop("comp", "properties")) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/xml")) cls: ClsType[None] = kwargs.pop("cls", None) - _content = self._serialize.body( - storage_service_properties, "StorageServiceProperties", is_xml=True - ) + _content = self._serialize.body(storage_service_properties, "StorageServiceProperties", is_xml=True) _request = build_set_properties_request( url=self._config.url, @@ -133,18 +115,14 @@ async def set_properties( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [202]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -152,22 +130,15 @@ async def set_properties( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) if cls: return cls(pipeline_response, None, response_headers) # type: ignore @distributed_trace_async async def get_properties( - self, - timeout: Optional[int] = None, - request_id_parameter: Optional[str] = None, - **kwargs: Any + self, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any ) -> _models.StorageServiceProperties: """gets the properties of a storage account's Queue service, including properties for Storage Analytics and CORS (Cross-Origin Resource Sharing) rules. @@ -195,12 +166,8 @@ async def get_properties( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - restype: Literal["service"] = kwargs.pop( - "restype", _params.pop("restype", "service") - ) - comp: Literal["properties"] = kwargs.pop( - "comp", _params.pop("comp", "properties") - ) + restype: Literal["service"] = kwargs.pop("restype", _params.pop("restype", "service")) + comp: Literal["properties"] = kwargs.pop("comp", _params.pop("comp", "properties")) cls: ClsType[_models.StorageServiceProperties] = kwargs.pop("cls", None) _request = build_get_properties_request( @@ -216,18 +183,14 @@ async def get_properties( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -235,16 +198,10 @@ async def get_properties( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - deserialized = self._deserialize( - "StorageServiceProperties", pipeline_response.http_response - ) + deserialized = self._deserialize("StorageServiceProperties", pipeline_response.http_response) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore @@ -253,10 +210,7 @@ async def get_properties( @distributed_trace_async async def get_statistics( - self, - timeout: Optional[int] = None, - request_id_parameter: Optional[str] = None, - **kwargs: Any + self, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any ) -> _models.StorageServiceStats: """Retrieves statistics related to replication for the Queue service. It is only available on the secondary location endpoint when read-access geo-redundant replication is enabled for the @@ -285,9 +239,7 @@ async def get_statistics( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - restype: Literal["service"] = kwargs.pop( - "restype", _params.pop("restype", "service") - ) + restype: Literal["service"] = kwargs.pop("restype", _params.pop("restype", "service")) comp: Literal["stats"] = kwargs.pop("comp", _params.pop("comp", "stats")) cls: ClsType[_models.StorageServiceStats] = kwargs.pop("cls", None) @@ -304,18 +256,14 @@ async def get_statistics( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -323,19 +271,11 @@ async def get_statistics( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) - deserialized = self._deserialize( - "StorageServiceStats", pipeline_response.http_response - ) + deserialized = self._deserialize("StorageServiceStats", pipeline_response.http_response) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore @@ -378,15 +318,9 @@ async def get_user_delegation_key( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - restype: Literal["service"] = kwargs.pop( - "restype", _params.pop("restype", "service") - ) - comp: Literal["userdelegationkey"] = kwargs.pop( - "comp", _params.pop("comp", "userdelegationkey") - ) - content_type: str = kwargs.pop( - "content_type", _headers.pop("Content-Type", "application/xml") - ) + restype: Literal["service"] = kwargs.pop("restype", _params.pop("restype", "service")) + comp: Literal["userdelegationkey"] = kwargs.pop("comp", _params.pop("comp", "userdelegationkey")) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/xml")) cls: ClsType[_models.UserDelegationKey] = kwargs.pop("cls", None) _content = self._serialize.body(key_info, "KeyInfo", is_xml=True) @@ -406,18 +340,14 @@ async def get_user_delegation_key( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -428,19 +358,11 @@ async def get_user_delegation_key( response_headers["x-ms-client-request-id"] = self._deserialize( "str", response.headers.get("x-ms-client-request-id") ) - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) - deserialized = self._deserialize( - "UserDelegationKey", pipeline_response.http_response - ) + deserialized = self._deserialize("UserDelegationKey", pipeline_response.http_response) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore @@ -522,18 +444,14 @@ async def list_queues_segment( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - await self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -541,19 +459,11 @@ async def list_queues_segment( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) - deserialized = self._deserialize( - "ListQueuesSegmentResponse", pipeline_response.http_response - ) + deserialized = self._deserialize("ListQueuesSegmentResponse", pipeline_response.http_response) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/models/_models_py3.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/models/_models_py3.py index e3953134126f..e28743c64d07 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/models/_models_py3.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/models/_models_py3.py @@ -361,12 +361,7 @@ class KeyInfo(_serialization.Model): } def __init__( - self, - *, - expiry: str, - start: Optional[str] = None, - delegated_user_tid: Optional[str] = None, - **kwargs: Any + self, *, expiry: str, start: Optional[str] = None, delegated_user_tid: Optional[str] = None, **kwargs: Any ) -> None: """ :keyword start: The date-time the key is active in ISO 8601 UTC time. @@ -664,9 +659,7 @@ class QueueItem(_serialization.Model): } _xml_map = {"name": "Queue"} - def __init__( - self, *, name: str, metadata: Optional[dict[str, str]] = None, **kwargs: Any - ) -> None: + def __init__(self, *, name: str, metadata: Optional[dict[str, str]] = None, **kwargs: Any) -> None: """ :keyword name: The name of the Queue. Required. :paramtype name: str @@ -727,9 +720,7 @@ class RetentionPolicy(_serialization.Model): "days": {"key": "Days", "type": "int"}, } - def __init__( - self, *, enabled: bool, days: Optional[int] = None, **kwargs: Any - ) -> None: + def __init__(self, *, enabled: bool, days: Optional[int] = None, **kwargs: Any) -> None: """ :keyword enabled: Indicates whether a retention policy is enabled for the storage service. Required. @@ -862,12 +853,7 @@ class StorageServiceStats(_serialization.Model): "geo_replication": {"key": "GeoReplication", "type": "GeoReplication"}, } - def __init__( - self, - *, - geo_replication: Optional["_models.GeoReplication"] = None, - **kwargs: Any - ) -> None: + def __init__(self, *, geo_replication: Optional["_models.GeoReplication"] = None, **kwargs: Any) -> None: """ :keyword geo_replication: Geo-Replication information for the Secondary Storage Service. :paramtype geo_replication: ~azure.storage.queue.models.GeoReplication diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/models/_patch.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/models/_patch.py index 0f5ec7712f5f..2e25743cab74 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/models/_patch.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/models/_patch.py @@ -11,9 +11,7 @@ from typing import List -__all__: List[str] = ( - [] -) # Add all objects you want publicly available to users at this package level +__all__: List[str] = [] # Add all objects you want publicly available to users at this package level def patch_sdk(): diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_message_id_operations.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_message_id_operations.py index 7e2ea937fa43..39c22976afbe 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_message_id_operations.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_message_id_operations.py @@ -28,9 +28,7 @@ from .._utils.serialization import Deserializer, Serializer T = TypeVar("T") -ClsType = Optional[ - Callable[[PipelineResponse[HttpRequest, HttpResponse], T, dict[str, Any]], Any] -] +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False @@ -50,9 +48,7 @@ def build_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - content_type: Optional[str] = kwargs.pop( - "content_type", _headers.pop("Content-Type", None) - ) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/xml") # Construct URL @@ -74,23 +70,12 @@ def build_update_request( # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header( - "request_id_parameter", request_id_parameter, "str" - ) + _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header( - "content_type", content_type, "str" - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, content=content, **kwargs) def build_delete_request( @@ -123,14 +108,10 @@ def build_delete_request( # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header( - "request_id_parameter", request_id_parameter, "str" - ) + _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="DELETE", url=_url, params=_params, headers=_headers, **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) class MessageIdOperations: @@ -147,18 +128,10 @@ class MessageIdOperations: def __init__(self, *args, **kwargs) -> None: input_args = list(args) - self._client: PipelineClient = ( - input_args.pop(0) if input_args else kwargs.pop("client") - ) - self._config: AzureQueueStorageConfiguration = ( - input_args.pop(0) if input_args else kwargs.pop("config") - ) - self._serialize: Serializer = ( - input_args.pop(0) if input_args else kwargs.pop("serializer") - ) - self._deserialize: Deserializer = ( - input_args.pop(0) if input_args else kwargs.pop("deserializer") - ) + self._client: PipelineClient = input_args.pop(0) if input_args else kwargs.pop("client") + self._config: AzureQueueStorageConfiguration = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize: Serializer = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize: Deserializer = input_args.pop(0) if input_args else kwargs.pop("deserializer") @distributed_trace def update( # pylint: disable=inconsistent-return-statements @@ -210,9 +183,7 @@ def update( # pylint: disable=inconsistent-return-statements _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = kwargs.pop("params", {}) or {} - content_type: Optional[str] = kwargs.pop( - "content_type", _headers.pop("Content-Type", "application/xml") - ) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", "application/xml")) content_type = content_type if queue_message else None cls: ClsType[None] = kwargs.pop("cls", None) @@ -236,18 +207,14 @@ def update( # pylint: disable=inconsistent-return-statements _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [204]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -255,18 +222,10 @@ def update( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) - response_headers["x-ms-popreceipt"] = self._deserialize( - "str", response.headers.get("x-ms-popreceipt") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) + response_headers["x-ms-popreceipt"] = self._deserialize("str", response.headers.get("x-ms-popreceipt")) response_headers["x-ms-time-next-visible"] = self._deserialize( "rfc-1123", response.headers.get("x-ms-time-next-visible") ) @@ -276,11 +235,7 @@ def update( # pylint: disable=inconsistent-return-statements @distributed_trace def delete( # pylint: disable=inconsistent-return-statements - self, - pop_receipt: str, - timeout: Optional[int] = None, - request_id_parameter: Optional[str] = None, - **kwargs: Any + self, pop_receipt: str, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any ) -> None: """The Delete operation deletes the specified message. @@ -324,18 +279,14 @@ def delete( # pylint: disable=inconsistent-return-statements _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [204]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -343,15 +294,9 @@ def delete( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) if cls: return cls(pipeline_response, None, response_headers) # type: ignore diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_messages_operations.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_messages_operations.py index 6b01ac95e89f..290bef2a7776 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_messages_operations.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_messages_operations.py @@ -28,9 +28,7 @@ from .._utils.serialization import Deserializer, Serializer T = TypeVar("T") -ClsType = Optional[ - Callable[[PipelineResponse[HttpRequest, HttpResponse], T, dict[str, Any]], Any] -] +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False @@ -61,9 +59,7 @@ def build_dequeue_request( # Construct parameters if number_of_messages is not None: - _params["numofmessages"] = _SERIALIZER.query( - "number_of_messages", number_of_messages, "int", minimum=1 - ) + _params["numofmessages"] = _SERIALIZER.query("number_of_messages", number_of_messages, "int", minimum=1) if visibilitytimeout is not None: _params["visibilitytimeout"] = _SERIALIZER.query( "visibilitytimeout", visibilitytimeout, "int", maximum=604800, minimum=0 @@ -74,23 +70,14 @@ def build_dequeue_request( # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header( - "request_id_parameter", request_id_parameter, "str" - ) + _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", url=_url, params=_params, headers=_headers, **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_clear_request( - url: str, - *, - version: str, - timeout: Optional[int] = None, - request_id_parameter: Optional[str] = None, - **kwargs: Any + url: str, *, version: str, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) @@ -112,14 +99,10 @@ def build_clear_request( # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header( - "request_id_parameter", request_id_parameter, "str" - ) + _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="DELETE", url=_url, params=_params, headers=_headers, **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) def build_enqueue_request( @@ -136,9 +119,7 @@ def build_enqueue_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - content_type: Optional[str] = kwargs.pop( - "content_type", _headers.pop("Content-Type", None) - ) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/xml") # Construct URL @@ -155,32 +136,19 @@ def build_enqueue_request( "visibilitytimeout", visibilitytimeout, "int", maximum=604800, minimum=0 ) if message_time_to_live is not None: - _params["messagettl"] = _SERIALIZER.query( - "message_time_to_live", message_time_to_live, "int", minimum=-1 - ) + _params["messagettl"] = _SERIALIZER.query("message_time_to_live", message_time_to_live, "int", minimum=-1) if timeout is not None: _params["timeout"] = _SERIALIZER.query("timeout", timeout, "int", minimum=0) # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header( - "request_id_parameter", request_id_parameter, "str" - ) + _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header( - "content_type", content_type, "str" - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - content=content, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, content=content, **kwargs) def build_peek_request( @@ -209,23 +177,17 @@ def build_peek_request( # Construct parameters _params["peekonly"] = _SERIALIZER.query("peekonly", peekonly, "str") if number_of_messages is not None: - _params["numofmessages"] = _SERIALIZER.query( - "number_of_messages", number_of_messages, "int", minimum=1 - ) + _params["numofmessages"] = _SERIALIZER.query("number_of_messages", number_of_messages, "int", minimum=1) if timeout is not None: _params["timeout"] = _SERIALIZER.query("timeout", timeout, "int", minimum=0) # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header( - "request_id_parameter", request_id_parameter, "str" - ) + _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", url=_url, params=_params, headers=_headers, **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) class MessagesOperations: @@ -242,18 +204,10 @@ class MessagesOperations: def __init__(self, *args, **kwargs) -> None: input_args = list(args) - self._client: PipelineClient = ( - input_args.pop(0) if input_args else kwargs.pop("client") - ) - self._config: AzureQueueStorageConfiguration = ( - input_args.pop(0) if input_args else kwargs.pop("config") - ) - self._serialize: Serializer = ( - input_args.pop(0) if input_args else kwargs.pop("serializer") - ) - self._deserialize: Deserializer = ( - input_args.pop(0) if input_args else kwargs.pop("deserializer") - ) + self._client: PipelineClient = input_args.pop(0) if input_args else kwargs.pop("client") + self._config: AzureQueueStorageConfiguration = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize: Serializer = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize: Deserializer = input_args.pop(0) if input_args else kwargs.pop("deserializer") @distributed_trace def dequeue( @@ -315,18 +269,14 @@ def dequeue( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -334,19 +284,11 @@ def dequeue( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) - deserialized = self._deserialize( - "[DequeuedMessageItem]", pipeline_response.http_response - ) + deserialized = self._deserialize("[DequeuedMessageItem]", pipeline_response.http_response) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore @@ -355,10 +297,7 @@ def dequeue( @distributed_trace def clear( # pylint: disable=inconsistent-return-statements - self, - timeout: Optional[int] = None, - request_id_parameter: Optional[str] = None, - **kwargs: Any + self, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any ) -> None: """The Clear operation deletes all messages from the specified queue. @@ -398,18 +337,14 @@ def clear( # pylint: disable=inconsistent-return-statements _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [204]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -417,15 +352,9 @@ def clear( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) if cls: return cls(pipeline_response, None, response_headers) # type: ignore @@ -484,9 +413,7 @@ def enqueue( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = kwargs.pop("params", {}) or {} - content_type: str = kwargs.pop( - "content_type", _headers.pop("Content-Type", "application/xml") - ) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/xml")) cls: ClsType[list[_models.EnqueuedMessage]] = kwargs.pop("cls", None) _content = self._serialize.body(queue_message, "QueueMessage", is_xml=True) @@ -506,18 +433,14 @@ def enqueue( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [201]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -525,19 +448,11 @@ def enqueue( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) - deserialized = self._deserialize( - "[EnqueuedMessage]", pipeline_response.http_response - ) + deserialized = self._deserialize("[EnqueuedMessage]", pipeline_response.http_response) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore @@ -583,9 +498,7 @@ def peek( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - peekonly: Literal["true"] = kwargs.pop( - "peekonly", _params.pop("peekonly", "true") - ) + peekonly: Literal["true"] = kwargs.pop("peekonly", _params.pop("peekonly", "true")) cls: ClsType[list[_models.PeekedMessageItem]] = kwargs.pop("cls", None) _request = build_peek_request( @@ -601,18 +514,14 @@ def peek( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -620,19 +529,11 @@ def peek( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) - deserialized = self._deserialize( - "[PeekedMessageItem]", pipeline_response.http_response - ) + deserialized = self._deserialize("[PeekedMessageItem]", pipeline_response.http_response) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_patch.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_patch.py index 0f5ec7712f5f..2e25743cab74 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_patch.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_patch.py @@ -11,9 +11,7 @@ from typing import List -__all__: List[str] = ( - [] -) # Add all objects you want publicly available to users at this package level +__all__: List[str] = [] # Add all objects you want publicly available to users at this package level def patch_sdk(): diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_queue_operations.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_queue_operations.py index 8cbdf2cc3713..ddd138f17de9 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_queue_operations.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_queue_operations.py @@ -28,9 +28,7 @@ from .._utils.serialization import Deserializer, Serializer T = TypeVar("T") -ClsType = Optional[ - Callable[[PipelineResponse[HttpRequest, HttpResponse], T, dict[str, Any]], Any] -] +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False @@ -67,23 +65,14 @@ def build_create_request( _headers["x-ms-meta"] = _SERIALIZER.header("metadata", metadata, "{str}") _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header( - "request_id_parameter", request_id_parameter, "str" - ) + _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", url=_url, params=_params, headers=_headers, **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_delete_request( - url: str, - *, - version: str, - timeout: Optional[int] = None, - request_id_parameter: Optional[str] = None, - **kwargs: Any + url: str, *, version: str, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) @@ -105,23 +94,14 @@ def build_delete_request( # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header( - "request_id_parameter", request_id_parameter, "str" - ) + _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="DELETE", url=_url, params=_params, headers=_headers, **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) def build_get_properties_request( - url: str, - *, - version: str, - timeout: Optional[int] = None, - request_id_parameter: Optional[str] = None, - **kwargs: Any + url: str, *, version: str, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) @@ -145,14 +125,10 @@ def build_get_properties_request( # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header( - "request_id_parameter", request_id_parameter, "str" - ) + _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", url=_url, params=_params, headers=_headers, **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_set_metadata_request( @@ -188,23 +164,14 @@ def build_set_metadata_request( _headers["x-ms-meta"] = _SERIALIZER.header("metadata", metadata, "{str}") _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header( - "request_id_parameter", request_id_parameter, "str" - ) + _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", url=_url, params=_params, headers=_headers, **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_get_access_policy_request( - url: str, - *, - version: str, - timeout: Optional[int] = None, - request_id_parameter: Optional[str] = None, - **kwargs: Any + url: str, *, version: str, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) @@ -228,14 +195,10 @@ def build_get_access_policy_request( # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header( - "request_id_parameter", request_id_parameter, "str" - ) + _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", url=_url, params=_params, headers=_headers, **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_set_access_policy_request( @@ -251,9 +214,7 @@ def build_set_access_policy_request( _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) comp: Literal["acl"] = kwargs.pop("comp", _params.pop("comp", "acl")) - content_type: Optional[str] = kwargs.pop( - "content_type", _headers.pop("Content-Type", None) - ) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/xml") # Construct URL @@ -272,23 +233,12 @@ def build_set_access_policy_request( # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header( - "request_id_parameter", request_id_parameter, "str" - ) + _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header( - "content_type", content_type, "str" - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, content=content, **kwargs) class QueueOperations: @@ -305,18 +255,10 @@ class QueueOperations: def __init__(self, *args, **kwargs) -> None: input_args = list(args) - self._client: PipelineClient = ( - input_args.pop(0) if input_args else kwargs.pop("client") - ) - self._config: AzureQueueStorageConfiguration = ( - input_args.pop(0) if input_args else kwargs.pop("config") - ) - self._serialize: Serializer = ( - input_args.pop(0) if input_args else kwargs.pop("serializer") - ) - self._deserialize: Deserializer = ( - input_args.pop(0) if input_args else kwargs.pop("deserializer") - ) + self._client: PipelineClient = input_args.pop(0) if input_args else kwargs.pop("client") + self._config: AzureQueueStorageConfiguration = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize: Serializer = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize: Deserializer = input_args.pop(0) if input_args else kwargs.pop("deserializer") @distributed_trace def create( # pylint: disable=inconsistent-return-statements @@ -371,18 +313,14 @@ def create( # pylint: disable=inconsistent-return-statements _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [201, 204]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -390,25 +328,16 @@ def create( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) if cls: return cls(pipeline_response, None, response_headers) # type: ignore @distributed_trace def delete( # pylint: disable=inconsistent-return-statements - self, - timeout: Optional[int] = None, - request_id_parameter: Optional[str] = None, - **kwargs: Any + self, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any ) -> None: """operation permanently deletes the specified queue. @@ -448,18 +377,14 @@ def delete( # pylint: disable=inconsistent-return-statements _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [204]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -467,25 +392,16 @@ def delete( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) if cls: return cls(pipeline_response, None, response_headers) # type: ignore @distributed_trace def get_properties( # pylint: disable=inconsistent-return-statements - self, - timeout: Optional[int] = None, - request_id_parameter: Optional[str] = None, - **kwargs: Any + self, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any ) -> None: """Retrieves user-defined metadata and queue properties on the specified queue. Metadata is associated with the queue as name-values pairs. @@ -528,18 +444,14 @@ def get_properties( # pylint: disable=inconsistent-return-statements _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -547,21 +459,13 @@ def get_properties( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-meta"] = self._deserialize( - "{str}", response.headers.get("x-ms-meta") - ) + response_headers["x-ms-meta"] = self._deserialize("{str}", response.headers.get("x-ms-meta")) response_headers["x-ms-approximate-messages-count"] = self._deserialize( "int", response.headers.get("x-ms-approximate-messages-count") ) - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) if cls: return cls(pipeline_response, None, response_headers) # type: ignore @@ -622,18 +526,14 @@ def set_metadata( # pylint: disable=inconsistent-return-statements _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [204]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -641,25 +541,16 @@ def set_metadata( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) if cls: return cls(pipeline_response, None, response_headers) # type: ignore @distributed_trace def get_access_policy( - self, - timeout: Optional[int] = None, - request_id_parameter: Optional[str] = None, - **kwargs: Any + self, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any ) -> list[_models.SignedIdentifier]: """returns details about any stored access policies specified on the queue that may be used with Shared Access Signatures. @@ -702,18 +593,14 @@ def get_access_policy( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -721,19 +608,11 @@ def get_access_policy( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) - deserialized = self._deserialize( - "[SignedIdentifier]", pipeline_response.http_response - ) + deserialized = self._deserialize("[SignedIdentifier]", pipeline_response.http_response) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore @@ -776,9 +655,7 @@ def set_access_policy( # pylint: disable=inconsistent-return-statements _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) comp: Literal["acl"] = kwargs.pop("comp", _params.pop("comp", "acl")) - content_type: Optional[str] = kwargs.pop( - "content_type", _headers.pop("Content-Type", "application/xml") - ) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", "application/xml")) content_type = content_type if queue_acl else None cls: ClsType[None] = kwargs.pop("cls", None) @@ -807,18 +684,14 @@ def set_access_policy( # pylint: disable=inconsistent-return-statements _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [204]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -826,15 +699,9 @@ def set_access_policy( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) if cls: return cls(pipeline_response, None, response_headers) # type: ignore diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_service_operations.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_service_operations.py index e66bf5d3bfaa..b20f5f5d24bd 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_service_operations.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_generated/operations/_service_operations.py @@ -28,9 +28,7 @@ from .._utils.serialization import Deserializer, Serializer T = TypeVar("T") -ClsType = Optional[ - Callable[[PipelineResponse[HttpRequest, HttpResponse], T, dict[str, Any]], Any] -] +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False @@ -48,13 +46,9 @@ def build_set_properties_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - restype: Literal["service"] = kwargs.pop( - "restype", _params.pop("restype", "service") - ) + restype: Literal["service"] = kwargs.pop("restype", _params.pop("restype", "service")) comp: Literal["properties"] = kwargs.pop("comp", _params.pop("comp", "properties")) - content_type: Optional[str] = kwargs.pop( - "content_type", _headers.pop("Content-Type", None) - ) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/xml") # Construct URL @@ -74,39 +68,21 @@ def build_set_properties_request( # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header( - "request_id_parameter", request_id_parameter, "str" - ) + _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header( - "content_type", content_type, "str" - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, content=content, **kwargs) def build_get_properties_request( - url: str, - *, - version: str, - timeout: Optional[int] = None, - request_id_parameter: Optional[str] = None, - **kwargs: Any + url: str, *, version: str, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - restype: Literal["service"] = kwargs.pop( - "restype", _params.pop("restype", "service") - ) + restype: Literal["service"] = kwargs.pop("restype", _params.pop("restype", "service")) comp: Literal["properties"] = kwargs.pop("comp", _params.pop("comp", "properties")) accept = _headers.pop("Accept", "application/xml") @@ -127,30 +103,19 @@ def build_get_properties_request( # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header( - "request_id_parameter", request_id_parameter, "str" - ) + _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", url=_url, params=_params, headers=_headers, **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_statistics_request( - url: str, - *, - version: str, - timeout: Optional[int] = None, - request_id_parameter: Optional[str] = None, - **kwargs: Any + url: str, *, version: str, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - restype: Literal["service"] = kwargs.pop( - "restype", _params.pop("restype", "service") - ) + restype: Literal["service"] = kwargs.pop("restype", _params.pop("restype", "service")) comp: Literal["stats"] = kwargs.pop("comp", _params.pop("comp", "stats")) accept = _headers.pop("Accept", "application/xml") @@ -171,14 +136,10 @@ def build_get_statistics_request( # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header( - "request_id_parameter", request_id_parameter, "str" - ) + _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", url=_url, params=_params, headers=_headers, **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_user_delegation_key_request( @@ -193,15 +154,9 @@ def build_get_user_delegation_key_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - restype: Literal["service"] = kwargs.pop( - "restype", _params.pop("restype", "service") - ) - comp: Literal["userdelegationkey"] = kwargs.pop( - "comp", _params.pop("comp", "userdelegationkey") - ) - content_type: Optional[str] = kwargs.pop( - "content_type", _headers.pop("Content-Type", None) - ) + restype: Literal["service"] = kwargs.pop("restype", _params.pop("restype", "service")) + comp: Literal["userdelegationkey"] = kwargs.pop("comp", _params.pop("comp", "userdelegationkey")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/xml") # Construct URL @@ -221,23 +176,12 @@ def build_get_user_delegation_key_request( # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header( - "request_id_parameter", request_id_parameter, "str" - ) + _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header( - "content_type", content_type, "str" - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - content=content, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, content=content, **kwargs) def build_list_queues_segment_request( @@ -273,9 +217,7 @@ def build_list_queues_segment_request( if marker is not None: _params["marker"] = _SERIALIZER.query("marker", marker, "str") if maxresults is not None: - _params["maxresults"] = _SERIALIZER.query( - "maxresults", maxresults, "int", minimum=1 - ) + _params["maxresults"] = _SERIALIZER.query("maxresults", maxresults, "int", minimum=1) if include is not None: _params["include"] = _SERIALIZER.query("include", include, "[str]", div=",") if timeout is not None: @@ -284,14 +226,10 @@ def build_list_queues_segment_request( # Construct headers _headers["x-ms-version"] = _SERIALIZER.header("version", version, "str") if request_id_parameter is not None: - _headers["x-ms-client-request-id"] = _SERIALIZER.header( - "request_id_parameter", request_id_parameter, "str" - ) + _headers["x-ms-client-request-id"] = _SERIALIZER.header("request_id_parameter", request_id_parameter, "str") _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", url=_url, params=_params, headers=_headers, **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) class ServiceOperations: @@ -308,18 +246,10 @@ class ServiceOperations: def __init__(self, *args, **kwargs) -> None: input_args = list(args) - self._client: PipelineClient = ( - input_args.pop(0) if input_args else kwargs.pop("client") - ) - self._config: AzureQueueStorageConfiguration = ( - input_args.pop(0) if input_args else kwargs.pop("config") - ) - self._serialize: Serializer = ( - input_args.pop(0) if input_args else kwargs.pop("serializer") - ) - self._deserialize: Deserializer = ( - input_args.pop(0) if input_args else kwargs.pop("deserializer") - ) + self._client: PipelineClient = input_args.pop(0) if input_args else kwargs.pop("client") + self._config: AzureQueueStorageConfiguration = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize: Serializer = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize: Deserializer = input_args.pop(0) if input_args else kwargs.pop("deserializer") @distributed_trace def set_properties( # pylint: disable=inconsistent-return-statements @@ -357,20 +287,12 @@ def set_properties( # pylint: disable=inconsistent-return-statements _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - restype: Literal["service"] = kwargs.pop( - "restype", _params.pop("restype", "service") - ) - comp: Literal["properties"] = kwargs.pop( - "comp", _params.pop("comp", "properties") - ) - content_type: str = kwargs.pop( - "content_type", _headers.pop("Content-Type", "application/xml") - ) + restype: Literal["service"] = kwargs.pop("restype", _params.pop("restype", "service")) + comp: Literal["properties"] = kwargs.pop("comp", _params.pop("comp", "properties")) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/xml")) cls: ClsType[None] = kwargs.pop("cls", None) - _content = self._serialize.body( - storage_service_properties, "StorageServiceProperties", is_xml=True - ) + _content = self._serialize.body(storage_service_properties, "StorageServiceProperties", is_xml=True) _request = build_set_properties_request( url=self._config.url, @@ -387,18 +309,14 @@ def set_properties( # pylint: disable=inconsistent-return-statements _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [202]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -406,22 +324,15 @@ def set_properties( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) if cls: return cls(pipeline_response, None, response_headers) # type: ignore @distributed_trace def get_properties( - self, - timeout: Optional[int] = None, - request_id_parameter: Optional[str] = None, - **kwargs: Any + self, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any ) -> _models.StorageServiceProperties: """gets the properties of a storage account's Queue service, including properties for Storage Analytics and CORS (Cross-Origin Resource Sharing) rules. @@ -449,12 +360,8 @@ def get_properties( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - restype: Literal["service"] = kwargs.pop( - "restype", _params.pop("restype", "service") - ) - comp: Literal["properties"] = kwargs.pop( - "comp", _params.pop("comp", "properties") - ) + restype: Literal["service"] = kwargs.pop("restype", _params.pop("restype", "service")) + comp: Literal["properties"] = kwargs.pop("comp", _params.pop("comp", "properties")) cls: ClsType[_models.StorageServiceProperties] = kwargs.pop("cls", None) _request = build_get_properties_request( @@ -470,18 +377,14 @@ def get_properties( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -489,16 +392,10 @@ def get_properties( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) - deserialized = self._deserialize( - "StorageServiceProperties", pipeline_response.http_response - ) + deserialized = self._deserialize("StorageServiceProperties", pipeline_response.http_response) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore @@ -507,10 +404,7 @@ def get_properties( @distributed_trace def get_statistics( - self, - timeout: Optional[int] = None, - request_id_parameter: Optional[str] = None, - **kwargs: Any + self, timeout: Optional[int] = None, request_id_parameter: Optional[str] = None, **kwargs: Any ) -> _models.StorageServiceStats: """Retrieves statistics related to replication for the Queue service. It is only available on the secondary location endpoint when read-access geo-redundant replication is enabled for the @@ -539,9 +433,7 @@ def get_statistics( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - restype: Literal["service"] = kwargs.pop( - "restype", _params.pop("restype", "service") - ) + restype: Literal["service"] = kwargs.pop("restype", _params.pop("restype", "service")) comp: Literal["stats"] = kwargs.pop("comp", _params.pop("comp", "stats")) cls: ClsType[_models.StorageServiceStats] = kwargs.pop("cls", None) @@ -558,18 +450,14 @@ def get_statistics( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -577,19 +465,11 @@ def get_statistics( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) - deserialized = self._deserialize( - "StorageServiceStats", pipeline_response.http_response - ) + deserialized = self._deserialize("StorageServiceStats", pipeline_response.http_response) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore @@ -632,15 +512,9 @@ def get_user_delegation_key( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - restype: Literal["service"] = kwargs.pop( - "restype", _params.pop("restype", "service") - ) - comp: Literal["userdelegationkey"] = kwargs.pop( - "comp", _params.pop("comp", "userdelegationkey") - ) - content_type: str = kwargs.pop( - "content_type", _headers.pop("Content-Type", "application/xml") - ) + restype: Literal["service"] = kwargs.pop("restype", _params.pop("restype", "service")) + comp: Literal["userdelegationkey"] = kwargs.pop("comp", _params.pop("comp", "userdelegationkey")) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/xml")) cls: ClsType[_models.UserDelegationKey] = kwargs.pop("cls", None) _content = self._serialize.body(key_info, "KeyInfo", is_xml=True) @@ -660,18 +534,14 @@ def get_user_delegation_key( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -682,19 +552,11 @@ def get_user_delegation_key( response_headers["x-ms-client-request-id"] = self._deserialize( "str", response.headers.get("x-ms-client-request-id") ) - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) - deserialized = self._deserialize( - "UserDelegationKey", pipeline_response.http_response - ) + deserialized = self._deserialize("UserDelegationKey", pipeline_response.http_response) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore @@ -776,18 +638,14 @@ def list_queues_segment( _request.url = self._client.format_url(_request.url) _stream = False - pipeline_response: PipelineResponse = ( - self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200]: - map_error( - status_code=response.status_code, response=response, error_map=error_map - ) + map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize( _models.StorageError, pipeline_response, @@ -795,19 +653,11 @@ def list_queues_segment( raise HttpResponseError(response=response, model=error) response_headers = {} - response_headers["x-ms-request-id"] = self._deserialize( - "str", response.headers.get("x-ms-request-id") - ) - response_headers["x-ms-version"] = self._deserialize( - "str", response.headers.get("x-ms-version") - ) - response_headers["Date"] = self._deserialize( - "rfc-1123", response.headers.get("Date") - ) + response_headers["x-ms-request-id"] = self._deserialize("str", response.headers.get("x-ms-request-id")) + response_headers["x-ms-version"] = self._deserialize("str", response.headers.get("x-ms-version")) + response_headers["Date"] = self._deserialize("rfc-1123", response.headers.get("Date")) - deserialized = self._deserialize( - "ListQueuesSegmentResponse", pipeline_response.http_response - ) + deserialized = self._deserialize("ListQueuesSegmentResponse", pipeline_response.http_response) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_message_encoding.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_message_encoding.py index 3732dee8d497..5dc0dc8f6a26 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_message_encoding.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_message_encoding.py @@ -41,9 +41,7 @@ def __call__(self, content: Any) -> str: if content: content = self.encode(content) if self.key_encryption_key is not None: - content = encrypt_queue_message( - content, self.key_encryption_key, self.encryption_version - ) + content = encrypt_queue_message(content, self.key_encryption_key, self.encryption_version) return content def configure( @@ -78,9 +76,7 @@ def __init__(self) -> None: self.key_encryption_key = None self.resolver = None - def __call__( - self, response: "PipelineResponse", obj: Iterable, headers: Dict[str, Any] - ) -> object: + def __call__(self, response: "PipelineResponse", obj: Iterable, headers: Dict[str, Any]) -> object: for message in obj: if message.message_text in [None, "", b""]: continue @@ -177,9 +173,7 @@ class NoEncodePolicy(MessageEncodePolicy): def encode(self, content: str) -> str: if isinstance(content, bytes): - raise TypeError( - "Message content must not be bytes. Use the BinaryBase64EncodePolicy to send bytes." - ) + raise TypeError("Message content must not be bytes. Use the BinaryBase64EncodePolicy to send bytes.") return content diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_models.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_models.py index ab4cd2c52f32..5fd01179d74e 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_models.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_models.py @@ -193,9 +193,7 @@ class CorsRule(GeneratedCorsRule): """The comma-delimited string representation of the list of headers allowed to be part of the cross-origin request.""" - def __init__( - self, allowed_origins: List[str], allowed_methods: List[str], **kwargs: Any - ) -> None: + def __init__(self, allowed_origins: List[str], allowed_methods: List[str], **kwargs: Any) -> None: self.allowed_origins = ",".join(allowed_origins) self.allowed_methods = ",".join(allowed_methods) self.allowed_headers = ",".join(kwargs.get("allowed_headers", [])) @@ -463,9 +461,7 @@ def _extract_data_cb(self, messages: Any) -> Tuple[str, List[QueueMessage]]: raise StopIteration("End of paging") if self._max_messages is not None: self._max_messages = self._max_messages - len(messages) - return "TOKEN_IGNORED", [ - QueueMessage._from_generated(q) for q in messages - ] # pylint: disable=protected-access + return "TOKEN_IGNORED", [QueueMessage._from_generated(q) for q in messages] # pylint: disable=protected-access class QueueProperties(DictMixin): @@ -555,17 +551,14 @@ def _get_next_cb(self, continuation_token: Optional[str]) -> Any: except HttpResponseError as error: process_storage_error(error) - def _extract_data_cb( - self, get_next_return: Any - ) -> Tuple[Optional[str], List[QueueProperties]]: + def _extract_data_cb(self, get_next_return: Any) -> Tuple[Optional[str], List[QueueProperties]]: self.location_mode, self._response = get_next_return self.service_endpoint = self._response.service_endpoint self.prefix = self._response.prefix self.marker = self._response.marker self.results_per_page = self._response.max_results props_list = [ - QueueProperties._from_generated(q) - for q in self._response.queue_items # pylint: disable=protected-access + QueueProperties._from_generated(q) for q in self._response.queue_items # pylint: disable=protected-access ] return self._response.next_marker or None, props_list @@ -596,13 +589,7 @@ def service_properties_deserialize(generated: Any) -> Dict[str, Any]: "analytics_logging": QueueAnalyticsLogging._from_generated( # pylint: disable=protected-access generated.logging ), - "hour_metrics": Metrics._from_generated( - generated.hour_metrics - ), # pylint: disable=protected-access - "minute_metrics": Metrics._from_generated( - generated.minute_metrics - ), # pylint: disable=protected-access - "cors": [ - CorsRule._from_generated(cors) for cors in generated.cors - ], # pylint: disable=protected-access + "hour_metrics": Metrics._from_generated(generated.hour_metrics), # pylint: disable=protected-access + "minute_metrics": Metrics._from_generated(generated.minute_metrics), # pylint: disable=protected-access + "cors": [CorsRule._from_generated(cors) for cors in generated.cors], # pylint: disable=protected-access } diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_client.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_client.py index b669da7e0161..17205bbf69eb 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_client.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_client.py @@ -115,18 +115,12 @@ def __init__( *, api_version: Optional[str] = None, secondary_hostname: Optional[str] = None, - message_encode_policy: Optional[ - Union["BinaryBase64EncodePolicy", "TextBase64EncodePolicy"] - ] = None, - message_decode_policy: Optional[ - Union["BinaryBase64DecodePolicy", "TextBase64DecodePolicy"] - ] = None, + message_encode_policy: Optional[Union["BinaryBase64EncodePolicy", "TextBase64EncodePolicy"]] = None, + message_decode_policy: Optional[Union["BinaryBase64DecodePolicy", "TextBase64DecodePolicy"]] = None, audience: Optional[str] = None, **kwargs: Any ) -> None: - parsed_url, sas_token = _parse_url( - account_url=account_url, queue_name=queue_name, credential=credential - ) + parsed_url, sas_token = _parse_url(account_url=account_url, queue_name=queue_name, credential=credential) self.queue_name = queue_name self._query_str, credential = self._format_query_string(sas_token, credential) super(QueueClient, self).__init__( @@ -157,9 +151,7 @@ def __exit__( exc: Optional[BaseException], tb: Optional[TracebackType], ) -> None: - self._client.__exit__( - typ, exc, tb - ) # pylint: disable=specify-parameter-names-in-call + self._client.__exit__(typ, exc, tb) # pylint: disable=specify-parameter-names-in-call def close(self) -> None: """This method is to close the sockets opened by the client. @@ -201,12 +193,8 @@ def from_queue_url( *, api_version: Optional[str] = None, secondary_hostname: Optional[str] = None, - message_encode_policy: Optional[ - Union["BinaryBase64EncodePolicy", "TextBase64EncodePolicy"] - ] = None, - message_decode_policy: Optional[ - Union["BinaryBase64DecodePolicy", "TextBase64DecodePolicy"] - ] = None, + message_encode_policy: Optional[Union["BinaryBase64EncodePolicy", "TextBase64EncodePolicy"]] = None, + message_decode_policy: Optional[Union["BinaryBase64DecodePolicy", "TextBase64DecodePolicy"]] = None, audience: Optional[str] = None, **kwargs: Any ) -> Self: @@ -276,12 +264,8 @@ def from_connection_string( *, api_version: Optional[str] = None, secondary_hostname: Optional[str] = None, - message_encode_policy: Optional[ - Union["BinaryBase64EncodePolicy", "TextBase64EncodePolicy"] - ] = None, - message_decode_policy: Optional[ - Union["BinaryBase64DecodePolicy", "TextBase64DecodePolicy"] - ] = None, + message_encode_policy: Optional[Union["BinaryBase64EncodePolicy", "TextBase64EncodePolicy"]] = None, + message_decode_policy: Optional[Union["BinaryBase64DecodePolicy", "TextBase64DecodePolicy"]] = None, audience: Optional[str] = None, **kwargs: Any ) -> Self: @@ -333,9 +317,7 @@ def from_connection_string( :dedent: 8 :caption: Create the queue client from connection string. """ - account_url, secondary, credential = parse_connection_str( - conn_str, credential, "queue" - ) + account_url, secondary, credential = parse_connection_str(conn_str, credential, "queue") return cls( account_url, queue_name=queue_name, @@ -350,11 +332,7 @@ def from_connection_string( @distributed_trace def create_queue( - self, - *, - metadata: Optional[Dict[str, str]] = None, - timeout: Optional[int] = None, - **kwargs: Any + self, *, metadata: Optional[Dict[str, str]] = None, timeout: Optional[int] = None, **kwargs: Any ) -> None: """Creates a new queue in the storage account. @@ -388,11 +366,7 @@ def create_queue( headers.update(add_metadata_headers(metadata)) try: return self._client.queue.create( - metadata=metadata, - timeout=timeout, - headers=headers, - cls=deserialize_queue_creation, - **kwargs + metadata=metadata, timeout=timeout, headers=headers, cls=deserialize_queue_creation, **kwargs ) except HttpResponseError as error: process_storage_error(error) @@ -432,9 +406,7 @@ def delete_queue(self, *, timeout: Optional[int] = None, **kwargs: Any) -> None: process_storage_error(error) @distributed_trace - def get_queue_properties( - self, *, timeout: Optional[int] = None, **kwargs: Any - ) -> "QueueProperties": + def get_queue_properties(self, *, timeout: Optional[int] = None, **kwargs: Any) -> "QueueProperties": """Returns all user-defined metadata for the specified queue. The data returned does not include the queue's list of messages. @@ -456,9 +428,7 @@ def get_queue_properties( try: response = cast( "QueueProperties", - self._client.queue.get_properties( - timeout=timeout, cls=deserialize_queue_properties, **kwargs - ), + self._client.queue.get_properties(timeout=timeout, cls=deserialize_queue_properties, **kwargs), ) except HttpResponseError as error: process_storage_error(error) @@ -467,11 +437,7 @@ def get_queue_properties( @distributed_trace def set_queue_metadata( - self, - metadata: Optional[Dict[str, str]] = None, - *, - timeout: Optional[int] = None, - **kwargs: Any + self, metadata: Optional[Dict[str, str]] = None, *, timeout: Optional[int] = None, **kwargs: Any ) -> Dict[str, Any]: """Sets user-defined metadata on the specified queue. @@ -508,9 +474,7 @@ def set_queue_metadata( process_storage_error(error) @distributed_trace - def get_queue_access_policy( - self, *, timeout: Optional[int] = None, **kwargs: Any - ) -> Dict[str, AccessPolicy]: + def get_queue_access_policy(self, *, timeout: Optional[int] = None, **kwargs: Any) -> Dict[str, AccessPolicy]: """Returns details about any stored access policies specified on the queue that may be used with Shared Access Signatures. @@ -526,9 +490,7 @@ def get_queue_access_policy( try: _, identifiers = cast( Tuple[Dict, List], - self._client.queue.get_access_policy( - timeout=timeout, cls=return_headers_and_deserialized, **kwargs - ), + self._client.queue.get_access_policy(timeout=timeout, cls=return_headers_and_deserialized, **kwargs), ) except HttpResponseError as error: process_storage_error(error) @@ -536,11 +498,7 @@ def get_queue_access_policy( @distributed_trace def set_queue_access_policy( - self, - signed_identifiers: Dict[str, AccessPolicy], - *, - timeout: Optional[int] = None, - **kwargs: Any + self, signed_identifiers: Dict[str, AccessPolicy], *, timeout: Optional[int] = None, **kwargs: Any ) -> None: """Sets stored access policies for the queue that may be used with Shared Access Signatures. @@ -589,9 +547,7 @@ def set_queue_access_policy( value.expiry = serialize_iso(value.expiry) identifiers.append(SignedIdentifier(id=key, access_policy=value)) try: - self._client.queue.set_access_policy( - queue_acl=identifiers or None, timeout=timeout, **kwargs - ) + self._client.queue.set_access_policy(queue_acl=identifiers or None, timeout=timeout, **kwargs) except HttpResponseError as error: process_storage_error(error) @@ -670,10 +626,12 @@ def send_message( encryption_version=self.encryption_version, ) except TypeError: - warnings.warn("TypeError when calling message_encode_policy.configure. \ + warnings.warn( + "TypeError when calling message_encode_policy.configure. \ It is likely missing the encryption_version parameter. \ Consider updating your encryption information/implementation. \ - Retrying without encryption_version.") + Retrying without encryption_version." + ) self._message_encode_policy.configure( require_encryption=self.require_encryption, key_encryption_key=self.key_encryption_key, @@ -704,11 +662,7 @@ def send_message( @distributed_trace def receive_message( - self, - *, - visibility_timeout: Optional[int] = None, - timeout: Optional[int] = None, - **kwargs: Any + self, *, visibility_timeout: Optional[int] = None, timeout: Optional[int] = None, **kwargs: Any ) -> Optional[QueueMessage]: """Removes one message from the front of the queue. @@ -769,9 +723,7 @@ def receive_message( **kwargs ) wrapped_message = ( - QueueMessage._from_generated(message[0]) - if message != [] - else None # pylint: disable=protected-access + QueueMessage._from_generated(message[0]) if message != [] else None # pylint: disable=protected-access ) return wrapped_message except HttpResponseError as error: @@ -868,9 +820,7 @@ def receive_messages( ) if max_messages is not None and messages_per_page is not None: if max_messages < messages_per_page: - raise ValueError( - "max_messages must be greater or equal to messages_per_page" - ) + raise ValueError("max_messages must be greater or equal to messages_per_page") return ItemPaged( command, results_per_page=messages_per_page, @@ -975,10 +925,12 @@ def update_message( encryption_version=self.encryption_version, ) except TypeError: - warnings.warn("TypeError when calling message_encode_policy.configure. \ + warnings.warn( + "TypeError when calling message_encode_policy.configure. \ It is likely missing the encryption_version parameter. \ Consider updating your encryption information/implementation. \ - Retrying without encryption_version.") + Retrying without encryption_version." + ) self._message_encode_policy.configure( self.require_encryption, self.key_encryption_key, @@ -1016,11 +968,7 @@ def update_message( @distributed_trace def peek_messages( - self, - max_messages: Optional[int] = None, - *, - timeout: Optional[int] = None, - **kwargs: Any + self, max_messages: Optional[int] = None, *, timeout: Optional[int] = None, **kwargs: Any ) -> List[QueueMessage]: """Retrieves one or more messages from the front of the queue, but does not alter the visibility of the message. @@ -1079,16 +1027,11 @@ def peek_messages( ) try: messages = self._client.messages.peek( - number_of_messages=max_messages, - timeout=timeout, - cls=self._message_decode_policy, - **kwargs + number_of_messages=max_messages, timeout=timeout, cls=self._message_decode_policy, **kwargs ) wrapped_messages = [] for peeked in messages: - wrapped_messages.append( - QueueMessage._from_generated(peeked) - ) # pylint: disable=protected-access + wrapped_messages.append(QueueMessage._from_generated(peeked)) # pylint: disable=protected-access return wrapped_messages except HttpResponseError as error: process_storage_error(error) @@ -1172,11 +1115,6 @@ def delete_message( if receipt is None: raise ValueError("pop_receipt must be present") try: - self._client.message_id.delete( - pop_receipt=receipt, - timeout=timeout, - queue_message_id=message_id, - **kwargs - ) + self._client.message_id.delete(pop_receipt=receipt, timeout=timeout, queue_message_id=message_id, **kwargs) except HttpResponseError as error: process_storage_error(error) diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_client_helpers.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_client_helpers.py index 831ac367058c..1ce357070db3 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_client_helpers.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_client_helpers.py @@ -66,16 +66,12 @@ def _parse_url( _, sas_token = parse_query(parsed_url.query) if not sas_token and not credential: - raise ValueError( - "You need to provide either a SAS token or an account shared key to authenticate." - ) + raise ValueError("You need to provide either a SAS token or an account shared key to authenticate.") return parsed_url, sas_token -def _format_url( - queue_name: Union[bytes, str], hostname: str, scheme: str, query_str: str -) -> str: +def _format_url(queue_name: Union[bytes, str], hostname: str, scheme: str, query_str: str) -> str: """Format the endpoint URL according to the current location mode hostname. :param Union[bytes, str] queue_name: The name of the queue. @@ -113,10 +109,7 @@ def _from_queue_url(queue_url: str) -> Tuple[str, str]: account_path = "" if len(queue_path) > 1: account_path = "/" + "/".join(queue_path[:-1]) - account_url = ( - f"{parsed_url.scheme}://{parsed_url.netloc.rstrip('/')}" - f"{account_path}?{parsed_url.query}" - ) + account_url = f"{parsed_url.scheme}://{parsed_url.netloc.rstrip('/')}" f"{account_path}?{parsed_url.query}" queue_name = unquote(queue_path[-1]) if not queue_name: raise ValueError("Invalid URL. Please provide a URL with a valid queue name") diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_service_client.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_service_client.py index 7095051a17f4..84fbef762fe0 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_service_client.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_service_client.py @@ -123,9 +123,7 @@ def __init__( audience: Optional[str] = None, **kwargs: Any, ) -> None: - parsed_url, sas_token = _parse_url( - account_url=account_url, credential=credential - ) + parsed_url, sas_token = _parse_url(account_url=account_url, credential=credential) self._query_str, credential = self._format_query_string(sas_token, credential) super(QueueServiceClient, self).__init__( parsed_url, @@ -153,9 +151,7 @@ def __exit__( exc: Optional[BaseException], tb: Optional[TracebackType], ) -> None: - self._client.__exit__( - typ, exc, tb - ) # pylint: disable=specify-parameter-names-in-call + self._client.__exit__(typ, exc, tb) # pylint: disable=specify-parameter-names-in-call def close(self) -> None: """This method is to close the sockets opened by the client. @@ -233,9 +229,7 @@ def from_connection_string( :dedent: 8 :caption: Creating the QueueServiceClient with a connection string. """ - account_url, secondary, credential = parse_connection_str( - conn_str, credential, "queue" - ) + account_url, secondary, credential = parse_connection_str(conn_str, credential, "queue") return cls( account_url, credential=credential, @@ -289,9 +283,7 @@ def get_user_delegation_key( return parse_to_internal_user_delegation_key(user_delegation_key) @distributed_trace - def get_service_stats( - self, *, timeout: Optional[int] = None, **kwargs: Any - ) -> Dict[str, Any]: + def get_service_stats(self, *, timeout: Optional[int] = None, **kwargs: Any) -> Dict[str, Any]: """Retrieves statistics related to replication for the Queue service. It is only available when read-access geo-redundant replication is enabled for @@ -316,17 +308,13 @@ def get_service_stats( :rtype: Dict[str, Any] """ try: - stats = self._client.service.get_statistics( - timeout=timeout, use_location=LocationMode.SECONDARY, **kwargs - ) + stats = self._client.service.get_statistics(timeout=timeout, use_location=LocationMode.SECONDARY, **kwargs) return service_stats_deserialize(stats) except HttpResponseError as error: process_storage_error(error) @distributed_trace - def get_service_properties( - self, *, timeout: Optional[int] = None, **kwargs: Any - ) -> Dict[str, Any]: + def get_service_properties(self, *, timeout: Optional[int] = None, **kwargs: Any) -> Dict[str, Any]: """Gets the properties of a storage account's Queue service, including Azure Storage Analytics. @@ -346,9 +334,7 @@ def get_service_properties( :caption: Getting queue service properties. """ try: - service_props = self._client.service.get_properties( - timeout=timeout, **kwargs - ) + service_props = self._client.service.get_properties(timeout=timeout, **kwargs) return service_properties_deserialize(service_props) except HttpResponseError as error: process_storage_error(error) @@ -544,9 +530,7 @@ def delete_queue( kwargs.setdefault("merge_span", True) queue_client.delete_queue(timeout=timeout, **kwargs) - def get_queue_client( - self, queue: Union["QueueProperties", str], **kwargs: Any - ) -> QueueClient: + def get_queue_client(self, queue: Union["QueueProperties", str], **kwargs: Any) -> QueueClient: """Get a client to interact with the specified queue. The queue need not already exist. @@ -573,9 +557,7 @@ def get_queue_client( queue_name = queue _pipeline = Pipeline( - transport=TransportWrapper( - self._pipeline._transport - ), # pylint: disable=protected-access + transport=TransportWrapper(self._pipeline._transport), # pylint: disable=protected-access policies=self._pipeline._impl_policies, # type: ignore # pylint: disable=protected-access ) diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_service_client_helpers.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_service_client_helpers.py index d87ad2ded690..62266ac058f6 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_service_client_helpers.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_queue_service_client_helpers.py @@ -62,8 +62,6 @@ def _parse_url( _, sas_token = parse_query(parsed_url.query) if not sas_token and not credential: - raise ValueError( - "You need to provide either a SAS token or an account shared key to authenticate." - ) + raise ValueError("You need to provide either a SAS token or an account shared key to authenticate.") return parsed_url, sas_token diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_serialize.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_serialize.py index 21afc3fc9c02..3a9b86f7b195 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_serialize.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_serialize.py @@ -41,7 +41,5 @@ def get_api_version(api_version: Optional[str]) -> str: if api_version and api_version not in _SUPPORTED_API_VERSIONS: versions = "\n".join(_SUPPORTED_API_VERSIONS) - raise ValueError( - f"Unsupported API version '{api_version}'. Please select from:\n{versions}" - ) + raise ValueError(f"Unsupported API version '{api_version}'. Please select from:\n{versions}") return api_version or _SUPPORTED_API_VERSIONS[-1] diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/authentication.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/authentication.py index 4a83361cbb1d..1c8cb02bd67d 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/authentication.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/authentication.py @@ -140,11 +140,7 @@ def __init__(self, account_name, account_key): @staticmethod def _get_headers(request, headers_to_sign): - headers = dict( - (name.lower(), value) - for name, value in request.http_request.headers.items() - if value - ) + headers = dict((name.lower(), value) for name, value in request.http_request.headers.items() if value) if "content-length" in headers and headers["content-length"] == "0": del headers["content-length"] return "\n".join(headers.get(x, "") for x in headers_to_sign) + "\n" diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client.py index a2ec8f687c09..e4e037e73239 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client.py @@ -89,7 +89,7 @@ def _construct_endpoints(netloc: str, account_part: str) -> Tuple[str, str, str] Construct primary and secondary hostnames from a storage account URL's netloc. :param str netloc: The network location in a URL. - :param account_part: The account part after parsing the URL. + :param str account_part: The account part after parsing the URL. :return: The account name, primary hostname, and secondary hostname. :rtype: Tuple[str, str, str] """ @@ -109,9 +109,7 @@ def _construct_endpoints(netloc: str, account_part: str) -> Tuple[str, str, str] account_name = account_name[: -len(suffix)] break primary_hostname = f"{account_part}{domain_suffix}" - secondary_hostname = ( - f"{account_name}{_SECONDARY_SUFFIX}{feature_suffix}{domain_suffix}" - ) + secondary_hostname = f"{account_name}{_SECONDARY_SUFFIX}{feature_suffix}{domain_suffix}" return account_name, primary_hostname, secondary_hostname @@ -158,8 +156,8 @@ def __init__( secondary_hostname = "" if len(account) > 1: - self.account_name, primary_hostname, secondary_hostname = ( - _construct_endpoints(parsed_url.netloc, account[0]) + self.account_name, primary_hostname, secondary_hostname = _construct_endpoints( + parsed_url.netloc, account[0] ) else: primary_hostname = (parsed_url.netloc + parsed_url.path).rstrip("/") @@ -184,9 +182,7 @@ def __init__( } self._sdk_moniker = f"storage-{service}/{VERSION}" - self._config, self._pipeline = self._create_pipeline( - self.credential, sdk_moniker=self._sdk_moniker, **kwargs - ) + self._config, self._pipeline = self._create_pipeline(self.credential, sdk_moniker=self._sdk_moniker, **kwargs) @property def url(self) -> str: @@ -335,9 +331,7 @@ def _create_pipeline( audience = str(kwargs.pop("audience")).rstrip("/") + DEFAULT_OAUTH_SCOPE else: audience = STORAGE_OAUTH_SCOPE - self._credential_policy = StorageBearerTokenCredentialPolicy( - cast(TokenCredential, credential), audience - ) + self._credential_policy = StorageBearerTokenCredentialPolicy(cast(TokenCredential, credential), audience) elif isinstance(credential, SharedKeyCredentialPolicy): self._credential_policy = credential elif isinstance(credential, AzureSasCredential): @@ -376,9 +370,7 @@ def _create_pipeline( config.transport = transport # type: ignore return config, Pipeline(transport, policies=policies) - def _batch_send( - self, *reqs: "HttpRequest", **kwargs: Any - ) -> Iterator["HttpResponse"]: + def _batch_send(self, *reqs: "HttpRequest", **kwargs: Any) -> Iterator["HttpResponse"]: """Given a series of request, do a Storage batch call. :param HttpRequest reqs: A collection of HttpRequest objects. @@ -397,8 +389,7 @@ def _batch_send( ), headers={ "x-ms-version": self.api_version, - "Content-Type": "multipart/mixed; boundary=" - + _get_batch_request_delimiter(batch_id, False, False), + "Content-Type": "multipart/mixed; boundary=" + _get_batch_request_delimiter(batch_id, False, False), }, ) @@ -408,9 +399,7 @@ def _batch_send( request.set_multipart_mixed(*reqs, policies=policies, enforce_https=False) - Pipeline._prepare_multipart_mixed_request( - request - ) # pylint: disable=protected-access + Pipeline._prepare_multipart_mixed_request(request) # pylint: disable=protected-access body = serialize_batch_body(request.multipart_mixed_info[0], batch_id) request.set_bytes_body(body) @@ -479,9 +468,7 @@ def _format_shared_key_credential( ) -> Any: if isinstance(credential, str): if not account_name: - raise ValueError( - "Unable to determine account name for shared key credential." - ) + raise ValueError("Unable to determine account name for shared key credential.") credential = {"account_name": account_name, "account_key": credential} if isinstance(credential, dict): if "account_name" not in credential: @@ -490,9 +477,7 @@ def _format_shared_key_credential( raise ValueError("Shared key credential missing 'account_key") return SharedKeyCredentialPolicy(**credential) if isinstance(credential, AzureNamedKeyCredential): - return SharedKeyCredentialPolicy( - credential.named_key.name, credential.named_key.key - ) + return SharedKeyCredentialPolicy(credential.named_key.name, credential.named_key.key) return credential @@ -551,10 +536,7 @@ def parse_connection_str( f"{conn_settings['DEFAULTENDPOINTSPROTOCOL']}://" f"{conn_settings['ACCOUNTNAME']}.{service}.{conn_settings['ENDPOINTSUFFIX']}" ) - secondary = ( - f"{conn_settings['ACCOUNTNAME']}-secondary." - f"{service}.{conn_settings['ENDPOINTSUFFIX']}" - ) + secondary = f"{conn_settings['ACCOUNTNAME']}-secondary." f"{service}.{conn_settings['ENDPOINTSUFFIX']}" except KeyError: pass @@ -565,9 +547,7 @@ def parse_connection_str( f"{service}.{conn_settings.get('ENDPOINTSUFFIX', SERVICE_HOST_BASE)}" ) except KeyError as exc: - raise ValueError( - "Connection string missing required connection details." - ) from exc + raise ValueError("Connection string missing required connection details.") from exc if service == "dfs": primary = primary.replace(".blob.", ".dfs.") if secondary: @@ -591,9 +571,7 @@ def create_configuration(**kwargs: Any) -> StorageConfiguration: def parse_query(query_str: str) -> Tuple[Optional[str], Optional[str]]: sas_values = QueryStringConstants.to_list() parsed_query = {k: v[0] for k, v in parse_qs(query_str).items()} - sas_params = [ - f"{k}={quote(v, safe='')}" for k, v in parsed_query.items() if k in sas_values - ] + sas_params = [f"{k}={quote(v, safe='')}" for k, v in parsed_query.items() if k in sas_values] sas_token = None if sas_params: sas_token = "&".join(sas_params) diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client_async.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client_async.py index 4df6570f02f0..74d80d8c21be 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client_async.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client_async.py @@ -154,9 +154,7 @@ def _create_pipeline( AioHttpTransport, ) except ImportError as exc: - raise ImportError( - "Unable to create async transport. Please check aiohttp is installed." - ) from exc + raise ImportError("Unable to create async transport. Please check aiohttp is installed.") from exc transport = AioHttpTransport(**kwargs) hosts = self._hosts policies = [ @@ -181,9 +179,7 @@ def _create_pipeline( config.transport = transport # type: ignore return config, AsyncPipeline(transport, policies=policies) # type: ignore - async def _batch_send( - self, *reqs: "HttpRequest", **kwargs: Any - ) -> AsyncList["HttpResponse"]: + async def _batch_send(self, *reqs: "HttpRequest", **kwargs: Any) -> AsyncList["HttpResponse"]: """Given a series of request, do a Storage batch call. :param HttpRequest reqs: A collection of HttpRequest objects. @@ -286,10 +282,7 @@ def parse_connection_str( f"{conn_settings['DEFAULTENDPOINTSPROTOCOL']}://" f"{conn_settings['ACCOUNTNAME']}.{service}.{conn_settings['ENDPOINTSUFFIX']}" ) - secondary = ( - f"{conn_settings['ACCOUNTNAME']}-secondary." - f"{service}.{conn_settings['ENDPOINTSUFFIX']}" - ) + secondary = f"{conn_settings['ACCOUNTNAME']}-secondary." f"{service}.{conn_settings['ENDPOINTSUFFIX']}" except KeyError: pass @@ -300,9 +293,7 @@ def parse_connection_str( f"{service}.{conn_settings.get('ENDPOINTSUFFIX', SERVICE_HOST_BASE)}" ) except KeyError as exc: - raise ValueError( - "Connection string missing required connection details." - ) from exc + raise ValueError("Connection string missing required connection details.") from exc if service == "dfs": primary = primary.replace(".blob.", ".dfs.") if secondary: diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/models.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/models.py index 162132eb0537..51565b636f6c 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/models.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/models.py @@ -71,9 +71,7 @@ class StorageErrorCode(str, Enum, metaclass=CaseInsensitiveEnumMeta): # Blob values APPEND_POSITION_CONDITION_NOT_MET = "AppendPositionConditionNotMet" - BLOB_ACCESS_TIER_NOT_SUPPORTED_FOR_ACCOUNT_TYPE = ( - "BlobAccessTierNotSupportedForAccountType" - ) + BLOB_ACCESS_TIER_NOT_SUPPORTED_FOR_ACCOUNT_TYPE = "BlobAccessTierNotSupportedForAccountType" BLOB_ALREADY_EXISTS = "BlobAlreadyExists" BLOB_NOT_FOUND = "BlobNotFound" BLOB_OVERWRITTEN = "BlobOverwritten" @@ -91,17 +89,11 @@ class StorageErrorCode(str, Enum, metaclass=CaseInsensitiveEnumMeta): COPY_ID_MISMATCH = "CopyIdMismatch" FEATURE_VERSION_MISMATCH = "FeatureVersionMismatch" INCREMENTAL_COPY_BLOB_MISMATCH = "IncrementalCopyBlobMismatch" - INCREMENTAL_COPY_OF_EARLIER_SNAPSHOT_NOT_ALLOWED = ( - "IncrementalCopyOfEarlierSnapshotNotAllowed" - ) + INCREMENTAL_COPY_OF_EARLIER_SNAPSHOT_NOT_ALLOWED = "IncrementalCopyOfEarlierSnapshotNotAllowed" #: Deprecated: Please use INCREMENTAL_COPY_OF_EARLIER_SNAPSHOT_NOT_ALLOWED instead. - INCREMENTAL_COPY_OF_EARLIER_VERSION_SNAPSHOT_NOT_ALLOWED = ( - "IncrementalCopyOfEarlierVersionSnapshotNotAllowed" - ) + INCREMENTAL_COPY_OF_EARLIER_VERSION_SNAPSHOT_NOT_ALLOWED = "IncrementalCopyOfEarlierVersionSnapshotNotAllowed" #: Deprecated: Please use INCREMENTAL_COPY_OF_EARLIER_VERSION_SNAPSHOT_NOT_ALLOWED instead. - INCREMENTAL_COPY_OF_ERALIER_VERSION_SNAPSHOT_NOT_ALLOWED = ( - "IncrementalCopyOfEarlierVersionSnapshotNotAllowed" - ) + INCREMENTAL_COPY_OF_ERALIER_VERSION_SNAPSHOT_NOT_ALLOWED = "IncrementalCopyOfEarlierVersionSnapshotNotAllowed" INCREMENTAL_COPY_SOURCE_MUST_BE_SNAPSHOT = "IncrementalCopySourceMustBeSnapshot" INFINITE_LEASE_DURATION_REQUIRED = "InfiniteLeaseDurationRequired" INVALID_BLOB_OR_BLOCK = "InvalidBlobOrBlock" @@ -129,9 +121,7 @@ class StorageErrorCode(str, Enum, metaclass=CaseInsensitiveEnumMeta): LEASE_NOT_PRESENT_WITH_LEASE_OPERATION = "LeaseNotPresentWithLeaseOperation" MAX_BLOB_SIZE_CONDITION_NOT_MET = "MaxBlobSizeConditionNotMet" NO_PENDING_COPY_OPERATION = "NoPendingCopyOperation" - OPERATION_NOT_ALLOWED_ON_INCREMENTAL_COPY_BLOB = ( - "OperationNotAllowedOnIncrementalCopyBlob" - ) + OPERATION_NOT_ALLOWED_ON_INCREMENTAL_COPY_BLOB = "OperationNotAllowedOnIncrementalCopyBlob" PENDING_COPY_OPERATION = "PendingCopyOperation" PREVIOUS_SNAPSHOT_CANNOT_BE_NEWER = "PreviousSnapshotCannotBeNewer" PREVIOUS_SNAPSHOT_NOT_FOUND = "PreviousSnapshotNotFound" @@ -169,13 +159,9 @@ class StorageErrorCode(str, Enum, metaclass=CaseInsensitiveEnumMeta): DELETE_PENDING = "DeletePending" DIRECTORY_NOT_EMPTY = "DirectoryNotEmpty" FILE_LOCK_CONFLICT = "FileLockConflict" - FILE_SHARE_PROVISIONED_BANDWIDTH_DOWNGRADE_NOT_ALLOWED = ( - "FileShareProvisionedBandwidthDowngradeNotAllowed" - ) + FILE_SHARE_PROVISIONED_BANDWIDTH_DOWNGRADE_NOT_ALLOWED = "FileShareProvisionedBandwidthDowngradeNotAllowed" FILE_SHARE_PROVISIONED_BANDWIDTH_INVALID = "FileShareProvisionedBandwidthInvalid" - FILE_SHARE_PROVISIONED_IOPS_DOWNGRADE_NOT_ALLOWED = ( - "FileShareProvisionedIopsDowngradeNotAllowed" - ) + FILE_SHARE_PROVISIONED_IOPS_DOWNGRADE_NOT_ALLOWED = "FileShareProvisionedIopsDowngradeNotAllowed" FILE_SHARE_PROVISIONED_IOPS_INVALID = "FileShareProvisionedIopsInvalid" FILE_SHARE_PROVISIONED_STORAGE_INVALID = "FileShareProvisionedStorageInvalid" INVALID_FILE_OR_DIRECTORY_PATH_NAME = "InvalidFileOrDirectoryPathName" @@ -191,15 +177,9 @@ class StorageErrorCode(str, Enum, metaclass=CaseInsensitiveEnumMeta): SHARE_SNAPSHOT_NOT_FOUND = "ShareSnapshotNotFound" SHARE_SNAPSHOT_OPERATION_NOT_SUPPORTED = "ShareSnapshotOperationNotSupported" SHARE_HAS_SNAPSHOTS = "ShareHasSnapshots" - TOTAL_SHARES_PROVISIONED_CAPACITY_EXCEEDS_ACCOUNT_LIMIT = ( - "TotalSharesProvisionedCapacityExceedsAccountLimit" - ) - TOTAL_SHARES_PROVISIONED_IOPS_EXCEEDS_ACCOUNT_LIMIT = ( - "TotalSharesProvisionedIopsExceedsAccountLimit" - ) - TOTAL_SHARES_PROVISIONED_BANDWIDTH_EXCEEDS_ACCOUNT_LIMIT = ( - "TotalSharesProvisionedBandwidthExceedsAccountLimit" - ) + TOTAL_SHARES_PROVISIONED_CAPACITY_EXCEEDS_ACCOUNT_LIMIT = "TotalSharesProvisionedCapacityExceedsAccountLimit" + TOTAL_SHARES_PROVISIONED_IOPS_EXCEEDS_ACCOUNT_LIMIT = "TotalSharesProvisionedIopsExceedsAccountLimit" + TOTAL_SHARES_PROVISIONED_BANDWIDTH_EXCEEDS_ACCOUNT_LIMIT = "TotalSharesProvisionedBandwidthExceedsAccountLimit" TOTAL_SHARES_COUNT_EXCEEDS_ACCOUNT_LIMIT = "TotalSharesCountExceedsAccountLimit" # DataLake values @@ -218,9 +198,7 @@ class StorageErrorCode(str, Enum, metaclass=CaseInsensitiveEnumMeta): FILE_SYSTEM_BEING_DELETED = "FilesystemBeingDeleted" INVALID_DESTINATION_PATH = "InvalidDestinationPath" INVALID_RENAME_SOURCE_PATH = "InvalidRenameSourcePath" - INVALID_SOURCE_OR_DESTINATION_RESOURCE_TYPE = ( - "InvalidSourceOrDestinationResourceType" - ) + INVALID_SOURCE_OR_DESTINATION_RESOURCE_TYPE = "InvalidSourceOrDestinationResourceType" LEASE_IS_ALREADY_BROKEN = "LeaseIsAlreadyBroken" LEASE_NAME_MISMATCH = "LeaseNameMismatch" PATH_CONFLICT = "PathConflict" @@ -289,9 +267,7 @@ class LocationMode(object): """ PRIMARY = "primary" #: Requests should be sent to the primary location. - SECONDARY = ( - "secondary" #: Requests should be sent to the secondary location, if possible. - ) + SECONDARY = "secondary" #: Requests should be sent to the secondary location, if possible. class ResourceTypes(object): @@ -324,11 +300,7 @@ def __init__( self.service = service self.container = container self.object = object - self._str = ( - ("s" if self.service else "") - + ("c" if self.container else "") - + ("o" if self.object else "") - ) + self._str = ("s" if self.service else "") + ("c" if self.container else "") + ("o" if self.object else "") def __str__(self): return self._str @@ -513,17 +485,11 @@ class Services(object): Access for the `~azure.storage.fileshare.ShareServiceClient`. Default is False. """ - def __init__( - self, *, blob: bool = False, queue: bool = False, fileshare: bool = False - ) -> None: + def __init__(self, *, blob: bool = False, queue: bool = False, fileshare: bool = False) -> None: self.blob = blob self.queue = queue self.fileshare = fileshare - self._str = ( - ("b" if self.blob else "") - + ("q" if self.queue else "") - + ("f" if self.fileshare else "") - ) + self._str = ("b" if self.blob else "") + ("q" if self.queue else "") + ("f" if self.fileshare else "") def __str__(self): return self._str @@ -627,14 +593,10 @@ def __init__(self, **kwargs): self.max_single_put_size = kwargs.pop("max_single_put_size", 64 * 1024 * 1024) self.copy_polling_interval = 15 self.max_block_size = kwargs.pop("max_block_size", 4 * 1024 * 1024) - self.min_large_block_upload_threshold = kwargs.get( - "min_large_block_upload_threshold", 4 * 1024 * 1024 + 1 - ) + self.min_large_block_upload_threshold = kwargs.get("min_large_block_upload_threshold", 4 * 1024 * 1024 + 1) self.use_byte_buffer = kwargs.pop("use_byte_buffer", False) self.max_page_size = kwargs.pop("max_page_size", 4 * 1024 * 1024) - self.min_large_chunk_upload_threshold = kwargs.pop( - "min_large_chunk_upload_threshold", 100 * 1024 * 1024 + 1 - ) + self.min_large_chunk_upload_threshold = kwargs.pop("min_large_chunk_upload_threshold", 100 * 1024 * 1024 + 1) self.max_single_get_size = kwargs.pop("max_single_get_size", 32 * 1024 * 1024) self.max_chunk_get_size = kwargs.pop("max_chunk_get_size", 4 * 1024 * 1024) self.max_range_size = kwargs.pop("max_range_size", 4 * 1024 * 1024) diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/policies.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/policies.py index cf3880d41acb..0127d571f003 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/policies.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/policies.py @@ -69,9 +69,7 @@ def is_exhausted(settings): def retry_hook(settings, **kwargs): if settings["hook"]: - settings["hook"]( - retry_count=settings["count"] - 1, location_mode=settings["mode"], **kwargs - ) + settings["hook"](retry_count=settings["count"] - 1, location_mode=settings["mode"], **kwargs) # Is this method/status code retryable? (Based on allowlists and control @@ -91,9 +89,7 @@ def is_retry(response, mode): # pylint: disable=too-many-return-statements # Response code 408 is a timeout and should be retried. return True if status >= 400: - error_code = response.http_response.headers.get( - "x-ms-copy-source-error-code" - ) + error_code = response.http_response.headers.get("x-ms-copy-source-error-code") if error_code in [ StorageErrorCode.OPERATION_TIMED_OUT, StorageErrorCode.INTERNAL_ERROR, @@ -112,12 +108,8 @@ def is_retry(response, mode): # pylint: disable=too-many-return-statements def is_checksum_retry(response): # retry if invalid content md5 - if response.context.get( - "validate_content", False - ) and response.http_response.headers.get("content-md5"): - computed_md5 = response.http_request.headers.get( - "content-md5", None - ) or encode_base64( + if response.context.get("validate_content", False) and response.http_response.headers.get("content-md5"): + computed_md5 = response.http_request.headers.get("content-md5", None) or encode_base64( StorageContentValidation.get_content_md5(response.http_response.body()) ) if response.http_response.headers["content-md5"] != computed_md5: @@ -154,9 +146,7 @@ def on_request(self, request: "PipelineRequest") -> None: request.http_request.headers["x-ms-date"] = current_time custom_id = request.context.options.pop("client_request_id", None) - request.http_request.headers["x-ms-client-request-id"] = custom_id or str( - uuid.uuid1() - ) + request.http_request.headers["x-ms-client-request-id"] = custom_id or str(uuid.uuid1()) # def on_response(self, request, response): # # raise exception if the echoed client request id from the service is not identical to the one we sent @@ -196,9 +186,7 @@ def on_request(self, request: "PipelineRequest") -> None: # Lock retries to the specific location request.context.options["retry_to_secondary"] = False if use_location not in self.hosts: - raise ValueError( - f"Attempting to use undefined host location {use_location}" - ) + raise ValueError(f"Attempting to use undefined host location {use_location}") if use_location != location_mode: # Update request URL to use the specified location updated = parsed_url._replace(netloc=self.hosts[use_location]) @@ -216,9 +204,7 @@ class StorageLoggingPolicy(NetworkTraceLoggingPolicy): def __init__(self, logging_enable: bool = False, **kwargs) -> None: self.logging_body = kwargs.pop("logging_body", False) - super(StorageLoggingPolicy, self).__init__( - logging_enable=logging_enable, **kwargs - ) + super(StorageLoggingPolicy, self).__init__(logging_enable=logging_enable, **kwargs) def on_request(self, request: "PipelineRequest") -> None: http_request = request.http_request @@ -269,9 +255,7 @@ def on_request(self, request: "PipelineRequest") -> None: except Exception as err: # pylint: disable=broad-except _LOGGER.debug("Failed to log request: %r", err) - def on_response( - self, request: "PipelineRequest", response: "PipelineResponse" - ) -> None: + def on_response(self, request: "PipelineRequest", response: "PipelineResponse") -> None: if response.context.pop("logging_enable", self.enable_http_logger): if not _LOGGER.isEnabledFor(logging.DEBUG): return @@ -286,9 +270,7 @@ def on_response( _LOGGER.debug("Response content:") pattern = re.compile(r'attachment; ?filename=["\w.]+', re.IGNORECASE) header = response.http_response.headers.get("content-disposition") - resp_content_type = response.http_response.headers.get( - "content-type", "" - ) + resp_content_type = response.http_response.headers.get("content-type", "") if header and pattern.match(header): filename = header.partition("=")[2] @@ -317,9 +299,7 @@ def __init__(self, **kwargs): super(StorageRequestHook, self).__init__() def on_request(self, request: "PipelineRequest") -> None: - request_callback = request.context.options.pop( - "raw_request_hook", self._request_callback - ) + request_callback = request.context.options.pop("raw_request_hook", self._request_callback) if request_callback: request_callback(request) @@ -337,50 +317,36 @@ def send(self, request: "PipelineRequest") -> "PipelineResponse": data_stream_total = request.context.options.pop("data_stream_total", None) download_stream_current = request.context.get("download_stream_current") if download_stream_current is None: - download_stream_current = request.context.options.pop( - "download_stream_current", None - ) + download_stream_current = request.context.options.pop("download_stream_current", None) upload_stream_current = request.context.get("upload_stream_current") if upload_stream_current is None: - upload_stream_current = request.context.options.pop( - "upload_stream_current", None - ) + upload_stream_current = request.context.options.pop("upload_stream_current", None) - response_callback = request.context.get( - "response_callback" - ) or request.context.options.pop("raw_response_hook", self._response_callback) + response_callback = request.context.get("response_callback") or request.context.options.pop( + "raw_response_hook", self._response_callback + ) response = self.next.send(request) - will_retry = is_retry( - response, request.context.options.get("mode") - ) or is_checksum_retry(response) + will_retry = is_retry(response, request.context.options.get("mode")) or is_checksum_retry(response) # Auth error could come from Bearer challenge, in which case this request will be made again is_auth_error = response.http_response.status_code == 401 should_update_counts = not (will_retry or is_auth_error) if should_update_counts and download_stream_current is not None: - download_stream_current += int( - response.http_response.headers.get("Content-Length", 0) - ) + download_stream_current += int(response.http_response.headers.get("Content-Length", 0)) if data_stream_total is None: content_range = response.http_response.headers.get("Content-Range") if content_range: - data_stream_total = int( - content_range.split(" ", 1)[1].split("/", 1)[1] - ) + data_stream_total = int(content_range.split(" ", 1)[1].split("/", 1)[1]) else: data_stream_total = download_stream_current elif should_update_counts and upload_stream_current is not None: - upload_stream_current += int( - response.http_request.headers.get("Content-Length", 0) - ) + upload_stream_current += int(response.http_request.headers.get("Content-Length", 0)) for pipeline_obj in [request, response]: if hasattr(pipeline_obj, "context"): pipeline_obj.context["data_stream_total"] = data_stream_total - pipeline_obj.context["download_stream_current"] = ( - download_stream_current - ) + pipeline_obj.context["download_stream_current"] = download_stream_current pipeline_obj.context["upload_stream_current"] = upload_stream_current if response_callback: response_callback(response) @@ -419,9 +385,7 @@ def get_content_md5(data): try: data.seek(pos, SEEK_SET) except (AttributeError, IOError) as exc: - raise ValueError( - "Data should be bytes or a seekable file-like object." - ) from exc + raise ValueError("Data should be bytes or a seekable file-like object.") from exc else: raise ValueError("Data should be bytes or a seekable file-like object.") @@ -430,19 +394,13 @@ def get_content_md5(data): def on_request(self, request: "PipelineRequest") -> None: validate_content = request.context.options.pop("validate_content", False) if validate_content and request.http_request.method != "GET": - computed_md5 = encode_base64( - StorageContentValidation.get_content_md5(request.http_request.data) - ) + computed_md5 = encode_base64(StorageContentValidation.get_content_md5(request.http_request.data)) request.http_request.headers[self.header_name] = computed_md5 request.context["validate_content_md5"] = computed_md5 request.context["validate_content"] = validate_content - def on_response( - self, request: "PipelineRequest", response: "PipelineResponse" - ) -> None: - if response.context.get( - "validate_content", False - ) and response.http_response.headers.get("content-md5"): + def on_response(self, request: "PipelineRequest", response: "PipelineResponse") -> None: + if response.context.get("validate_content", False) and response.http_response.headers.get("content-md5"): computed_md5 = request.context.get("validate_content_md5") or encode_base64( StorageContentValidation.get_content_md5(response.http_response.body()) ) @@ -480,9 +438,7 @@ def __init__(self, **kwargs: Any) -> None: self.retry_to_secondary = kwargs.pop("retry_to_secondary", False) super(StorageRetryPolicy, self).__init__() - def _set_next_host_location( - self, settings: Dict[str, Any], request: "PipelineRequest" - ) -> None: + def _set_next_host_location(self, settings: Dict[str, Any], request: "PipelineRequest") -> None: """ A function which sets the next host location on the request, if applicable. @@ -521,9 +477,7 @@ def configure_retries(self, request: "PipelineRequest") -> Dict[str, Any]: "connect": options.pop("retry_connect", self.connect_retries), "read": options.pop("retry_read", self.read_retries), "status": options.pop("retry_status", self.status_retries), - "retry_secondary": options.pop( - "retry_to_secondary", self.retry_to_secondary - ), + "retry_secondary": options.pop("retry_to_secondary", self.retry_to_secondary), "mode": options.pop("location_mode", LocationMode.PRIMARY), "hosts": options.pop("hosts", None), "hook": options.pop("retry_hook", None), @@ -532,9 +486,7 @@ def configure_retries(self, request: "PipelineRequest") -> Dict[str, Any]: "history": [], } - def get_backoff_time( - self, settings: Dict[str, Any] - ) -> float: # pylint: disable=unused-argument + def get_backoff_time(self, settings: Dict[str, Any]) -> float: # pylint: disable=unused-argument """Formula for computing the current backoff. Should be calculated by child class. @@ -597,9 +549,7 @@ def increment( # status_forcelist and a the given method is in the allowlist if response: settings["status"] -= 1 - settings["history"].append( - RequestHistory(request, http_response=response) - ) + settings["history"].append(RequestHistory(request, http_response=response)) if not is_exhausted(settings): if request.method not in ["PUT"] and settings["retry_secondary"]: @@ -634,9 +584,7 @@ def send(self, request): while retries_remaining: try: response = self.next.send(request) - if is_retry(response, retry_settings["mode"]) or is_checksum_retry( - response - ): + if is_retry(response, retry_settings["mode"]) or is_checksum_retry(response): retries_remaining = self.increment( retry_settings, request=request.http_request, @@ -655,9 +603,7 @@ def send(self, request): except AzureError as err: if isinstance(err, AzureSigningError): raise - retries_remaining = self.increment( - retry_settings, request=request.http_request, error=err - ) + retries_remaining = self.increment(retry_settings, request=request.http_request, error=err) if retries_remaining: retry_hook( retry_settings, @@ -717,9 +663,7 @@ def __init__( self.initial_backoff = initial_backoff self.increment_base = increment_base self.random_jitter_range = random_jitter_range - super(ExponentialRetry, self).__init__( - retry_total=retry_total, retry_to_secondary=retry_to_secondary, **kwargs - ) + super(ExponentialRetry, self).__init__(retry_total=retry_total, retry_to_secondary=retry_to_secondary, **kwargs) def get_backoff_time(self, settings: Dict[str, Any]) -> float: """ @@ -732,14 +676,8 @@ def get_backoff_time(self, settings: Dict[str, Any]) -> float: :rtype: float """ random_generator = random.Random() - backoff = self.initial_backoff + ( - 0 if settings["count"] == 0 else pow(self.increment_base, settings["count"]) - ) - random_range_start = ( - backoff - self.random_jitter_range - if backoff > self.random_jitter_range - else 0 - ) + backoff = self.initial_backoff + (0 if settings["count"] == 0 else pow(self.increment_base, settings["count"])) + random_range_start = backoff - self.random_jitter_range if backoff > self.random_jitter_range else 0 random_range_end = backoff + self.random_jitter_range return random_generator.uniform(random_range_start, random_range_end) @@ -777,9 +715,7 @@ def __init__( """ self.backoff = backoff self.random_jitter_range = random_jitter_range - super(LinearRetry, self).__init__( - retry_total=retry_total, retry_to_secondary=retry_to_secondary, **kwargs - ) + super(LinearRetry, self).__init__(retry_total=retry_total, retry_to_secondary=retry_to_secondary, **kwargs) def get_backoff_time(self, settings: Dict[str, Any]) -> float: """ @@ -794,11 +730,7 @@ def get_backoff_time(self, settings: Dict[str, Any]) -> float: random_generator = random.Random() # the backoff interval normally does not change, however there is the possibility # that it was modified by accessing the property directly after initializing the object - random_range_start = ( - self.backoff - self.random_jitter_range - if self.backoff > self.random_jitter_range - else 0 - ) + random_range_start = self.backoff - self.random_jitter_range if self.backoff > self.random_jitter_range else 0 random_range_end = self.backoff + self.random_jitter_range return random_generator.uniform(random_range_start, random_range_end) @@ -806,16 +738,10 @@ def get_backoff_time(self, settings: Dict[str, Any]) -> float: class StorageBearerTokenCredentialPolicy(BearerTokenCredentialPolicy): """Custom Bearer token credential policy for following Storage Bearer challenges""" - def __init__( - self, credential: "TokenCredential", audience: str, **kwargs: Any - ) -> None: - super(StorageBearerTokenCredentialPolicy, self).__init__( - credential, audience, **kwargs - ) + def __init__(self, credential: "TokenCredential", audience: str, **kwargs: Any) -> None: + super(StorageBearerTokenCredentialPolicy, self).__init__(credential, audience, **kwargs) - def on_challenge( - self, request: "PipelineRequest", response: "PipelineResponse" - ) -> bool: + def on_challenge(self, request: "PipelineRequest", response: "PipelineResponse") -> bool: """Handle the challenge from the service and authorize the request. :param request: The request object. diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/policies_async.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/policies_async.py index 7d130217c50d..f4d235c082d8 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/policies_async.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/policies_async.py @@ -39,32 +39,20 @@ async def retry_hook(settings, **kwargs): if settings["hook"]: if asyncio.iscoroutine(settings["hook"]): - await settings["hook"]( - retry_count=settings["count"] - 1, - location_mode=settings["mode"], - **kwargs - ) + await settings["hook"](retry_count=settings["count"] - 1, location_mode=settings["mode"], **kwargs) else: - settings["hook"]( - retry_count=settings["count"] - 1, - location_mode=settings["mode"], - **kwargs - ) + settings["hook"](retry_count=settings["count"] - 1, location_mode=settings["mode"], **kwargs) async def is_checksum_retry(response): # retry if invalid content md5 - if response.context.get( - "validate_content", False - ) and response.http_response.headers.get("content-md5"): + if response.context.get("validate_content", False) and response.http_response.headers.get("content-md5"): if hasattr(response.http_response, "load_body"): try: await response.http_response.load_body() # Load the body in memory and close the socket except (StreamClosedError, StreamConsumedError): pass - computed_md5 = response.http_request.headers.get( - "content-md5", None - ) or encode_base64( + computed_md5 = response.http_request.headers.get("content-md5", None) or encode_base64( StorageContentValidation.get_content_md5(response.http_response.body()) ) if response.http_response.headers["content-md5"] != computed_md5: @@ -85,50 +73,36 @@ async def send(self, request: "PipelineRequest") -> "PipelineResponse": data_stream_total = request.context.options.pop("data_stream_total", None) download_stream_current = request.context.get("download_stream_current") if download_stream_current is None: - download_stream_current = request.context.options.pop( - "download_stream_current", None - ) + download_stream_current = request.context.options.pop("download_stream_current", None) upload_stream_current = request.context.get("upload_stream_current") if upload_stream_current is None: - upload_stream_current = request.context.options.pop( - "upload_stream_current", None - ) + upload_stream_current = request.context.options.pop("upload_stream_current", None) - response_callback = request.context.get( - "response_callback" - ) or request.context.options.pop("raw_response_hook", self._response_callback) + response_callback = request.context.get("response_callback") or request.context.options.pop( + "raw_response_hook", self._response_callback + ) response = await self.next.send(request) - will_retry = is_retry( - response, request.context.options.get("mode") - ) or await is_checksum_retry(response) + will_retry = is_retry(response, request.context.options.get("mode")) or await is_checksum_retry(response) # Auth error could come from Bearer challenge, in which case this request will be made again is_auth_error = response.http_response.status_code == 401 should_update_counts = not (will_retry or is_auth_error) if should_update_counts and download_stream_current is not None: - download_stream_current += int( - response.http_response.headers.get("Content-Length", 0) - ) + download_stream_current += int(response.http_response.headers.get("Content-Length", 0)) if data_stream_total is None: content_range = response.http_response.headers.get("Content-Range") if content_range: - data_stream_total = int( - content_range.split(" ", 1)[1].split("/", 1)[1] - ) + data_stream_total = int(content_range.split(" ", 1)[1].split("/", 1)[1]) else: data_stream_total = download_stream_current elif should_update_counts and upload_stream_current is not None: - upload_stream_current += int( - response.http_request.headers.get("Content-Length", 0) - ) + upload_stream_current += int(response.http_request.headers.get("Content-Length", 0)) for pipeline_obj in [request, response]: if hasattr(pipeline_obj, "context"): pipeline_obj.context["data_stream_total"] = data_stream_total - pipeline_obj.context["download_stream_current"] = ( - download_stream_current - ) + pipeline_obj.context["download_stream_current"] = download_stream_current pipeline_obj.context["upload_stream_current"] = upload_stream_current if response_callback: if asyncio.iscoroutine(response_callback): @@ -157,9 +131,7 @@ async def send(self, request): while retries_remaining: try: response = await self.next.send(request) - if is_retry( - response, retry_settings["mode"] - ) or await is_checksum_retry(response): + if is_retry(response, retry_settings["mode"]) or await is_checksum_retry(response): retries_remaining = self.increment( retry_settings, request=request.http_request, @@ -178,9 +150,7 @@ async def send(self, request): except AzureError as err: if isinstance(err, AzureSigningError): raise - retries_remaining = self.increment( - retry_settings, request=request.http_request, error=err - ) + retries_remaining = self.increment(retry_settings, request=request.http_request, error=err) if retries_remaining: await retry_hook( retry_settings, @@ -242,9 +212,7 @@ def __init__( self.initial_backoff = initial_backoff self.increment_base = increment_base self.random_jitter_range = random_jitter_range - super(ExponentialRetry, self).__init__( - retry_total=retry_total, retry_to_secondary=retry_to_secondary, **kwargs - ) + super(ExponentialRetry, self).__init__(retry_total=retry_total, retry_to_secondary=retry_to_secondary, **kwargs) def get_backoff_time(self, settings: Dict[str, Any]) -> float: """ @@ -257,14 +225,8 @@ def get_backoff_time(self, settings: Dict[str, Any]) -> float: :rtype: int or None """ random_generator = random.Random() - backoff = self.initial_backoff + ( - 0 if settings["count"] == 0 else pow(self.increment_base, settings["count"]) - ) - random_range_start = ( - backoff - self.random_jitter_range - if backoff > self.random_jitter_range - else 0 - ) + backoff = self.initial_backoff + (0 if settings["count"] == 0 else pow(self.increment_base, settings["count"])) + random_range_start = backoff - self.random_jitter_range if backoff > self.random_jitter_range else 0 random_range_end = backoff + self.random_jitter_range return random_generator.uniform(random_range_start, random_range_end) @@ -302,9 +264,7 @@ def __init__( """ self.backoff = backoff self.random_jitter_range = random_jitter_range - super(LinearRetry, self).__init__( - retry_total=retry_total, retry_to_secondary=retry_to_secondary, **kwargs - ) + super(LinearRetry, self).__init__(retry_total=retry_total, retry_to_secondary=retry_to_secondary, **kwargs) def get_backoff_time(self, settings: Dict[str, Any]) -> float: """ @@ -319,11 +279,7 @@ def get_backoff_time(self, settings: Dict[str, Any]) -> float: random_generator = random.Random() # the backoff interval normally does not change, however there is the possibility # that it was modified by accessing the property directly after initializing the object - random_range_start = ( - self.backoff - self.random_jitter_range - if self.backoff > self.random_jitter_range - else 0 - ) + random_range_start = self.backoff - self.random_jitter_range if self.backoff > self.random_jitter_range else 0 random_range_end = self.backoff + self.random_jitter_range return random_generator.uniform(random_range_start, random_range_end) @@ -331,16 +287,10 @@ def get_backoff_time(self, settings: Dict[str, Any]) -> float: class AsyncStorageBearerTokenCredentialPolicy(AsyncBearerTokenCredentialPolicy): """Custom Bearer token credential policy for following Storage Bearer challenges""" - def __init__( - self, credential: "AsyncTokenCredential", audience: str, **kwargs: Any - ) -> None: - super(AsyncStorageBearerTokenCredentialPolicy, self).__init__( - credential, audience, **kwargs - ) + def __init__(self, credential: "AsyncTokenCredential", audience: str, **kwargs: Any) -> None: + super(AsyncStorageBearerTokenCredentialPolicy, self).__init__(credential, audience, **kwargs) - async def on_challenge( - self, request: "PipelineRequest", response: "PipelineResponse" - ) -> bool: + async def on_challenge(self, request: "PipelineRequest", response: "PipelineResponse") -> bool: try: auth_header = response.http_response.headers.get("WWW-Authenticate") challenge = StorageHttpChallenge(auth_header) diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/request_handlers.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/request_handlers.py index 1cc701c9659e..699635565b18 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/request_handlers.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/request_handlers.py @@ -117,13 +117,11 @@ def validate_and_format_range_headers( if align_to_page: if start_range is not None and start_range % 512 != 0: raise ValueError( - f"Invalid page blob start_range: {start_range}. " - "The size must be aligned to a 512-byte boundary." + f"Invalid page blob start_range: {start_range}. " "The size must be aligned to a 512-byte boundary." ) if end_range is not None and end_range % 512 != 511: raise ValueError( - f"Invalid page blob end_range: {end_range}. " - "The size must be aligned to a 512-byte boundary." + f"Invalid page blob end_range: {end_range}. " "The size must be aligned to a 512-byte boundary." ) # Format based on whether end_range is present @@ -137,13 +135,9 @@ def validate_and_format_range_headers( range_validation = None if check_content_md5: if start_range is None or end_range is None: - raise ValueError( - "Both start and end range required for MD5 content validation." - ) + raise ValueError("Both start and end range required for MD5 content validation.") if end_range - start_range > 4 * 1024 * 1024: - raise ValueError( - "Getting content MD5 for a range greater than 4MB is not supported." - ) + raise ValueError("Getting content MD5 for a range greater than 4MB is not supported.") range_validation = "true" return range_header, range_validation @@ -178,34 +172,26 @@ def serialize_batch_body(requests, batch_id): if requests is None or len(requests) == 0: raise ValueError("Please provide sub-request(s) for this batch request") - delimiter_bytes = ( - _get_batch_request_delimiter(batch_id, True, False) + _HTTP_LINE_ENDING - ).encode("utf-8") + delimiter_bytes = (_get_batch_request_delimiter(batch_id, True, False) + _HTTP_LINE_ENDING).encode("utf-8") newline_bytes = _HTTP_LINE_ENDING.encode("utf-8") batch_body = [] content_index = 0 for request in requests: - request.headers.update( - {"Content-ID": str(content_index), "Content-Length": str(0)} - ) + request.headers.update({"Content-ID": str(content_index), "Content-Length": str(0)}) batch_body.append(delimiter_bytes) batch_body.append(_make_body_from_sub_request(request)) batch_body.append(newline_bytes) content_index += 1 - batch_body.append( - _get_batch_request_delimiter(batch_id, True, True).encode("utf-8") - ) + batch_body.append(_get_batch_request_delimiter(batch_id, True, True).encode("utf-8")) # final line of body MUST have \r\n at the end, or it will not be properly read by the service batch_body.append(newline_bytes) return b"".join(batch_body) -def _get_batch_request_delimiter( - batch_id, is_prepend_dashes=False, is_append_dashes=False -): +def _get_batch_request_delimiter(batch_id, is_prepend_dashes=False, is_append_dashes=False): """ Gets the delimiter used for this batch request's mixed/multipart HTTP format. diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/response_handlers.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/response_handlers.py index c9ce88c58912..8c4e5dfb80c2 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/response_handlers.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/response_handlers.py @@ -35,9 +35,7 @@ class PartialBatchErrorException(HttpResponseError): def __init__(self, message, response, parts): self.parts = parts - super(PartialBatchErrorException, self).__init__( - message=message, response=response - ) + super(PartialBatchErrorException, self).__init__(message=message, response=response) # Parses the blob length from the content range header: bytes 1-3/65537 @@ -62,35 +60,21 @@ def normalize_headers(headers): def deserialize_metadata(response, obj, headers): # pylint: disable=unused-argument try: - raw_metadata = { - k: v - for k, v in response.http_response.headers.items() - if k.lower().startswith("x-ms-meta-") - } + raw_metadata = {k: v for k, v in response.http_response.headers.items() if k.lower().startswith("x-ms-meta-")} except AttributeError: - raw_metadata = { - k: v - for k, v in response.headers.items() - if k.lower().startswith("x-ms-meta-") - } + raw_metadata = {k: v for k, v in response.headers.items() if k.lower().startswith("x-ms-meta-")} return {k[10:]: v for k, v in raw_metadata.items()} -def return_response_headers( - response, deserialized, response_headers -): # pylint: disable=unused-argument +def return_response_headers(response, deserialized, response_headers): # pylint: disable=unused-argument return normalize_headers(response_headers) -def return_headers_and_deserialized( - response, deserialized, response_headers -): # pylint: disable=unused-argument +def return_headers_and_deserialized(response, deserialized, response_headers): # pylint: disable=unused-argument return normalize_headers(response_headers), deserialized -def return_context_and_deserialized( - response, deserialized, response_headers -): # pylint: disable=unused-argument +def return_context_and_deserialized(response, deserialized, response_headers): # pylint: disable=unused-argument return response.http_response.location_mode, deserialized @@ -127,9 +111,7 @@ def process_storage_error(storage_error) -> NoReturn: # type: ignore [misc] # p additional_data = {} error_dict = {} try: - error_body = ContentDecodePolicy.deserialize_from_http_generics( - storage_error.response - ) + error_body = ContentDecodePolicy.deserialize_from_http_generics(storage_error.response) try: if error_body is None or len(error_body) == 0: error_body = storage_error.response.reason @@ -153,9 +135,7 @@ def process_storage_error(storage_error) -> NoReturn: # type: ignore [misc] # p if error_dict and isinstance(error_dict, dict): error_code = error_dict.get("code") error_message = error_dict.get("message") - additional_data = { - k: v for k, v in error_dict.items() if k not in {"code", "message"} - } + additional_data = {k: v for k, v in error_dict.items() if k not in {"code", "message"}} except DecodeError: pass @@ -209,10 +189,7 @@ def process_storage_error(storage_error) -> NoReturn: # type: ignore [misc] # p for name, info in additional_data.items(): error_message += f"\n{name}:{info}" - if ( - additional_data.get("headername") == "x-ms-version" - and error_code == StorageErrorCode.INVALID_HEADER_VALUE - ): + if additional_data.get("headername") == "x-ms-version" and error_code == StorageErrorCode.INVALID_HEADER_VALUE: error_message = ( "The provided service version is not enabled on this storage account." + f"Please see {SV_DOCS_URL} for additional information.\n" @@ -241,20 +218,10 @@ def parse_to_internal_user_delegation_key(service_user_delegation_key): internal_user_delegation_key = UserDelegationKey() internal_user_delegation_key.signed_oid = service_user_delegation_key.signed_oid internal_user_delegation_key.signed_tid = service_user_delegation_key.signed_tid - internal_user_delegation_key.signed_delegated_user_tid = ( - service_user_delegation_key.signed_delegated_user_tid - ) - internal_user_delegation_key.signed_start = _to_utc_datetime( - service_user_delegation_key.signed_start - ) - internal_user_delegation_key.signed_expiry = _to_utc_datetime( - service_user_delegation_key.signed_expiry - ) - internal_user_delegation_key.signed_service = ( - service_user_delegation_key.signed_service - ) - internal_user_delegation_key.signed_version = ( - service_user_delegation_key.signed_version - ) + internal_user_delegation_key.signed_delegated_user_tid = service_user_delegation_key.signed_delegated_user_tid + internal_user_delegation_key.signed_start = _to_utc_datetime(service_user_delegation_key.signed_start) + internal_user_delegation_key.signed_expiry = _to_utc_datetime(service_user_delegation_key.signed_expiry) + internal_user_delegation_key.signed_service = service_user_delegation_key.signed_service + internal_user_delegation_key.signed_version = service_user_delegation_key.signed_version internal_user_delegation_key.value = service_user_delegation_key.value return internal_user_delegation_key diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/shared_access_signature.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/shared_access_signature.py index 44f4c2812d17..60d2a3475f94 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/shared_access_signature.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/shared_access_signature.py @@ -219,9 +219,7 @@ def add_id(self, policy_id): self._add_query(QueryStringConstants.SIGNED_IDENTIFIER, policy_id) def add_user_delegation_oid(self, user_delegation_oid): - self._add_query( - QueryStringConstants.SIGNED_DELEGATED_USER_OID, user_delegation_oid - ) + self._add_query(QueryStringConstants.SIGNED_DELEGATED_USER_OID, user_delegation_oid) def add_account(self, services, resource_types): self._add_query(QueryStringConstants.SIGNED_SERVICES, services) @@ -236,9 +234,7 @@ def add_override_response_headers( content_type, ): self._add_query(QueryStringConstants.SIGNED_CACHE_CONTROL, cache_control) - self._add_query( - QueryStringConstants.SIGNED_CONTENT_DISPOSITION, content_disposition - ) + self._add_query(QueryStringConstants.SIGNED_CONTENT_DISPOSITION, content_disposition) self._add_query(QueryStringConstants.SIGNED_CONTENT_ENCODING, content_encoding) self._add_query(QueryStringConstants.SIGNED_CONTENT_LANGUAGE, content_language) self._add_query(QueryStringConstants.SIGNED_CONTENT_TYPE, content_type) @@ -248,9 +244,7 @@ def add_request_headers(self, request_headers): return # String-to-Sign (not encoded): "k1:v1\nk2:v2\n...kn:vn\n" - self._sts_srh = ( - "\n".join([f"{k}:{v}" for k, v in request_headers.items()]) + "\n" - ) + self._sts_srh = "\n".join([f"{k}:{v}" for k, v in request_headers.items()]) + "\n" # SAS query param: comma-separated list of encoded header keys only srh_keys = ",".join([url_quote(k) for k in request_headers.keys()]) @@ -261,9 +255,7 @@ def add_request_query_params(self, request_query_params): return # String-to-Sign (not encoded): "k1:v1\nk2:v2\n...kn:vn\n" - self._sts_srq = "\n" + "\n".join( - [f"{k}:{v}" for k, v in request_query_params.items()] - ) + self._sts_srq = "\n" + "\n".join([f"{k}:{v}" for k, v in request_query_params.items()]) # SAS query param: comma-separated list of encoded query-param keys only srq_keys = ",".join([url_quote(k) for k in request_query_params.keys()]) @@ -295,6 +287,4 @@ def get_value_to_append(query): self.string_to_sign = string_to_sign def get_token(self) -> str: - return "&".join( - [f"{n}={url_quote(v)}" for n, v in self.query_dict.items() if v is not None] - ) + return "&".join([f"{n}={url_quote(v)}" for n, v in self.query_dict.items() if v is not None]) diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/uploads.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/uploads.py index 97641795aacd..341d034fd07c 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/uploads.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/uploads.py @@ -17,9 +17,7 @@ from .response_handlers import return_response_headers _LARGE_BLOB_UPLOAD_MAX_READ_BUFFER_SIZE = 4 * 1024 * 1024 -_ERROR_VALUE_SHOULD_BE_SEEKABLE_STREAM = ( - "{0} should be a seekable file-like/io.IOBase type stream object." -) +_ERROR_VALUE_SHOULD_BE_SEEKABLE_STREAM = "{0} should be a seekable file-like/io.IOBase type stream object." def _parallel_uploads(executor, uploader, pending, running): @@ -75,13 +73,9 @@ def upload_data_chunks( executor.submit(with_current_context(uploader.process_chunk), u) for u in islice(upload_tasks, 0, max_concurrency) ] - range_ids = _parallel_uploads( - executor, uploader.process_chunk, upload_tasks, running_futures - ) + range_ids = _parallel_uploads(executor, uploader.process_chunk, upload_tasks, running_futures) else: - range_ids = [ - uploader.process_chunk(result) for result in uploader.get_chunk_streams() - ] + range_ids = [uploader.process_chunk(result) for result in uploader.get_chunk_streams()] if any(range_ids): return [r[1] for r in sorted(range_ids, key=lambda r: r[0])] return uploader.response_headers @@ -115,9 +109,7 @@ def upload_substream_blocks( with futures.ThreadPoolExecutor(max_concurrency) as executor: upload_tasks = uploader.get_substream_blocks() running_futures = [ - executor.submit( - with_current_context(uploader.process_substream_block), u - ) + executor.submit(with_current_context(uploader.process_substream_block), u) for u in islice(upload_tasks, 0, max_concurrency) ] range_ids = _parallel_uploads( @@ -127,9 +119,7 @@ def upload_substream_blocks( running_futures, ) else: - range_ids = [ - uploader.process_substream_block(b) for b in uploader.get_substream_blocks() - ] + range_ids = [uploader.process_substream_block(b) for b in uploader.get_substream_blocks()] if any(range_ids): return sorted(range_ids) return [] @@ -244,11 +234,7 @@ def get_substream_blocks(self): raise ValueError("Unable to determine content length of upload data.") blocks = int(ceil(blob_length / (self.chunk_size * 1.0))) - last_block_size = ( - self.chunk_size - if blob_length % self.chunk_size == 0 - else blob_length % self.chunk_size - ) + last_block_size = self.chunk_size if blob_length % self.chunk_size == 0 else blob_length % self.chunk_size for i in range(blocks): index = i * self.chunk_size @@ -332,12 +318,8 @@ def _upload_chunk(self, chunk_offset, chunk_data): **self.request_options, ) - if not self.parallel and self.request_options.get( - "modified_access_conditions" - ): - self.request_options["modified_access_conditions"].if_match = ( - self.response_headers["etag"] - ) + if not self.parallel and self.request_options.get("modified_access_conditions"): + self.request_options["modified_access_conditions"].if_match = self.response_headers["etag"] def _upload_substream_block(self, index, block_stream): pass @@ -361,9 +343,9 @@ def _upload_chunk(self, chunk_offset, chunk_data): ) self.current_length = int(self.response_headers["blob_append_offset"]) else: - self.request_options[ - "append_position_access_conditions" - ].append_position = (self.current_length + chunk_offset) + self.request_options["append_position_access_conditions"].append_position = ( + self.current_length + chunk_offset + ) self.response_headers = self.service.append_block( body=chunk_data, content_length=len(chunk_data), @@ -392,9 +374,7 @@ def _upload_chunk(self, chunk_offset, chunk_data): ) if not self.parallel and self.request_options.get("modified_access_conditions"): - self.request_options["modified_access_conditions"].if_match = ( - self.response_headers["etag"] - ) + self.request_options["modified_access_conditions"].if_match = self.response_headers["etag"] def _upload_substream_block(self, index, block_stream): try: @@ -453,9 +433,7 @@ def __init__(self, wrapped_stream, stream_begin_index, length, lockObj): # we must avoid buffering more than necessary, and also not use up too much memory # so the max buffer size is capped at 4MB self._max_buffer_size = ( - length - if length < _LARGE_BLOB_UPLOAD_MAX_READ_BUFFER_SIZE - else _LARGE_BLOB_UPLOAD_MAX_READ_BUFFER_SIZE + length if length < _LARGE_BLOB_UPLOAD_MAX_READ_BUFFER_SIZE else _LARGE_BLOB_UPLOAD_MAX_READ_BUFFER_SIZE ) self._current_buffer_start = 0 self._current_buffer_size = 0 @@ -503,9 +481,7 @@ def read(self, size=None): with self._buffer: # either read in the max buffer size specified on the class # or read in just enough data for the current block/sub stream - current_max_buffer_size = min( - self._max_buffer_size, self._length - self._position - ) + current_max_buffer_size = min(self._max_buffer_size, self._length - self._position) # lock is only defined if max_concurrency > 1 (parallel uploads) if self._lock: @@ -515,12 +491,8 @@ def read(self, size=None): self._wrapped_stream.seek(absolute_position, SEEK_SET) # If we can't seek to the right location, our read will be corrupted so fail fast. if self._wrapped_stream.tell() != absolute_position: - raise IOError( - "Stream failed to seek to the desired location." - ) - buffer_from_stream = self._wrapped_stream.read( - current_max_buffer_size - ) + raise IOError("Stream failed to seek to the desired location.") + buffer_from_stream = self._wrapped_stream.read(current_max_buffer_size) else: absolute_position = self._stream_begin_index + self._position # It's possible that there's connection problem during data transfer, @@ -529,9 +501,7 @@ def read(self, size=None): if self._wrapped_stream.tell() != absolute_position: self._wrapped_stream.seek(absolute_position, SEEK_SET) - buffer_from_stream = self._wrapped_stream.read( - current_max_buffer_size - ) + buffer_from_stream = self._wrapped_stream.read(current_max_buffer_size) if buffer_from_stream: # update the buffer with new data from the wrapped stream @@ -573,10 +543,7 @@ def seek(self, offset, whence=0): # check if buffer is still valid # if not, drop buffer - if ( - pos < self._current_buffer_start - or pos >= self._current_buffer_start + self._current_buffer_size - ): + if pos < self._current_buffer_start or pos >= self._current_buffer_start + self._current_buffer_size: self._buffer.close() self._buffer = BytesIO() else: # if yes seek to correct position diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/uploads_async.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/uploads_async.py index 678d6e2c7074..388429a288a4 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/uploads_async.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/uploads_async.py @@ -90,15 +90,11 @@ async def upload_data_chunks( for _ in range(max_concurrency): try: chunk = await upload_tasks.__anext__() - running_futures.append( - asyncio.ensure_future(uploader.process_chunk(chunk)) - ) + running_futures.append(asyncio.ensure_future(uploader.process_chunk(chunk))) except StopAsyncIteration: break - range_ids = await _async_parallel_uploads( - uploader.process_chunk, upload_tasks, running_futures - ) + range_ids = await _async_parallel_uploads(uploader.process_chunk, upload_tasks, running_futures) else: range_ids = [] async for chunk in uploader.get_chunk_streams(): @@ -136,12 +132,9 @@ async def upload_substream_blocks( if parallel: upload_tasks = uploader.get_substream_blocks() running_futures = [ - asyncio.ensure_future(uploader.process_substream_block(u)) - for u in islice(upload_tasks, 0, max_concurrency) + asyncio.ensure_future(uploader.process_substream_block(u)) for u in islice(upload_tasks, 0, max_concurrency) ] - range_ids = await _parallel_uploads( - uploader.process_substream_block, upload_tasks, running_futures - ) + range_ids = await _parallel_uploads(uploader.process_substream_block, upload_tasks, running_futures) else: range_ids = [] for block in uploader.get_substream_blocks(): @@ -262,11 +255,7 @@ def get_substream_blocks(self): raise ValueError("Unable to determine content length of upload data.") blocks = int(ceil(blob_length / (self.chunk_size * 1.0))) - last_block_size = ( - self.chunk_size - if blob_length % self.chunk_size == 0 - else blob_length % self.chunk_size - ) + last_block_size = self.chunk_size if blob_length % self.chunk_size == 0 else blob_length % self.chunk_size for i in range(blocks): index = i * self.chunk_size @@ -274,9 +263,7 @@ def get_substream_blocks(self): yield index, SubStream(self.stream, index, length, lock) async def process_substream_block(self, block_data): - return await self._upload_substream_block_with_progress( - block_data[0], block_data[1] - ) + return await self._upload_substream_block_with_progress(block_data[0], block_data[1]) async def _upload_substream_block(self, index, block_stream): raise NotImplementedError("Must be implemented by child class.") @@ -355,12 +342,8 @@ async def _upload_chunk(self, chunk_offset, chunk_data): **self.request_options, ) - if not self.parallel and self.request_options.get( - "modified_access_conditions" - ): - self.request_options["modified_access_conditions"].if_match = ( - self.response_headers["etag"] - ) + if not self.parallel and self.request_options.get("modified_access_conditions"): + self.request_options["modified_access_conditions"].if_match = self.response_headers["etag"] async def _upload_substream_block(self, index, block_stream): pass @@ -384,9 +367,9 @@ async def _upload_chunk(self, chunk_offset, chunk_data): ) self.current_length = int(self.response_headers["blob_append_offset"]) else: - self.request_options[ - "append_position_access_conditions" - ].append_position = (self.current_length + chunk_offset) + self.request_options["append_position_access_conditions"].append_position = ( + self.current_length + chunk_offset + ) self.response_headers = await self.service.append_block( body=chunk_data, content_length=len(chunk_data), @@ -414,9 +397,7 @@ async def _upload_chunk(self, chunk_offset, chunk_data): ) if not self.parallel and self.request_options.get("modified_access_conditions"): - self.request_options["modified_access_conditions"].if_match = ( - self.response_headers["etag"] - ) + self.request_options["modified_access_conditions"].if_match = self.response_headers["etag"] async def _upload_substream_block(self, index, block_stream): try: diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared_access_signature.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared_access_signature.py index de5de8ff3c08..75f49f70ec64 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared_access_signature.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared_access_signature.py @@ -50,9 +50,7 @@ def __init__( A user delegation key can be obtained from the service by authenticating with an AAD identity; this can be accomplished by calling get_user_delegation_key on any Queue service object. """ - super(QueueSharedAccessSignature, self).__init__( - account_name, account_key, x_ms_version=X_MS_VERSION - ) + super(QueueSharedAccessSignature, self).__init__(account_name, account_key, x_ms_version=X_MS_VERSION) self.user_delegation_key = user_delegation_key def generate_queue( @@ -136,9 +134,7 @@ def generate_queue( class _QueueSharedAccessHelper(_SharedAccessHelper): - def add_resource_signature( - self, account_name: str, account_key: str, path: str, user_delegation_key=None - ): + def add_resource_signature(self, account_name: str, account_key: str, path: str, user_delegation_key=None): def get_value_to_append(query): return_value = self.query_dict.get(query) or "" return return_value + "\n" @@ -158,15 +154,9 @@ def get_value_to_append(query): ) if user_delegation_key is not None: - self._add_query( - QueryStringConstants.SIGNED_OID, user_delegation_key.signed_oid - ) - self._add_query( - QueryStringConstants.SIGNED_TID, user_delegation_key.signed_tid - ) - self._add_query( - QueryStringConstants.SIGNED_KEY_START, user_delegation_key.signed_start - ) + self._add_query(QueryStringConstants.SIGNED_OID, user_delegation_key.signed_oid) + self._add_query(QueryStringConstants.SIGNED_TID, user_delegation_key.signed_tid) + self._add_query(QueryStringConstants.SIGNED_KEY_START, user_delegation_key.signed_start) self._add_query( QueryStringConstants.SIGNED_KEY_EXPIRY, user_delegation_key.signed_expiry, @@ -191,15 +181,11 @@ def get_value_to_append(query): + get_value_to_append(QueryStringConstants.SIGNED_KEY_EXPIRY) + get_value_to_append(QueryStringConstants.SIGNED_KEY_SERVICE) + get_value_to_append(QueryStringConstants.SIGNED_KEY_VERSION) - + get_value_to_append( - QueryStringConstants.SIGNED_KEY_DELEGATED_USER_TID - ) + + get_value_to_append(QueryStringConstants.SIGNED_KEY_DELEGATED_USER_TID) + get_value_to_append(QueryStringConstants.SIGNED_DELEGATED_USER_OID) ) else: - string_to_sign += get_value_to_append( - QueryStringConstants.SIGNED_IDENTIFIER - ) + string_to_sign += get_value_to_append(QueryStringConstants.SIGNED_IDENTIFIER) string_to_sign += ( get_value_to_append(QueryStringConstants.SIGNED_IP) @@ -214,11 +200,7 @@ def get_value_to_append(query): self._add_query( QueryStringConstants.SIGNED_SIGNATURE, sign_string( - ( - account_key - if user_delegation_key is None - else user_delegation_key.value - ), + (account_key if user_delegation_key is None else user_delegation_key.value), string_to_sign, ), ) @@ -378,18 +360,12 @@ def generate_queue_sas( """ if not policy_id: if not expiry: - raise ValueError( - "'expiry' parameter must be provided when not using a stored access policy." - ) + raise ValueError("'expiry' parameter must be provided when not using a stored access policy.") if not permission: - raise ValueError( - "'permission' parameter must be provided when not using a stored access policy." - ) + raise ValueError("'permission' parameter must be provided when not using a stored access policy.") if not user_delegation_key and not account_key: raise ValueError("Either user_delegation_key or account_key must be provided.") - sas = QueueSharedAccessSignature( - account_name, account_key=account_key, user_delegation_key=user_delegation_key - ) + sas = QueueSharedAccessSignature(account_name, account_key=account_key, user_delegation_key=user_delegation_key) return sas.generate_queue( queue_name, permission=permission, diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_models.py b/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_models.py index fa59de55c652..cbd506fbd183 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_models.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_models.py @@ -69,9 +69,7 @@ async def _extract_data_cb(self, messages: Any) -> Tuple[str, List[QueueMessage] raise StopAsyncIteration("End of paging") if self._max_messages is not None: self._max_messages = self._max_messages - len(messages) - return "TOKEN_IGNORED", [ - QueueMessage._from_generated(q) for q in messages - ] # pylint: disable=protected-access + return "TOKEN_IGNORED", [QueueMessage._from_generated(q) for q in messages] # pylint: disable=protected-access class QueuePropertiesPaged(AsyncPageIterator): @@ -132,17 +130,14 @@ async def _get_next_cb(self, continuation_token: Optional[str]) -> Any: except HttpResponseError as error: process_storage_error(error) - async def _extract_data_cb( - self, get_next_return: Any - ) -> Tuple[Optional[str], List[QueueProperties]]: + async def _extract_data_cb(self, get_next_return: Any) -> Tuple[Optional[str], List[QueueProperties]]: self.location_mode, self._response = get_next_return self.service_endpoint = self._response.service_endpoint self.prefix = self._response.prefix self.marker = self._response.marker self.results_per_page = self._response.max_results props_list = [ - QueueProperties._from_generated(q) - for q in self._response.queue_items # pylint: disable=protected-access + QueueProperties._from_generated(q) for q in self._response.queue_items # pylint: disable=protected-access ] next_marker = self._response.next_marker return next_marker or None, props_list diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_queue_client_async.py b/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_queue_client_async.py index d106a17431f3..ed1c7e8b64b6 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_queue_client_async.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_queue_client_async.py @@ -124,22 +124,14 @@ def __init__( *, api_version: Optional[str] = None, secondary_hostname: Optional[str] = None, - message_encode_policy: Optional[ - Union["BinaryBase64EncodePolicy", "TextBase64EncodePolicy"] - ] = None, - message_decode_policy: Optional[ - Union["BinaryBase64DecodePolicy", "TextBase64DecodePolicy"] - ] = None, + message_encode_policy: Optional[Union["BinaryBase64EncodePolicy", "TextBase64EncodePolicy"]] = None, + message_decode_policy: Optional[Union["BinaryBase64DecodePolicy", "TextBase64DecodePolicy"]] = None, audience: Optional[str] = None, **kwargs: Any ) -> None: - kwargs["retry_policy"] = kwargs.get("retry_policy") or ExponentialRetry( - **kwargs - ) + kwargs["retry_policy"] = kwargs.get("retry_policy") or ExponentialRetry(**kwargs) loop = kwargs.pop("loop", None) - parsed_url, sas_token = _parse_url( - account_url=account_url, queue_name=queue_name, credential=credential - ) + parsed_url, sas_token = _parse_url(account_url=account_url, queue_name=queue_name, credential=credential) self.queue_name = queue_name self._query_str, credential = self._format_query_string(sas_token, credential) super(QueueClient, self).__init__( @@ -173,9 +165,7 @@ async def __aexit__( exc: Optional[BaseException], tb: Optional[TracebackType], ) -> None: - await self._client.__aexit__( - typ, exc, tb - ) # pylint: disable=specify-parameter-names-in-call + await self._client.__aexit__(typ, exc, tb) # pylint: disable=specify-parameter-names-in-call async def close(self) -> None: """This method is to close the sockets opened by the client. @@ -217,12 +207,8 @@ def from_queue_url( *, api_version: Optional[str] = None, secondary_hostname: Optional[str] = None, - message_encode_policy: Optional[ - Union["BinaryBase64EncodePolicy", "TextBase64EncodePolicy"] - ] = None, - message_decode_policy: Optional[ - Union["BinaryBase64DecodePolicy", "TextBase64DecodePolicy"] - ] = None, + message_encode_policy: Optional[Union["BinaryBase64EncodePolicy", "TextBase64EncodePolicy"]] = None, + message_decode_policy: Optional[Union["BinaryBase64DecodePolicy", "TextBase64DecodePolicy"]] = None, audience: Optional[str] = None, **kwargs: Any ) -> Self: @@ -292,12 +278,8 @@ def from_connection_string( *, api_version: Optional[str] = None, secondary_hostname: Optional[str] = None, - message_encode_policy: Optional[ - Union["BinaryBase64EncodePolicy", "TextBase64EncodePolicy"] - ] = None, - message_decode_policy: Optional[ - Union["BinaryBase64DecodePolicy", "TextBase64DecodePolicy"] - ] = None, + message_encode_policy: Optional[Union["BinaryBase64EncodePolicy", "TextBase64EncodePolicy"]] = None, + message_decode_policy: Optional[Union["BinaryBase64DecodePolicy", "TextBase64DecodePolicy"]] = None, audience: Optional[str] = None, **kwargs: Any ) -> Self: @@ -349,9 +331,7 @@ def from_connection_string( :dedent: 8 :caption: Create the queue client from connection string. """ - account_url, secondary, credential = parse_connection_str( - conn_str, credential, "queue" - ) + account_url, secondary, credential = parse_connection_str(conn_str, credential, "queue") return cls( account_url, queue_name=queue_name, @@ -366,11 +346,7 @@ def from_connection_string( @distributed_trace_async async def create_queue( - self, - *, - metadata: Optional[Dict[str, str]] = None, - timeout: Optional[int] = None, - **kwargs: Any + self, *, metadata: Optional[Dict[str, str]] = None, timeout: Optional[int] = None, **kwargs: Any ) -> None: """Creates a new queue in the storage account. @@ -404,19 +380,13 @@ async def create_queue( headers.update(add_metadata_headers(metadata)) try: return await self._client.queue.create( - metadata=metadata, - timeout=timeout, - headers=headers, - cls=deserialize_queue_creation, - **kwargs + metadata=metadata, timeout=timeout, headers=headers, cls=deserialize_queue_creation, **kwargs ) except HttpResponseError as error: process_storage_error(error) @distributed_trace_async - async def delete_queue( - self, *, timeout: Optional[int] = None, **kwargs: Any - ) -> None: + async def delete_queue(self, *, timeout: Optional[int] = None, **kwargs: Any) -> None: """Deletes the specified queue and any messages it contains. When a queue is successfully deleted, it is immediately marked for deletion @@ -450,9 +420,7 @@ async def delete_queue( process_storage_error(error) @distributed_trace_async - async def get_queue_properties( - self, *, timeout: Optional[int] = None, **kwargs: Any - ) -> "QueueProperties": + async def get_queue_properties(self, *, timeout: Optional[int] = None, **kwargs: Any) -> "QueueProperties": """Returns all user-defined metadata for the specified queue. The data returned does not include the queue's list of messages. @@ -474,9 +442,7 @@ async def get_queue_properties( try: response = cast( "QueueProperties", - await self._client.queue.get_properties( - timeout=timeout, cls=deserialize_queue_properties, **kwargs - ), + await self._client.queue.get_properties(timeout=timeout, cls=deserialize_queue_properties, **kwargs), ) except HttpResponseError as error: process_storage_error(error) @@ -485,11 +451,7 @@ async def get_queue_properties( @distributed_trace_async async def set_queue_metadata( - self, - metadata: Optional[Dict[str, str]] = None, - *, - timeout: Optional[int] = None, - **kwargs: Any + self, metadata: Optional[Dict[str, str]] = None, *, timeout: Optional[int] = None, **kwargs: Any ) -> Dict[str, Any]: """Sets user-defined metadata on the specified queue. @@ -526,9 +488,7 @@ async def set_queue_metadata( process_storage_error(error) @distributed_trace_async - async def get_queue_access_policy( - self, *, timeout: Optional[int] = None, **kwargs: Any - ) -> Dict[str, AccessPolicy]: + async def get_queue_access_policy(self, *, timeout: Optional[int] = None, **kwargs: Any) -> Dict[str, AccessPolicy]: """Returns details about any stored access policies specified on the queue that may be used with Shared Access Signatures. @@ -554,11 +514,7 @@ async def get_queue_access_policy( @distributed_trace_async async def set_queue_access_policy( - self, - signed_identifiers: Dict[str, AccessPolicy], - *, - timeout: Optional[int] = None, - **kwargs: Any + self, signed_identifiers: Dict[str, AccessPolicy], *, timeout: Optional[int] = None, **kwargs: Any ) -> None: """Sets stored access policies for the queue that may be used with Shared Access Signatures. @@ -607,9 +563,7 @@ async def set_queue_access_policy( value.expiry = serialize_iso(value.expiry) identifiers.append(SignedIdentifier(id=key, access_policy=value)) try: - await self._client.queue.set_access_policy( - queue_acl=identifiers or None, timeout=timeout, **kwargs - ) + await self._client.queue.set_access_policy(queue_acl=identifiers or None, timeout=timeout, **kwargs) except HttpResponseError as error: process_storage_error(error) @@ -688,10 +642,12 @@ async def send_message( encryption_version=self.encryption_version, ) except TypeError: - warnings.warn("TypeError when calling message_encode_policy.configure. \ + warnings.warn( + "TypeError when calling message_encode_policy.configure. \ It is likely missing the encryption_version parameter. \ Consider updating your encryption information/implementation. \ - Retrying without encryption_version.") + Retrying without encryption_version." + ) self._message_encode_policy.configure( require_encryption=self.require_encryption, key_encryption_key=self.key_encryption_key, @@ -722,11 +678,7 @@ async def send_message( @distributed_trace_async async def receive_message( - self, - *, - visibility_timeout: Optional[int] = None, - timeout: Optional[int] = None, - **kwargs: Any + self, *, visibility_timeout: Optional[int] = None, timeout: Optional[int] = None, **kwargs: Any ) -> Optional[QueueMessage]: """Removes one message from the front of the queue. @@ -787,9 +739,7 @@ async def receive_message( **kwargs ) wrapped_message = ( - QueueMessage._from_generated(message[0]) - if message != [] - else None # pylint: disable=protected-access + QueueMessage._from_generated(message[0]) if message != [] else None # pylint: disable=protected-access ) return wrapped_message except HttpResponseError as error: @@ -876,9 +826,7 @@ def receive_messages( ) if max_messages is not None and messages_per_page is not None: if max_messages < messages_per_page: - raise ValueError( - "max_messages must be greater or equal to messages_per_page" - ) + raise ValueError("max_messages must be greater or equal to messages_per_page") return AsyncItemPaged( command, results_per_page=messages_per_page, @@ -983,10 +931,12 @@ async def update_message( encryption_version=self.encryption_version, ) except TypeError: - warnings.warn("TypeError when calling message_encode_policy.configure. \ + warnings.warn( + "TypeError when calling message_encode_policy.configure. \ It is likely missing the encryption_version parameter. \ Consider updating your encryption information/implementation. \ - Retrying without encryption_version.") + Retrying without encryption_version." + ) self._message_encode_policy.configure( self.require_encryption, self.key_encryption_key, @@ -1024,11 +974,7 @@ async def update_message( @distributed_trace_async async def peek_messages( - self, - max_messages: Optional[int] = None, - *, - timeout: Optional[int] = None, - **kwargs: Any + self, max_messages: Optional[int] = None, *, timeout: Optional[int] = None, **kwargs: Any ) -> List[QueueMessage]: """Retrieves one or more messages from the front of the queue, but does not alter the visibility of the message. @@ -1087,24 +1033,17 @@ async def peek_messages( ) try: messages = await self._client.messages.peek( - number_of_messages=max_messages, - timeout=timeout, - cls=self._message_decode_policy, - **kwargs + number_of_messages=max_messages, timeout=timeout, cls=self._message_decode_policy, **kwargs ) wrapped_messages = [] for peeked in messages: - wrapped_messages.append( - QueueMessage._from_generated(peeked) - ) # pylint: disable=protected-access + wrapped_messages.append(QueueMessage._from_generated(peeked)) # pylint: disable=protected-access return wrapped_messages except HttpResponseError as error: process_storage_error(error) @distributed_trace_async - async def clear_messages( - self, *, timeout: Optional[int] = None, **kwargs: Any - ) -> None: + async def clear_messages(self, *, timeout: Optional[int] = None, **kwargs: Any) -> None: """Deletes all messages from the specified queue. :keyword int timeout: @@ -1183,10 +1122,7 @@ async def delete_message( raise ValueError("pop_receipt must be present") try: await self._client.message_id.delete( - pop_receipt=receipt, - timeout=timeout, - queue_message_id=message_id, - **kwargs + pop_receipt=receipt, timeout=timeout, queue_message_id=message_id, **kwargs ) except HttpResponseError as error: process_storage_error(error) diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_queue_service_client_async.py b/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_queue_service_client_async.py index 39f7c9e930bf..bd694412a038 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_queue_service_client_async.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/aio/_queue_service_client_async.py @@ -121,13 +121,9 @@ def __init__( audience: Optional[str] = None, **kwargs: Any, ) -> None: - kwargs["retry_policy"] = kwargs.get("retry_policy") or ExponentialRetry( - **kwargs - ) + kwargs["retry_policy"] = kwargs.get("retry_policy") or ExponentialRetry(**kwargs) loop = kwargs.pop("loop", None) - parsed_url, sas_token = _parse_url( - account_url=account_url, credential=credential - ) + parsed_url, sas_token = _parse_url(account_url=account_url, credential=credential) self._query_str, credential = self._format_query_string(sas_token, credential) super(QueueServiceClient, self).__init__( parsed_url, @@ -157,9 +153,7 @@ async def __aexit__( exc: Optional[BaseException], tb: Optional[TracebackType], ) -> None: - await self._client.__aexit__( - typ, exc, tb - ) # pylint: disable=specify-parameter-names-in-call + await self._client.__aexit__(typ, exc, tb) # pylint: disable=specify-parameter-names-in-call async def close(self) -> None: """This method is to close the sockets opened by the client. @@ -234,9 +228,7 @@ def from_connection_string( :dedent: 8 :caption: Creating the QueueServiceClient with a connection string. """ - account_url, secondary, credential = parse_connection_str( - conn_str, credential, "queue" - ) + account_url, secondary, credential = parse_connection_str(conn_str, credential, "queue") return cls( account_url, credential=credential, @@ -290,9 +282,7 @@ async def get_user_delegation_key( return parse_to_internal_user_delegation_key(user_delegation_key) @distributed_trace_async - async def get_service_stats( - self, *, timeout: Optional[int] = None, **kwargs: Any - ) -> Dict[str, Any]: + async def get_service_stats(self, *, timeout: Optional[int] = None, **kwargs: Any) -> Dict[str, Any]: """Retrieves statistics related to replication for the Queue service. It is only available when read-access geo-redundant replication is enabled for @@ -325,9 +315,7 @@ async def get_service_stats( process_storage_error(error) @distributed_trace_async - async def get_service_properties( - self, *, timeout: Optional[int] = None, **kwargs: Any - ) -> Dict[str, Any]: + async def get_service_properties(self, *, timeout: Optional[int] = None, **kwargs: Any) -> Dict[str, Any]: """Gets the properties of a storage account's Queue service, including Azure Storage Analytics. @@ -347,9 +335,7 @@ async def get_service_properties( :caption: Getting queue service properties. """ try: - service_props = await self._client.service.get_properties( - timeout=timeout, **kwargs - ) + service_props = await self._client.service.get_properties(timeout=timeout, **kwargs) return service_properties_deserialize(service_props) except HttpResponseError as error: process_storage_error(error) @@ -545,9 +531,7 @@ async def delete_queue( kwargs.setdefault("merge_span", True) await queue_client.delete_queue(timeout=timeout, **kwargs) - def get_queue_client( - self, queue: Union["QueueProperties", str], **kwargs: Any - ) -> QueueClient: + def get_queue_client(self, queue: Union["QueueProperties", str], **kwargs: Any) -> QueueClient: """Get a client to interact with the specified queue. The queue need not already exist. @@ -574,9 +558,7 @@ def get_queue_client( queue_name = queue _pipeline = AsyncPipeline( - transport=AsyncTransportWrapper( - self._pipeline._transport - ), # pylint: disable=protected-access + transport=AsyncTransportWrapper(self._pipeline._transport), # pylint: disable=protected-access policies=self._pipeline._impl_policies, # type: ignore # pylint: disable=protected-access ) diff --git a/sdk/storage/azure-storage-queue/samples/queue_samples_authentication.py b/sdk/storage/azure-storage-queue/samples/queue_samples_authentication.py index 4103b979677d..0b0790576860 100644 --- a/sdk/storage/azure-storage-queue/samples/queue_samples_authentication.py +++ b/sdk/storage/azure-storage-queue/samples/queue_samples_authentication.py @@ -50,9 +50,7 @@ def authentication_by_connection_string(self): # [START auth_from_connection_string] from azure.storage.queue import QueueServiceClient - queue_service = QueueServiceClient.from_connection_string( - conn_str=self.connection_string - ) + queue_service = QueueServiceClient.from_connection_string(conn_str=self.connection_string) # [END auth_from_connection_string] # Get information for the Queue Service @@ -71,9 +69,7 @@ def authentication_by_shared_key(self): # [START create_queue_service_client] from azure.storage.queue import QueueServiceClient - queue_service = QueueServiceClient( - account_url=self.account_url, credential=self.access_key - ) + queue_service = QueueServiceClient(account_url=self.account_url, credential=self.access_key) # [END create_queue_service_client] # Get information for the Queue Service @@ -96,9 +92,7 @@ def authentication_by_oauth(self): # Instantiate a QueueServiceClient using a token credential from azure.storage.queue import QueueServiceClient - queue_service = QueueServiceClient( - account_url=self.account_url, credential=token_credential - ) + queue_service = QueueServiceClient(account_url=self.account_url, credential=token_credential) # [END create_queue_service_client_oauth] # Get information for the Queue Service @@ -121,9 +115,7 @@ def authentication_by_shared_access_signature(self): # Instantiate a QueueServiceClient using a connection string from azure.storage.queue import QueueServiceClient - queue_service = QueueServiceClient.from_connection_string( - conn_str=self.connection_string - ) + queue_service = QueueServiceClient.from_connection_string(conn_str=self.connection_string) # Create a SAS token to use for authentication of a client from azure.storage.queue import ( @@ -140,9 +132,7 @@ def authentication_by_shared_access_signature(self): expiry=datetime.utcnow() + timedelta(hours=1), ) - token_auth_queue_service = QueueServiceClient( - account_url=self.account_url, credential=sas_token - ) + token_auth_queue_service = QueueServiceClient(account_url=self.account_url, credential=sas_token) # Get information for the Queue Service properties = token_auth_queue_service.get_service_properties() diff --git a/sdk/storage/azure-storage-queue/samples/queue_samples_authentication_async.py b/sdk/storage/azure-storage-queue/samples/queue_samples_authentication_async.py index 848552d0bff7..1948ba8a4478 100644 --- a/sdk/storage/azure-storage-queue/samples/queue_samples_authentication_async.py +++ b/sdk/storage/azure-storage-queue/samples/queue_samples_authentication_async.py @@ -51,9 +51,7 @@ async def authentication_by_connection_string_async(self): # [START async_auth_from_connection_string] from azure.storage.queue.aio import QueueServiceClient - queue_service = QueueServiceClient.from_connection_string( - conn_str=self.connection_string - ) + queue_service = QueueServiceClient.from_connection_string(conn_str=self.connection_string) # [END async_auth_from_connection_string] # Get information for the Queue Service @@ -73,9 +71,7 @@ async def authentication_by_shared_key_async(self): # [START async_create_queue_service_client] from azure.storage.queue.aio import QueueServiceClient - queue_service = QueueServiceClient( - account_url=self.account_url, credential=self.access_key - ) + queue_service = QueueServiceClient(account_url=self.account_url, credential=self.access_key) # [END async_create_queue_service_client] # Get information for the Queue Service async with queue_service: @@ -98,9 +94,7 @@ async def authentication_by_oauth_async(self): # Instantiate a QueueServiceClient using a token credential from azure.storage.queue.aio import QueueServiceClient - queue_service = QueueServiceClient( - account_url=self.account_url, credential=token_credential - ) + queue_service = QueueServiceClient(account_url=self.account_url, credential=token_credential) # [END async_create_queue_service_client_oauth] # Get information for the Queue Service @@ -124,9 +118,7 @@ async def authentication_by_shared_access_signature_async(self): # Instantiate a QueueServiceClient using a connection string from azure.storage.queue.aio import QueueServiceClient - queue_service = QueueServiceClient.from_connection_string( - conn_str=self.connection_string - ) + queue_service = QueueServiceClient.from_connection_string(conn_str=self.connection_string) # Create a SAS token to use for authentication of a client from azure.storage.queue import ( @@ -142,9 +134,7 @@ async def authentication_by_shared_access_signature_async(self): permission=AccountSasPermissions(read=True), expiry=datetime.utcnow() + timedelta(hours=1), ) - token_auth_queue_service = QueueServiceClient( - account_url=self.account_url, credential=sas_token - ) + token_auth_queue_service = QueueServiceClient(account_url=self.account_url, credential=sas_token) # Get information for the Queue Service async with token_auth_queue_service: diff --git a/sdk/storage/azure-storage-queue/samples/queue_samples_hello_world.py b/sdk/storage/azure-storage-queue/samples/queue_samples_hello_world.py index f82108505bc7..03969be87f7d 100644 --- a/sdk/storage/azure-storage-queue/samples/queue_samples_hello_world.py +++ b/sdk/storage/azure-storage-queue/samples/queue_samples_hello_world.py @@ -40,9 +40,7 @@ def create_client_with_connection_string(self): # Instantiate the QueueServiceClient from a connection string from azure.storage.queue import QueueServiceClient - queue_service = QueueServiceClient.from_connection_string( - conn_str=self.connection_string - ) + queue_service = QueueServiceClient.from_connection_string(conn_str=self.connection_string) # Get queue service properties properties = queue_service.get_service_properties() @@ -59,9 +57,7 @@ def queue_and_messages_example(self): # Instantiate the QueueClient from a connection string from azure.storage.queue import QueueClient - queue = QueueClient.from_connection_string( - conn_str=self.connection_string, queue_name="myqueue" - ) + queue = QueueClient.from_connection_string(conn_str=self.connection_string, queue_name="myqueue") # Create the queue # [START create_queue] diff --git a/sdk/storage/azure-storage-queue/samples/queue_samples_hello_world_async.py b/sdk/storage/azure-storage-queue/samples/queue_samples_hello_world_async.py index 05f7f2096272..dc7d1dee4342 100644 --- a/sdk/storage/azure-storage-queue/samples/queue_samples_hello_world_async.py +++ b/sdk/storage/azure-storage-queue/samples/queue_samples_hello_world_async.py @@ -41,9 +41,7 @@ async def create_client_with_connection_string_async(self): # Instantiate the QueueServiceClient from a connection string from azure.storage.queue.aio import QueueServiceClient - queue_service = QueueServiceClient.from_connection_string( - conn_str=self.connection_string - ) + queue_service = QueueServiceClient.from_connection_string(conn_str=self.connection_string) # Get queue service properties async with queue_service: @@ -61,9 +59,7 @@ async def queue_and_messages_example_async(self): # Instantiate the QueueClient from a connection string from azure.storage.queue.aio import QueueClient - queue = QueueClient.from_connection_string( - conn_str=self.connection_string, queue_name="asyncmyqueue" - ) + queue = QueueClient.from_connection_string(conn_str=self.connection_string, queue_name="asyncmyqueue") async with queue: # Create the queue diff --git a/sdk/storage/azure-storage-queue/samples/queue_samples_message.py b/sdk/storage/azure-storage-queue/samples/queue_samples_message.py index e216ee981ccd..946f64e8e321 100644 --- a/sdk/storage/azure-storage-queue/samples/queue_samples_message.py +++ b/sdk/storage/azure-storage-queue/samples/queue_samples_message.py @@ -41,11 +41,7 @@ def set_access_policy(self): queue = QueueClient.from_connection_string(self.connection_string, "myqueue1") if queue.account_name is None: - print( - "Connection string did not provide an account name." - + "\n" - + "Test: set_access_policy" - ) + print("Connection string did not provide an account name." + "\n" + "Test: set_access_policy") sys.exit(1) # [END create_queue_client_from_connection_string] @@ -84,9 +80,7 @@ def set_access_policy(self): # Authenticate with the sas token # [START create_queue_client] - token_auth_queue = QueueClient.from_queue_url( - queue_url=queue.url, credential=sas_token - ) + token_auth_queue = QueueClient.from_queue_url(queue_url=queue.url, credential=sas_token) # [END create_queue_client] # Use the newly authenticated client to receive messages @@ -139,9 +133,7 @@ def send_and_receive_messages(self): try: # [START send_messages] queue.send_message("message1") - queue.send_message( - "message2", visibility_timeout=30 - ) # wait 30s before becoming visible + queue.send_message("message2", visibility_timeout=30) # wait 30s before becoming visible queue.send_message("message3") queue.send_message("message4") queue.send_message("message5") diff --git a/sdk/storage/azure-storage-queue/samples/queue_samples_message_async.py b/sdk/storage/azure-storage-queue/samples/queue_samples_message_async.py index 861e640cca96..d04393a6d3b1 100644 --- a/sdk/storage/azure-storage-queue/samples/queue_samples_message_async.py +++ b/sdk/storage/azure-storage-queue/samples/queue_samples_message_async.py @@ -40,15 +40,9 @@ async def set_access_policy_async(self): # [START async_create_queue_client_from_connection_string] from azure.storage.queue.aio import QueueClient - queue = QueueClient.from_connection_string( - self.connection_string, "myqueueasync1" - ) + queue = QueueClient.from_connection_string(self.connection_string, "myqueueasync1") if queue.account_name is None: - print( - "Connection string did not provide an account name." - + "\n" - + "Test: set_access_policy_async" - ) + print("Connection string did not provide an account name." + "\n" + "Test: set_access_policy_async") sys.exit(1) # [END async_create_queue_client_from_connection_string] @@ -86,9 +80,7 @@ async def set_access_policy_async(self): # Authenticate with the sas token # [START async_create_queue_client] - token_auth_queue = QueueClient.from_queue_url( - queue_url=queue.url, credential=sas_token - ) + token_auth_queue = QueueClient.from_queue_url(queue_url=queue.url, credential=sas_token) # [END async_create_queue_client] # Use the newly authenticated client to receive messages @@ -106,9 +98,7 @@ async def queue_metadata_async(self): # Instantiate a queue client from azure.storage.queue.aio import QueueClient - queue = QueueClient.from_connection_string( - self.connection_string, "myqueueasync2" - ) + queue = QueueClient.from_connection_string(self.connection_string, "myqueueasync2") # Create the queue async with queue: @@ -136,9 +126,7 @@ async def send_and_receive_messages_async(self): # Instantiate a queue client from azure.storage.queue.aio import QueueClient - queue = QueueClient.from_connection_string( - self.connection_string, "myqueueasync3" - ) + queue = QueueClient.from_connection_string(self.connection_string, "myqueueasync3") # Create the queue async with queue: @@ -148,9 +136,7 @@ async def send_and_receive_messages_async(self): # [START async_send_messages] await asyncio.gather( queue.send_message("message1"), - queue.send_message( - "message2", visibility_timeout=30 - ), # wait 30s before becoming visible + queue.send_message("message2", visibility_timeout=30), # wait 30s before becoming visible queue.send_message("message3"), queue.send_message("message4"), queue.send_message("message5"), @@ -189,9 +175,7 @@ async def receive_one_message_from_queue(self): # Instantiate a queue client from azure.storage.queue.aio import QueueClient - queue = QueueClient.from_connection_string( - self.connection_string, "myqueueasync4" - ) + queue = QueueClient.from_connection_string(self.connection_string, "myqueueasync4") # Create the queue async with queue: @@ -230,9 +214,7 @@ async def delete_and_clear_messages_async(self): # Instantiate a queue client from azure.storage.queue.aio import QueueClient - queue = QueueClient.from_connection_string( - self.connection_string, "myqueueasync5" - ) + queue = QueueClient.from_connection_string(self.connection_string, "myqueueasync5") # Create the queue async with queue: @@ -273,9 +255,7 @@ async def peek_messages_async(self): # Instantiate a queue client from azure.storage.queue.aio import QueueClient - queue = QueueClient.from_connection_string( - self.connection_string, "myqueueasync6" - ) + queue = QueueClient.from_connection_string(self.connection_string, "myqueueasync6") # Create the queue async with queue: @@ -315,9 +295,7 @@ async def update_message_async(self): # Instantiate a queue client from azure.storage.queue.aio import QueueClient - queue = QueueClient.from_connection_string( - self.connection_string, "myqueueasync7" - ) + queue = QueueClient.from_connection_string(self.connection_string, "myqueueasync7") # Create the queue async with queue: @@ -333,9 +311,7 @@ async def update_message_async(self): # Update the message async for message in messages: - message = await queue.update_message( - message, visibility_timeout=0, content="updated" - ) + message = await queue.update_message(message, visibility_timeout=0, content="updated") # [END async_update_message] break @@ -351,9 +327,7 @@ async def receive_messages_with_max_messages(self): # Instantiate a queue client from azure.storage.queue.aio import QueueClient - queue = QueueClient.from_connection_string( - self.connection_string, "myqueueasync8" - ) + queue = QueueClient.from_connection_string(self.connection_string, "myqueueasync8") # Create the queue async with queue: diff --git a/sdk/storage/azure-storage-queue/samples/queue_samples_service.py b/sdk/storage/azure-storage-queue/samples/queue_samples_service.py index 25acaa9a8e6c..e34a1afc7724 100644 --- a/sdk/storage/azure-storage-queue/samples/queue_samples_service.py +++ b/sdk/storage/azure-storage-queue/samples/queue_samples_service.py @@ -36,9 +36,7 @@ def queue_service_properties(self): # Instantiate the QueueServiceClient from a connection string from azure.storage.queue import QueueServiceClient - queue_service = QueueServiceClient.from_connection_string( - conn_str=self.connection_string - ) + queue_service = QueueServiceClient.from_connection_string(conn_str=self.connection_string) # [START set_queue_service_properties] # Create service properties @@ -97,9 +95,7 @@ def queue_service_properties(self): cors = [cors_rule1, cors_rule2] # Set the service properties - queue_service.set_service_properties( - logging, hour_metrics, minute_metrics, cors - ) + queue_service.set_service_properties(logging, hour_metrics, minute_metrics, cors) # [END set_queue_service_properties] # [START get_queue_service_properties] @@ -114,9 +110,7 @@ def queues_in_account(self): # Instantiate the QueueServiceClient from a connection string from azure.storage.queue import QueueServiceClient - queue_service = QueueServiceClient.from_connection_string( - conn_str=self.connection_string - ) + queue_service = QueueServiceClient.from_connection_string(conn_str=self.connection_string) # [START qsc_create_queue] queue_service.create_queue("myqueueservice1") @@ -148,9 +142,7 @@ def get_queue_client(self): # Instantiate the QueueServiceClient from a connection string from azure.storage.queue import QueueServiceClient, QueueClient - queue_service = QueueServiceClient.from_connection_string( - conn_str=self.connection_string - ) + queue_service = QueueServiceClient.from_connection_string(conn_str=self.connection_string) # [START get_queue_client] # Get the queue client to interact with a specific queue diff --git a/sdk/storage/azure-storage-queue/samples/queue_samples_service_async.py b/sdk/storage/azure-storage-queue/samples/queue_samples_service_async.py index eab448d09aa2..79296c6d6545 100644 --- a/sdk/storage/azure-storage-queue/samples/queue_samples_service_async.py +++ b/sdk/storage/azure-storage-queue/samples/queue_samples_service_async.py @@ -37,9 +37,7 @@ async def queue_service_properties_async(self): # Instantiate the QueueServiceClient from a connection string from azure.storage.queue.aio import QueueServiceClient - queue_service = QueueServiceClient.from_connection_string( - conn_str=self.connection_string - ) + queue_service = QueueServiceClient.from_connection_string(conn_str=self.connection_string) async with queue_service: # [START async_set_queue_service_properties] @@ -99,9 +97,7 @@ async def queue_service_properties_async(self): cors = [cors_rule1, cors_rule2] # Set the service properties - await queue_service.set_service_properties( - logging, hour_metrics, minute_metrics, cors - ) + await queue_service.set_service_properties(logging, hour_metrics, minute_metrics, cors) # [END async_set_queue_service_properties] # [START async_get_queue_service_properties] @@ -116,9 +112,7 @@ async def queues_in_account_async(self): # Instantiate the QueueServiceClient from a connection string from azure.storage.queue.aio import QueueServiceClient - queue_service = QueueServiceClient.from_connection_string( - conn_str=self.connection_string - ) + queue_service = QueueServiceClient.from_connection_string(conn_str=self.connection_string) async with queue_service: # [START async_qsc_create_queue] @@ -151,9 +145,7 @@ async def get_queue_client_async(self): # Instantiate the QueueServiceClient from a connection string from azure.storage.queue.aio import QueueServiceClient, QueueClient - queue_service = QueueServiceClient.from_connection_string( - conn_str=self.connection_string - ) + queue_service = QueueServiceClient.from_connection_string(conn_str=self.connection_string) # [START async_get_queue_client] # Get the queue client to interact with a specific queue diff --git a/sdk/storage/azure-storage-queue/tests/conftest.py b/sdk/storage/azure-storage-queue/tests/conftest.py index 44b62a8ba46f..8a80ea7d6c86 100644 --- a/sdk/storage/azure-storage-queue/tests/conftest.py +++ b/sdk/storage/azure-storage-queue/tests/conftest.py @@ -21,18 +21,10 @@ @pytest.fixture(scope="session", autouse=True) def add_sanitizers(test_proxy): - subscription_id = os.environ.get( - "AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000" - ) - tenant_id = os.environ.get( - "STORAGE_TENANT_ID", "00000000-0000-0000-0000-000000000000" - ) - add_general_regex_sanitizer( - regex=subscription_id, value="00000000-0000-0000-0000-000000000000" - ) - add_general_regex_sanitizer( - regex=tenant_id, value="00000000-0000-0000-0000-000000000000" - ) + subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + tenant_id = os.environ.get("STORAGE_TENANT_ID", "00000000-0000-0000-0000-000000000000") + add_general_regex_sanitizer(regex=subscription_id, value="00000000-0000-0000-0000-000000000000") + add_general_regex_sanitizer(regex=tenant_id, value="00000000-0000-0000-0000-000000000000") add_header_regex_sanitizer(key="Set-Cookie", value="[set-cookie;]") add_header_regex_sanitizer(key="Cookie", value="cookie;") add_oauth_response_sanitizer() diff --git a/sdk/storage/azure-storage-queue/tests/encryption_test_helper.py b/sdk/storage/azure-storage-queue/tests/encryption_test_helper.py index 07f3e4896872..7d657b882dd5 100644 --- a/sdk/storage/azure-storage-queue/tests/encryption_test_helper.py +++ b/sdk/storage/azure-storage-queue/tests/encryption_test_helper.py @@ -55,9 +55,7 @@ def resolve_key(self, kid): class RSAKeyWrapper: def __init__(self, kid="local:key2"): - self.private_key = generate_private_key( - public_exponent=65537, key_size=2048, backend=default_backend() - ) + self.private_key = generate_private_key(public_exponent=65537, key_size=2048, backend=default_backend()) self.public_key = self.private_key.public_key() self.kid = kid @@ -65,9 +63,7 @@ def wrap_key(self, key, algorithm="RSA"): if algorithm == "RSA": return self.public_key.encrypt( key, - OAEP( - mgf=MGF1(algorithm=SHA1()), algorithm=SHA1(), label=None - ), # nosec # nosec + OAEP(mgf=MGF1(algorithm=SHA1()), algorithm=SHA1(), label=None), # nosec # nosec ) raise ValueError(_ERROR_UNKNOWN_KEY_WRAP_ALGORITHM) @@ -76,9 +72,7 @@ def unwrap_key(self, key, algorithm): if algorithm == "RSA": return self.private_key.decrypt( key, - OAEP( - mgf=MGF1(algorithm=SHA1()), algorithm=SHA1(), label=None - ), # nosec # nosec + OAEP(mgf=MGF1(algorithm=SHA1()), algorithm=SHA1(), label=None), # nosec # nosec ) raise ValueError(_ERROR_UNKNOWN_KEY_WRAP_ALGORITHM) diff --git a/sdk/storage/azure-storage-queue/tests/settings/testcase.py b/sdk/storage/azure-storage-queue/tests/settings/testcase.py index 562121a4772c..5598f9302918 100644 --- a/sdk/storage/azure-storage-queue/tests/settings/testcase.py +++ b/sdk/storage/azure-storage-queue/tests/settings/testcase.py @@ -28,19 +28,11 @@ LOGGING_FORMAT = "%(asctime)s %(name)-20s %(levelname)-5s %(message)s" -os.environ["STORAGE_ACCOUNT_NAME"] = ( - os.environ.get("STORAGE_ACCOUNT_NAME", None) or STORAGE_ACCOUNT_NAME -) -os.environ["STORAGE_ACCOUNT_KEY"] = ( - os.environ.get("STORAGE_ACCOUNT_KEY", None) or STORAGE_ACCOUNT_KEY -) +os.environ["STORAGE_ACCOUNT_NAME"] = os.environ.get("STORAGE_ACCOUNT_NAME", None) or STORAGE_ACCOUNT_NAME +os.environ["STORAGE_ACCOUNT_KEY"] = os.environ.get("STORAGE_ACCOUNT_KEY", None) or STORAGE_ACCOUNT_KEY -os.environ["AZURE_TEST_RUN_LIVE"] = ( - os.environ.get("AZURE_TEST_RUN_LIVE", None) or RUN_IN_LIVE -) -os.environ["AZURE_SKIP_LIVE_RECORDING"] = ( - os.environ.get("AZURE_SKIP_LIVE_RECORDING", None) or SKIP_LIVE_RECORDING -) +os.environ["AZURE_TEST_RUN_LIVE"] = os.environ.get("AZURE_TEST_RUN_LIVE", None) or RUN_IN_LIVE +os.environ["AZURE_SKIP_LIVE_RECORDING"] = os.environ.get("AZURE_SKIP_LIVE_RECORDING", None) or SKIP_LIVE_RECORDING os.environ["PROTOCOL"] = PROTOCOL os.environ["ACCOUNT_URL_SUFFIX"] = ACCOUNT_URL_SUFFIX diff --git a/sdk/storage/azure-storage-queue/tests/test_queue.py b/sdk/storage/azure-storage-queue/tests/test_queue.py index ab88a435a127..7f956db3f17e 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue.py @@ -62,9 +62,7 @@ def test_create_queue(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) created = queue_client.create_queue() @@ -78,9 +76,7 @@ def test_create_queue_fail_on_exist(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) created = queue_client.create_queue() with pytest.raises(ResourceExistsError): @@ -132,9 +128,7 @@ def test_delete_non_existing_queue(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) # Asserts @@ -148,9 +142,7 @@ def test_delete_existing_queue_fail_not_exist(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) created = queue_client.create_queue() @@ -166,9 +158,7 @@ def test_list_queues(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queues = list(qsc.list_queues()) @@ -185,22 +175,18 @@ def test_list_queues_with_options(self, **kwargs): # Arrange prefix = "listqueue" - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_list = [] for i in range(0, 4): self._create_queue(qsc, prefix + str(i), queue_list) # Action - generator1 = qsc.list_queues( - name_starts_with=prefix, results_per_page=3 - ).by_page() + generator1 = qsc.list_queues(name_starts_with=prefix, results_per_page=3).by_page() queues1 = list(next(generator1)) - generator2 = qsc.list_queues( - name_starts_with=prefix, include_metadata=True - ).by_page(generator1.continuation_token) + generator2 = qsc.list_queues(name_starts_with=prefix, include_metadata=True).by_page( + generator1.continuation_token + ) queues2 = list(next(generator2)) # Asserts @@ -223,9 +209,7 @@ def test_list_queues_with_metadata(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = self._get_queue_reference(qsc) queue.create_queue() queue.set_queue_metadata(metadata={"val1": "test", "val2": "blah"}) @@ -252,9 +236,7 @@ def test_list_queues_account_sas(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() sas_token = self.generate_sas( @@ -267,9 +249,7 @@ def test_list_queues_account_sas(self, **kwargs): ) # Act - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), credential=sas_token - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), credential=sas_token) queues = list(qsc.list_queues()) # Assert @@ -283,9 +263,7 @@ def test_set_queue_metadata(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = self._get_queue_reference(qsc) metadata = {"hello": "world", "number": "43"} queue.create_queue() @@ -303,9 +281,7 @@ def test_get_queue_metadata_message_count(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() sent_message = queue_client.send_message("message1") @@ -323,9 +299,7 @@ def test_queue_exists(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = self._get_queue_reference(qsc) queue.create_queue() @@ -342,9 +316,7 @@ def test_queue_not_exists(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = qsc.get_queue_client(self.get_resource_name("missing")) # Act with pytest.raises(ResourceNotFoundError): @@ -359,9 +331,7 @@ def test_put_message(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action. No exception means pass. No asserts needed. - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -384,9 +354,7 @@ def test_put_message_large_time_to_live(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() # There should be no upper bound on a queue message's time to live @@ -396,9 +364,7 @@ def test_put_message_large_time_to_live(self, **kwargs): messages = queue_client.peek_messages() # Assert - assert messages[0].expires_on >= ( - messages[0].inserted_on + timedelta(seconds=1024 * 1024 * 1024 - 3600) - ) + assert messages[0].expires_on >= (messages[0].inserted_on + timedelta(seconds=1024 * 1024 * 1024 - 3600)) @QueuePreparer() @recorded_by_proxy @@ -407,9 +373,7 @@ def test_put_message_infinite_time_to_live(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1", time_to_live=-1) @@ -427,9 +391,7 @@ def test_get_messages(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -457,9 +419,7 @@ def test_receive_one_message(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() assert queue_client.receive_message() is None @@ -495,18 +455,14 @@ def test_get_messages_with_options(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") queue_client.send_message("message2") queue_client.send_message("message3") queue_client.send_message("message4") - pager = queue_client.receive_messages( - messages_per_page=4, visibility_timeout=20 - ) + pager = queue_client.receive_messages(messages_per_page=4, visibility_timeout=20) result = list(pager) # Asserts @@ -530,9 +486,7 @@ def test_get_messages_with_max_messages(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -569,9 +523,7 @@ def test_get_messages_with_too_little_messages(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -603,9 +555,7 @@ def test_get_messages_with_page_bigger_than_max(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -625,9 +575,7 @@ def test_get_messages_with_remainder(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -683,9 +631,7 @@ def test_peek_messages(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -714,9 +660,7 @@ def test_peek_messages_with_options(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -745,9 +689,7 @@ def test_clear_messages(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -768,9 +710,7 @@ def test_delete_message(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -794,9 +734,7 @@ def test_update_message(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -833,9 +771,7 @@ def test_update_message_content(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -877,9 +813,7 @@ def test_account_sas(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -917,12 +851,8 @@ def test_azure_named_key_credential_access(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - named_key = AzureNamedKeyCredential( - storage_account_name, storage_account_key.secret - ) - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), named_key - ) + named_key = AzureNamedKeyCredential(storage_account_name, storage_account_key.secret) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), named_key) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -953,24 +883,18 @@ def test_token_credential(self, **kwargs): token_credential = self.get_credential(QueueServiceClient) # Action 1: make sure token works - service = QueueServiceClient( - self.account_url(storage_account_name, "queue"), credential=token_credential - ) + service = QueueServiceClient(self.account_url(storage_account_name, "queue"), credential=token_credential) queues = service.get_service_properties() assert queues is not None # Action 2: change token value to make request fail fake_credential = FakeTokenCredential() - service = QueueServiceClient( - self.account_url(storage_account_name, "queue"), credential=fake_credential - ) + service = QueueServiceClient(self.account_url(storage_account_name, "queue"), credential=fake_credential) with pytest.raises(ClientAuthenticationError): list(service.list_queues()) # Action 3: update token to make it working again - service = QueueServiceClient( - self.account_url(storage_account_name, "queue"), credential=token_credential - ) + service = QueueServiceClient(self.account_url(storage_account_name, "queue"), credential=token_credential) queues = list(service.list_queues()) assert queues is not None @@ -981,9 +905,7 @@ def test_sas_read(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -1019,9 +941,7 @@ def test_sas_add(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() token = self.generate_sas( @@ -1051,9 +971,7 @@ def test_sas_update(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -1091,9 +1009,7 @@ def test_sas_process(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -1127,21 +1043,15 @@ def test_sas_signed_identifier(self, **kwargs): # Arrange access_policy = AccessPolicy() - start_time = self.get_datetime_variable( - variables, "start_time", datetime.utcnow() - timedelta(hours=1) - ) - expiry_time = self.get_datetime_variable( - variables, "expiry_time", datetime.utcnow() + timedelta(hours=1) - ) + start_time = self.get_datetime_variable(variables, "start_time", datetime.utcnow() - timedelta(hours=1)) + expiry_time = self.get_datetime_variable(variables, "expiry_time", datetime.utcnow() + timedelta(hours=1)) access_policy.start = start_time access_policy.expiry = expiry_time access_policy.permission = QueueSasPermissions(read=True) identifiers = {"testid": access_policy} - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() resp = queue_client.set_queue_access_policy(identifiers) @@ -1180,9 +1090,7 @@ def test_get_queue_acl(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() @@ -1200,9 +1108,7 @@ def test_get_queue_acl_iter(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() @@ -1222,9 +1128,7 @@ def test_get_queue_acl_with_non_existing_queue(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) # Act @@ -1240,9 +1144,7 @@ def test_set_queue_acl(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() @@ -1261,9 +1163,7 @@ def test_set_queue_acl_with_empty_signed_identifiers(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() @@ -1282,9 +1182,7 @@ def test_set_queue_acl_with_empty_signed_identifier(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() @@ -1308,19 +1206,13 @@ def test_set_queue_acl_with_signed_identifiers(self, **kwargs): variables = kwargs.pop("variables", {}) # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() # Act - expiry_time = self.get_datetime_variable( - variables, "expiry_time", datetime.utcnow() + timedelta(hours=1) - ) - start_time = self.get_datetime_variable( - variables, "start_time", datetime.utcnow() - timedelta(minutes=5) - ) + expiry_time = self.get_datetime_variable(variables, "expiry_time", datetime.utcnow() + timedelta(hours=1)) + start_time = self.get_datetime_variable(variables, "start_time", datetime.utcnow() - timedelta(minutes=5)) access_policy = AccessPolicy( permission=QueueSasPermissions(read=True), expiry=expiry_time, @@ -1346,9 +1238,7 @@ def test_set_queue_acl_too_many_ids(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() @@ -1368,9 +1258,7 @@ def test_set_queue_acl_with_non_existing_queue(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) # Act @@ -1386,9 +1274,7 @@ def test_unicode_create_queue_unicode_name(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_name = "啊齄丂狛狜" with pytest.raises(HttpResponseError): @@ -1405,9 +1291,7 @@ def test_unicode_get_messages_unicode_data(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1㚈") @@ -1430,9 +1314,7 @@ def test_unicode_update_message_unicode_data(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) queue_client.create_queue() queue_client.send_message("message1") @@ -1481,9 +1363,7 @@ def test_storage_account_audience_queue_service_client(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) qsc.get_service_properties() # Act @@ -1505,9 +1385,7 @@ def test_bad_audience_queue_service_client(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) qsc.get_service_properties() # Act @@ -1581,19 +1459,11 @@ def test_get_user_delegation_sas(self, **kwargs): variables = kwargs.pop("variables", {}) token_credential = self.get_credential(QueueServiceClient) - service = QueueServiceClient( - self.account_url(storage_account_name, "queue"), credential=token_credential - ) + service = QueueServiceClient(self.account_url(storage_account_name, "queue"), credential=token_credential) start = self.get_datetime_variable(variables, "start", datetime.utcnow()) - expiry = self.get_datetime_variable( - variables, "expiry", datetime.utcnow() + timedelta(hours=1) - ) - user_delegation_key_1 = service.get_user_delegation_key( - start=start, expiry=expiry - ) - user_delegation_key_2 = service.get_user_delegation_key( - start=start, expiry=expiry - ) + expiry = self.get_datetime_variable(variables, "expiry", datetime.utcnow() + timedelta(hours=1)) + user_delegation_key_1 = service.get_user_delegation_key(start=start, expiry=expiry) + user_delegation_key_2 = service.get_user_delegation_key(start=start, expiry=expiry) # Assert key1 is valid assert user_delegation_key_1.signed_oid is not None @@ -1608,15 +1478,9 @@ def test_get_user_delegation_sas(self, **kwargs): assert user_delegation_key_1.signed_oid == user_delegation_key_2.signed_oid assert user_delegation_key_1.signed_tid == user_delegation_key_2.signed_tid assert user_delegation_key_1.signed_start == user_delegation_key_2.signed_start - assert ( - user_delegation_key_1.signed_expiry == user_delegation_key_2.signed_expiry - ) - assert ( - user_delegation_key_1.signed_version == user_delegation_key_2.signed_version - ) - assert ( - user_delegation_key_1.signed_service == user_delegation_key_2.signed_service - ) + assert user_delegation_key_1.signed_expiry == user_delegation_key_2.signed_expiry + assert user_delegation_key_1.signed_version == user_delegation_key_2.signed_version + assert user_delegation_key_1.signed_service == user_delegation_key_2.signed_service assert user_delegation_key_1.value == user_delegation_key_2.value return variables @@ -1628,9 +1492,7 @@ def test_queue_cross_tenant_sas(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") token_credential = self.get_credential(QueueServiceClient) - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), credential=token_credential - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), credential=token_credential) start = datetime.utcnow() expiry = datetime.utcnow() + timedelta(hours=1) token = token_credential.get_token("https://storage.azure.com/.default") @@ -1662,9 +1524,7 @@ def test_queue_cross_tenant_sas(self, **kwargs): assert "sduoid=" + user_delegation_oid in queue_token assert "skdutid=" + delegated_user_tid in queue_token - queue_client = QueueClient.from_queue_url( - queue_url=f"{queue.url}?{queue_token}", credential=token_credential - ) + queue_client = QueueClient.from_queue_url(queue_url=f"{queue.url}?{queue_token}", credential=token_credential) message = "addedmessage" queue_msg = queue_client.send_message(message) assert queue_msg is not None diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_api_version.py b/sdk/storage/azure-storage-queue/tests/test_queue_api_version.py index 37fbd7cc3de9..61eed578c786 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_api_version.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_api_version.py @@ -22,9 +22,7 @@ def setUp(self): def test_service_client_api_version_property(self): self.setUp() - service_client = QueueServiceClient( - "https://foo.queue.core.windows.net/account", credential="fake_key" - ) + service_client = QueueServiceClient("https://foo.queue.core.windows.net/account", credential="fake_key") assert service_client.api_version == self.api_version_2 assert service_client._client._config.version == self.api_version_2 diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_api_version_async.py b/sdk/storage/azure-storage-queue/tests/test_queue_api_version_async.py index 7350ca87f7fa..2bae873c98e3 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_api_version_async.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_api_version_async.py @@ -22,9 +22,7 @@ def setUp(self): def test_service_client_api_version_property(self): self.setUp() - service_client = QueueServiceClient( - "https://foo.queue.core.windows.net/account", credential="fake_key" - ) + service_client = QueueServiceClient("https://foo.queue.core.windows.net/account", credential="fake_key") assert service_client.api_version == self.api_version_2 assert service_client._client._config.version == self.api_version_2 diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_async.py b/sdk/storage/azure-storage-queue/tests/test_queue_async.py index b3171ea7074c..8878f8c401b6 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_async.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_async.py @@ -60,9 +60,7 @@ async def test_create_queue(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) created = await queue_client.create_queue() @@ -76,9 +74,7 @@ async def test_create_queue_fail_on_exist(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) created = await queue_client.create_queue() with pytest.raises(ResourceExistsError): @@ -94,9 +90,7 @@ async def test_create_queue_fail_on_exist_different_metadata(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) created = await queue_client.create_queue() with pytest.raises(ResourceExistsError): @@ -112,9 +106,7 @@ async def test_create_queue_with_options(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) await queue_client.create_queue(metadata={"val1": "test", "val2": "blah"}) props = await queue_client.get_queue_properties() @@ -132,9 +124,7 @@ async def test_get_messages_with_max_messages(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) await queue_client.create_queue() await queue_client.send_message("message1") @@ -172,9 +162,7 @@ async def test_get_messages_with_too_little_messages(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) await queue_client.create_queue() await queue_client.send_message("message1") @@ -207,9 +195,7 @@ async def test_get_messages_with_page_bigger_than_max(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) await queue_client.create_queue() await queue_client.send_message("message1") @@ -229,9 +215,7 @@ async def test_get_messages_with_remainder(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) await queue_client.create_queue() await queue_client.send_message("message1") @@ -248,9 +232,7 @@ async def test_get_messages_with_remainder(self, **kwargs): await queue_client.send_message("message12") result = [] - async for m in queue_client.receive_messages( - messages_per_page=3, max_messages=10 - ): + async for m in queue_client.receive_messages(messages_per_page=3, max_messages=10): result.append(m) remainder = [] @@ -291,9 +273,7 @@ async def test_delete_non_existing_queue(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) # Asserts @@ -307,9 +287,7 @@ async def test_delete_existing_queue_fail_not_exist(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) created = await queue_client.create_queue() @@ -325,9 +303,7 @@ async def test_list_queues(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) await queue_client.create_queue() queues = [] @@ -345,25 +321,21 @@ async def test_list_queues_with_options(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_list = [] prefix = "listqueue" for i in range(0, 4): await self._create_queue(qsc, prefix + str(i), queue_list) # Action - generator1 = qsc.list_queues( - name_starts_with=prefix, results_per_page=3 - ).by_page() + generator1 = qsc.list_queues(name_starts_with=prefix, results_per_page=3).by_page() queues1 = [] async for el in await generator1.__anext__(): queues1.append(el) - generator2 = qsc.list_queues( - name_starts_with=prefix, include_metadata=True - ).by_page(generator1.continuation_token) + generator2 = qsc.list_queues(name_starts_with=prefix, include_metadata=True).by_page( + generator1.continuation_token + ) queues2 = [] async for el in await generator2.__anext__(): queues2.append(el) @@ -387,16 +359,12 @@ async def test_list_queues_with_metadata(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = await self._create_queue(qsc) await queue.set_queue_metadata(metadata={"val1": "test", "val2": "blah"}) listed_queue = [] - async for q in qsc.list_queues( - name_starts_with=queue.queue_name, results_per_page=1, include_metadata=True - ): + async for q in qsc.list_queues(name_starts_with=queue.queue_name, results_per_page=1, include_metadata=True): listed_queue.append(q) listed_queue = listed_queue[0] @@ -414,9 +382,7 @@ async def test_list_queues_account_sas(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) await queue_client.create_queue() sas_token = self.generate_sas( @@ -429,9 +395,7 @@ async def test_list_queues_account_sas(self, **kwargs): ) # Act - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), credential=sas_token - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), credential=sas_token) queues = [] async for q in qsc.list_queues(): queues.append(q) @@ -447,9 +411,7 @@ async def test_set_queue_metadata(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) metadata = {"hello": "world", "number": "43"} queue = await self._create_queue(qsc) @@ -467,9 +429,7 @@ async def test_get_queue_metadata_message_count(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = await self._create_queue(qsc) await queue_client.send_message("message1") props = await queue_client.get_queue_properties() @@ -485,9 +445,7 @@ async def test_queue_exists(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = await self._create_queue(qsc) # Act @@ -503,9 +461,7 @@ async def test_queue_not_exists(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = qsc.get_queue_client(self.get_resource_name("missing")) # Act with pytest.raises(ResourceNotFoundError): @@ -520,9 +476,7 @@ async def test_put_message(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action. No exception means pass. No asserts needed. - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = await self._create_queue(qsc) await queue_client.send_message("message1") await queue_client.send_message("message2") @@ -544,9 +498,7 @@ async def test_put_message_large_time_to_live(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = await self._create_queue(qsc) # There should be no upper bound on a queue message's time to live await queue_client.send_message("message1", time_to_live=1024 * 1024 * 1024) @@ -555,9 +507,7 @@ async def test_put_message_large_time_to_live(self, **kwargs): messages = await queue_client.peek_messages() # Assert - assert messages[0].expires_on >= ( - messages[0].inserted_on + timedelta(seconds=1024 * 1024 * 1024 - 3600) - ) + assert messages[0].expires_on >= (messages[0].inserted_on + timedelta(seconds=1024 * 1024 * 1024 - 3600)) @QueuePreparer() @recorded_by_proxy_async @@ -566,9 +516,7 @@ async def test_put_message_infinite_time_to_live(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = await self._create_queue(qsc) await queue_client.send_message("message1", time_to_live=-1) @@ -585,9 +533,7 @@ async def test_get_messages(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = await self._create_queue(qsc) await queue_client.send_message("message1") await queue_client.send_message("message2") @@ -618,9 +564,7 @@ async def test_receive_one_message(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = await self._create_queue(qsc) assert await queue_client.receive_message() is None @@ -655,17 +599,13 @@ async def test_get_messages_with_options(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = await self._create_queue(qsc) await queue_client.send_message("message1") await queue_client.send_message("message2") await queue_client.send_message("message3") await queue_client.send_message("message4") - pager = queue_client.receive_messages( - messages_per_page=4, visibility_timeout=20 - ) + pager = queue_client.receive_messages(messages_per_page=4, visibility_timeout=20) result = [] async for el in pager: result.append(el) @@ -691,9 +631,7 @@ async def test_peek_messages(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = await self._create_queue(qsc) await queue_client.send_message("message1") await queue_client.send_message("message2") @@ -721,9 +659,7 @@ async def test_peek_messages_with_options(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = await self._create_queue(qsc) await queue_client.send_message("message1") await queue_client.send_message("message2") @@ -751,9 +687,7 @@ async def test_clear_messages(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = await self._create_queue(qsc) await queue_client.send_message("message1") await queue_client.send_message("message2") @@ -773,9 +707,7 @@ async def test_delete_message(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = await self._create_queue(qsc) await queue_client.send_message("message1") await queue_client.send_message("message2") @@ -798,9 +730,7 @@ async def test_update_message(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = await self._create_queue(qsc) await queue_client.send_message("message1") messages = [] @@ -841,9 +771,7 @@ async def test_update_message_content(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = await self._create_queue(qsc) await queue_client.send_message("message1") @@ -889,9 +817,7 @@ async def test_account_sas(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Arrange queue_client = await self._create_queue(qsc) @@ -930,12 +856,8 @@ async def test_azure_named_key_credential_access(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - named_key = AzureNamedKeyCredential( - storage_account_name, storage_account_key.secret - ) - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), named_key - ) + named_key = AzureNamedKeyCredential(storage_account_name, storage_account_key.secret) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), named_key) queue_client = self._get_queue_reference(qsc) await queue_client.create_queue() await queue_client.send_message("message1") @@ -963,30 +885,22 @@ async def test_token_credential(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) token_credential = self.get_credential(QueueServiceClient, is_async=True) # Action 1: make sure token works - service = QueueServiceClient( - self.account_url(storage_account_name, "queue"), credential=token_credential - ) + service = QueueServiceClient(self.account_url(storage_account_name, "queue"), credential=token_credential) queues = await service.get_service_properties() assert queues is not None # Action 2: change token value to make request fail fake_credential = AsyncFakeCredential() - service = QueueServiceClient( - self.account_url(storage_account_name, "queue"), credential=fake_credential - ) + service = QueueServiceClient(self.account_url(storage_account_name, "queue"), credential=fake_credential) with pytest.raises(ClientAuthenticationError): await service.get_service_properties() # Action 3: update token to make it working again - service = QueueServiceClient( - self.account_url(storage_account_name, "queue"), credential=token_credential - ) + service = QueueServiceClient(self.account_url(storage_account_name, "queue"), credential=token_credential) queues = await service.get_service_properties() # Not raise means success assert queues is not None @@ -996,9 +910,7 @@ async def test_sas_read(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Arrange queue_client = await self._create_queue(qsc) @@ -1034,9 +946,7 @@ async def test_sas_add(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Arrange queue_client = await self._create_queue(qsc) @@ -1070,9 +980,7 @@ async def test_sas_update(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Arrange queue_client = await self._create_queue(qsc) @@ -1115,9 +1023,7 @@ async def test_sas_process(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Arrange queue_client = await self._create_queue(qsc) @@ -1153,18 +1059,12 @@ async def test_sas_signed_identifier(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") variables = kwargs.pop("variables", {}) - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Arrange access_policy = AccessPolicy() - start_time = self.get_datetime_variable( - variables, "start_time", datetime.utcnow() - timedelta(hours=1) - ) - expiry_time = self.get_datetime_variable( - variables, "expiry_time", datetime.utcnow() + timedelta(hours=1) - ) + start_time = self.get_datetime_variable(variables, "start_time", datetime.utcnow() - timedelta(hours=1)) + expiry_time = self.get_datetime_variable(variables, "expiry_time", datetime.utcnow() + timedelta(hours=1)) access_policy.start = start_time access_policy.expiry = expiry_time access_policy.permission = QueueSasPermissions(read=True) @@ -1207,9 +1107,7 @@ async def test_get_queue_acl(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Arrange queue_client = await self._create_queue(qsc) @@ -1226,9 +1124,7 @@ async def test_get_queue_acl_iter(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Arrange queue_client = await self._create_queue(qsc) @@ -1247,9 +1143,7 @@ async def test_get_queue_acl_with_non_existing_queue(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Arrange queue_client = self._get_queue_reference(qsc) @@ -1265,9 +1159,7 @@ async def test_set_queue_acl(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Arrange queue_client = await self._create_queue(qsc) @@ -1285,9 +1177,7 @@ async def test_set_queue_acl_with_empty_signed_identifiers(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Arrange queue_client = await self._create_queue(qsc) @@ -1305,9 +1195,7 @@ async def test_set_queue_acl_with_empty_signed_identifier(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Arrange queue_client = await self._create_queue(qsc) @@ -1331,18 +1219,12 @@ async def test_set_queue_acl_with_signed_identifiers(self, **kwargs): variables = kwargs.pop("variables", {}) # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = await self._create_queue(qsc) # Act - expiry_time = self.get_datetime_variable( - variables, "expiry_time", datetime.utcnow() + timedelta(hours=1) - ) - start_time = self.get_datetime_variable( - variables, "start_time", datetime.utcnow() - timedelta(minutes=5) - ) + expiry_time = self.get_datetime_variable(variables, "expiry_time", datetime.utcnow() + timedelta(hours=1)) + start_time = self.get_datetime_variable(variables, "start_time", datetime.utcnow() - timedelta(minutes=5)) access_policy = AccessPolicy( permission=QueueSasPermissions(read=True), expiry=expiry_time, @@ -1350,9 +1232,7 @@ async def test_set_queue_acl_with_signed_identifiers(self, **kwargs): ) identifiers = {"testid": access_policy} - resp = await queue_client.set_queue_access_policy( - signed_identifiers=identifiers - ) + resp = await queue_client.set_queue_access_policy(signed_identifiers=identifiers) # Assert assert resp is None @@ -1370,9 +1250,7 @@ async def test_set_queue_acl_too_many_ids(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = await self._create_queue(qsc) # Act @@ -1391,9 +1269,7 @@ async def test_set_queue_acl_with_non_existing_queue(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = self._get_queue_reference(qsc) # Act @@ -1407,9 +1283,7 @@ async def test_unicode_create_queue_unicode_name(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_name = "啊齄丂狛狜" with pytest.raises(HttpResponseError): @@ -1426,9 +1300,7 @@ async def test_unicode_get_messages_unicode_data(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = await self._create_queue(qsc) await queue_client.send_message("message1㚈") message = None @@ -1451,9 +1323,7 @@ async def test_unicode_update_message_unicode_data(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue_client = await self._create_queue(qsc) await queue_client.send_message("message1") messages = [] @@ -1505,9 +1375,7 @@ async def test_storage_account_audience_queue_service_client(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) await qsc.get_service_properties() # Act @@ -1529,9 +1397,7 @@ async def test_bad_audience_queue_service_client(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) await qsc.get_service_properties() # Act @@ -1607,19 +1473,11 @@ async def test_get_user_delegation_sas(self, **kwargs): variables = kwargs.pop("variables", {}) token_credential = self.get_credential(QueueServiceClient, is_async=True) - service = QueueServiceClient( - self.account_url(storage_account_name, "queue"), credential=token_credential - ) + service = QueueServiceClient(self.account_url(storage_account_name, "queue"), credential=token_credential) start = self.get_datetime_variable(variables, "start", datetime.utcnow()) - expiry = self.get_datetime_variable( - variables, "expiry", datetime.utcnow() + timedelta(hours=1) - ) - user_delegation_key_1 = await service.get_user_delegation_key( - start=start, expiry=expiry - ) - user_delegation_key_2 = await service.get_user_delegation_key( - start=start, expiry=expiry - ) + expiry = self.get_datetime_variable(variables, "expiry", datetime.utcnow() + timedelta(hours=1)) + user_delegation_key_1 = await service.get_user_delegation_key(start=start, expiry=expiry) + user_delegation_key_2 = await service.get_user_delegation_key(start=start, expiry=expiry) # Assert key1 is valid assert user_delegation_key_1.signed_oid is not None @@ -1634,15 +1492,9 @@ async def test_get_user_delegation_sas(self, **kwargs): assert user_delegation_key_1.signed_oid == user_delegation_key_2.signed_oid assert user_delegation_key_1.signed_tid == user_delegation_key_2.signed_tid assert user_delegation_key_1.signed_start == user_delegation_key_2.signed_start - assert ( - user_delegation_key_1.signed_expiry == user_delegation_key_2.signed_expiry - ) - assert ( - user_delegation_key_1.signed_version == user_delegation_key_2.signed_version - ) - assert ( - user_delegation_key_1.signed_service == user_delegation_key_2.signed_service - ) + assert user_delegation_key_1.signed_expiry == user_delegation_key_2.signed_expiry + assert user_delegation_key_1.signed_version == user_delegation_key_2.signed_version + assert user_delegation_key_1.signed_service == user_delegation_key_2.signed_service assert user_delegation_key_1.value == user_delegation_key_2.value return variables @@ -1654,9 +1506,7 @@ async def test_queue_cross_tenant_sas(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") token_credential = self.get_credential(QueueServiceClient, is_async=True) - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), credential=token_credential - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), credential=token_credential) start = datetime.utcnow() expiry = datetime.utcnow() + timedelta(hours=1) token = await token_credential.get_token("https://storage.azure.com/.default") @@ -1688,9 +1538,7 @@ async def test_queue_cross_tenant_sas(self, **kwargs): assert "sduoid=" + user_delegation_oid in queue_token assert "skdutid=" + delegated_user_tid in queue_token - queue_client = QueueClient.from_queue_url( - queue_url=f"{queue.url}?{queue_token}", credential=token_credential - ) + queue_client = QueueClient.from_queue_url(queue_url=f"{queue.url}?{queue_token}", credential=token_credential) message = "addedmessage" queue_msg = await queue_client.send_message(message) assert queue_msg is not None diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_client.py b/sdk/storage/azure-storage-queue/tests/test_queue_client.py index 42d242327437..d7359bef3fc0 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_client.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_client.py @@ -43,22 +43,15 @@ def setUp(self): self.token_credential = self.get_credential(QueueServiceClient) # --Helpers----------------------------------------------------------------- - def validate_standard_account_endpoints( - self, service, url_type, account_name, account_key - ): + def validate_standard_account_endpoints(self, service, url_type, account_name, account_key): assert service is not None assert service.account_name == account_name assert service.credential.account_name == account_name assert service.credential.account_key == account_key.secret assert f"{account_name}.{url_type}.core.windows.net" in service.url - assert ( - f"{account_name}-secondary.{url_type}.core.windows.net" - in service.secondary_endpoint - ) + assert f"{account_name}-secondary.{url_type}.core.windows.net" in service.secondary_endpoint - def validate_ipv6_account_endpoints( - self, service, account_name, account_key, primary_endpoint, secondary_endpoint - ): + def validate_ipv6_account_endpoints(self, service, account_name, account_key, primary_endpoint, secondary_endpoint): assert service is not None assert service.scheme == "https" assert service.account_name == account_name @@ -96,9 +89,7 @@ def test_create_service_with_key(self, **kwargs): ) # Assert - self.validate_standard_account_endpoints( - service, url, storage_account_name, storage_account_key - ) + self.validate_standard_account_endpoints(service, url, storage_account_name, storage_account_key) assert service.scheme == "https" @QueuePreparer() @@ -109,9 +100,7 @@ def test_create_service_with_connection_string(self, **kwargs): for service_type in SERVICES.items(): # Act service = service_type[0].from_connection_string( - self.connection_string( - storage_account_name, storage_account_key.secret - ), + self.connection_string(storage_account_name, storage_account_key.secret), queue_name="test", ) @@ -139,9 +128,7 @@ def test_create_service_with_sas(self, **kwargs): # Assert assert service is not None assert service.account_name == storage_account_name - assert service.url.startswith( - "https://" + storage_account_name + ".queue.core.windows.net" - ) + assert service.url.startswith("https://" + storage_account_name + ".queue.core.windows.net") assert service.url.endswith(self.sas_token) assert service.credential is None @@ -162,9 +149,7 @@ def test_create_service_with_token(self, **kwargs): # Assert assert service is not None assert service.account_name == storage_account_name - assert service.url.startswith( - "https://" + storage_account_name + ".queue.core.windows.net" - ) + assert service.url.startswith("https://" + storage_account_name + ".queue.core.windows.net") assert service.credential == self.token_credential assert not hasattr(service.credential, "account_key") assert hasattr(service.credential, "get_token") @@ -178,9 +163,7 @@ def test_create_service_with_token_and_http(self, **kwargs): for service_type in SERVICES: # Act with pytest.raises(ValueError): - url = self.account_url(storage_account_name, "queue").replace( - "https", "http" - ) + url = self.account_url(storage_account_name, "queue").replace("https", "http") service_type(url, credential=self.token_credential, queue_name="foo") @QueuePreparer() @@ -192,12 +175,8 @@ def test_create_service_china(self, **kwargs): for service_type in SERVICES.items(): # Act - url = self.account_url(storage_account_name, "queue").replace( - "core.windows.net", "core.chinacloudapi.cn" - ) - service = service_type[0]( - url, credential=storage_account_key.secret, queue_name="foo" - ) + url = self.account_url(storage_account_name, "queue").replace("core.windows.net", "core.chinacloudapi.cn") + service = service_type[0](url, credential=storage_account_key.secret, queue_name="foo") # Assert assert service is not None @@ -226,12 +205,8 @@ def test_create_service_protocol(self, **kwargs): for service_type in SERVICES.items(): # Act - url = self.account_url(storage_account_name, "queue").replace( - "https", "http" - ) - service = service_type[0]( - url, credential=storage_account_key.secret, queue_name="foo" - ) + url = self.account_url(storage_account_name, "queue").replace("https", "http") + service = service_type[0](url, credential=storage_account_key.secret, queue_name="foo") # Assert self.validate_standard_account_endpoints( @@ -250,14 +225,9 @@ def test_create_service_empty_key(self, **kwargs): for service_type in QUEUE_SERVICES: # Act with pytest.raises(ValueError) as e: - test_service = service_type( - "testaccount", credential="", queue_name="foo" - ) + test_service = service_type("testaccount", credential="", queue_name="foo") - assert ( - str(e.value) - == "You need to provide either a SAS token or an account shared key to authenticate." - ) + assert str(e.value) == "You need to provide either a SAS token or an account shared key to authenticate." @QueuePreparer() def test_create_service_with_socket_timeout(self, **kwargs): @@ -284,14 +254,8 @@ def test_create_service_with_socket_timeout(self, **kwargs): self.validate_standard_account_endpoints( service, service_type[1], storage_account_name, storage_account_key ) - assert ( - service._client._client._pipeline._transport.connection_config.timeout - == 22 - ) - assert ( - default_service._client._client._pipeline._transport.connection_config.timeout - in [20, (20, 2000)] - ) + assert service._client._client._pipeline._transport.connection_config.timeout == 22 + assert default_service._client._client._pipeline._transport.connection_config.timeout in [20, (20, 2000)] @pytest.mark.parametrize( "account_url, expected_primary, expected_secondary", @@ -329,9 +293,7 @@ def test_create_service_with_socket_timeout(self, **kwargs): ], ) @QueuePreparer() - def test_create_service_ipv6( - self, account_url, expected_primary, expected_secondary, **kwargs - ): + def test_create_service_ipv6(self, account_url, expected_primary, expected_secondary, **kwargs): storage_account_name = "myaccount" storage_account_key = kwargs.pop("storage_account_key") @@ -387,9 +349,7 @@ def test_create_service_ipv6_custom_domain(self): hostname = "github.com" account_url = f"https://{hostname}" for service_type in SERVICES.keys(): - service = service_type( - account_url, credential=token_credential, queue_name="foo" - ) + service = service_type(account_url, credential=token_credential, queue_name="foo") assert service is not None assert service.scheme == "https" assert service.account_name is None @@ -408,9 +368,7 @@ def test_create_service_with_connection_string_key(self, **kwargs): for service_type in SERVICES.items(): # Act - service = service_type[0].from_connection_string( - conn_string, queue_name="foo" - ) + service = service_type[0].from_connection_string(conn_string, queue_name="foo") # Assert self.validate_standard_account_endpoints( @@ -433,9 +391,7 @@ def test_create_service_with_connection_string_sas(self, **kwargs): # Assert assert service is not None assert service.account_name == storage_account_name - assert service.url.startswith( - "https://" + storage_account_name + ".queue.core.windows.net" - ) + assert service.url.startswith("https://" + storage_account_name + ".queue.core.windows.net") assert service.url.endswith(self.sas_token) assert service.credential is None @@ -454,9 +410,7 @@ def test_create_service_with_connection_string_endpoint_protocol(self, **kwargs) for service_type in SERVICES.items(): # Act - service = service_type[0].from_connection_string( - conn_string, queue_name="foo" - ) + service = service_type[0].from_connection_string(conn_string, queue_name="foo") # Assert assert service is not None @@ -481,9 +435,7 @@ def test_create_service_with_connection_string_endpoint_protocol(self, **kwargs) def test_create_service_use_development_storage(self): for service_type in SERVICES.items(): # Act - service = service_type[0].from_connection_string( - "UseDevelopmentStorage=true;", queue_name="test" - ) + service = service_type[0].from_connection_string("UseDevelopmentStorage=true;", queue_name="test") # Assert assert service is not None @@ -507,9 +459,7 @@ def test_create_service_with_connection_string_custom_domain(self, **kwargs): ) # Act - service = service_type[0].from_connection_string( - conn_string, queue_name="foo" - ) + service = service_type[0].from_connection_string(conn_string, queue_name="foo") # Assert assert service is not None @@ -537,9 +487,7 @@ def test_create_service_with_conn_str_custom_domain_trailing_slash(self, **kwarg "QueueEndpoint=www.mydomain.com/;" ) # Act - service = service_type[0].from_connection_string( - conn_string, queue_name="foo" - ) + service = service_type[0].from_connection_string(conn_string, queue_name="foo") # Assert assert service is not None @@ -577,9 +525,7 @@ def test_create_service_with_conn_str_custom_domain_sec_override(self, **kwargs) assert service.credential.account_name == storage_account_name assert service.credential.account_key == storage_account_key.secret assert service.primary_endpoint.startswith("https://www.mydomain.com/") - assert service.secondary_endpoint.startswith( - "https://www-sec.mydomain.com/" - ) + assert service.secondary_endpoint.startswith("https://www-sec.mydomain.com/") @QueuePreparer() def test_create_service_with_conn_str_fails_if_sec_without_primary(self, **kwargs): @@ -597,9 +543,7 @@ def test_create_service_with_conn_str_fails_if_sec_without_primary(self, **kwarg # Fails if primary excluded with pytest.raises(ValueError): - service = service_type[0].from_connection_string( - conn_string, queue_name="foo" - ) + service = service_type[0].from_connection_string(conn_string, queue_name="foo") @QueuePreparer() def test_create_service_with_conn_str_succeeds_if_sec_with_primary(self, **kwargs): @@ -615,9 +559,7 @@ def test_create_service_with_conn_str_succeeds_if_sec_with_primary(self, **kwarg f"{_CONNECTION_ENDPOINTS_SECONDARY.get(service_type[1])}=www-sec.mydomain.com;" ) # Act - service = service_type[0].from_connection_string( - conn_string, queue_name="foo" - ) + service = service_type[0].from_connection_string(conn_string, queue_name="foo") # Assert assert service is not None @@ -625,18 +567,14 @@ def test_create_service_with_conn_str_succeeds_if_sec_with_primary(self, **kwarg assert service.credential.account_name == storage_account_name assert service.credential.account_key == storage_account_key.secret assert service.primary_endpoint.startswith("https://www.mydomain.com/") - assert service.secondary_endpoint.startswith( - "https://www-sec.mydomain.com/" - ) + assert service.secondary_endpoint.startswith("https://www-sec.mydomain.com/") @QueuePreparer() def test_create_service_with_custom_account_endpoint_path(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - custom_account_url = ( - "http://local-machine:11002/custom/account/path/" + self.sas_token - ) + custom_account_url = "http://local-machine:11002/custom/account/path/" + self.sas_token for service_type in SERVICES.items(): conn_string = ( f"DefaultEndpointsProtocol=http;" @@ -645,9 +583,7 @@ def test_create_service_with_custom_account_endpoint_path(self, **kwargs): f"QueueEndpoint={custom_account_url};" ) # Act - service = service_type[0].from_connection_string( - conn_string, queue_name="foo" - ) + service = service_type[0].from_connection_string(conn_string, queue_name="foo") # Assert assert service.account_name == storage_account_name @@ -659,29 +595,21 @@ def test_create_service_with_custom_account_endpoint_path(self, **kwargs): assert service.account_name == None assert service.credential == None assert service.primary_hostname == "local-machine:11002/custom/account/path" - assert service.url.startswith( - "http://local-machine:11002/custom/account/path/?" - ) + assert service.url.startswith("http://local-machine:11002/custom/account/path/?") service = QueueClient(account_url=custom_account_url, queue_name="foo") assert service.account_name == None assert service.queue_name == "foo" assert service.credential == None assert service.primary_hostname == "local-machine:11002/custom/account/path" - assert service.url.startswith( - "http://local-machine:11002/custom/account/path/foo?" - ) + assert service.url.startswith("http://local-machine:11002/custom/account/path/foo?") - service = QueueClient.from_queue_url( - "http://local-machine:11002/custom/account/path/foo" + self.sas_token - ) + service = QueueClient.from_queue_url("http://local-machine:11002/custom/account/path/foo" + self.sas_token) assert service.account_name == None assert service.queue_name == "foo" assert service.credential == None assert service.primary_hostname == "local-machine:11002/custom/account/path" - assert service.url.startswith( - "http://local-machine:11002/custom/account/path/foo?" - ) + assert service.url.startswith("http://local-machine:11002/custom/account/path/foo?") @QueuePreparer() @recorded_by_proxy @@ -743,10 +671,7 @@ def test_user_agent_default(self, **kwargs): def callback(response): assert "User-Agent" in response.http_request.headers - assert ( - f"azsdk-python-storage-queue/{VERSION}" - in response.http_request.headers["User-Agent"] - ) + assert f"azsdk-python-storage-queue/{VERSION}" in response.http_request.headers["User-Agent"] service.get_service_properties(raw_response_hook=callback) @@ -780,9 +705,7 @@ def callback(response): f"Python/{platform.python_version()} ({platform.platform()})" ) in response.http_request.headers["User-Agent"] - service.get_service_properties( - raw_response_hook=callback, user_agent="TestApp/v2.0" - ) + service.get_service_properties(raw_response_hook=callback, user_agent="TestApp/v2.0") @QueuePreparer() @recorded_by_proxy @@ -802,9 +725,7 @@ def callback(response): f"Python/{platform.python_version()} ({platform.platform()})" ) in response.http_request.headers["User-Agent"] - service.get_service_properties( - raw_response_hook=callback, user_agent="customer_user_agent" - ) + service.get_service_properties(raw_response_hook=callback, user_agent="customer_user_agent") @QueuePreparer() def test_create_queue_client_with_complete_queue_url(self, **kwargs): @@ -813,9 +734,7 @@ def test_create_queue_client_with_complete_queue_url(self, **kwargs): # Arrange queue_url = self.account_url(storage_account_name, "queue") + "/foo" - service = QueueClient( - queue_url, queue_name="bar", credential=storage_account_key.secret - ) + service = QueueClient(queue_url, queue_name="bar", credential=storage_account_key.secret) # Assert assert service.scheme == "https" @@ -837,20 +756,12 @@ def test_error_with_malformed_conn_str(self): for service_type in SERVICES.items(): # Act with pytest.raises(ValueError) as e: - service = service_type[0].from_connection_string( - conn_str, queue_name="test" - ) + service = service_type[0].from_connection_string(conn_str, queue_name="test") if conn_str in ("", "foobar", "foo;bar;baz", ";"): - assert ( - str(e.value) - == "Connection string is either blank or malformed." - ) + assert str(e.value) == "Connection string is either blank or malformed." elif conn_str in ("foobar=baz=foo", "foo=;bar=;", "=", "=;=="): - assert ( - str(e.value) - == "Connection string missing required connection details." - ) + assert str(e.value) == "Connection string missing required connection details." @QueuePreparer() def test_closing_pipeline_client(self, **kwargs): @@ -893,12 +804,8 @@ def test_get_and_set_queue_access_policy_oauth(self, **kwargs): self.setUp() # Arrange - service_client = QueueServiceClient( - self.account_url(storage_account_name, "queue"), self.token_credential - ) - queue_client = service_client.get_queue_client( - self.get_resource_name("pyqueuesync") - ) + service_client = QueueServiceClient(self.account_url(storage_account_name, "queue"), self.token_credential) + queue_client = service_client.get_queue_client(self.get_resource_name("pyqueuesync")) queue_client.create_queue() # Act / Assert diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_client_async.py b/sdk/storage/azure-storage-queue/tests/test_queue_client_async.py index 43d38fb2da67..5b942028a125 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_client_async.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_client_async.py @@ -41,22 +41,15 @@ def setUp(self): self.token_credential = self.get_credential(QueueServiceClient, is_async=True) # --Helpers----------------------------------------------------------------- - def validate_standard_account_endpoints( - self, service, url_type, storage_account_name, storage_account_key - ): + def validate_standard_account_endpoints(self, service, url_type, storage_account_name, storage_account_key): assert service is not None assert service.account_name == storage_account_name assert service.credential.account_name == storage_account_name assert service.credential.account_key == storage_account_key.secret assert f"{storage_account_name}.{url_type}.core.windows.net" in service.url - assert ( - f"{storage_account_name}-secondary.{url_type}.core.windows.net" - in service.secondary_endpoint - ) + assert f"{storage_account_name}-secondary.{url_type}.core.windows.net" in service.secondary_endpoint - def validate_ipv6_account_endpoints( - self, service, account_name, account_key, primary_endpoint, secondary_endpoint - ): + def validate_ipv6_account_endpoints(self, service, account_name, account_key, primary_endpoint, secondary_endpoint): assert service is not None assert service.scheme == "https" assert service.account_name == account_name @@ -94,9 +87,7 @@ def test_create_service_with_key(self, **kwargs): ) # Assert - self.validate_standard_account_endpoints( - service, url, storage_account_name, storage_account_key - ) + self.validate_standard_account_endpoints(service, url, storage_account_name, storage_account_key) assert service.scheme == "https" @QueuePreparer() @@ -107,9 +98,7 @@ def test_create_service_with_connection_string(self, **kwargs): for service_type in SERVICES.items(): # Act service = service_type[0].from_connection_string( - self.connection_string( - storage_account_name, storage_account_key.secret - ), + self.connection_string(storage_account_name, storage_account_key.secret), queue_name="test", ) @@ -137,9 +126,7 @@ def test_create_service_with_sas(self, **kwargs): # Assert assert service is not None assert service.account_name == storage_account_name - assert service.url.startswith( - "https://" + storage_account_name + ".queue.core.windows.net" - ) + assert service.url.startswith("https://" + storage_account_name + ".queue.core.windows.net") assert service.url.endswith(self.sas_token) assert service.credential is None @@ -159,9 +146,7 @@ async def test_create_service_with_token(self, **kwargs): # Assert assert service is not None assert service.account_name == storage_account_name - assert service.url.startswith( - "https://" + storage_account_name + ".queue.core.windows.net" - ) + assert service.url.startswith("https://" + storage_account_name + ".queue.core.windows.net") assert service.credential == self.token_credential assert not hasattr(service.credential, "account_key") assert hasattr(service.credential, "get_token") @@ -174,9 +159,7 @@ async def test_create_service_with_token_and_http(self, **kwargs): for service_type in SERVICES: # Act with pytest.raises(ValueError): - url = self.account_url(storage_account_name, "queue").replace( - "https", "http" - ) + url = self.account_url(storage_account_name, "queue").replace("https", "http") service_type(url, credential=self.token_credential, queue_name="foo") @QueuePreparer() @@ -188,12 +171,8 @@ def test_create_service_china(self, **kwargs): for service_type in SERVICES.items(): # Act - url = self.account_url(storage_account_name, "queue").replace( - "core.windows.net", "core.chinacloudapi.cn" - ) - service = service_type[0]( - url, credential=storage_account_key.secret, queue_name="foo" - ) + url = self.account_url(storage_account_name, "queue").replace("core.windows.net", "core.chinacloudapi.cn") + service = service_type[0](url, credential=storage_account_key.secret, queue_name="foo") # Assert assert service is not None @@ -222,12 +201,8 @@ def test_create_service_protocol(self, **kwargs): for service_type in SERVICES.items(): # Act - url = self.account_url(storage_account_name, "queue").replace( - "https", "http" - ) - service = service_type[0]( - url, credential=storage_account_key.secret, queue_name="foo" - ) + url = self.account_url(storage_account_name, "queue").replace("https", "http") + service = service_type[0](url, credential=storage_account_key.secret, queue_name="foo") # Assert self.validate_standard_account_endpoints( @@ -246,14 +221,9 @@ def test_create_service_empty_key(self, **kwargs): for service_type in QUEUE_SERVICES: # Act with pytest.raises(ValueError) as e: - test_service = service_type( - "testaccount", credential="", queue_name="foo" - ) + test_service = service_type("testaccount", credential="", queue_name="foo") - assert ( - str(e.value) - == "You need to provide either a SAS token or an account shared key to authenticate." - ) + assert str(e.value) == "You need to provide either a SAS token or an account shared key to authenticate." @QueuePreparer() def test_create_service_with_socket_timeout(self, **kwargs): @@ -280,14 +250,8 @@ def test_create_service_with_socket_timeout(self, **kwargs): self.validate_standard_account_endpoints( service, service_type[1], storage_account_name, storage_account_key ) - assert ( - service._client._client._pipeline._transport.connection_config.timeout - == 22 - ) - assert ( - default_service._client._client._pipeline._transport.connection_config.timeout - in [20, (20, 2000)] - ) + assert service._client._client._pipeline._transport.connection_config.timeout == 22 + assert default_service._client._client._pipeline._transport.connection_config.timeout in [20, (20, 2000)] @pytest.mark.parametrize( "account_url, expected_primary, expected_secondary", @@ -325,9 +289,7 @@ def test_create_service_with_socket_timeout(self, **kwargs): ], ) @QueuePreparer() - def test_create_service_ipv6( - self, account_url, expected_primary, expected_secondary, **kwargs - ): + def test_create_service_ipv6(self, account_url, expected_primary, expected_secondary, **kwargs): storage_account_name = "myaccount" storage_account_key = kwargs.pop("storage_account_key") @@ -383,9 +345,7 @@ def test_create_service_ipv6_custom_domain(self): hostname = "github.com" account_url = f"https://{hostname}" for service_type in SERVICES.keys(): - service = service_type( - account_url, credential=token_credential, queue_name="foo" - ) + service = service_type(account_url, credential=token_credential, queue_name="foo") assert service is not None assert service.scheme == "https" assert service.account_name is None @@ -400,15 +360,10 @@ def test_create_service_with_connection_string_key(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - conn_string = ( - f"AccountName={storage_account_name};" - f"AccountKey={storage_account_key.secret};" - ) + conn_string = f"AccountName={storage_account_name};" f"AccountKey={storage_account_key.secret};" for service_type in SERVICES.items(): # Act - service = service_type[0].from_connection_string( - conn_string, queue_name="foo" - ) + service = service_type[0].from_connection_string(conn_string, queue_name="foo") # Assert self.validate_standard_account_endpoints( @@ -422,10 +377,7 @@ def test_create_service_with_connection_string_sas(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - conn_string = ( - f"AccountName={storage_account_name};" - f"SharedAccessSignature={self.sas_token};" - ) + conn_string = f"AccountName={storage_account_name};" f"SharedAccessSignature={self.sas_token};" for service_type in SERVICES: # Act @@ -434,9 +386,7 @@ def test_create_service_with_connection_string_sas(self, **kwargs): # Assert assert service is not None assert service.account_name == storage_account_name - assert service.url.startswith( - "https://" + storage_account_name + ".queue.core.windows.net" - ) + assert service.url.startswith("https://" + storage_account_name + ".queue.core.windows.net") assert service.url.endswith(self.sas_token) assert service.credential is None @@ -454,9 +404,7 @@ def test_create_service_with_conn_str_endpoint_protocol(self, **kwargs): for service_type in SERVICES.items(): # Act - service = service_type[0].from_connection_string( - conn_string, queue_name="foo" - ) + service = service_type[0].from_connection_string(conn_string, queue_name="foo") # Assert assert service is not None @@ -481,9 +429,7 @@ def test_create_service_with_conn_str_endpoint_protocol(self, **kwargs): def test_create_service_use_development_storage(self): for service_type in SERVICES.items(): # Act - service = service_type[0].from_connection_string( - "UseDevelopmentStorage=true;", queue_name="test" - ) + service = service_type[0].from_connection_string("UseDevelopmentStorage=true;", queue_name="test") # Assert assert service is not None @@ -507,9 +453,7 @@ def test_create_service_with_connection_string_custom_domain(self, **kwargs): ) # Act - service = service_type[0].from_connection_string( - conn_string, queue_name="foo" - ) + service = service_type[0].from_connection_string(conn_string, queue_name="foo") # Assert assert service is not None @@ -535,9 +479,7 @@ def test_create_serv_with_cs_custom_dmn_trlng_slash(self, **kwargs): ) # Act - service = service_type[0].from_connection_string( - conn_string, queue_name="foo" - ) + service = service_type[0].from_connection_string(conn_string, queue_name="foo") # Assert assert service is not None @@ -573,9 +515,7 @@ def test_create_service_with_cs_custom_dmn_sec_override(self, **kwargs): assert service.credential.account_name == storage_account_name assert service.credential.account_key == storage_account_key.secret assert service.primary_endpoint.startswith("https://www.mydomain.com/") - assert service.secondary_endpoint.startswith( - "https://www-sec.mydomain.com/" - ) + assert service.secondary_endpoint.startswith("https://www-sec.mydomain.com/") @QueuePreparer() def test_create_service_with_cs_fails_if_sec_without_prim(self, **kwargs): @@ -594,9 +534,7 @@ def test_create_service_with_cs_fails_if_sec_without_prim(self, **kwargs): # Fails if primary excluded with pytest.raises(ValueError): - service = service_type[0].from_connection_string( - conn_string, queue_name="foo" - ) + service = service_type[0].from_connection_string(conn_string, queue_name="foo") @QueuePreparer() def test_create_service_with_cs_succeeds_if_sec_with_prim(self, **kwargs): @@ -613,9 +551,7 @@ def test_create_service_with_cs_succeeds_if_sec_with_prim(self, **kwargs): ) # Act - service = service_type[0].from_connection_string( - conn_string, queue_name="foo" - ) + service = service_type[0].from_connection_string(conn_string, queue_name="foo") # Assert assert service is not None @@ -623,18 +559,14 @@ def test_create_service_with_cs_succeeds_if_sec_with_prim(self, **kwargs): assert service.credential.account_name == storage_account_name assert service.credential.account_key == storage_account_key.secret assert service.primary_endpoint.startswith("https://www.mydomain.com/") - assert service.secondary_endpoint.startswith( - "https://www-sec.mydomain.com/" - ) + assert service.secondary_endpoint.startswith("https://www-sec.mydomain.com/") @QueuePreparer() def test_create_service_with_custom_account_endpoint_path(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - custom_account_url = ( - "http://local-machine:11002/custom/account/path/" + self.sas_token - ) + custom_account_url = "http://local-machine:11002/custom/account/path/" + self.sas_token for service_type in SERVICES.items(): conn_string = ( f"DefaultEndpointsProtocol=http;AccountName={storage_account_name};" @@ -643,9 +575,7 @@ def test_create_service_with_custom_account_endpoint_path(self, **kwargs): ) # Act - service = service_type[0].from_connection_string( - conn_string, queue_name="foo" - ) + service = service_type[0].from_connection_string(conn_string, queue_name="foo") # Assert assert service.account_name == storage_account_name @@ -657,29 +587,21 @@ def test_create_service_with_custom_account_endpoint_path(self, **kwargs): assert service.account_name == None assert service.credential == None assert service.primary_hostname == "local-machine:11002/custom/account/path" - assert service.url.startswith( - "http://local-machine:11002/custom/account/path/?" - ) + assert service.url.startswith("http://local-machine:11002/custom/account/path/?") service = QueueClient(account_url=custom_account_url, queue_name="foo") assert service.account_name == None assert service.queue_name == "foo" assert service.credential == None assert service.primary_hostname == "local-machine:11002/custom/account/path" - assert service.url.startswith( - "http://local-machine:11002/custom/account/path/foo?" - ) + assert service.url.startswith("http://local-machine:11002/custom/account/path/foo?") - service = QueueClient.from_queue_url( - "http://local-machine:11002/custom/account/path/foo" + self.sas_token - ) + service = QueueClient.from_queue_url("http://local-machine:11002/custom/account/path/foo" + self.sas_token) assert service.account_name == None assert service.queue_name == "foo" assert service.credential == None assert service.primary_hostname == "local-machine:11002/custom/account/path" - assert service.url.startswith( - "http://local-machine:11002/custom/account/path/foo?" - ) + assert service.url.startswith("http://local-machine:11002/custom/account/path/foo?") @QueuePreparer() @recorded_by_proxy_async @@ -741,10 +663,7 @@ async def test_user_agent_default(self, **kwargs): def callback(response): assert "User-Agent" in response.http_request.headers - assert ( - f"azsdk-python-storage-queue/{VERSION}" - in response.http_request.headers["User-Agent"] - ) + assert f"azsdk-python-storage-queue/{VERSION}" in response.http_request.headers["User-Agent"] await service.get_service_properties(raw_response_hook=callback) @@ -778,9 +697,7 @@ def callback(response): f"Python/{platform.python_version()} ({platform.platform()})" ) in response.http_request.headers["User-Agent"] - await service.get_service_properties( - raw_response_hook=callback, user_agent="TestApp/v2.0" - ) + await service.get_service_properties(raw_response_hook=callback, user_agent="TestApp/v2.0") @QueuePreparer() @recorded_by_proxy_async @@ -800,9 +717,7 @@ def callback(response): f"Python/{platform.python_version()} ({platform.platform()})" ) in response.http_request.headers["User-Agent"] - await service.get_service_properties( - raw_response_hook=callback, user_agent="customer_user_agent" - ) + await service.get_service_properties(raw_response_hook=callback, user_agent="customer_user_agent") @QueuePreparer() async def test_closing_pipeline_client(self, **kwargs): @@ -845,12 +760,8 @@ async def test_get_and_set_queue_access_policy_oauth(self, **kwargs): self.setUp() # Arrange - service_client = QueueServiceClient( - self.account_url(storage_account_name, "queue"), self.token_credential - ) - queue_client = service_client.get_queue_client( - self.get_resource_name("pyqueueasync") - ) + service_client = QueueServiceClient(self.account_url(storage_account_name, "queue"), self.token_credential) + queue_client = service_client.get_queue_client(self.get_resource_name("pyqueueasync")) await queue_client.create_queue() # Act / Assert diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_encodings.py b/sdk/storage/azure-storage-queue/tests/test_queue_encodings.py index 989c6d256a55..ac704c1b2bd8 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_encodings.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_encodings.py @@ -66,9 +66,7 @@ def test_message_text_xml(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange. - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) message = "" queue = qsc.get_queue_client(self.get_resource_name(TEST_QUEUE_PREFIX)) @@ -84,9 +82,7 @@ def test_message_text_xml_whitespace(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange. - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) message = " mess\t age1\n" queue = qsc.get_queue_client(self.get_resource_name(TEST_QUEUE_PREFIX)) @@ -100,9 +96,7 @@ def test_message_text_xml_invalid_chars(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action. - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = self._get_queue_reference(qsc) message = "\u0001" @@ -117,9 +111,7 @@ def test_message_text_base64(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange. - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = QueueClient( account_url=self.account_url(storage_account_name, "queue"), queue_name=self.get_resource_name(TEST_QUEUE_PREFIX), @@ -140,9 +132,7 @@ def test_message_bytes_base64(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange. - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = QueueClient( account_url=self.account_url(storage_account_name, "queue"), queue_name=self.get_resource_name(TEST_QUEUE_PREFIX), @@ -163,9 +153,7 @@ def test_message_bytes_fails(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = qsc.get_queue_client(self.get_resource_name("failqueue")) queue.create_queue() @@ -177,8 +165,7 @@ def test_message_bytes_fails(self, **kwargs): # Asserts assert str( e.exception.startswith( - "Message content must not be bytes. " - "Use the BinaryBase64EncodePolicy to send bytes." + "Message content must not be bytes. " "Use the BinaryBase64EncodePolicy to send bytes." ) ) @@ -188,9 +175,7 @@ def test_message_text_fails(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = QueueClient( account_url=self.account_url(storage_account_name, "queue"), queue_name=self.get_resource_name(TEST_QUEUE_PREFIX), @@ -214,9 +199,7 @@ def test_message_base64_decode_fails(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = QueueClient( account_url=self.account_url(storage_account_name, "queue"), queue_name=self.get_resource_name(TEST_QUEUE_PREFIX), diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_encodings_async.py b/sdk/storage/azure-storage-queue/tests/test_queue_encodings_async.py index 795e4fb18795..90951d298e72 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_encodings_async.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_encodings_async.py @@ -64,9 +64,7 @@ async def test_message_text_xml(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange. - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) message = "" queue = qsc.get_queue_client(self.get_resource_name(TEST_QUEUE_PREFIX)) @@ -80,9 +78,7 @@ async def test_message_text_xml_whitespace(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange. - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) message = " mess\t age1\n" queue = qsc.get_queue_client(self.get_resource_name(TEST_QUEUE_PREFIX)) @@ -96,9 +92,7 @@ async def test_message_text_xml_invalid_chars(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Action. - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = self._get_queue_reference(qsc) message = "\u0001" @@ -113,9 +107,7 @@ async def test_message_text_base64(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange. - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = QueueClient( account_url=self.account_url(storage_account_name, "queue"), queue_name=self.get_resource_name(TEST_QUEUE_PREFIX), @@ -136,9 +128,7 @@ async def test_message_bytes_base64(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange. - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = QueueClient( account_url=self.account_url(storage_account_name, "queue"), queue_name=self.get_resource_name(TEST_QUEUE_PREFIX), @@ -159,9 +149,7 @@ async def test_message_bytes_fails(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = await self._create_queue(qsc) # Action. with pytest.raises(TypeError) as e: @@ -171,8 +159,7 @@ async def test_message_bytes_fails(self, **kwargs): # Asserts assert str( e.exception.startswith( - "Message content must not be bytes. " - "Use the BinaryBase64EncodePolicy to send bytes." + "Message content must not be bytes. " "Use the BinaryBase64EncodePolicy to send bytes." ) ) @@ -182,9 +169,7 @@ async def test_message_text_fails(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = QueueClient( account_url=self.account_url(storage_account_name, "queue"), queue_name=self.get_resource_name(TEST_QUEUE_PREFIX), @@ -208,9 +193,7 @@ async def test_message_base64_decode_fails(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = QueueClient( account_url=self.account_url(storage_account_name, "queue"), queue_name=self.get_resource_name(TEST_QUEUE_PREFIX), diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_encryption.py b/sdk/storage/azure-storage-queue/tests/test_queue_encryption.py index 97c52230381b..08feb2090119 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_encryption.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_encryption.py @@ -77,9 +77,7 @@ def test_get_messages_encrypted_kek(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) qsc.key_encryption_key = KeyWrapper("key1") queue = self._create_queue(qsc) queue.send_message("encrypted_message_2") @@ -97,9 +95,7 @@ def test_get_messages_encrypted_resolver(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) qsc.key_encryption_key = KeyWrapper("key1") queue = self._create_queue(qsc) queue.send_message("encrypted_message_2") @@ -121,9 +117,7 @@ def test_peek_messages_encrypted_kek(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) qsc.key_encryption_key = KeyWrapper("key1") queue = self._create_queue(qsc) queue.send_message("encrypted_message_3") @@ -141,9 +135,7 @@ def test_peek_messages_encrypted_resolver(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) qsc.key_encryption_key = KeyWrapper("key1") queue = self._create_queue(qsc) queue.send_message("encrypted_message_4") @@ -168,9 +160,7 @@ def test_peek_messages_encrypted_kek_RSA(self, **kwargs): # the playback test will fail due to a change in kek values. # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) qsc.key_encryption_key = RSAKeyWrapper("key2") queue = self._create_queue(qsc) queue.send_message("encrypted_message_3") @@ -188,9 +178,7 @@ def test_update_encrypted_message(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = self._create_queue(qsc) queue.key_encryption_key = KeyWrapper("key1") queue.send_message("Update Me") @@ -213,9 +201,7 @@ def test_update_encrypted_binary_message(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = self._create_queue( qsc, message_encode_policy=BinaryBase64EncodePolicy(), @@ -249,12 +235,8 @@ def test_update_encrypted_raw_text_message(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) - queue = self._create_queue( - qsc, message_encode_policy=None, message_decode_policy=None - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + queue = self._create_queue(qsc, message_encode_policy=None, message_decode_policy=None) queue.key_encryption_key = KeyWrapper("key1") raw_text = "Update Me" @@ -279,12 +261,8 @@ def test_update_encrypted_json_message(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) - queue = self._create_queue( - qsc, message_encode_policy=None, message_decode_policy=None - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) + queue = self._create_queue(qsc, message_encode_policy=None, message_decode_policy=None) queue.key_encryption_key = KeyWrapper("key1") message_dict = {"val1": 1, "val2": "2"} @@ -312,9 +290,7 @@ def test_invalid_value_kek_wrap(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = self._create_queue(qsc) queue.key_encryption_key = KeyWrapper("key1") queue.key_encryption_key.get_kid = None @@ -322,9 +298,7 @@ def test_invalid_value_kek_wrap(self, **kwargs): with pytest.raises(AttributeError) as e: queue.send_message("message") - assert str(e.value.args[0]), _ERROR_OBJECT_INVALID.format( - "key encryption key" == "get_kid" - ) + assert str(e.value.args[0]), _ERROR_OBJECT_INVALID.format("key encryption key" == "get_kid") queue.key_encryption_key = KeyWrapper("key1") queue.key_encryption_key.get_kid = None @@ -343,17 +317,13 @@ def test_missing_attribute_kek_wrap(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = self._create_queue(qsc) valid_key = KeyWrapper("key1") # Act - invalid_key_1 = ( - lambda: None - ) # functions are objects, so this effectively creates an empty object + invalid_key_1 = lambda: None # functions are objects, so this effectively creates an empty object invalid_key_1.get_key_wrap_algorithm = valid_key.get_key_wrap_algorithm invalid_key_1.get_kid = valid_key.get_kid # No attribute wrap_key @@ -361,9 +331,7 @@ def test_missing_attribute_kek_wrap(self, **kwargs): with pytest.raises(AttributeError): queue.send_message("message") - invalid_key_2 = ( - lambda: None - ) # functions are objects, so this effectively creates an empty object + invalid_key_2 = lambda: None # functions are objects, so this effectively creates an empty object invalid_key_2.wrap_key = valid_key.wrap_key invalid_key_2.get_kid = valid_key.get_kid # No attribute get_key_wrap_algorithm @@ -371,9 +339,7 @@ def test_missing_attribute_kek_wrap(self, **kwargs): with pytest.raises(AttributeError): queue.send_message("message") - invalid_key_3 = ( - lambda: None - ) # functions are objects, so this effectively creates an empty object + invalid_key_3 = lambda: None # functions are objects, so this effectively creates an empty object invalid_key_3.get_key_wrap_algorithm = valid_key.get_key_wrap_algorithm invalid_key_3.wrap_key = valid_key.wrap_key # No attribute get_kid @@ -388,9 +354,7 @@ def test_invalid_value_kek_unwrap(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = self._create_queue(qsc) queue.key_encryption_key = KeyWrapper("key1") queue.send_message("message") @@ -411,18 +375,14 @@ def test_missing_attribute_kek_unwrap(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = self._create_queue(qsc) queue.key_encryption_key = KeyWrapper("key1") queue.send_message("message") # Act valid_key = KeyWrapper("key1") - invalid_key_1 = ( - lambda: None - ) # functions are objects, so this effectively creates an empty object + invalid_key_1 = lambda: None # functions are objects, so this effectively creates an empty object invalid_key_1.unwrap_key = valid_key.unwrap_key # No attribute get_kid queue.key_encryption_key = invalid_key_1 @@ -431,9 +391,7 @@ def test_missing_attribute_kek_unwrap(self, **kwargs): assert "Decryption failed." in str(e.value.args[0]) - invalid_key_2 = ( - lambda: None - ) # functions are objects, so this effectively creates an empty object + invalid_key_2 = lambda: None # functions are objects, so this effectively creates an empty object invalid_key_2.get_kid = valid_key.get_kid # No attribute unwrap_key queue.key_encryption_key = invalid_key_2 @@ -447,9 +405,7 @@ def test_validate_encryption(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = self._create_queue(qsc) kek = KeyWrapper("key1") queue.key_encryption_key = kek @@ -471,9 +427,7 @@ def test_validate_encryption(self, **kwargs): ) encryption_agent = encryption_data["EncryptionAgent"] - encryption_agent = _EncryptionAgent( - encryption_agent["EncryptionAlgorithm"], encryption_agent["Protocol"] - ) + encryption_agent = _EncryptionAgent(encryption_agent["EncryptionAlgorithm"], encryption_agent["Protocol"]) encryption_data = _EncryptionData( b64decode(encryption_data["ContentEncryptionIV"].encode(encoding="utf-8")), @@ -516,9 +470,7 @@ def test_put_with_strict_mode(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = self._create_queue(qsc) kek = KeyWrapper("key1") queue.key_encryption_key = kek @@ -540,9 +492,7 @@ def test_get_with_strict_mode(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = self._create_queue(qsc) queue.send_message("message") @@ -551,9 +501,7 @@ def test_get_with_strict_mode(self, **kwargs): with pytest.raises(ValueError) as e: next(queue.receive_messages()) - assert "Message was either not encrypted or metadata was incorrect." in str( - e.value.args[0] - ) + assert "Message was either not encrypted or metadata was incorrect." in str(e.value.args[0]) @QueuePreparer() @recorded_by_proxy @@ -562,9 +510,7 @@ def test_encryption_add_encrypted_64k_message(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = self._create_queue(qsc) message = "a" * 1024 * 64 @@ -583,9 +529,7 @@ def test_encryption_nonmatching_kid(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) queue = self._create_queue(qsc) queue.key_encryption_key = KeyWrapper("key1") queue.send_message("message") @@ -861,9 +805,7 @@ def assert_user_agent(request): key_encryption_key=kek, ) queue = self._create_queue(qsc) - queue.send_message( - content, raw_request_hook=assert_user_agent, user_agent=app_id - ) + queue.send_message(content, raw_request_hook=assert_user_agent, user_agent=app_id) # Test client constructor level keyword qsc = QueueServiceClient( diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_encryption_async.py b/sdk/storage/azure-storage-queue/tests/test_queue_encryption_async.py index 02177d3375b4..955c6ebdad7c 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_encryption_async.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_encryption_async.py @@ -76,9 +76,7 @@ async def test_get_messages_encrypted_kek(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) qsc.key_encryption_key = KeyWrapper("key1") queue = await self._create_queue(qsc) await queue.send_message("encrypted_message_2") @@ -98,9 +96,7 @@ async def test_get_messages_encrypted_resolver(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) qsc.key_encryption_key = KeyWrapper("key1") queue = await self._create_queue(qsc) await queue.send_message("encrypted_message_2") @@ -123,9 +119,7 @@ async def test_peek_messages_encrypted_kek(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Arrange qsc.key_encryption_key = KeyWrapper("key1") queue = await self._create_queue(qsc) @@ -143,9 +137,7 @@ async def test_peek_messages_encrypted_resolver(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Arrange qsc.key_encryption_key = KeyWrapper("key1") queue = await self._create_queue(qsc) @@ -167,9 +159,7 @@ async def test_peek_messages_encrypted_kek_RSA(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # We can only generate random RSA keys, so this must be run live or # the playback test will fail due to a change in kek values. @@ -190,9 +180,7 @@ async def test_update_encrypted_message(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Arrange queue = await self._create_queue(qsc) queue.key_encryption_key = KeyWrapper("key1") @@ -219,9 +207,7 @@ async def test_update_encrypted_binary_message(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Arrange queue = await self._create_queue( qsc, @@ -255,13 +241,9 @@ async def test_update_encrypted_raw_text_message(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Arrange - queue = await self._create_queue( - qsc, message_encode_policy=None, message_decode_policy=None - ) + queue = await self._create_queue(qsc, message_encode_policy=None, message_decode_policy=None) queue.key_encryption_key = KeyWrapper("key1") raw_text = "Update Me" @@ -287,13 +269,9 @@ async def test_update_encrypted_json_message(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Arrange - queue = await self._create_queue( - qsc, message_encode_policy=None, message_decode_policy=None - ) + queue = await self._create_queue(qsc, message_encode_policy=None, message_decode_policy=None) queue.key_encryption_key = KeyWrapper("key1") message_dict = {"val1": 1, "val2": "2"} @@ -324,9 +302,7 @@ async def test_invalid_value_kek_wrap(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Arrange queue = await self._create_queue(qsc) queue.key_encryption_key = KeyWrapper("key1") @@ -335,9 +311,7 @@ async def test_invalid_value_kek_wrap(self, **kwargs): with pytest.raises(AttributeError) as e: await queue.send_message("message") - assert str(e.value.args[0]), _ERROR_OBJECT_INVALID.format( - "key encryption key" == "get_kid" - ) + assert str(e.value.args[0]), _ERROR_OBJECT_INVALID.format("key encryption key" == "get_kid") queue.key_encryption_key = KeyWrapper("key1") queue.key_encryption_key.get_kid = None @@ -355,18 +329,14 @@ async def test_missing_attribute_kek_wrap(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Arrange queue = await self._create_queue(qsc) valid_key = KeyWrapper("key1") # Act - invalid_key_1 = ( - lambda: None - ) # functions are objects, so this effectively creates an empty object + invalid_key_1 = lambda: None # functions are objects, so this effectively creates an empty object invalid_key_1.get_key_wrap_algorithm = valid_key.get_key_wrap_algorithm invalid_key_1.get_kid = valid_key.get_kid # No attribute wrap_key @@ -374,9 +344,7 @@ async def test_missing_attribute_kek_wrap(self, **kwargs): with pytest.raises(AttributeError): await queue.send_message("message") - invalid_key_2 = ( - lambda: None - ) # functions are objects, so this effectively creates an empty object + invalid_key_2 = lambda: None # functions are objects, so this effectively creates an empty object invalid_key_2.wrap_key = valid_key.wrap_key invalid_key_2.get_kid = valid_key.get_kid # No attribute get_key_wrap_algorithm @@ -384,9 +352,7 @@ async def test_missing_attribute_kek_wrap(self, **kwargs): with pytest.raises(AttributeError): await queue.send_message("message") - invalid_key_3 = ( - lambda: None - ) # functions are objects, so this effectively creates an empty object + invalid_key_3 = lambda: None # functions are objects, so this effectively creates an empty object invalid_key_3.get_key_wrap_algorithm = valid_key.get_key_wrap_algorithm invalid_key_3.wrap_key = valid_key.wrap_key # No attribute get_kid @@ -400,9 +366,7 @@ async def test_invalid_value_kek_unwrap(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Arrange queue = await self._create_queue(qsc) queue.key_encryption_key = KeyWrapper("key1") @@ -423,9 +387,7 @@ async def test_missing_attribute_kek_unwrap(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Arrange queue = await self._create_queue(qsc) queue.key_encryption_key = KeyWrapper("key1") @@ -433,9 +395,7 @@ async def test_missing_attribute_kek_unwrap(self, **kwargs): # Act valid_key = KeyWrapper("key1") - invalid_key_1 = ( - lambda: None - ) # functions are objects, so this effectively creates an empty object + invalid_key_1 = lambda: None # functions are objects, so this effectively creates an empty object invalid_key_1.unwrap_key = valid_key.unwrap_key # No attribute get_kid queue.key_encryption_key = invalid_key_1 @@ -444,9 +404,7 @@ async def test_missing_attribute_kek_unwrap(self, **kwargs): assert "Decryption failed." in str(e.value.args[0]) - invalid_key_2 = ( - lambda: None - ) # functions are objects, so this effectively creates an empty object + invalid_key_2 = lambda: None # functions are objects, so this effectively creates an empty object invalid_key_2.get_kid = valid_key.get_kid # No attribute unwrap_key queue.key_encryption_key = invalid_key_2 @@ -459,9 +417,7 @@ async def test_validate_encryption(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Arrange queue = await self._create_queue(qsc) kek = KeyWrapper("key1") @@ -484,9 +440,7 @@ async def test_validate_encryption(self, **kwargs): ) encryption_agent = encryption_data["EncryptionAgent"] - encryption_agent = _EncryptionAgent( - encryption_agent["EncryptionAlgorithm"], encryption_agent["Protocol"] - ) + encryption_agent = _EncryptionAgent(encryption_agent["EncryptionAlgorithm"], encryption_agent["Protocol"]) encryption_data = _EncryptionData( b64decode(encryption_data["ContentEncryptionIV"].encode(encoding="utf-8")), @@ -528,9 +482,7 @@ async def test_put_with_strict_mode(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Arrange queue = await self._create_queue(qsc) kek = KeyWrapper("key1") @@ -552,9 +504,7 @@ async def test_get_with_strict_mode(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Arrange queue = await self._create_queue(qsc) await queue.send_message("message") @@ -566,9 +516,7 @@ async def test_get_with_strict_mode(self, **kwargs): async for m in queue.receive_messages(): messages.append(m) _ = messages[0] - assert "Message was either not encrypted or metadata was incorrect." in str( - e.value.args[0] - ) + assert "Message was either not encrypted or metadata was incorrect." in str(e.value.args[0]) @QueuePreparer() @recorded_by_proxy_async @@ -576,9 +524,7 @@ async def test_encryption_add_encrypted_64k_message(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Arrange queue = await self._create_queue(qsc) message = "a" * 1024 * 64 @@ -597,9 +543,7 @@ async def test_encryption_nonmatching_kid(self, **kwargs): storage_account_name = kwargs.pop("storage_account_name") storage_account_key = kwargs.pop("storage_account_key") - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Arrange queue = await self._create_queue(qsc) queue.key_encryption_key = KeyWrapper("key1") @@ -878,9 +822,7 @@ def assert_user_agent(request): key_encryption_key=kek, ) queue = await self._create_queue(qsc) - await queue.send_message( - content, raw_request_hook=assert_user_agent, user_agent=app_id - ) + await queue.send_message(content, raw_request_hook=assert_user_agent, user_agent=app_id) # Test client constructor level keyword qsc = QueueServiceClient( diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_service_properties.py b/sdk/storage/azure-storage-queue/tests/test_queue_service_properties.py index e3deba34540d..bfb063905112 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_service_properties.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_service_properties.py @@ -67,9 +67,7 @@ def _assert_delete_retention_policy_not_equal(self, policy1, policy2): assert policy1 != policy2 return - assert (policy1.enabled == policy2.enabled) is False or ( - policy1.days == policy2.days - ) is False + assert (policy1.enabled == policy2.enabled) is False or (policy1.days == policy2.days) is False def _assert_metrics_equal(self, metrics1, metrics2): if metrics1 is None or metrics2 is None: @@ -79,9 +77,7 @@ def _assert_metrics_equal(self, metrics1, metrics2): assert metrics1.version == metrics2.version assert metrics1.enabled == metrics2.enabled assert metrics1.include_apis == metrics2.include_apis - self._assert_retention_equal( - metrics1.retention_policy, metrics2.retention_policy - ) + self._assert_retention_equal(metrics1.retention_policy, metrics2.retention_policy) def _assert_cors_equal(self, cors1, cors2): if cors1 is None or cors2 is None: @@ -112,9 +108,7 @@ def test_queue_service_properties(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Act resp = qsc.set_service_properties( analytics_logging=QueueAnalyticsLogging(), @@ -136,9 +130,7 @@ def test_set_logging(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) logging = QueueAnalyticsLogging( read=True, write=True, @@ -160,9 +152,7 @@ def test_set_hour_metrics(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) hour_metrics = Metrics( enabled=True, include_apis=True, @@ -183,9 +173,7 @@ def test_set_minute_metrics(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) minute_metrics = Metrics( enabled=True, include_apis=True, @@ -206,9 +194,7 @@ def test_set_cors(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) cors_rule1 = CorsRule(["www.xyz.com"], ["GET"]) allowed_origins = ["www.xyz.com", "www.ab.com", "www.bc.com"] @@ -259,17 +245,13 @@ def test_too_many_cors_rules(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) cors = [] for i in range(0, 6): cors.append(CorsRule(["www.xyz.com"], ["GET"])) # Assert - pytest.raises( - HttpResponseError, qsc.set_service_properties, None, None, None, cors - ) + pytest.raises(HttpResponseError, qsc.set_service_properties, None, None, None, cors) @QueuePreparer() @recorded_by_proxy @@ -278,9 +260,7 @@ def test_retention_too_long(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) minute_metrics = Metrics( enabled=True, include_apis=True, @@ -288,9 +268,7 @@ def test_retention_too_long(self, **kwargs): ) # Assert - pytest.raises( - HttpResponseError, qsc.set_service_properties, None, None, minute_metrics - ) + pytest.raises(HttpResponseError, qsc.set_service_properties, None, None, minute_metrics) # ------------------------------------------------------------------------------ diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_service_properties_async.py b/sdk/storage/azure-storage-queue/tests/test_queue_service_properties_async.py index 19f966488406..d461bac0d042 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_service_properties_async.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_service_properties_async.py @@ -63,9 +63,7 @@ def _assert_delete_retention_policy_not_equal(self, policy1, policy2): assert policy1 != policy2 return - assert (policy1.enabled == policy2.enabled) is False or ( - policy1.days == policy2.days - ) is False + assert (policy1.enabled == policy2.enabled) is False or (policy1.days == policy2.days) is False def _assert_metrics_equal(self, metrics1, metrics2): if metrics1 is None or metrics2 is None: @@ -75,9 +73,7 @@ def _assert_metrics_equal(self, metrics1, metrics2): assert metrics1.version == metrics2.version assert metrics1.enabled == metrics2.enabled assert metrics1.include_apis == metrics2.include_apis - self._assert_retention_equal( - metrics1.retention_policy, metrics2.retention_policy - ) + self._assert_retention_equal(metrics1.retention_policy, metrics2.retention_policy) def _assert_cors_equal(self, cors1, cors2): if cors1 is None or cors2 is None: @@ -108,9 +104,7 @@ async def test_queue_service_properties(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Act resp = await qsc.set_service_properties( @@ -133,9 +127,7 @@ async def test_set_logging(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) logging = QueueAnalyticsLogging( read=True, write=True, @@ -157,9 +149,7 @@ async def test_set_hour_metrics(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) hour_metrics = Metrics( enabled=True, include_apis=True, @@ -180,9 +170,7 @@ async def test_set_minute_metrics(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) minute_metrics = Metrics( enabled=True, include_apis=True, @@ -203,9 +191,7 @@ async def test_set_cors(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) cors_rule1 = CorsRule(["www.xyz.com"], ["GET"]) allowed_origins = ["www.xyz.com", "www.ab.com", "www.bc.com"] @@ -248,9 +234,7 @@ async def test_retention_no_days(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Assert - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) pytest.raises(ValueError, RetentionPolicy, True, None) @QueuePreparer() @@ -260,9 +244,7 @@ async def test_too_many_cors_rules(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) cors = [] for _ in range(0, 6): cors.append(CorsRule(["www.xyz.com"], ["GET"])) @@ -278,9 +260,7 @@ async def test_retention_too_long(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) minute_metrics = Metrics( enabled=True, include_apis=True, diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_service_stats.py b/sdk/storage/azure-storage-queue/tests/test_queue_service_stats.py index aa818fb53473..6c07b58a264c 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_service_stats.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_service_stats.py @@ -40,9 +40,7 @@ def test_queue_service_stats(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Act stats = qsc.get_service_stats() @@ -57,9 +55,7 @@ def test_queue_service_stats_when_unavailable(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Act stats = qsc.get_service_stats() diff --git a/sdk/storage/azure-storage-queue/tests/test_queue_service_stats_async.py b/sdk/storage/azure-storage-queue/tests/test_queue_service_stats_async.py index 2c7ca3b097ec..23a0f0ade37e 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_service_stats_async.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_service_stats_async.py @@ -40,9 +40,7 @@ async def test_queue_service_stats(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Act stats = await qsc.get_service_stats() @@ -57,9 +55,7 @@ async def test_queue_service_stats_when_unavailable(self, **kwargs): storage_account_key = kwargs.pop("storage_account_key") # Arrange - qsc = QueueServiceClient( - self.account_url(storage_account_name, "queue"), storage_account_key.secret - ) + qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key.secret) # Act stats = await qsc.get_service_stats() From 3d8650d3f5ed240383c001e3aaeec6c84c4d4396 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 27 Mar 2026 21:58:06 -0400 Subject: [PATCH 15/16] Changelogs --- sdk/storage/azure-storage-blob/CHANGELOG.md | 2 +- .../azure/storage/blob/_shared/base_client.py | 2 +- sdk/storage/azure-storage-file-datalake/CHANGELOG.md | 2 +- .../azure/storage/filedatalake/_shared/base_client.py | 2 +- sdk/storage/azure-storage-file-share/CHANGELOG.md | 2 +- .../azure/storage/fileshare/_shared/base_client.py | 2 +- sdk/storage/azure-storage-queue/CHANGELOG.md | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/sdk/storage/azure-storage-blob/CHANGELOG.md b/sdk/storage/azure-storage-blob/CHANGELOG.md index afba2e87753f..558142d2830c 100644 --- a/sdk/storage/azure-storage-blob/CHANGELOG.md +++ b/sdk/storage/azure-storage-blob/CHANGELOG.md @@ -1,6 +1,6 @@ # Release History -## 12.30.0b1 (2026-03-26) +## 12.30.0b1 (2026-03-30) ### Features Added - Added support for service version 2026-06-06. diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_shared/base_client.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_shared/base_client.py index 9674127b7952..8fd641acd2c2 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_shared/base_client.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_shared/base_client.py @@ -82,7 +82,7 @@ def _construct_endpoints(netloc: str, account_part: str) -> Tuple[str, str, str] Construct primary and secondary hostnames from a storage account URL's netloc. :param str netloc: The network location in a URL. - :param account_part: The account part after parsing the URL. + :param str account_part: The account part after parsing the URL. :return: The account name, primary hostname, and secondary hostname. :rtype: Tuple[str, str, str] """ diff --git a/sdk/storage/azure-storage-file-datalake/CHANGELOG.md b/sdk/storage/azure-storage-file-datalake/CHANGELOG.md index e0ecbb7b7767..84023d4cb254 100644 --- a/sdk/storage/azure-storage-file-datalake/CHANGELOG.md +++ b/sdk/storage/azure-storage-file-datalake/CHANGELOG.md @@ -1,6 +1,6 @@ # Release History -## 12.25.0b1 (2026-03-26) +## 12.25.0b1 (2026-03-30) ### Features Added - Added support for service version 2026-06-06. diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared/base_client.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared/base_client.py index ea3ceefded6f..57095ca402aa 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared/base_client.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared/base_client.py @@ -82,7 +82,7 @@ def _construct_endpoints(netloc: str, account_part: str) -> Tuple[str, str, str] Construct primary and secondary hostnames from a storage account URL's netloc. :param str netloc: The network location in a URL. - :param account_part: The account part after parsing the URL. + :param str account_part: The account part after parsing the URL. :return: The account name, primary hostname, and secondary hostname. :rtype: Tuple[str, str, str] """ diff --git a/sdk/storage/azure-storage-file-share/CHANGELOG.md b/sdk/storage/azure-storage-file-share/CHANGELOG.md index 23171cb39d6c..59a3eabdd064 100644 --- a/sdk/storage/azure-storage-file-share/CHANGELOG.md +++ b/sdk/storage/azure-storage-file-share/CHANGELOG.md @@ -1,6 +1,6 @@ # Release History -## 12.26.0b1 (2026-03-26) +## 12.26.0b1 (2026-03-30) ### Features Added - Added support for service version 2026-06-06. diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/base_client.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/base_client.py index ea3ceefded6f..57095ca402aa 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/base_client.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/base_client.py @@ -82,7 +82,7 @@ def _construct_endpoints(netloc: str, account_part: str) -> Tuple[str, str, str] Construct primary and secondary hostnames from a storage account URL's netloc. :param str netloc: The network location in a URL. - :param account_part: The account part after parsing the URL. + :param str account_part: The account part after parsing the URL. :return: The account name, primary hostname, and secondary hostname. :rtype: Tuple[str, str, str] """ diff --git a/sdk/storage/azure-storage-queue/CHANGELOG.md b/sdk/storage/azure-storage-queue/CHANGELOG.md index 9aa5c12bd37c..f48f6c62d0ea 100644 --- a/sdk/storage/azure-storage-queue/CHANGELOG.md +++ b/sdk/storage/azure-storage-queue/CHANGELOG.md @@ -1,6 +1,6 @@ # Release History -## 12.17.0b1 (2026-03-26) +## 12.17.0b1 (2026-03-30) ### Features Added - Added support for service version 2026-06-06. From 72bcf69fe4f98099ce26e58e6376d95e744806f7 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 27 Mar 2026 23:15:50 -0400 Subject: [PATCH 16/16] More pylint problems --- .../azure/storage/queue/_shared/authentication.py | 4 ++-- .../azure/storage/queue/_shared/base_client.py | 4 ++-- .../azure/storage/queue/_shared/base_client_async.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/authentication.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/authentication.py index 1c8cb02bd67d..cdbeeace2427 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/authentication.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/authentication.py @@ -16,9 +16,9 @@ pass try: - from azure.core.pipeline.transport import ( + from azure.core.pipeline.transport import ( # pylint: disable=non-abstract-transport-import AioHttpTransport, - ) # pylint: disable=non-abstract-transport-import + ) except ImportError: AioHttpTransport = None diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client.py index e4e037e73239..86734de7a20b 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client.py @@ -68,10 +68,10 @@ if TYPE_CHECKING: from azure.core.credentials_async import AsyncTokenCredential - from azure.core.pipeline.transport import ( + from azure.core.pipeline.transport import ( # pylint: disable=C4756 HttpRequest, HttpResponse, - ) # pylint: disable=C4756 + ) _LOGGER = logging.getLogger(__name__) _SERVICE_PARAMS = { diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client_async.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client_async.py index 74d80d8c21be..54446f7fc5b4 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client_async.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client_async.py @@ -49,10 +49,10 @@ from .._shared_access_signature import _is_credential_sastoken if TYPE_CHECKING: - from azure.core.pipeline.transport import ( + from azure.core.pipeline.transport import ( # pylint: disable=C4756 HttpRequest, HttpResponse, - ) # pylint: disable=C4756 + ) _LOGGER = logging.getLogger(__name__) _SERVICE_PARAMS = {