Skip to content

Commit 101138a

Browse files
lmazuelrajivnandivada
authored andcommitted
KV client and auth file (Azure#5716)
* KV client and auth file wrt base_url * Resource for token if KV client * 1.1.22
1 parent d23ad84 commit 101138a

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

sdk/core/azure-common/HISTORY.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
Release History
44
===============
55

6+
1.1.22 (2019-06-06)
7+
+++++++++++++++++++
8+
9+
- Fix KeyVaultClient support for get_client_from_auth_file
10+
611
1.1.21 (2019-05-21)
712
+++++++++++++++++++
813

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
# license information.
55
#--------------------------------------------------------------------------
66

7-
VERSION = "1.1.21"
7+
VERSION = "1.1.22"

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222

2323

2424
def _instantiate_client(client_class, **kwargs):
25-
"""Instantiate a client from kwargs, removing the subscription_id/tenant_id argument if unsupported.
25+
"""Instantiate a client from kwargs, removing the subscription_id/tenant_id/base_url argument if unsupported.
2626
"""
2727
args = get_arg_spec(client_class.__init__).args
28-
for key in ['subscription_id', 'tenant_id']:
28+
for key in ['subscription_id', 'tenant_id', 'base_url']:
2929
if key not in kwargs:
3030
continue
3131
if key not in args:
@@ -144,6 +144,7 @@ def get_client_from_json_dict(client_class, config_dict, **kwargs):
144144
:return: An instantiated client
145145
"""
146146
is_graphrbac = client_class.__name__ == 'GraphRbacManagementClient'
147+
is_keyvault = client_class.__name__ == 'KeyVaultClient'
147148
parameters = {
148149
'subscription_id': config_dict.get('subscriptionId'),
149150
'base_url': config_dict.get('resourceManagerEndpointUrl'),
@@ -156,6 +157,8 @@ def get_client_from_json_dict(client_class, config_dict, **kwargs):
156157
# Get the right resource for Credentials
157158
if is_graphrbac:
158159
resource = config_dict['activeDirectoryGraphResourceId']
160+
elif is_keyvault:
161+
resource = "https://vault.azure.net"
159162
else:
160163
if "activeDirectoryResourceId" not in config_dict and 'resourceManagerEndpointUrl' not in config_dict:
161164
raise ValueError("Need activeDirectoryResourceId or resourceManagerEndpointUrl key")

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ def __init__(self, credentials, tenant_id, base_url):
148148
self.tenant_id = tenant_id
149149
self.base_url = base_url
150150

151+
class KeyVaultClient(object):
152+
def __init__(self, credentials):
153+
if credentials is None:
154+
raise ValueError("Parameter 'credentials' must not be None.")
155+
156+
self.credentials = credentials
157+
151158
for encoding in ['utf-8', 'utf-8-sig', 'ascii']:
152159

153160
temp_auth_file = tempfile.NamedTemporaryFile(delete=False)
@@ -195,6 +202,13 @@ def __init__(self, credentials, tenant_id, base_url):
195202
'password'
196203
)
197204

205+
client = get_client_from_auth_file(KeyVaultClient, temp_auth_file.name)
206+
assert client.credentials._args == (
207+
"https://vault.azure.net",
208+
'a2ab11af-01aa-4759-8345-7803287dbd39',
209+
'password'
210+
)
211+
198212
os.unlink(temp_auth_file.name)
199213

200214

0 commit comments

Comments
 (0)