Skip to content

Commit ef231f1

Browse files
authored
Make explicit that auth file is not supported anymore (Azure#17395)
1 parent b6e2230 commit ef231f1

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

sdk/core/azure-common/azure/common/client_factory.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ def get_client_from_cli_profile(client_class, **kwargs):
109109
return _instantiate_client(client_class, **parameters)
110110

111111

112+
def _is_autorest_v3(client_class):
113+
"""Is this client a autorestv3/track2 one?.
114+
Could be refined later if necessary.
115+
"""
116+
args = get_arg_spec(client_class.__init__).args
117+
return "credential" in args
118+
119+
112120
def get_client_from_json_dict(client_class, config_dict, **kwargs):
113121
"""Return a SDK client initialized with a JSON auth dict.
114122
@@ -152,6 +160,12 @@ def get_client_from_json_dict(client_class, config_dict, **kwargs):
152160
:param dict config_dict: A config dict.
153161
:return: An instantiated client
154162
"""
163+
if _is_autorest_v3(client_class):
164+
raise ValueError(
165+
"Auth file or JSON dict are deprecated auth approach and are not supported anymore. "
166+
"Please read https://aka.ms/azsdk/python/azidmigration for details"
167+
)
168+
155169
import adal
156170
from msrestazure.azure_active_directory import AdalAuthentication
157171

sdk/core/azure-common/tests/test_client_factory.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import os
1111
import tempfile
1212
import unittest
13+
import pytest
1314
try:
1415
from unittest import mock
1516
except ImportError:
@@ -112,6 +113,7 @@ def __init__(self, credentials):
112113
get_azure_cli_credentials.assert_called_with(resource="https://vault.azure.net", with_tenant=True)
113114
assert client.credentials == 'credentials'
114115

116+
115117
@mock.patch('azure.common.client_factory.get_cli_active_cloud')
116118
@mock.patch('azure.common.client_factory.get_azure_cli_credentials')
117119
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):
225227

226228
self.credentials = credentials
227229

230+
class KeyVaultClientTrack2(object):
231+
def __init__(self, credential):
232+
if credential is None:
233+
raise ValueError("Parameter 'credentials' must not be None.")
234+
235+
self.credential = credential
236+
228237
for encoding in ['utf-8', 'utf-8-sig', 'ascii']:
229238

230239
temp_auth_file = tempfile.NamedTemporaryFile(delete=False)
@@ -279,6 +288,10 @@ def __init__(self, credentials):
279288
'password'
280289
)
281290

291+
with pytest.raises(ValueError) as excinfo:
292+
get_client_from_auth_file(KeyVaultClientTrack2, temp_auth_file.name)
293+
assert "https://aka.ms/azsdk/python/azidmigration" in str(excinfo.value)
294+
282295
os.unlink(temp_auth_file.name)
283296

284297

0 commit comments

Comments
 (0)