diff --git a/sdk/core/azure-common/azure/common/client_factory.py b/sdk/core/azure-common/azure/common/client_factory.py index 27ffd2eb66c5..7ea9cef929ff 100644 --- a/sdk/core/azure-common/azure/common/client_factory.py +++ b/sdk/core/azure-common/azure/common/client_factory.py @@ -109,6 +109,14 @@ def get_client_from_cli_profile(client_class, **kwargs): return _instantiate_client(client_class, **parameters) +def _is_autorest_v3(client_class): + """Is this client a autorestv3/track2 one?. + Could be refined later if necessary. + """ + args = get_arg_spec(client_class.__init__).args + return "credential" in args + + def get_client_from_json_dict(client_class, config_dict, **kwargs): """Return a SDK client initialized with a JSON auth dict. @@ -152,6 +160,12 @@ def get_client_from_json_dict(client_class, config_dict, **kwargs): :param dict config_dict: A config dict. :return: An instantiated client """ + if _is_autorest_v3(client_class): + raise ValueError( + "Auth file or JSON dict are deprecated auth approach and are not supported anymore. " + "Please read https://aka.ms/azsdk/python/azidmigration for details" + ) + import adal from msrestazure.azure_active_directory import AdalAuthentication diff --git a/sdk/core/azure-common/tests/test_client_factory.py b/sdk/core/azure-common/tests/test_client_factory.py index b6d86570221d..dbf277440fc4 100644 --- a/sdk/core/azure-common/tests/test_client_factory.py +++ b/sdk/core/azure-common/tests/test_client_factory.py @@ -10,6 +10,7 @@ import os import tempfile import unittest +import pytest try: from unittest import mock except ImportError: @@ -112,6 +113,7 @@ def __init__(self, credentials): get_azure_cli_credentials.assert_called_with(resource="https://vault.azure.net", with_tenant=True) assert client.credentials == 'credentials' + @mock.patch('azure.common.client_factory.get_cli_active_cloud') @mock.patch('azure.common.client_factory.get_azure_cli_credentials') def test_get_client_from_cli_profile_core(self, get_azure_cli_credentials, get_cli_active_cloud): @@ -225,6 +227,13 @@ def __init__(self, credentials): self.credentials = credentials + class KeyVaultClientTrack2(object): + def __init__(self, credential): + if credential is None: + raise ValueError("Parameter 'credentials' must not be None.") + + self.credential = credential + for encoding in ['utf-8', 'utf-8-sig', 'ascii']: temp_auth_file = tempfile.NamedTemporaryFile(delete=False) @@ -279,6 +288,10 @@ def __init__(self, credentials): 'password' ) + with pytest.raises(ValueError) as excinfo: + get_client_from_auth_file(KeyVaultClientTrack2, temp_auth_file.name) + assert "https://aka.ms/azsdk/python/azidmigration" in str(excinfo.value) + os.unlink(temp_auth_file.name)