From 637e3c55ed5c4777b1aebea2f258025e51cc846e Mon Sep 17 00:00:00 2001 From: Vincent Tran Date: Thu, 23 Jun 2022 17:00:22 -0700 Subject: [PATCH 01/17] Ready for draft PR blob, then finish blob --- .../azure/storage/blob/_shared/base_client.py | 6 ++- ...est_azure_named_key_credential_access.yaml | 40 +++++++++++++++++++ ...est_azure_named_key_credential_access.yaml | 29 ++++++++++++++ .../tests/test_common_blob.py | 15 ++++++- .../tests/test_common_blob_async.py | 16 +++++++- 5 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 sdk/storage/azure-storage-blob/tests/recordings/test_common_blob.test_azure_named_key_credential_access.yaml create mode 100644 sdk/storage/azure-storage-blob/tests/recordings/test_common_blob_async.test_azure_named_key_credential_access.yaml 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 60d1d775f9db..29246c7d3373 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 @@ -21,7 +21,7 @@ import six from azure.core.configuration import Configuration -from azure.core.credentials import AzureSasCredential +from azure.core.credentials import AzureSasCredential, AzureNamedKeyCredential from azure.core.exceptions import HttpResponseError from azure.core.pipeline import Pipeline from azure.core.pipeline.transport import RequestsTransport, HttpTransport @@ -54,6 +54,8 @@ from .._version import VERSION from .response_handlers import process_storage_error, PartialBatchErrorException +if TYPE_CHECKING: + from azure.core.credentials import TokenCredential _LOGGER = logging.getLogger(__name__) _SERVICE_PARAMS = { @@ -364,6 +366,8 @@ def _format_shared_key_credential(account_name, credential): if "account_key" not in 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 credential diff --git a/sdk/storage/azure-storage-blob/tests/recordings/test_common_blob.test_azure_named_key_credential_access.yaml b/sdk/storage/azure-storage-blob/tests/recordings/test_common_blob.test_azure_named_key_credential_access.yaml new file mode 100644 index 000000000000..00ddc7cfd9e6 --- /dev/null +++ b/sdk/storage/azure-storage-blob/tests/recordings/test_common_blob.test_azure_named_key_credential_access.yaml @@ -0,0 +1,40 @@ +interactions: +- request: + body: null + headers: + Accept: + - application/xml + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '0' + User-Agent: + - azsdk-python-storage-blob/12.13.0 Python/3.10.2 (Windows-10-10.0.19044-SP0) + x-ms-date: + - Thu, 23 Jun 2022 23:44:15 GMT + x-ms-version: + - '2021-08-06' + method: PUT + uri: https://storagename.blob.core.windows.net/container76851672?restype=container + response: + body: + string: '' + headers: + content-length: + - '0' + date: + - Thu, 23 Jun 2022 23:44:16 GMT + etag: + - '"0x8DA557248FF6AA9"' + last-modified: + - Thu, 23 Jun 2022 23:44:16 GMT + server: + - Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0 + x-ms-version: + - '2021-08-06' + status: + code: 201 + message: Created +version: 1 diff --git a/sdk/storage/azure-storage-blob/tests/recordings/test_common_blob_async.test_azure_named_key_credential_access.yaml b/sdk/storage/azure-storage-blob/tests/recordings/test_common_blob_async.test_azure_named_key_credential_access.yaml new file mode 100644 index 000000000000..c83ff83bf5fc --- /dev/null +++ b/sdk/storage/azure-storage-blob/tests/recordings/test_common_blob_async.test_azure_named_key_credential_access.yaml @@ -0,0 +1,29 @@ +interactions: +- request: + body: null + headers: + Accept: + - application/xml + User-Agent: + - azsdk-python-storage-blob/12.13.0 Python/3.10.2 (Windows-10-10.0.19044-SP0) + x-ms-date: + - Thu, 23 Jun 2022 23:47:19 GMT + x-ms-version: + - '2021-08-06' + method: PUT + uri: https://storagename.blob.core.windows.net/container81e18ef?restype=container + response: + body: + string: '' + headers: + content-length: '0' + date: Thu, 23 Jun 2022 23:47:19 GMT + etag: '"0x8DA5572B65BCF75"' + last-modified: Thu, 23 Jun 2022 23:47:20 GMT + server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0 + x-ms-version: '2021-08-06' + status: + code: 201 + message: Created + url: https://vincenttranstock.blob.core.windows.net/container81e18ef?restype=container +version: 1 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 335ec13bdeef..c6cb064930fb 100644 --- a/sdk/storage/azure-storage-blob/tests/test_common_blob.py +++ b/sdk/storage/azure-storage-blob/tests/test_common_blob.py @@ -18,7 +18,7 @@ from azure.core import MatchConditions -from azure.core.credentials import AzureSasCredential +from azure.core.credentials import AzureSasCredential, AzureNamedKeyCredential from azure.core.exceptions import ( HttpResponseError, ResourceNotFoundError, @@ -1995,6 +1995,19 @@ def test_account_sas_credential(self, storage_account_name, storage_account_key) self.assertEqual(blob_name, blob_properties.name) self.assertEqual(self.container_name, container_properties.name) + @BlobPreparer() + def test_azure_named_key_credential_access(self, storage_account_name, storage_account_key): + named_key = AzureNamedKeyCredential(storage_account_name, storage_account_key) + bsc = BlobServiceClient(self.account_url(storage_account_name, "blob"), named_key) + container_name = self._get_container_reference() + + # Act + container = bsc.get_container_client(container_name) + created = container.create_container() + + # Assert + self.assertTrue(created) + @BlobPreparer() def test_get_user_delegation_key(self, storage_account_name, storage_account_key): # Act 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 907e1055ee98..d8e27db56a26 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 @@ -19,7 +19,7 @@ from azure.mgmt.storage.aio import StorageManagementClient from azure.core import MatchConditions -from azure.core.credentials import AzureSasCredential +from azure.core.credentials import AzureSasCredential, AzureNamedKeyCredential from azure.core.exceptions import ( HttpResponseError, ResourceNotFoundError, @@ -2037,6 +2037,20 @@ async def test_account_sas_credential(self, storage_account_name, storage_accoun self.assertEqual(blob_name, blob_properties.name) self.assertEqual(self.container_name, container_properties.name) + @BlobPreparer() + @AsyncStorageTestCase.await_prepared_test + async def test_azure_named_key_credential_access(self, storage_account_name, storage_account_key): + named_key = AzureNamedKeyCredential(storage_account_name, storage_account_key) + bsc = BlobServiceClient(self.account_url(storage_account_name, "blob"), named_key) + container_name = self._get_container_reference() + + # Act + container = bsc.get_container_client(container_name) + created = await container.create_container() + + # Assert + self.assertTrue(created) + @pytest.mark.live_test_only @BlobPreparer() @AsyncStorageTestCase.await_prepared_test From c99f6f4f1c6388279205fdad7c7543908c5308e4 Mon Sep 17 00:00:00 2001 From: Vincent Tran Date: Thu, 23 Jun 2022 17:06:29 -0700 Subject: [PATCH 02/17] Forgot to copy in typehint --- .../azure/storage/blob/_shared/base_client.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 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 29246c7d3373..fb59d7aa2c2d 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 @@ -7,9 +7,11 @@ import uuid import warnings from typing import ( # pylint: disable=unused-import - Optional, Any, + Dict, Tuple, + Union, + Optional ) try: @@ -71,7 +73,7 @@ def __init__( self, parsed_url, # type: Any service, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[AzureNamedKeyCredential, AzureSasCredential, Dict[str,str], str, "TokenCredential"]] **kwargs # type: Any ): # type: (...) -> None From 27193701f435dcbe2f5530528b1dc8834530c769 Mon Sep 17 00:00:00 2001 From: Vincent Tran Date: Thu, 23 Jun 2022 17:25:17 -0700 Subject: [PATCH 03/17] PR feedback --- .../azure/storage/blob/_blob_service_client.py | 6 ++++-- .../azure/storage/blob/_shared/base_client.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_service_client.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_service_client.py index 9c2651638204..7bc3e6ac044b 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_service_client.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_service_client.py @@ -74,10 +74,12 @@ class BlobServiceClient(StorageAccountHostsMixin): :param credential: The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account - shared access key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword str api_version: The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility. 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 fb59d7aa2c2d..b1060336f835 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 @@ -73,7 +73,7 @@ def __init__( self, parsed_url, # type: Any service, # type: str - credential=None, # type: Optional[Union[AzureNamedKeyCredential, AzureSasCredential, Dict[str,str], str, "TokenCredential"]] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] **kwargs # type: Any ): # type: (...) -> None From 4bc285b830d4712481f226f3226404bab6df1e52 Mon Sep 17 00:00:00 2001 From: Vincent Tran Date: Tue, 28 Jun 2022 14:41:22 -0700 Subject: [PATCH 04/17] Make Pylint happy so we can proceed --- .../azure/storage/blob/_shared/base_client.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 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 b1060336f835..775eae538ab1 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 @@ -11,7 +11,8 @@ Dict, Tuple, Union, - Optional + Optional, + TYPE_CHECKING ) try: @@ -73,7 +74,8 @@ def __init__( self, parsed_url, # type: Any service, # type: str - credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] + credential= None, # type: Optional[Union[str, Dict[str, str], + # AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] **kwargs # type: Any ): # type: (...) -> None From f9e4c0c7c20055d9ffe061dab0abbcd8a7117f73 Mon Sep 17 00:00:00 2001 From: Vincent Tran Date: Tue, 28 Jun 2022 16:48:41 -0700 Subject: [PATCH 05/17] Finished blob --- .../azure/storage/blob/__init__.py | 10 ++++++--- .../azure/storage/blob/_blob_client.py | 21 ++++++++++++------- .../storage/blob/_blob_service_client.py | 9 +++++--- .../azure/storage/blob/_container_client.py | 21 ++++++++++++------- .../azure/storage/blob/aio/__init__.py | 12 +++++++---- .../storage/blob/aio/_blob_client_async.py | 6 ++++-- .../blob/aio/_blob_service_client_async.py | 6 ++++-- .../blob/aio/_container_client_async.py | 6 ++++-- 8 files changed, 61 insertions(+), 30 deletions(-) diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/__init__.py b/sdk/storage/azure-storage-blob/azure/storage/blob/__init__.py index 58442edc91ea..0eb10c87283e 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/__init__.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/__init__.py @@ -85,10 +85,12 @@ def upload_blob_to_url( :param credential: The credentials with which to authenticate. This is optional if the blob URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account - shared access key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword bool overwrite: Whether the blob to be uploaded should overwrite the current data. If True, upload_blob_to_url will overwrite any existing data. If set to False, the @@ -141,10 +143,12 @@ def download_blob_from_url( :param credential: The credentials with which to authenticate. This is optional if the blob URL already has a SAS token or the blob is public. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword bool overwrite: Whether the local file should be overwritten if it already exists. The default value is `False` - in which case a ValueError will be raised if the file already exists. If set to diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client.py index 7522aebd9f91..277b30c7885c 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client.py @@ -100,10 +100,12 @@ class BlobClient(StorageAccountHostsMixin): # pylint: disable=too-many-public-m :param credential: The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account - shared access key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword str api_version: The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility. @@ -217,10 +219,12 @@ def from_blob_url(cls, blob_url, credential=None, snapshot=None, **kwargs): The credentials with which to authenticate. This is optional if the account URL already has a SAS token, or the connection string already has shared access key values. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account shared access - key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :param str snapshot: The optional blob snapshot on which to operate. This can be the snapshot ID string or the response returned from :func:`create_snapshot`. If specified, this will override @@ -304,9 +308,12 @@ def from_connection_string( The credentials with which to authenticate. This is optional if the account URL already has a SAS token, or the connection string already has shared access key values. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account shared access - key, or an instance of a TokenCredentials class from azure.identity. - Credentials provided here will take precedence over those in the connection string. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. + If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential + - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :returns: A Blob client. :rtype: ~azure.storage.blob.BlobClient diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_service_client.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_service_client.py index 7bc3e6ac044b..1158f86a50c3 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_service_client.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_service_client.py @@ -161,9 +161,12 @@ def from_connection_string( The credentials with which to authenticate. This is optional if the account URL already has a SAS token, or the connection string already has shared access key values. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account shared access - key, or an instance of a TokenCredentials class from azure.identity. - Credentials provided here will take precedence over those in the connection string. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. + If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential + - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :returns: A Blob service client. :rtype: ~azure.storage.blob.BlobServiceClient diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py index 5bc1cb6feede..cd50318dd34f 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py @@ -93,10 +93,12 @@ class ContainerClient(StorageAccountHostsMixin): # pylint: disable=too-many-p :param credential: The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account - shared access key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword str api_version: The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility. @@ -185,10 +187,12 @@ def from_container_url(cls, container_url, credential=None, **kwargs): The credentials with which to authenticate. This is optional if the account URL already has a SAS token, or the connection string already has shared access key values. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account shared access - key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :returns: A container client. :rtype: ~azure.storage.blob.ContainerClient """ @@ -234,9 +238,12 @@ def from_connection_string( The credentials with which to authenticate. This is optional if the account URL already has a SAS token, or the connection string already has shared access key values. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account shared access - key, or an instance of a TokenCredentials class from azure.identity. - Credentials provided here will take precedence over those in the connection string. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. + If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential + - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :returns: A container client. :rtype: ~azure.storage.blob.ContainerClient diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/__init__.py b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/__init__.py index cfd991e34507..79d0be1c8031 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/__init__.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/__init__.py @@ -31,13 +31,15 @@ async def upload_blob_to_url( :param data: The data to upload. This can be bytes, text, an iterable or a file-like object. :type data: bytes or str or Iterable - :param credential: + :param credential: The credentials with which to authenticate. This is optional if the blob URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account - shared access key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword bool overwrite: Whether the blob to be uploaded should overwrite the current data. If True, upload_blob_to_url will overwrite any existing data. If set to False, the @@ -90,10 +92,12 @@ async def download_blob_from_url( :param credential: The credentials with which to authenticate. This is optional if the blob URL already has a SAS token or the blob is public. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword bool overwrite: Whether the local file should be overwritten if it already exists. The default value is `False` - in which case a ValueError will be raised if the file already exists. If set to diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_blob_client_async.py b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_blob_client_async.py index 0bc10f73afec..f8cf4a84b8fb 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_blob_client_async.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_blob_client_async.py @@ -65,10 +65,12 @@ class BlobClient(AsyncStorageAccountHostsMixin, BlobClientBase): # pylint: disa :param credential: The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account - shared access key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword str api_version: The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility. diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_blob_service_client_async.py b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_blob_service_client_async.py index a952cf9fa39b..2af074ef8bd1 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_blob_service_client_async.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_blob_service_client_async.py @@ -63,10 +63,12 @@ class BlobServiceClient(AsyncStorageAccountHostsMixin, BlobServiceClientBase): :param credential: The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account - shared access key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword str api_version: The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility. diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_container_client_async.py b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_container_client_async.py index a72555d36212..8ea5cc55fcfa 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_container_client_async.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_container_client_async.py @@ -62,10 +62,12 @@ class ContainerClient(AsyncStorageAccountHostsMixin, ContainerClientBase): :param credential: The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account - shared access key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword str api_version: The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility. From d3951064263f595f276215aa5d3e2aa0fd124fce Mon Sep 17 00:00:00 2001 From: Vincent Tran Date: Wed, 29 Jun 2022 14:03:25 -0700 Subject: [PATCH 06/17] Bring back 1 line --- .../azure/storage/blob/_shared/base_client.py | 3 +-- 1 file changed, 1 insertion(+), 2 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 775eae538ab1..31a654ba6c35 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 @@ -74,8 +74,7 @@ def __init__( self, parsed_url, # type: Any service, # type: str - credential= None, # type: Optional[Union[str, Dict[str, str], - # AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] + credential= None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=protected-access **kwargs # type: Any ): # type: (...) -> None From 0b57430201cec568950f72e31ba6c8cc0ce91854 Mon Sep 17 00:00:00 2001 From: Vincent Tran Date: Wed, 29 Jun 2022 15:28:00 -0700 Subject: [PATCH 07/17] Fixed up connection string docstrings in blob & dlake, added dlake --- .../azure/storage/blob/_blob_client.py | 3 +- .../storage/blob/_blob_service_client.py | 3 +- .../azure/storage/blob/_container_client.py | 3 +- .../azure/storage/blob/_shared/base_client.py | 2 +- .../_data_lake_directory_client.py | 12 ++++-- .../filedatalake/_data_lake_file_client.py | 12 ++++-- .../filedatalake/_data_lake_service_client.py | 6 ++- .../filedatalake/_file_system_client.py | 12 ++++-- .../storage/filedatalake/_path_client.py | 6 ++- .../filedatalake/_shared/base_client.py | 7 +++- .../aio/_data_lake_directory_client_async.py | 6 ++- .../aio/_data_lake_file_client_async.py | 6 ++- .../aio/_data_lake_service_client_async.py | 6 ++- .../aio/_file_system_client_async.py | 6 ++- .../filedatalake/aio/_path_client_async.py | 6 ++- ...est_azure_named_key_credential_access.yaml | 37 +++++++++++++++++++ ...est_azure_named_key_credential_access.yaml | 29 +++++++++++++++ .../tests/test_datalake_service_client.py | 12 ++++++ .../test_datalake_service_client_async.py | 12 ++++++ 19 files changed, 151 insertions(+), 35 deletions(-) create mode 100644 sdk/storage/azure-storage-file-datalake/tests/recordings/test_datalake_service_client.test_azure_named_key_credential_access.yaml create mode 100644 sdk/storage/azure-storage-file-datalake/tests/recordings/test_datalake_service_client_async.test_azure_named_key_credential_access.yaml diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client.py index 277b30c7885c..70c90670c2af 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client.py @@ -310,8 +310,7 @@ def from_connection_string( access key values. The value can be a SAS token string, an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, an account shared access key, or an instance of a TokenCredentials class from azure.identity. - If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + Credentials provided here will take precedence over those in the connection string. If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" should be the storage account key. :returns: A Blob client. diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_service_client.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_service_client.py index 1158f86a50c3..3be290925ae6 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_service_client.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_service_client.py @@ -163,8 +163,7 @@ def from_connection_string( access key values. The value can be a SAS token string, an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, an account shared access key, or an instance of a TokenCredentials class from azure.identity. - If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + Credentials provided here will take precedence over those in the connection string. If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" should be the storage account key. :returns: A Blob service client. diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py index cd50318dd34f..406823a3cbe6 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py @@ -240,8 +240,7 @@ def from_connection_string( access key values. The value can be a SAS token string, an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, an account shared access key, or an instance of a TokenCredentials class from azure.identity. - If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + Credentials provided here will take precedence over those in the connection string. If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" should be the storage account key. :returns: A container client. 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 31a654ba6c35..8fddc4bddc9b 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 @@ -74,7 +74,7 @@ def __init__( self, parsed_url, # type: Any service, # type: str - credential= None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=protected-access + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=too-many-lines **kwargs # type: Any ): # type: (...) -> None diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py index fb7584680b04..aa1148128dde 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py @@ -47,10 +47,12 @@ class DataLakeDirectoryClient(PathClient): :param credential: The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, and account - shared access key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword str api_version: The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility. @@ -99,9 +101,11 @@ def from_connection_string( The credentials with which to authenticate. This is optional if the account URL already has a SAS token, or the connection string already has shared access key values. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, and account shared access - key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. Credentials provided here will take precedence over those in the connection string. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :return: a DataLakeDirectoryClient :rtype: ~azure.storage.filedatalake.DataLakeDirectoryClient """ diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_file_client.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_file_client.py index 40f8402798ce..f0bfe414c66c 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_file_client.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_file_client.py @@ -57,10 +57,12 @@ class DataLakeFileClient(PathClient): :param credential: The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account - shared access key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword str api_version: The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility. @@ -109,9 +111,11 @@ def from_connection_string( The credentials with which to authenticate. This is optional if the account URL already has a SAS token, or the connection string already has shared access key values. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account shared access - key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. Credentials provided here will take precedence over those in the connection string. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :return a DataLakeFileClient :rtype ~azure.storage.filedatalake.DataLakeFileClient """ 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 4ac2a4447711..1680770320f1 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 @@ -47,10 +47,12 @@ class DataLakeServiceClient(StorageAccountHostsMixin): :param credential: The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account - shared access key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword str api_version: The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility. 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 9b33a6166928..a5997033214e 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 @@ -58,10 +58,12 @@ class FileSystemClient(StorageAccountHostsMixin): :param credential: The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account - shared access key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword str api_version: The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility. @@ -164,9 +166,11 @@ def from_connection_string( The credentials with which to authenticate. This is optional if the account URL already has a SAS token, or the connection string already has shared access key values. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account shared access - key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. Credentials provided here will take precedence over those in the connection string. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :return a FileSystemClient :rtype ~azure.storage.filedatalake.FileSystemClient 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 16f7cf8a3f44..eb41c691344f 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 @@ -52,10 +52,12 @@ class PathClient(StorageAccountHostsMixin): :param credential: The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account - shared access key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword str api_version: The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility. 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 b80d04a57363..61f759817a8b 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 @@ -9,6 +9,7 @@ Optional, Any, Tuple, + TYPE_CHECKING ) try: @@ -20,7 +21,7 @@ import six from azure.core.configuration import Configuration -from azure.core.credentials import AzureSasCredential +from azure.core.credentials import AzureSasCredential, AzureNamedKeyCredential from azure.core.exceptions import HttpResponseError from azure.core.pipeline import Pipeline from azure.core.pipeline.transport import RequestsTransport, HttpTransport @@ -67,7 +68,7 @@ def __init__( self, parsed_url, # type: Any service, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=too-many-lines **kwargs # type: Any ): # type: (...) -> None @@ -355,6 +356,8 @@ def _format_shared_key_credential(account_name, credential): if "account_key" not in 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 credential diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_directory_client_async.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_directory_client_async.py index a31bbaca52df..a88d906e6718 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_directory_client_async.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_directory_client_async.py @@ -47,10 +47,12 @@ class DataLakeDirectoryClient(PathClient, DataLakeDirectoryClientBase): :param credential: The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account - shared access key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword str api_version: The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility. diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_file_client_async.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_file_client_async.py index 3f17c560d62e..dc96ebf8f9f8 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_file_client_async.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_file_client_async.py @@ -48,10 +48,12 @@ class DataLakeFileClient(PathClient, DataLakeFileClientBase): :param credential: The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account - shared access key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword str api_version: The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility. 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 7e68d3015882..b775faa50dbf 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 @@ -44,10 +44,12 @@ class DataLakeServiceClient(AsyncStorageAccountHostsMixin, DataLakeServiceClient :param credential: The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account - shared access key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword str api_version: The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility. 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 27548cc9d7b5..b6aad25cd80e 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 @@ -61,10 +61,12 @@ class FileSystemClient(AsyncStorageAccountHostsMixin, FileSystemClientBase): :param credential: The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account - shared access key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword str api_version: The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility. 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 eafb88b490d3..b6925373d771 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 @@ -44,10 +44,12 @@ class PathClient(AsyncStorageAccountHostsMixin, PathClientBase): :param credential: The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account - shared access key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword str api_version: The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility. diff --git a/sdk/storage/azure-storage-file-datalake/tests/recordings/test_datalake_service_client.test_azure_named_key_credential_access.yaml b/sdk/storage/azure-storage-file-datalake/tests/recordings/test_datalake_service_client.test_azure_named_key_credential_access.yaml new file mode 100644 index 000000000000..658d475fc855 --- /dev/null +++ b/sdk/storage/azure-storage-file-datalake/tests/recordings/test_datalake_service_client.test_azure_named_key_credential_access.yaml @@ -0,0 +1,37 @@ +interactions: +- request: + body: null + headers: + Accept: + - application/xml + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - azsdk-python-storage-blob/12.13.0 Python/3.10.2 (Windows-10-10.0.19044-SP0) + x-ms-date: + - Wed, 29 Jun 2022 21:32:45 GMT + x-ms-version: + - '2021-08-06' + method: GET + uri: https://storagename.blob.core.windows.net/?restype=service&comp=properties + response: + body: + string: "\uFEFF1.0falsefalsefalsefalse1.0truetruetrue71.0falsefalsefalsefalsefalse" + headers: + content-type: + - application/xml + date: + - Wed, 29 Jun 2022 21:32:44 GMT + server: + - Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0 + transfer-encoding: + - chunked + x-ms-version: + - '2021-08-06' + status: + code: 200 + message: OK +version: 1 diff --git a/sdk/storage/azure-storage-file-datalake/tests/recordings/test_datalake_service_client_async.test_azure_named_key_credential_access.yaml b/sdk/storage/azure-storage-file-datalake/tests/recordings/test_datalake_service_client_async.test_azure_named_key_credential_access.yaml new file mode 100644 index 000000000000..e4cbdbcf852d --- /dev/null +++ b/sdk/storage/azure-storage-file-datalake/tests/recordings/test_datalake_service_client_async.test_azure_named_key_credential_access.yaml @@ -0,0 +1,29 @@ +interactions: +- request: + body: null + headers: + Accept: + - application/xml + User-Agent: + - azsdk-python-storage-blob/12.13.0 Python/3.10.2 (Windows-10-10.0.19044-SP0) + x-ms-date: + - Wed, 29 Jun 2022 21:34:07 GMT + x-ms-version: + - '2021-08-06' + method: GET + uri: https://storagename.blob.core.windows.net/?restype=service&comp=properties + response: + body: + string: "\uFEFF1.0falsefalsefalsefalse1.0truetruetrue71.0falsefalsefalsefalsefalse" + headers: + content-type: application/xml + date: Wed, 29 Jun 2022 21:34:06 GMT + server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0 + transfer-encoding: chunked + x-ms-version: '2021-08-06' + status: + code: 200 + message: OK + url: https://vincenttranhns.blob.core.windows.net/?restype=service&comp=properties +version: 1 diff --git a/sdk/storage/azure-storage-file-datalake/tests/test_datalake_service_client.py b/sdk/storage/azure-storage-file-datalake/tests/test_datalake_service_client.py index 7fc281eb5dd9..e3b39925712e 100644 --- a/sdk/storage/azure-storage-file-datalake/tests/test_datalake_service_client.py +++ b/sdk/storage/azure-storage-file-datalake/tests/test_datalake_service_client.py @@ -19,6 +19,7 @@ from settings.testcase import DataLakePreparer from devtools_testutils.storage import StorageTestCase +from azure.core.credentials import AzureNamedKeyCredential # ------------------------------------------------------------------------------ from azure.storage.filedatalake._models import AnalyticsLogging, Metrics, RetentionPolicy, \ @@ -348,3 +349,14 @@ def test_connectionstring_without_secondary(self): assert client.url == 'https://foo.dfs.core.windows.net/fsname/dname' assert client.primary_hostname == 'foo.dfs.core.windows.net' assert not client.secondary_hostname + + @DataLakePreparer() + def test_azure_named_key_credential_access(self, datalake_storage_account_name, datalake_storage_account_key): + named_key = AzureNamedKeyCredential(datalake_storage_account_name, datalake_storage_account_key) + dsc = DataLakeServiceClient(self.account_url(datalake_storage_account_name, "blob"), named_key) + + # Act + props = dsc.get_service_properties() + + # Assert + self.assertIsNotNone(props) diff --git a/sdk/storage/azure-storage-file-datalake/tests/test_datalake_service_client_async.py b/sdk/storage/azure-storage-file-datalake/tests/test_datalake_service_client_async.py index 84d05e467c73..2d8fec0910d4 100644 --- a/sdk/storage/azure-storage-file-datalake/tests/test_datalake_service_client_async.py +++ b/sdk/storage/azure-storage-file-datalake/tests/test_datalake_service_client_async.py @@ -19,6 +19,7 @@ ) from devtools_testutils.storage.aio import AsyncStorageTestCase as StorageTestCase from settings.testcase import DataLakePreparer +from azure.core.credentials import AzureNamedKeyCredential # ------------------------------------------------------------------------------ from azure.storage.filedatalake._models import AnalyticsLogging, Metrics, RetentionPolicy, \ @@ -343,3 +344,14 @@ async def test_connectionstring_without_secondary(self): assert client.url == 'https://foo.dfs.core.windows.net/fsname/dname' assert client.primary_hostname == 'foo.dfs.core.windows.net' assert not client.secondary_hostname + + @DataLakePreparer() + async def test_azure_named_key_credential_access(self, datalake_storage_account_name, datalake_storage_account_key): + named_key = AzureNamedKeyCredential(datalake_storage_account_name, datalake_storage_account_key) + dsc = DataLakeServiceClient(self.account_url(datalake_storage_account_name, "blob"), named_key) + + # Act + props = await dsc.get_service_properties() + + # Assert + self.assertIsNotNone(props) From 7f96b23eb5be04c369fa9aa2d214e9ab240c366a Mon Sep 17 00:00:00 2001 From: Vincent Tran Date: Wed, 29 Jun 2022 15:56:26 -0700 Subject: [PATCH 08/17] Added cf support --- .../storage/blob/changefeed/_change_feed_client.py | 12 ++++++++---- .../tests/test_change_feed.py | 12 ++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/sdk/storage/azure-storage-blob-changefeed/azure/storage/blob/changefeed/_change_feed_client.py b/sdk/storage/azure-storage-blob-changefeed/azure/storage/blob/changefeed/_change_feed_client.py index 9072aa760ad2..e64a494768ae 100644 --- a/sdk/storage/azure-storage-blob-changefeed/azure/storage/blob/changefeed/_change_feed_client.py +++ b/sdk/storage/azure-storage-blob-changefeed/azure/storage/blob/changefeed/_change_feed_client.py @@ -25,10 +25,12 @@ class ChangeFeedClient(object): # pylint: disable=too-many-public-methods :param credential: The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account - shared access key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword str secondary_hostname: The hostname of the secondary endpoint. :keyword int max_single_get_size: @@ -71,9 +73,11 @@ def from_connection_string( The credentials with which to authenticate. This is optional if the account URL already has a SAS token, or the connection string already has shared access key values. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account shared access - key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. Credentials provided here will take precedence over those in the connection string. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :returns: A change feed client. :rtype: ~azure.storage.blob.changefeed.ChangeFeedClient diff --git a/sdk/storage/azure-storage-blob-changefeed/tests/test_change_feed.py b/sdk/storage/azure-storage-blob-changefeed/tests/test_change_feed.py index 04b860916f9b..b20c8654bfd0 100644 --- a/sdk/storage/azure-storage-blob-changefeed/tests/test_change_feed.py +++ b/sdk/storage/azure-storage-blob-changefeed/tests/test_change_feed.py @@ -21,6 +21,7 @@ from devtools_testutils.storage import StorageTestCase from settings.testcase import ChangeFeedPreparer +from azure.core.credentials import AzureNamedKeyCredential @pytest.mark.playback_test_only class StorageChangeFeedTest(StorageTestCase): @@ -333,3 +334,14 @@ def test_list_3_shards_events_works_with_1_shard_cursor(self, storage_account_na dict_token_with_1_shard = json.loads(token_with_1_shard) self.assertEqual(len(dict_token_with_1_shard['CurrentSegmentCursor']['ShardCursors']), 1) self.assertEqual(len(dict_token['CurrentSegmentCursor']['ShardCursors']), 3) + + @ChangeFeedPreparer() + def test_azure_named_key_credential_access(self, storage_account_name, storage_account_key): + named_key = AzureNamedKeyCredential(storage_account_name, storage_account_key) + cf_client = ChangeFeedClient(self.account_url(storage_account_name, "blob"), named_key) + + # Act + change_feed = cf_client.list_changes() + + # Assert + self.assertIsNotNone(change_feed) From e017e74cbc6d8032909af1c9af48103541f72ab6 Mon Sep 17 00:00:00 2001 From: Vincent Tran Date: Wed, 29 Jun 2022 18:24:28 -0700 Subject: [PATCH 09/17] Add supp for file share, fix pylint, comment out cf (recording not generating) --- .../tests/test_change_feed.py | 20 +- .../azure/storage/blob/_shared/base_client.py | 2 +- .../filedatalake/_shared/base_client.py | 4 +- .../storage/fileshare/_directory_client.py | 32 ++- .../azure/storage/fileshare/_file_client.py | 30 ++- .../azure/storage/fileshare/_share_client.py | 30 ++- .../fileshare/_share_service_client.py | 20 +- .../storage/fileshare/_shared/base_client.py | 9 +- .../fileshare/aio/_directory_client_async.py | 10 +- .../fileshare/aio/_file_client_async.py | 10 +- .../fileshare/aio/_share_client_async.py | 10 +- .../aio/_share_service_client_async.py | 10 +- ...est_azure_named_key_credential_access.yaml | 217 ++++++++++++++++++ ...est_azure_named_key_credential_access.yaml | 153 ++++++++++++ .../tests/test_file.py | 21 +- .../tests/test_file_async.py | 22 +- 16 files changed, 538 insertions(+), 62 deletions(-) create mode 100644 sdk/storage/azure-storage-file-share/tests/recordings/test_file.test_azure_named_key_credential_access.yaml create mode 100644 sdk/storage/azure-storage-file-share/tests/recordings/test_file_async.test_azure_named_key_credential_access.yaml diff --git a/sdk/storage/azure-storage-blob-changefeed/tests/test_change_feed.py b/sdk/storage/azure-storage-blob-changefeed/tests/test_change_feed.py index b20c8654bfd0..72285c7d9101 100644 --- a/sdk/storage/azure-storage-blob-changefeed/tests/test_change_feed.py +++ b/sdk/storage/azure-storage-blob-changefeed/tests/test_change_feed.py @@ -335,13 +335,13 @@ def test_list_3_shards_events_works_with_1_shard_cursor(self, storage_account_na self.assertEqual(len(dict_token_with_1_shard['CurrentSegmentCursor']['ShardCursors']), 1) self.assertEqual(len(dict_token['CurrentSegmentCursor']['ShardCursors']), 3) - @ChangeFeedPreparer() - def test_azure_named_key_credential_access(self, storage_account_name, storage_account_key): - named_key = AzureNamedKeyCredential(storage_account_name, storage_account_key) - cf_client = ChangeFeedClient(self.account_url(storage_account_name, "blob"), named_key) - - # Act - change_feed = cf_client.list_changes() - - # Assert - self.assertIsNotNone(change_feed) + # @ChangeFeedPreparer() + # def test_azure_named_key_credential_access(self, storage_account_name, storage_account_key): + # named_key = AzureNamedKeyCredential(storage_account_name, storage_account_key) + # cf_client = ChangeFeedClient(self.account_url(storage_account_name, "blob"), named_key) + # + # # Act + # change_feed = cf_client.list_changes() + # + # # Assert + # self.assertIsNotNone(change_feed) 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 8fddc4bddc9b..5df0bd77289d 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 @@ -74,7 +74,7 @@ def __init__( self, parsed_url, # type: Any service, # type: str - credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=too-many-lines + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None 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 61f759817a8b..c7eb497b137c 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 @@ -54,6 +54,8 @@ from .._version import VERSION from .response_handlers import process_storage_error, PartialBatchErrorException +if TYPE_CHECKING: + from azure.core.credentials import TokenCredential _LOGGER = logging.getLogger(__name__) _SERVICE_PARAMS = { @@ -68,7 +70,7 @@ def __init__( self, parsed_url, # type: Any service, # type: str - credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=too-many-lines + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_directory_client.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_directory_client.py index 9c5e756a52b2..c17249b6534d 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_directory_client.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_directory_client.py @@ -63,10 +63,14 @@ class ShareDirectoryClient(StorageAccountHostsMixin): An optional share snapshot on which to operate. This can be the snapshot ID string or the response returned from :func:`ShareClient.create_snapshot`. :param credential: - The credential with which to authenticate. This is optional if the + The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials or an account - shared access key. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. + If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential + - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword str api_version: The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility. @@ -135,10 +139,14 @@ def from_directory_url(cls, directory_url, # type: str An optional share snapshot on which to operate. This can be the snapshot ID string or the response returned from :func:`ShareClient.create_snapshot`. :param credential: - The credential with which to authenticate. This is optional if the - account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials or an account - shared access key. + The credentials with which to authenticate. This is optional if the + account URL already has a SAS token. The value can be a SAS token string, + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. + If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential + - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :returns: A directory client. :rtype: ~azure.storage.fileshare.ShareDirectoryClient """ @@ -198,10 +206,14 @@ def from_connection_string( :param str directory_path: The directory path. :param credential: - The credential with which to authenticate. This is optional if the + The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials or an account - shared access key. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. + If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential + - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :returns: A directory client. :rtype: ~azure.storage.fileshare.ShareDirectoryClient """ diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_file_client.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_file_client.py index 7fa33632a785..a20ae45608ce 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_file_client.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_file_client.py @@ -121,10 +121,14 @@ class ShareFileClient(StorageAccountHostsMixin): An optional file snapshot on which to operate. This can be the snapshot ID string or the response returned from :func:`ShareClient.create_snapshot`. :param credential: - The credential with which to authenticate. This is optional if the + The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials or an account - shared access key. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. + If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential + - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword str api_version: The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility. @@ -196,10 +200,14 @@ def from_file_url( An optional file snapshot on which to operate. This can be the snapshot ID string or the response returned from :func:`ShareClient.create_snapshot`. :param credential: - The credential with which to authenticate. This is optional if the + The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials or an account - shared access key. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. + If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential + - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :returns: A File client. :rtype: ~azure.storage.fileshare.ShareFileClient """ @@ -257,10 +265,14 @@ def from_connection_string( An optional file snapshot on which to operate. This can be the snapshot ID string or the response returned from :func:`ShareClient.create_snapshot`. :param credential: - The credential with which to authenticate. This is optional if the + The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials or an account - shared access key. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. + If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential + - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :returns: A File client. :rtype: ~azure.storage.fileshare.ShareFileClient diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_client.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_client.py index c5ee3aaed14e..53561d13b3aa 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_client.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_client.py @@ -62,10 +62,14 @@ class ShareClient(StorageAccountHostsMixin): # pylint: disable=too-many-public-m An optional share snapshot on which to operate. This can be the snapshot ID string or the response returned from :func:`create_snapshot`. :param credential: - The credential with which to authenticate. This is optional if the + The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials or an account - shared access key. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. + If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential + - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword str api_version: The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility. @@ -130,10 +134,14 @@ def from_share_url(cls, share_url, # type: str An optional share snapshot on which to operate. This can be the snapshot ID string or the response returned from :func:`create_snapshot`. :param credential: - The credential with which to authenticate. This is optional if the + The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials or an account - shared access key. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. + If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential + - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :returns: A share client. :rtype: ~azure.storage.fileshare.ShareClient """ @@ -203,10 +211,14 @@ def from_connection_string( The optional share snapshot on which to operate. This can be the snapshot ID string or the response returned from :func:`create_snapshot`. :param credential: - The credential with which to authenticate. This is optional if the + The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials or an account - shared access key. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. + If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential + - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :returns: A share client. :rtype: ~azure.storage.fileshare.ShareClient diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_service_client.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_service_client.py index 46721ee9ea86..e934c8eb35b1 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_service_client.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_service_client.py @@ -58,10 +58,14 @@ class ShareServiceClient(StorageAccountHostsMixin): in the URL path (e.g. share or file) will be discarded. This URL can be optionally authenticated with a SAS token. :param credential: - The credential with which to authenticate. This is optional if the + The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials or an account - shared access key. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. + If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential + - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword str api_version: The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility. @@ -124,10 +128,14 @@ def from_connection_string( :param str conn_str: A connection string to an Azure Storage account. :param credential: - The credential with which to authenticate. This is optional if the + The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials or an account - shared access key. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. + If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential + - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :returns: A File Share service client. :rtype: ~azure.storage.fileshare.ShareServiceClient 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 b80d04a57363..c7eb497b137c 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 @@ -9,6 +9,7 @@ Optional, Any, Tuple, + TYPE_CHECKING ) try: @@ -20,7 +21,7 @@ import six from azure.core.configuration import Configuration -from azure.core.credentials import AzureSasCredential +from azure.core.credentials import AzureSasCredential, AzureNamedKeyCredential from azure.core.exceptions import HttpResponseError from azure.core.pipeline import Pipeline from azure.core.pipeline.transport import RequestsTransport, HttpTransport @@ -53,6 +54,8 @@ from .._version import VERSION from .response_handlers import process_storage_error, PartialBatchErrorException +if TYPE_CHECKING: + from azure.core.credentials import TokenCredential _LOGGER = logging.getLogger(__name__) _SERVICE_PARAMS = { @@ -67,7 +70,7 @@ def __init__( self, parsed_url, # type: Any service, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None @@ -355,6 +358,8 @@ def _format_shared_key_credential(account_name, credential): if "account_key" not in 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 credential diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_directory_client_async.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_directory_client_async.py index 586571e2d7b5..330017804cef 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_directory_client_async.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_directory_client_async.py @@ -54,10 +54,14 @@ class ShareDirectoryClient(AsyncStorageAccountHostsMixin, ShareDirectoryClientBa An optional share snapshot on which to operate. This can be the snapshot ID string or the response returned from :func:`ShareClient.create_snapshot`. :param credential: - The credential with which to authenticate. This is optional if the + The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials or an account - shared access key. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. + If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential + - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword str api_version: The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility. diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_file_client_async.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_file_client_async.py index 9bc8fc00ac1f..3081fab0cf11 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_file_client_async.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_file_client_async.py @@ -109,10 +109,14 @@ class ShareFileClient(AsyncStorageAccountHostsMixin, ShareFileClientBase): An optional file snapshot on which to operate. This can be the snapshot ID string or the response returned from :func:`ShareClient.create_snapshot`. :param credential: - The credential with which to authenticate. This is optional if the + The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials or an account - shared access key. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. + If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential + - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword str api_version: The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility. diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_client_async.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_client_async.py index 437fb6d3050e..4c1ebdc8ba11 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_client_async.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_client_async.py @@ -51,10 +51,14 @@ class ShareClient(AsyncStorageAccountHostsMixin, ShareClientBase): An optional share snapshot on which to operate. This can be the snapshot ID string or the response returned from :func:`create_snapshot`. :param credential: - The credential with which to authenticate. This is optional if the + The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials or an account - shared access key. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. + If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential + - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword str api_version: The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility. diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_service_client_async.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_service_client_async.py index 9cf53d32933b..bc6943b3bca6 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_service_client_async.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_service_client_async.py @@ -51,10 +51,14 @@ class ShareServiceClient(AsyncStorageAccountHostsMixin, ShareServiceClientBase): in the URL path (e.g. share or file) will be discarded. This URL can be optionally authenticated with a SAS token. :param credential: - The credential with which to authenticate. This is optional if the + The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials or an account - shared access key. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. + If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential + - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword str api_version: The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility. diff --git a/sdk/storage/azure-storage-file-share/tests/recordings/test_file.test_azure_named_key_credential_access.yaml b/sdk/storage/azure-storage-file-share/tests/recordings/test_file.test_azure_named_key_credential_access.yaml new file mode 100644 index 000000000000..0477b4ee2baa --- /dev/null +++ b/sdk/storage/azure-storage-file-share/tests/recordings/test_file.test_azure_named_key_credential_access.yaml @@ -0,0 +1,217 @@ +interactions: +- request: + body: null + headers: + Accept: + - application/xml + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '0' + User-Agent: + - azsdk-python-storage-file-share/12.9.0 Python/3.10.2 (Windows-10-10.0.19044-SP0) + x-ms-date: + - Thu, 30 Jun 2022 01:15:33 GMT + x-ms-version: + - '2021-06-08' + method: PUT + uri: https://storagename.file.core.windows.net/utsharedf1d138b?restype=share + response: + body: + string: "\uFEFFShareAlreadyExistsThe + specified share already exists.\nRequestId:f8bf0e99-201a-0033-411e-8c8569000000\nTime:2022-06-30T01:15:32.9622302Z" + headers: + content-length: + - '222' + content-type: + - application/xml + date: + - Thu, 30 Jun 2022 01:15:32 GMT + server: + - Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0 + x-ms-error-code: + - ShareAlreadyExists + x-ms-version: + - '2021-06-08' + status: + code: 409 + message: The specified share already exists. +- request: + body: null + headers: + Accept: + - application/xml + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '0' + User-Agent: + - azsdk-python-storage-file-share/12.9.0 Python/3.10.2 (Windows-10-10.0.19044-SP0) + x-ms-content-length: + - '1024' + x-ms-date: + - Thu, 30 Jun 2022 01:15:34 GMT + x-ms-file-attributes: + - none + x-ms-file-creation-time: + - now + x-ms-file-last-write-time: + - now + x-ms-file-permission: + - Inherit + x-ms-type: + - file + x-ms-version: + - '2021-06-08' + method: PUT + uri: https://storagename.file.core.windows.net/utsharedf1d138b/filedf1d138b + response: + body: + string: '' + headers: + content-length: + - '0' + date: + - Thu, 30 Jun 2022 01:15:32 GMT + etag: + - '"0x8DA5A3607D7398B"' + last-modified: + - Thu, 30 Jun 2022 01:15:33 GMT + server: + - Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0 + x-ms-file-attributes: + - Archive + x-ms-file-change-time: + - '2022-06-30T01:15:33.2625803Z' + x-ms-file-creation-time: + - '2022-06-30T01:15:33.2625803Z' + x-ms-file-id: + - '13835128424026341376' + x-ms-file-last-write-time: + - '2022-06-30T01:15:33.2625803Z' + x-ms-file-parent-id: + - '0' + x-ms-file-permission-key: + - 8723072292820393796*15109150453380773834 + x-ms-request-server-encrypted: + - 'true' + x-ms-version: + - '2021-06-08' + status: + code: 201 + message: Created +- request: + body: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + headers: + Accept: + - application/xml + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '1024' + Content-Type: + - application/octet-stream + User-Agent: + - azsdk-python-storage-file-share/12.9.0 Python/3.10.2 (Windows-10-10.0.19044-SP0) + x-ms-date: + - Thu, 30 Jun 2022 01:15:34 GMT + x-ms-range: + - bytes=0-1023 + x-ms-version: + - '2021-06-08' + x-ms-write: + - update + method: PUT + uri: https://storagename.file.core.windows.net/utsharedf1d138b/filedf1d138b?comp=range + response: + body: + string: '' + headers: + content-length: + - '0' + content-md5: + - yaNM/IXZgmmMasifdgcavQ== + date: + - Thu, 30 Jun 2022 01:15:32 GMT + etag: + - '"0x8DA5A3607F85154"' + last-modified: + - Thu, 30 Jun 2022 01:15:33 GMT + server: + - Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0 + x-ms-file-last-write-time: + - '2022-06-30T01:15:33.4794580Z' + x-ms-request-server-encrypted: + - 'true' + x-ms-version: + - '2021-06-08' + status: + code: 201 + message: Created +- request: + body: null + headers: + Accept: + - application/xml + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - azsdk-python-storage-file-share/12.9.0 Python/3.10.2 (Windows-10-10.0.19044-SP0) + x-ms-date: + - Thu, 30 Jun 2022 01:15:34 GMT + x-ms-version: + - '2021-06-08' + method: HEAD + uri: https://storagename.file.core.windows.net/utsharedf1d138b/filedf1d138b + response: + body: + string: '' + headers: + content-length: + - '1024' + content-type: + - application/octet-stream + date: + - Thu, 30 Jun 2022 01:15:33 GMT + etag: + - '"0x8DA5A3607F85154"' + last-modified: + - Thu, 30 Jun 2022 01:15:33 GMT + server: + - Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0 + x-ms-file-attributes: + - Archive + x-ms-file-change-time: + - '2022-06-30T01:15:33.4794580Z' + x-ms-file-creation-time: + - '2022-06-30T01:15:33.2625803Z' + x-ms-file-id: + - '13835128424026341376' + x-ms-file-last-write-time: + - '2022-06-30T01:15:33.4794580Z' + x-ms-file-parent-id: + - '0' + x-ms-file-permission-key: + - 8723072292820393796*15109150453380773834 + x-ms-lease-state: + - available + x-ms-lease-status: + - unlocked + x-ms-server-encrypted: + - 'true' + x-ms-type: + - File + x-ms-version: + - '2021-06-08' + status: + code: 200 + message: OK +version: 1 diff --git a/sdk/storage/azure-storage-file-share/tests/recordings/test_file_async.test_azure_named_key_credential_access.yaml b/sdk/storage/azure-storage-file-share/tests/recordings/test_file_async.test_azure_named_key_credential_access.yaml new file mode 100644 index 000000000000..f86ec867e7ca --- /dev/null +++ b/sdk/storage/azure-storage-file-share/tests/recordings/test_file_async.test_azure_named_key_credential_access.yaml @@ -0,0 +1,153 @@ +interactions: +- request: + body: null + headers: + Accept: + - application/xml + User-Agent: + - azsdk-python-storage-file-share/12.9.0 Python/3.10.2 (Windows-10-10.0.19044-SP0) + x-ms-date: + - Thu, 30 Jun 2022 01:16:46 GMT + x-ms-version: + - '2021-06-08' + method: PUT + uri: https://storagename.file.core.windows.net/utshare5f4c1608?restype=share + response: + body: + string: '' + headers: + content-length: '0' + date: Thu, 30 Jun 2022 01:16:44 GMT + etag: '"0x8DA5A3632D1E948"' + last-modified: Thu, 30 Jun 2022 01:16:45 GMT + server: Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0 + x-ms-version: '2021-06-08' + status: + code: 201 + message: Created + url: https://vincenttrancanary.file.core.windows.net/utshare5f4c1608?restype=share +- request: + body: null + headers: + Accept: + - application/xml + User-Agent: + - azsdk-python-storage-file-share/12.9.0 Python/3.10.2 (Windows-10-10.0.19044-SP0) + x-ms-content-length: + - '1024' + x-ms-date: + - Thu, 30 Jun 2022 01:16:46 GMT + x-ms-file-attributes: + - none + x-ms-file-creation-time: + - now + x-ms-file-last-write-time: + - now + x-ms-file-permission: + - Inherit + x-ms-type: + - file + x-ms-version: + - '2021-06-08' + method: PUT + uri: https://storagename.file.core.windows.net/utshare5f4c1608/file5f4c1608 + response: + body: + string: '' + headers: + content-length: '0' + date: Thu, 30 Jun 2022 01:16:45 GMT + etag: '"0x8DA5A36333D6D57"' + last-modified: Thu, 30 Jun 2022 01:16:46 GMT + server: Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0 + x-ms-file-attributes: Archive + x-ms-file-change-time: '2022-06-30T01:16:46.0744023Z' + x-ms-file-creation-time: '2022-06-30T01:16:46.0744023Z' + x-ms-file-id: '13835128424026341376' + x-ms-file-last-write-time: '2022-06-30T01:16:46.0744023Z' + x-ms-file-parent-id: '0' + x-ms-file-permission-key: 8723072292820393796*15109150453380773834 + x-ms-request-server-encrypted: 'true' + x-ms-version: '2021-06-08' + status: + code: 201 + message: Created + url: https://vincenttrancanary.file.core.windows.net/utshare5f4c1608/file5f4c1608 +- request: + body: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + headers: + Accept: + - application/xml + Content-Length: + - '1024' + Content-Type: + - application/octet-stream + User-Agent: + - azsdk-python-storage-file-share/12.9.0 Python/3.10.2 (Windows-10-10.0.19044-SP0) + x-ms-date: + - Thu, 30 Jun 2022 01:16:47 GMT + x-ms-range: + - bytes=0-1023 + x-ms-version: + - '2021-06-08' + x-ms-write: + - update + method: PUT + uri: https://storagename.file.core.windows.net/utshare5f4c1608/file5f4c1608?comp=range + response: + body: + string: '' + headers: + content-length: '0' + content-md5: yaNM/IXZgmmMasifdgcavQ== + date: Thu, 30 Jun 2022 01:16:45 GMT + etag: '"0x8DA5A36334DE5B2"' + last-modified: Thu, 30 Jun 2022 01:16:46 GMT + server: Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0 + x-ms-file-last-write-time: '2022-06-30T01:16:46.1823410Z' + x-ms-request-server-encrypted: 'true' + x-ms-version: '2021-06-08' + status: + code: 201 + message: Created + url: https://vincenttrancanary.file.core.windows.net/utshare5f4c1608/file5f4c1608?comp=range +- request: + body: null + headers: + Accept: + - application/xml + User-Agent: + - azsdk-python-storage-file-share/12.9.0 Python/3.10.2 (Windows-10-10.0.19044-SP0) + x-ms-date: + - Thu, 30 Jun 2022 01:16:47 GMT + x-ms-version: + - '2021-06-08' + method: HEAD + uri: https://storagename.file.core.windows.net/utshare5f4c1608/file5f4c1608 + response: + body: + string: '' + headers: + content-length: '1024' + content-type: application/octet-stream + date: Thu, 30 Jun 2022 01:16:45 GMT + etag: '"0x8DA5A36334DE5B2"' + last-modified: Thu, 30 Jun 2022 01:16:46 GMT + server: Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0 + x-ms-file-attributes: Archive + x-ms-file-change-time: '2022-06-30T01:16:46.1823410Z' + x-ms-file-creation-time: '2022-06-30T01:16:46.0744023Z' + x-ms-file-id: '13835128424026341376' + x-ms-file-last-write-time: '2022-06-30T01:16:46.1823410Z' + x-ms-file-parent-id: '0' + x-ms-file-permission-key: 8723072292820393796*15109150453380773834 + x-ms-lease-state: available + x-ms-lease-status: unlocked + x-ms-server-encrypted: 'true' + x-ms-type: File + x-ms-version: '2021-06-08' + status: + code: 200 + message: OK + url: https://vincenttrancanary.file.core.windows.net/utshare5f4c1608/file5f4c1608 +version: 1 diff --git a/sdk/storage/azure-storage-file-share/tests/test_file.py b/sdk/storage/azure-storage-file-share/tests/test_file.py index 74808a38d439..65154a005ecf 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_file.py +++ b/sdk/storage/azure-storage-file-share/tests/test_file.py @@ -14,7 +14,7 @@ import pytest import uuid from azure.core import MatchConditions -from azure.core.credentials import AzureSasCredential +from azure.core.credentials import AzureSasCredential, AzureNamedKeyCredential from azure.core.exceptions import HttpResponseError, ResourceNotFoundError, ResourceExistsError from azure.storage.blob import BlobServiceClient @@ -2106,6 +2106,25 @@ def test_account_sas_credential(self, storage_account_name, storage_account_key) # Assert self.assertIsNotNone(properties) + @FileSharePreparer() + def test_azure_named_key_credential_access(self, storage_account_name, storage_account_key): + + self._setup(storage_account_name, storage_account_key) + file_client = self._create_file() + named_key = AzureNamedKeyCredential(storage_account_name, storage_account_key) + + # Act + file_client = ShareFileClient( + self.account_url(storage_account_name, "file"), + share_name=self.share_name, + file_path=file_client.file_name, + credential=named_key) + + properties = file_client.get_file_properties() + + # Assert + self.assertIsNotNone(properties) + @FileSharePreparer() def test_account_sas_raises_if_sas_already_in_uri(self, storage_account_name, storage_account_key): with self.assertRaises(ValueError): diff --git a/sdk/storage/azure-storage-file-share/tests/test_file_async.py b/sdk/storage/azure-storage-file-share/tests/test_file_async.py index 697afed18c3c..80fdb10da1a9 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_file_async.py +++ b/sdk/storage/azure-storage-file-share/tests/test_file_async.py @@ -10,7 +10,7 @@ import unittest from datetime import datetime, timedelta -from azure.core.credentials import AzureSasCredential +from azure.core.credentials import AzureSasCredential, AzureNamedKeyCredential from azure.core.pipeline.transport import AioHttpTransport from multidict import CIMultiDict, CIMultiDictProxy import requests @@ -2280,6 +2280,26 @@ async def test_account_sas_credential_async(self, storage_account_name, storage_ # Assert self.assertIsNotNone(properties) + @FileSharePreparer() + @AsyncStorageTestCase.await_prepared_test + async def test_azure_named_key_credential_access(self, storage_account_name, storage_account_key): + + self._setup(storage_account_name, storage_account_key) + file_client = await self._create_file(storage_account_name, storage_account_key) + named_key = AzureNamedKeyCredential(storage_account_name, storage_account_key) + + # Act + file_client = ShareFileClient( + self.account_url(storage_account_name, "file"), + share_name=self.share_name, + file_path=file_client.file_name, + credential=named_key) + + properties = await file_client.get_file_properties() + + # Assert + self.assertIsNotNone(properties) + @FileSharePreparer() def test_account_sas_raises_if_sas_already_in_uri(self, storage_account_name, storage_account_key): with self.assertRaises(ValueError): From 398815d097e5a0692fd51acf81a6f127b05bada0 Mon Sep 17 00:00:00 2001 From: Vincent Tran Date: Wed, 29 Jun 2022 18:38:26 -0700 Subject: [PATCH 10/17] Add support for queue --- .../azure/storage/queue/_queue_client.py | 23 +++- .../storage/queue/_queue_service_client.py | 15 ++- .../storage/queue/_shared/base_client.py | 10 +- .../storage/queue/aio/_queue_client_async.py | 8 +- .../queue/aio/_queue_service_client_async.py | 8 +- ...est_azure_named_key_credential_access.yaml | 117 ++++++++++++++++++ ...est_azure_named_key_credential_access.yaml | 91 ++++++++++++++ .../azure-storage-queue/tests/test_queue.py | 18 ++- .../tests/test_queue_async.py | 18 ++- 9 files changed, 290 insertions(+), 18 deletions(-) create mode 100644 sdk/storage/azure-storage-queue/tests/recordings/test_queue.test_azure_named_key_credential_access.yaml create mode 100644 sdk/storage/azure-storage-queue/tests/recordings/test_queue_async.test_azure_named_key_credential_access.yaml 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 3d40078a432d..91739cb5435a 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 @@ -53,8 +53,12 @@ class QueueClient(StorageAccountHostsMixin): :param credential: The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account - shared access key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. + If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential + - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword str api_version: The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility. @@ -133,8 +137,12 @@ def from_queue_url(cls, :param credential: The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account - shared access key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. + If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential + - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :returns: A queue client. :rtype: ~azure.storage.queue.QueueClient """ @@ -180,8 +188,11 @@ def from_connection_string( The credentials with which to authenticate. This is optional if the account URL already has a SAS token, or the connection string already has shared access key values. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account shared access - key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. + Credentials provided here will take precedence over those in the connection string. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :returns: A queue client. :rtype: ~azure.storage.queue.QueueClient 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 e58b348c5e39..f3a93e8cffbc 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 @@ -63,8 +63,12 @@ class QueueServiceClient(StorageAccountHostsMixin): :param credential: The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account - shared access key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. + If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential + - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword str api_version: The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility. @@ -131,8 +135,11 @@ def from_connection_string( The credentials with which to authenticate. This is optional if the account URL already has a SAS token, or the connection string already has shared access key values. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account shared access - key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. + Credentials provided here will take precedence over those in the connection string. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :returns: A Queue service client. :rtype: ~azure.storage.queue.QueueClient 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 7b56dba2507d..8f6585434b5a 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 @@ -10,6 +10,7 @@ Optional, Any, Tuple, + TYPE_CHECKING ) try: @@ -21,7 +22,7 @@ import six from azure.core.configuration import Configuration -from azure.core.credentials import AzureSasCredential +from azure.core.credentials import AzureSasCredential, AzureNamedKeyCredential from azure.core.exceptions import HttpResponseError from azure.core.pipeline import Pipeline from azure.core.pipeline.transport import RequestsTransport, HttpTransport @@ -54,6 +55,9 @@ from .._version import VERSION from .response_handlers import process_storage_error, PartialBatchErrorException +if TYPE_CHECKING: + from azure.core.credentials import TokenCredential + _LOGGER = logging.getLogger(__name__) _SERVICE_PARAMS = { @@ -68,7 +72,7 @@ def __init__( self, parsed_url, # type: Any service, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None @@ -363,6 +367,8 @@ def _format_shared_key_credential(account_name, credential): if "account_key" not in 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 credential 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 747b3ffd935a..9dc0efa5187f 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 @@ -55,8 +55,12 @@ class QueueClient(AsyncStorageAccountHostsMixin, QueueClientBase): :param credential: The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account - shared access key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. + If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential + - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword str api_version: The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility. 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 f286504c83aa..8115a6255af0 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 @@ -63,8 +63,12 @@ class QueueServiceClient(AsyncStorageAccountHostsMixin, QueueServiceClientBase): :param credential: The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, - an instance of a AzureSasCredential from azure.core.credentials, an account - shared access key, or an instance of a TokenCredentials class from azure.identity. + an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, + an account shared access key, or an instance of a TokenCredentials class from azure.identity. + If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential + - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. + If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" + should be the storage account key. :keyword str api_version: The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility. diff --git a/sdk/storage/azure-storage-queue/tests/recordings/test_queue.test_azure_named_key_credential_access.yaml b/sdk/storage/azure-storage-queue/tests/recordings/test_queue.test_azure_named_key_credential_access.yaml new file mode 100644 index 000000000000..880fc14b7fdc --- /dev/null +++ b/sdk/storage/azure-storage-queue/tests/recordings/test_queue.test_azure_named_key_credential_access.yaml @@ -0,0 +1,117 @@ +interactions: +- request: + body: null + headers: + Accept: + - application/xml + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '0' + User-Agent: + - azsdk-python-storage-queue/12.4.0 Python/3.10.2 (Windows-10-10.0.19044-SP0) + x-ms-date: + - Thu, 30 Jun 2022 01:31:30 GMT + x-ms-version: + - '2021-02-12' + method: PUT + uri: https://storagename.queue.core.windows.net/pyqueuesyncf7f71410 + response: + body: + string: '' + headers: + content-length: + - '0' + date: + - Thu, 30 Jun 2022 01:31:29 GMT + server: + - Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0 + x-ms-version: + - '2021-02-12' + status: + code: 201 + message: Created +- request: + body: ' + + message1' + headers: + Accept: + - application/xml + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '103' + Content-Type: + - application/xml + User-Agent: + - azsdk-python-storage-queue/12.4.0 Python/3.10.2 (Windows-10-10.0.19044-SP0) + x-ms-date: + - Thu, 30 Jun 2022 01:31:31 GMT + x-ms-version: + - '2021-02-12' + method: POST + uri: https://storagename.queue.core.windows.net/pyqueuesyncf7f71410/messages + response: + body: + string: "\uFEFFdc87d0b7-05a4-471c-8a0d-5c2ade57397bThu, + 30 Jun 2022 01:31:30 GMTThu, 07 Jul 2022 01:31:30 + GMTAgAAAAMAAAAAAAAAlHXjHyGM2AE=Thu, + 30 Jun 2022 01:31:30 GMT" + headers: + content-type: + - application/xml + date: + - Thu, 30 Jun 2022 01:31:30 GMT + server: + - Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0 + transfer-encoding: + - chunked + x-ms-version: + - '2021-02-12' + status: + code: 201 + message: Created +- request: + body: null + headers: + Accept: + - application/xml + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - azsdk-python-storage-queue/12.4.0 Python/3.10.2 (Windows-10-10.0.19044-SP0) + x-ms-date: + - Thu, 30 Jun 2022 01:31:31 GMT + x-ms-version: + - '2021-02-12' + method: GET + uri: https://storagename.queue.core.windows.net/pyqueuesyncf7f71410/messages?peekonly=true + response: + body: + string: "\uFEFFdc87d0b7-05a4-471c-8a0d-5c2ade57397bThu, + 30 Jun 2022 01:31:30 GMTThu, 07 Jul 2022 01:31:30 + GMT0message1" + headers: + cache-control: + - no-cache + content-type: + - application/xml + date: + - Thu, 30 Jun 2022 01:31:30 GMT + server: + - Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0 + transfer-encoding: + - chunked + x-ms-version: + - '2021-02-12' + status: + code: 200 + message: OK +version: 1 diff --git a/sdk/storage/azure-storage-queue/tests/recordings/test_queue_async.test_azure_named_key_credential_access.yaml b/sdk/storage/azure-storage-queue/tests/recordings/test_queue_async.test_azure_named_key_credential_access.yaml new file mode 100644 index 000000000000..708dfd79c783 --- /dev/null +++ b/sdk/storage/azure-storage-queue/tests/recordings/test_queue_async.test_azure_named_key_credential_access.yaml @@ -0,0 +1,91 @@ +interactions: +- request: + body: null + headers: + Accept: + - application/xml + User-Agent: + - azsdk-python-storage-queue/12.4.0 Python/3.10.2 (Windows-10-10.0.19044-SP0) + x-ms-date: + - Thu, 30 Jun 2022 01:32:54 GMT + x-ms-version: + - '2021-02-12' + method: PUT + uri: https://storagename.queue.core.windows.net/pyqueueasync7b44168d + response: + body: + string: '' + headers: + content-length: '0' + date: Thu, 30 Jun 2022 01:32:53 GMT + server: Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0 + x-ms-version: '2021-02-12' + status: + code: 201 + message: Created + url: https://vincenttranstock.queue.core.windows.net/pyqueueasync7b44168d +- request: + body: ' + + message1' + headers: + Accept: + - application/xml + Content-Length: + - '103' + Content-Type: + - application/xml + User-Agent: + - azsdk-python-storage-queue/12.4.0 Python/3.10.2 (Windows-10-10.0.19044-SP0) + x-ms-date: + - Thu, 30 Jun 2022 01:32:55 GMT + x-ms-version: + - '2021-02-12' + method: POST + uri: https://storagename.queue.core.windows.net/pyqueueasync7b44168d/messages + response: + body: + string: "\uFEFFdee316b0-a564-41da-a385-006dcf1c8e50Thu, + 30 Jun 2022 01:32:54 GMTThu, 07 Jul 2022 01:32:54 + GMTAgAAAAMAAAAAAAAAav7cUSGM2AE=Thu, + 30 Jun 2022 01:32:54 GMT" + headers: + content-type: application/xml + date: Thu, 30 Jun 2022 01:32:53 GMT + server: Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0 + transfer-encoding: chunked + x-ms-version: '2021-02-12' + status: + code: 201 + message: Created + url: https://vincenttranstock.queue.core.windows.net/pyqueueasync7b44168d/messages +- request: + body: null + headers: + Accept: + - application/xml + User-Agent: + - azsdk-python-storage-queue/12.4.0 Python/3.10.2 (Windows-10-10.0.19044-SP0) + x-ms-date: + - Thu, 30 Jun 2022 01:32:55 GMT + x-ms-version: + - '2021-02-12' + method: GET + uri: https://storagename.queue.core.windows.net/pyqueueasync7b44168d/messages?peekonly=true + response: + body: + string: "\uFEFFdee316b0-a564-41da-a385-006dcf1c8e50Thu, + 30 Jun 2022 01:32:54 GMTThu, 07 Jul 2022 01:32:54 + GMT0message1" + headers: + cache-control: no-cache + content-type: application/xml + date: Thu, 30 Jun 2022 01:32:53 GMT + server: Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0 + transfer-encoding: chunked + x-ms-version: '2021-02-12' + status: + code: 200 + message: OK + url: https://vincenttranstock.queue.core.windows.net/pyqueueasync7b44168d/messages?peekonly=true +version: 1 diff --git a/sdk/storage/azure-storage-queue/tests/test_queue.py b/sdk/storage/azure-storage-queue/tests/test_queue.py index 4c8e623ae383..4c2d0f723d61 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue.py @@ -14,7 +14,7 @@ date, ) -from azure.core.credentials import AzureSasCredential +from azure.core.credentials import AzureSasCredential, AzureNamedKeyCredential from azure.core.pipeline.transport import RequestsTransport from azure.core.exceptions import ( HttpResponseError, @@ -725,6 +725,22 @@ def test_account_sas(self, storage_account_name, storage_account_key): self.assertNotEqual('', message.id) self.assertEqual(u'message1', message.content) + @QueuePreparer() + def test_azure_named_key_credential_access(self, storage_account_name, storage_account_key): + + # Arrange + named_key = AzureNamedKeyCredential(storage_account_name, storage_account_key) + 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(u'message1') + + # Act + result = queue_client.peek_messages() + + # Assert + self.assertIsNotNone(result) + @QueuePreparer() def test_account_sas_raises_if_sas_already_in_uri(self, storage_account_name, storage_account_key): with self.assertRaises(ValueError): 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 0a67b04fe15a..4070cdde8bb3 100644 --- a/sdk/storage/azure-storage-queue/tests/test_queue_async.py +++ b/sdk/storage/azure-storage-queue/tests/test_queue_async.py @@ -14,7 +14,7 @@ date, ) -from azure.core.credentials import AzureSasCredential +from azure.core.credentials import AzureSasCredential, AzureNamedKeyCredential from azure.core.pipeline.transport import AioHttpTransport from azure.core.exceptions import ( HttpResponseError, @@ -779,6 +779,22 @@ async def test_account_sas(self, storage_account_name, storage_account_key): self.assertNotEqual('', message.id) self.assertEqual(u'message1', message.content) + @QueuePreparer() + async def test_azure_named_key_credential_access(self, storage_account_name, storage_account_key): + + # Arrange + named_key = AzureNamedKeyCredential(storage_account_name, storage_account_key) + 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(u'message1') + + # Act + result = await queue_client.peek_messages() + + # Assert + self.assertIsNotNone(result) + @QueuePreparer() def test_account_sas_raises_if_sas_already_in_uri(self, storage_account_name, storage_account_key): with self.assertRaises(ValueError): From 7806af2d92c6ed36fb2e9a64fd777ae03150eca2 Mon Sep 17 00:00:00 2001 From: Vincent Tran Date: Wed, 29 Jun 2022 18:42:15 -0700 Subject: [PATCH 11/17] Newline fix --- sdk/storage/azure-storage-file-share/tests/test_file.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/storage/azure-storage-file-share/tests/test_file.py b/sdk/storage/azure-storage-file-share/tests/test_file.py index a31120ae66f7..ad71cad0a6f5 100644 --- a/sdk/storage/azure-storage-file-share/tests/test_file.py +++ b/sdk/storage/azure-storage-file-share/tests/test_file.py @@ -13,7 +13,6 @@ import requests import uuid from azure.core import MatchConditions - from azure.core.credentials import AzureSasCredential, AzureNamedKeyCredential from azure.core.exceptions import HttpResponseError, ResourceNotFoundError, ResourceExistsError from azure.storage.blob import BlobServiceClient From f2fca51aed715d12992ece0759786c663f5dc566 Mon Sep 17 00:00:00 2001 From: Vincent Tran Date: Thu, 30 Jun 2022 11:27:02 -0700 Subject: [PATCH 12/17] Re-record datalake tests --- ...rvice_client.test_azure_named_key_credential_access.yaml | 6 +++--- ...client_async.test_azure_named_key_credential_access.yaml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sdk/storage/azure-storage-file-datalake/tests/recordings/test_datalake_service_client.test_azure_named_key_credential_access.yaml b/sdk/storage/azure-storage-file-datalake/tests/recordings/test_datalake_service_client.test_azure_named_key_credential_access.yaml index 658d475fc855..4d6bd20c81db 100644 --- a/sdk/storage/azure-storage-file-datalake/tests/recordings/test_datalake_service_client.test_azure_named_key_credential_access.yaml +++ b/sdk/storage/azure-storage-file-datalake/tests/recordings/test_datalake_service_client.test_azure_named_key_credential_access.yaml @@ -11,7 +11,7 @@ interactions: User-Agent: - azsdk-python-storage-blob/12.13.0 Python/3.10.2 (Windows-10-10.0.19044-SP0) x-ms-date: - - Wed, 29 Jun 2022 21:32:45 GMT + - Thu, 30 Jun 2022 18:26:05 GMT x-ms-version: - '2021-08-06' method: GET @@ -19,12 +19,12 @@ interactions: response: body: string: "\uFEFF1.0falsefalsefalsefalse1.0truetruetrue71.0falsefalsefalsefalsefalse" + />falsefalsefalse2014-02-14" headers: content-type: - application/xml date: - - Wed, 29 Jun 2022 21:32:44 GMT + - Thu, 30 Jun 2022 18:26:04 GMT server: - Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0 transfer-encoding: diff --git a/sdk/storage/azure-storage-file-datalake/tests/recordings/test_datalake_service_client_async.test_azure_named_key_credential_access.yaml b/sdk/storage/azure-storage-file-datalake/tests/recordings/test_datalake_service_client_async.test_azure_named_key_credential_access.yaml index e4cbdbcf852d..aa13f43de678 100644 --- a/sdk/storage/azure-storage-file-datalake/tests/recordings/test_datalake_service_client_async.test_azure_named_key_credential_access.yaml +++ b/sdk/storage/azure-storage-file-datalake/tests/recordings/test_datalake_service_client_async.test_azure_named_key_credential_access.yaml @@ -7,7 +7,7 @@ interactions: User-Agent: - azsdk-python-storage-blob/12.13.0 Python/3.10.2 (Windows-10-10.0.19044-SP0) x-ms-date: - - Wed, 29 Jun 2022 21:34:07 GMT + - Thu, 30 Jun 2022 18:26:23 GMT x-ms-version: - '2021-08-06' method: GET @@ -15,10 +15,10 @@ interactions: response: body: string: "\uFEFF1.0falsefalsefalsefalse1.0truetruetrue71.0falsefalsefalsefalsefalse" + />falsefalsefalse2014-02-14" headers: content-type: application/xml - date: Wed, 29 Jun 2022 21:34:06 GMT + date: Thu, 30 Jun 2022 18:26:21 GMT server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0 transfer-encoding: chunked x-ms-version: '2021-08-06' From 4bae706bc61e80b2dd365bcb05d6f641a3b9bb26 Mon Sep 17 00:00:00 2001 From: Vincent Tran Date: Thu, 30 Jun 2022 11:57:46 -0700 Subject: [PATCH 13/17] Omit changefeed test --- .../tests/test_change_feed.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/sdk/storage/azure-storage-blob-changefeed/tests/test_change_feed.py b/sdk/storage/azure-storage-blob-changefeed/tests/test_change_feed.py index 72285c7d9101..35885ce159af 100644 --- a/sdk/storage/azure-storage-blob-changefeed/tests/test_change_feed.py +++ b/sdk/storage/azure-storage-blob-changefeed/tests/test_change_feed.py @@ -334,14 +334,3 @@ def test_list_3_shards_events_works_with_1_shard_cursor(self, storage_account_na dict_token_with_1_shard = json.loads(token_with_1_shard) self.assertEqual(len(dict_token_with_1_shard['CurrentSegmentCursor']['ShardCursors']), 1) self.assertEqual(len(dict_token['CurrentSegmentCursor']['ShardCursors']), 3) - - # @ChangeFeedPreparer() - # def test_azure_named_key_credential_access(self, storage_account_name, storage_account_key): - # named_key = AzureNamedKeyCredential(storage_account_name, storage_account_key) - # cf_client = ChangeFeedClient(self.account_url(storage_account_name, "blob"), named_key) - # - # # Act - # change_feed = cf_client.list_changes() - # - # # Assert - # self.assertIsNotNone(change_feed) From e192ca0ce1b644f0542c530dfdc856dada8f54d6 Mon Sep 17 00:00:00 2001 From: Vincent Tran Date: Fri, 8 Jul 2022 17:56:44 -0700 Subject: [PATCH 14/17] Add credential typehint to all func. prototypes --- .../storage/blob/changefeed/_change_feed_client.py | 4 ++-- .../tests/test_change_feed.py | 1 - .../azure/storage/blob/__init__.py | 4 ++-- .../azure/storage/blob/_blob_client.py | 13 +++++++++---- .../azure/storage/blob/_blob_service_client.py | 4 ++-- .../azure/storage/blob/_container_client.py | 12 ++++++++---- .../azure/storage/blob/aio/__init__.py | 4 ++-- .../azure/storage/blob/aio/_blob_client_async.py | 2 +- .../storage/blob/aio/_blob_service_client_async.py | 2 +- .../storage/blob/aio/_container_client_async.py | 2 +- .../filedatalake/_data_lake_directory_client.py | 4 ++-- .../storage/filedatalake/_data_lake_file_client.py | 4 ++-- .../storage/filedatalake/_file_system_client.py | 4 ++-- .../azure/storage/filedatalake/_path_client.py | 2 +- .../aio/_data_lake_directory_client_async.py | 2 +- .../aio/_data_lake_file_client_async.py | 2 +- .../aio/_data_lake_service_client_async.py | 2 +- .../filedatalake/aio/_file_system_client_async.py | 2 +- .../storage/filedatalake/aio/_path_client_async.py | 2 +- .../azure/storage/fileshare/_directory_client.py | 6 +++--- .../azure/storage/fileshare/_file_client.py | 6 +++--- .../azure/storage/fileshare/_share_client.py | 6 +++--- .../storage/fileshare/_share_service_client.py | 4 ++-- .../fileshare/aio/_directory_client_async.py | 2 +- .../storage/fileshare/aio/_file_client_async.py | 2 +- .../storage/fileshare/aio/_share_client_async.py | 2 +- .../fileshare/aio/_share_service_client_async.py | 2 +- .../azure/storage/queue/_queue_client.py | 6 +++--- .../azure/storage/queue/_queue_service_client.py | 4 ++-- .../azure/storage/queue/aio/_queue_client_async.py | 2 +- .../queue/aio/_queue_service_client_async.py | 2 +- 31 files changed, 62 insertions(+), 54 deletions(-) diff --git a/sdk/storage/azure-storage-blob-changefeed/azure/storage/blob/changefeed/_change_feed_client.py b/sdk/storage/azure-storage-blob-changefeed/azure/storage/blob/changefeed/_change_feed_client.py index e64a494768ae..c91eccc5f53b 100644 --- a/sdk/storage/azure-storage-blob-changefeed/azure/storage/blob/changefeed/_change_feed_client.py +++ b/sdk/storage/azure-storage-blob-changefeed/azure/storage/blob/changefeed/_change_feed_client.py @@ -53,7 +53,7 @@ class ChangeFeedClient(object): # pylint: disable=too-many-public-methods """ def __init__( self, account_url, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None @@ -62,7 +62,7 @@ def __init__( @classmethod def from_connection_string( cls, conn_str, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> ChangeFeedClient """Create ChangeFeedClient from a Connection String. diff --git a/sdk/storage/azure-storage-blob-changefeed/tests/test_change_feed.py b/sdk/storage/azure-storage-blob-changefeed/tests/test_change_feed.py index 35885ce159af..04b860916f9b 100644 --- a/sdk/storage/azure-storage-blob-changefeed/tests/test_change_feed.py +++ b/sdk/storage/azure-storage-blob-changefeed/tests/test_change_feed.py @@ -21,7 +21,6 @@ from devtools_testutils.storage import StorageTestCase from settings.testcase import ChangeFeedPreparer -from azure.core.credentials import AzureNamedKeyCredential @pytest.mark.playback_test_only class StorageChangeFeedTest(StorageTestCase): diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/__init__.py b/sdk/storage/azure-storage-blob/azure/storage/blob/__init__.py index 0eb10c87283e..15f20338c80f 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/__init__.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/__init__.py @@ -70,7 +70,7 @@ def upload_blob_to_url( blob_url, # type: str data, # type: Union[Iterable[AnyStr], IO[AnyStr]] - credential=None, # type: Any + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs): # type: (...) -> Dict[str, Any] """Upload data to a given URL @@ -129,7 +129,7 @@ def _download_to_stream(client, handle, **kwargs): def download_blob_from_url( blob_url, # type: str output, # type: str - credential=None, # type: Any + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs): # type: (...) -> None """Download the contents of a blob to a local file or stream. diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client.py index 7dd09e490945..714ae1b116b0 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client.py @@ -153,7 +153,7 @@ def __init__( container_name, # type: str blob_name, # type: str snapshot=None, # type: Optional[Union[str, Dict[str, Any]]] - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None @@ -212,8 +212,13 @@ def _encode_source_url(self, source_url): return '?'.join(result) @classmethod - def from_blob_url(cls, blob_url, credential=None, snapshot=None, **kwargs): - # type: (Type[ClassType], str, Optional[Any], Optional[Union[str, Dict[str, Any]]], Any) -> ClassType + def from_blob_url( + cls, # type: Type[ClassType] + blob_url, # type: str + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long + snapshot=None, # type: Optional[Union[str, Dict[str, Any]]] + **kwargs # type: Any + ): # type: (...) -> ClassType """Create BlobClient from a blob url. This doesn't support customized blob url with '/' in blob name. :param str blob_url: @@ -295,7 +300,7 @@ def from_connection_string( container_name, # type: str blob_name, # type: str snapshot=None, # type: Optional[str] - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> ClassType """Create BlobClient from a Connection String. diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_service_client.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_service_client.py index 227cba13d552..ed7fb2819ae9 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_service_client.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_service_client.py @@ -120,7 +120,7 @@ class BlobServiceClient(StorageAccountHostsMixin, StorageEncryptionMixin): def __init__( self, account_url, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None @@ -150,7 +150,7 @@ def _format_url(self, hostname): def from_connection_string( cls, # type: Type[ClassType] conn_str, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> ClassType """Create BlobServiceClient from a Connection String. diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py index a518c415e175..48517ae3e6ac 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py @@ -134,7 +134,7 @@ class ContainerClient(StorageAccountHostsMixin, StorageEncryptionMixin): # py def __init__( self, account_url, # type: str container_name, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None @@ -170,8 +170,12 @@ def _format_url(self, hostname): self._query_str) @classmethod - def from_container_url(cls, container_url, credential=None, **kwargs): - # type: (Type[ClassType], str, Optional[Any], Any) -> ClassType + def from_container_url( + cls, # type: Type[ClassType] + container_url, # type: str + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long + **kwargs # type: Any + ): # type: (...) -> ClassType """Create ContainerClient from a container url. :param str container_url: @@ -219,7 +223,7 @@ def from_connection_string( cls, # type: Type[ClassType] conn_str, # type: str container_name, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> ClassType """Create ContainerClient from a Connection String. diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/__init__.py b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/__init__.py index 79d0be1c8031..e8286fe217b1 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/__init__.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/__init__.py @@ -19,7 +19,7 @@ async def upload_blob_to_url( blob_url, # type: str data, # type: Union[Iterable[AnyStr], IO[AnyStr]] - credential=None, # type: Any + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs): # type: (...) -> dict[str, Any] """Upload data to a given URL @@ -78,7 +78,7 @@ async def _download_to_stream(client, handle, **kwargs): async def download_blob_from_url( blob_url, # type: str output, # type: str - credential=None, # type: Any + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs): # type: (...) -> None """Download the contents of a blob to a local file or stream. diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_blob_client_async.py b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_blob_client_async.py index 7ba13cc07f2b..93a2cf6d51df 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_blob_client_async.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_blob_client_async.py @@ -119,7 +119,7 @@ def __init__( container_name, # type: str blob_name, # type: str snapshot=None, # type: Optional[Union[str, Dict[str, Any]]] - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_blob_service_client_async.py b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_blob_service_client_async.py index ed50fb2cff64..7a5ba88e45f3 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_blob_service_client_async.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_blob_service_client_async.py @@ -116,7 +116,7 @@ class BlobServiceClient(AsyncStorageAccountHostsMixin, BlobServiceClientBase, St def __init__( self, account_url, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_container_client_async.py b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_container_client_async.py index 9e8f886e8e98..13a48cf91d94 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_container_client_async.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_container_client_async.py @@ -111,7 +111,7 @@ class ContainerClient(AsyncStorageAccountHostsMixin, ContainerClientBase, Storag def __init__( self, account_url, # type: str container_name, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py index 9fe548ff57ce..6ba16641392a 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py @@ -70,7 +70,7 @@ def __init__( self, account_url, # type: str file_system_name, # type: str directory_name, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None @@ -83,7 +83,7 @@ def from_connection_string( conn_str, # type: str file_system_name, # type: str directory_name, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> ClassType """ diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_file_client.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_file_client.py index e270d6769872..53c62b68005a 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_file_client.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_file_client.py @@ -80,7 +80,7 @@ def __init__( self, account_url, # type: str file_system_name, # type: str file_path, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None @@ -93,7 +93,7 @@ def from_connection_string( conn_str, # type: str file_system_name, # type: str file_path, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> ClassType """ 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 6ab758b40815..ab25f4c176f2 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 @@ -80,7 +80,7 @@ class FileSystemClient(StorageAccountHostsMixin): def __init__( self, account_url, # type: str file_system_name, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None @@ -152,7 +152,7 @@ def from_connection_string( cls, # type: Type[ClassType] conn_str, # type: str file_system_name, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> ClassType """ 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 9fb27e272ee9..d8ee044b43ea 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 @@ -61,7 +61,7 @@ def __init__( self, account_url, # type: str file_system_name, # type: str path_name, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_directory_client_async.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_directory_client_async.py index b2b7a3e87d03..70eba7129172 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_directory_client_async.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_directory_client_async.py @@ -71,7 +71,7 @@ def __init__( self, account_url, # type: str file_system_name, # type: str directory_name, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_file_client_async.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_file_client_async.py index 38ad605f8802..cdc08c5fdcdb 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_file_client_async.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_file_client_async.py @@ -72,7 +72,7 @@ def __init__( self, account_url, # type: str file_system_name, # type: str file_path, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None 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 60e0daafb7f3..c71160695f37 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 @@ -73,7 +73,7 @@ class DataLakeServiceClient(AsyncStorageAccountHostsMixin, DataLakeServiceClient def __init__( self, account_url, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None 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 762dfd5dc460..e0c962334c90 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 @@ -84,7 +84,7 @@ class FileSystemClient(AsyncStorageAccountHostsMixin, FileSystemClientBase): def __init__( self, account_url, # type: str file_system_name, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None 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 f24ad8eaac11..6209df416f92 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 @@ -53,7 +53,7 @@ def __init__( self, account_url, # type: str file_system_name, # type: str path_name, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_directory_client.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_directory_client.py index dadc60fdf630..3c4132a59512 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_directory_client.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_directory_client.py @@ -86,7 +86,7 @@ def __init__( # type: ignore share_name, # type: str directory_path, # type: str snapshot=None, # type: Optional[Union[str, Dict[str, Any]]] - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Optional[Any] ): # type: (...) -> None @@ -127,7 +127,7 @@ def __init__( # type: ignore @classmethod def from_directory_url(cls, directory_url, # type: str snapshot=None, # type: Optional[Union[str, Dict[str, Any]]] - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Optional[Any] ): # type: (...) -> ShareDirectoryClient @@ -193,7 +193,7 @@ def from_connection_string( cls, conn_str, # type: str share_name, # type: str directory_path, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> ShareDirectoryClient diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_file_client.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_file_client.py index 64661864346c..c3d3afdd461f 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_file_client.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_file_client.py @@ -146,7 +146,7 @@ def __init__( # type: ignore share_name, # type: str file_path, # type: str snapshot=None, # type: Optional[Union[str, Dict[str, Any]]] - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None @@ -191,7 +191,7 @@ def __init__( # type: ignore def from_file_url( cls, file_url, # type: str snapshot=None, # type: Optional[Union[str, Dict[str, Any]]] - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> ShareFileClient @@ -251,7 +251,7 @@ def from_connection_string( share_name, # type: str file_path, # type: str snapshot=None, # type: Optional[Union[str, Dict[str, Any]]] - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> ShareFileClient diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_client.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_client.py index 53561d13b3aa..4a699e1c2f67 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_client.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_client.py @@ -84,7 +84,7 @@ def __init__( # type: ignore self, account_url, # type: str share_name, # type: str snapshot=None, # type: Optional[Union[str, Dict[str, Any]]] - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None @@ -124,7 +124,7 @@ def __init__( # type: ignore @classmethod def from_share_url(cls, share_url, # type: str snapshot=None, # type: Optional[Union[str, Dict[str, Any]]] - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> ShareClient @@ -197,7 +197,7 @@ def from_connection_string( cls, conn_str, # type: str share_name, # type: str snapshot=None, # type: Optional[str] - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> ShareClient diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_service_client.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_service_client.py index e934c8eb35b1..da9c8a065957 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_service_client.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_share_service_client.py @@ -87,7 +87,7 @@ class ShareServiceClient(StorageAccountHostsMixin): """ def __init__( self, account_url, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None @@ -120,7 +120,7 @@ def _format_url(self, hostname): @classmethod def from_connection_string( cls, conn_str, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> ShareServiceClient """Create ShareServiceClient from a Connection String. diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_directory_client_async.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_directory_client_async.py index 4fdbd621f5a9..1ec1380c61dd 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_directory_client_async.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_directory_client_async.py @@ -79,7 +79,7 @@ def __init__( # type: ignore share_name, # type: str directory_path, # type: str snapshot=None, # type: Optional[Union[str, Dict[str, Any]]] - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Optional[Any] ): # type: (...) -> None diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_file_client_async.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_file_client_async.py index 02bed090ddfb..a27def34d133 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_file_client_async.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_file_client_async.py @@ -138,7 +138,7 @@ def __init__( # type: ignore share_name, # type: str file_path, # type: str snapshot=None, # type: Optional[Union[str, Dict[str, Any]]] - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_client_async.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_client_async.py index 4c1ebdc8ba11..2fe3850b3270 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_client_async.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_client_async.py @@ -75,7 +75,7 @@ def __init__( # type: ignore self, account_url, # type: str share_name, # type: str snapshot=None, # type: Optional[Union[str, Dict[str, Any]]] - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_service_client_async.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_service_client_async.py index bc6943b3bca6..482bebc73793 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_service_client_async.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_share_service_client_async.py @@ -82,7 +82,7 @@ class ShareServiceClient(AsyncStorageAccountHostsMixin, ShareServiceClientBase): """ def __init__( self, account_url, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None 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 300cfc763b14..6bc3442178cc 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 @@ -79,7 +79,7 @@ class QueueClient(StorageAccountHostsMixin, StorageEncryptionMixin): def __init__( self, account_url, # type: str queue_name, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None @@ -124,7 +124,7 @@ def _format_url(self, hostname): @classmethod def from_queue_url(cls, queue_url, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> QueueClient @@ -171,7 +171,7 @@ def from_queue_url(cls, def from_connection_string( cls, conn_str, # type: str queue_name, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> QueueClient 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 e3807955ab91..4978b84e6faa 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 @@ -88,7 +88,7 @@ class QueueServiceClient(StorageAccountHostsMixin, StorageEncryptionMixin): def __init__( self, account_url, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None @@ -119,7 +119,7 @@ def _format_url(self, hostname): @classmethod def from_connection_string( cls, conn_str, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> QueueServiceClient """Create QueueServiceClient from a Connection String. 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 eec4ebccf945..b387df37c521 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 @@ -87,7 +87,7 @@ def __init__( self, account_url, # type: str queue_name, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None 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 5ff5c0167257..297445149ce7 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 @@ -87,7 +87,7 @@ class QueueServiceClient(AsyncStorageAccountHostsMixin, QueueServiceClientBase, def __init__( self, account_url, # type: str - credential=None, # type: Optional[Any] + credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long **kwargs # type: Any ): # type: (...) -> None From 3ac2acf3c6cdea7d7b35da131636db7fa89d786a Mon Sep 17 00:00:00 2001 From: Vincent Tran Date: Mon, 11 Jul 2022 17:29:41 -0700 Subject: [PATCH 15/17] Re-record failing dsc tests --- ...ice_client.test_azure_named_key_credential_access.yaml | 6 +++--- ...ient_async.test_azure_named_key_credential_access.yaml | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/sdk/storage/azure-storage-file-datalake/tests/recordings/test_datalake_service_client.test_azure_named_key_credential_access.yaml b/sdk/storage/azure-storage-file-datalake/tests/recordings/test_datalake_service_client.test_azure_named_key_credential_access.yaml index 4d6bd20c81db..56be9ab4cc92 100644 --- a/sdk/storage/azure-storage-file-datalake/tests/recordings/test_datalake_service_client.test_azure_named_key_credential_access.yaml +++ b/sdk/storage/azure-storage-file-datalake/tests/recordings/test_datalake_service_client.test_azure_named_key_credential_access.yaml @@ -11,7 +11,7 @@ interactions: User-Agent: - azsdk-python-storage-blob/12.13.0 Python/3.10.2 (Windows-10-10.0.19044-SP0) x-ms-date: - - Thu, 30 Jun 2022 18:26:05 GMT + - Tue, 12 Jul 2022 00:28:51 GMT x-ms-version: - '2021-08-06' method: GET @@ -19,12 +19,12 @@ interactions: response: body: string: "\uFEFF1.0falsefalsefalsefalse1.0truetruetrue71.0falsefalsefalsefalsefalse2014-02-14" + />falsefalsefalse" headers: content-type: - application/xml date: - - Thu, 30 Jun 2022 18:26:04 GMT + - Tue, 12 Jul 2022 00:28:51 GMT server: - Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0 transfer-encoding: diff --git a/sdk/storage/azure-storage-file-datalake/tests/recordings/test_datalake_service_client_async.test_azure_named_key_credential_access.yaml b/sdk/storage/azure-storage-file-datalake/tests/recordings/test_datalake_service_client_async.test_azure_named_key_credential_access.yaml index aa13f43de678..17aa5e7ad1c3 100644 --- a/sdk/storage/azure-storage-file-datalake/tests/recordings/test_datalake_service_client_async.test_azure_named_key_credential_access.yaml +++ b/sdk/storage/azure-storage-file-datalake/tests/recordings/test_datalake_service_client_async.test_azure_named_key_credential_access.yaml @@ -7,7 +7,7 @@ interactions: User-Agent: - azsdk-python-storage-blob/12.13.0 Python/3.10.2 (Windows-10-10.0.19044-SP0) x-ms-date: - - Thu, 30 Jun 2022 18:26:23 GMT + - Tue, 12 Jul 2022 00:29:02 GMT x-ms-version: - '2021-08-06' method: GET @@ -15,15 +15,15 @@ interactions: response: body: string: "\uFEFF1.0falsefalsefalsefalse1.0truetruetrue71.0falsefalsefalsefalsefalse2014-02-14" + />falsefalsefalse" headers: content-type: application/xml - date: Thu, 30 Jun 2022 18:26:21 GMT + date: Tue, 12 Jul 2022 00:29:01 GMT server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0 transfer-encoding: chunked x-ms-version: '2021-08-06' status: code: 200 message: OK - url: https://vincenttranhns.blob.core.windows.net/?restype=service&comp=properties + url: https://vincenttranhnscanary.blob.core.windows.net/?restype=service&comp=properties version: 1 From 725ef105cb5ccf2f006c19543c59c52ec5ac8fcb Mon Sep 17 00:00:00 2001 From: Vincent Tran Date: Tue, 12 Jul 2022 16:21:46 -0700 Subject: [PATCH 16/17] Bump version for DataLake dependency --- sdk/storage/azure-storage-file-datalake/setup.py | 2 +- shared_requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/storage/azure-storage-file-datalake/setup.py b/sdk/storage/azure-storage-file-datalake/setup.py index b36376c93520..d939a6d5dc75 100644 --- a/sdk/storage/azure-storage-file-datalake/setup.py +++ b/sdk/storage/azure-storage-file-datalake/setup.py @@ -78,6 +78,6 @@ install_requires=[ "azure-core<2.0.0,>=1.23.1", "msrest>=0.6.21", - "azure-storage-blob<13.0.0,>=12.13.0" + "azure-storage-blob<13.0.0,>=12.14.0b1" ], ) diff --git a/shared_requirements.txt b/shared_requirements.txt index 28aeac4e7c67..c726c721c523 100644 --- a/shared_requirements.txt +++ b/shared_requirements.txt @@ -158,7 +158,7 @@ chardet<5,>=3.0.2 #override azure-storage-queue azure-core<2.0.0,>=1.23.1 #override azure-storage-file-share azure-core<2.0.0,>=1.23.1 #override azure-storage-file-datalake azure-core<2.0.0,>=1.23.1 -#override azure-storage-file-datalake azure-storage-blob<13.0.0,>=12.13.0 +#override azure-storage-file-datalake azure-storage-blob<13.0.0,>=12.14.0b1 #override azure-security-attestation azure-core<2.0.0,>=1.8.2 #override azure-data-tables msrest>=0.6.19 #override azure-schemaregistry azure-core<2.0.0,>=1.23.0 From 5da9f68589ef4851205f343a03c405f1186df094 Mon Sep 17 00:00:00 2001 From: Vincent Tran Date: Fri, 22 Jul 2022 12:30:41 -0700 Subject: [PATCH 17/17] Added changelog entry --- sdk/storage/azure-storage-blob/CHANGELOG.md | 1 + sdk/storage/azure-storage-file-datalake/CHANGELOG.md | 1 + sdk/storage/azure-storage-file-share/CHANGELOG.md | 1 + sdk/storage/azure-storage-queue/CHANGELOG.md | 1 + 4 files changed, 4 insertions(+) diff --git a/sdk/storage/azure-storage-blob/CHANGELOG.md b/sdk/storage/azure-storage-blob/CHANGELOG.md index faa366275423..2acede653540 100644 --- a/sdk/storage/azure-storage-blob/CHANGELOG.md +++ b/sdk/storage/azure-storage-blob/CHANGELOG.md @@ -3,6 +3,7 @@ ## 12.14.0b1 (Unreleased) ### Features Added +- Added support for `AzureNamedKeyCredential` as a valid `credential` type. ### Bugs Fixed diff --git a/sdk/storage/azure-storage-file-datalake/CHANGELOG.md b/sdk/storage/azure-storage-file-datalake/CHANGELOG.md index cc7bbeebb708..59ccef0349ee 100644 --- a/sdk/storage/azure-storage-file-datalake/CHANGELOG.md +++ b/sdk/storage/azure-storage-file-datalake/CHANGELOG.md @@ -3,6 +3,7 @@ ## 12.9.0b1 (Unreleased) ### Features Added +- Added support for `AzureNamedKeyCredential` as a valid `credential` type. ### Bugs Fixed diff --git a/sdk/storage/azure-storage-file-share/CHANGELOG.md b/sdk/storage/azure-storage-file-share/CHANGELOG.md index 6da9deb8e468..ca725a4d5ab3 100644 --- a/sdk/storage/azure-storage-file-share/CHANGELOG.md +++ b/sdk/storage/azure-storage-file-share/CHANGELOG.md @@ -3,6 +3,7 @@ ## 12.10.0b1 (Unreleased) ### Features Added +- Added support for `AzureNamedKeyCredential` as a valid `credential` type. ### Bugs Fixed diff --git a/sdk/storage/azure-storage-queue/CHANGELOG.md b/sdk/storage/azure-storage-queue/CHANGELOG.md index eec4854bb733..63a91bcfe4ad 100644 --- a/sdk/storage/azure-storage-queue/CHANGELOG.md +++ b/sdk/storage/azure-storage-queue/CHANGELOG.md @@ -3,6 +3,7 @@ ## 12.5.0b1 (Unreleased) ### Features Added +- Added support for `AzureNamedKeyCredential` as a valid `credential` type. ### Bugs Fixed