From 92caf75f23ca8b6ed1c9ea85515c6479ab042c6a Mon Sep 17 00:00:00 2001 From: Laurent Mazuel Date: Thu, 6 Jun 2019 11:07:21 -0700 Subject: [PATCH 1/3] KV client and auth file wrt base_url --- .../azure-common/azure/common/client_factory.py | 4 ++-- sdk/core/azure-common/tests/test_client_factory.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/sdk/core/azure-common/azure/common/client_factory.py b/sdk/core/azure-common/azure/common/client_factory.py index b69cd83d238d..84b198f95248 100644 --- a/sdk/core/azure-common/azure/common/client_factory.py +++ b/sdk/core/azure-common/azure/common/client_factory.py @@ -22,10 +22,10 @@ def _instantiate_client(client_class, **kwargs): - """Instantiate a client from kwargs, removing the subscription_id/tenant_id argument if unsupported. + """Instantiate a client from kwargs, removing the subscription_id/tenant_id/base_url argument if unsupported. """ args = get_arg_spec(client_class.__init__).args - for key in ['subscription_id', 'tenant_id']: + for key in ['subscription_id', 'tenant_id', 'base_url']: if key not in kwargs: continue if key not in args: diff --git a/sdk/core/azure-common/tests/test_client_factory.py b/sdk/core/azure-common/tests/test_client_factory.py index 01705df55d21..e794c0bcf6bc 100644 --- a/sdk/core/azure-common/tests/test_client_factory.py +++ b/sdk/core/azure-common/tests/test_client_factory.py @@ -148,6 +148,13 @@ def __init__(self, credentials, tenant_id, base_url): self.tenant_id = tenant_id self.base_url = base_url + class KeyVaultClient(object): + def __init__(self, credentials): + if credentials is None: + raise ValueError("Parameter 'credentials' must not be None.") + + self.credentials = credentials + for encoding in ['utf-8', 'utf-8-sig', 'ascii']: temp_auth_file = tempfile.NamedTemporaryFile(delete=False) @@ -195,6 +202,13 @@ def __init__(self, credentials, tenant_id, base_url): 'password' ) + client = get_client_from_auth_file(KeyVaultClient, temp_auth_file.name) + assert client.credentials._args == ( + 'https://management.azure.com/', + 'a2ab11af-01aa-4759-8345-7803287dbd39', + 'password' + ) + os.unlink(temp_auth_file.name) From 30538ec3ed37df2fd0ed7afc9b09c4e21280eea1 Mon Sep 17 00:00:00 2001 From: Laurent Mazuel Date: Thu, 6 Jun 2019 11:29:20 -0700 Subject: [PATCH 2/3] Resource for token if KV client --- sdk/core/azure-common/azure/common/client_factory.py | 3 +++ sdk/core/azure-common/tests/test_client_factory.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/sdk/core/azure-common/azure/common/client_factory.py b/sdk/core/azure-common/azure/common/client_factory.py index 84b198f95248..f61220ed6c63 100644 --- a/sdk/core/azure-common/azure/common/client_factory.py +++ b/sdk/core/azure-common/azure/common/client_factory.py @@ -144,6 +144,7 @@ def get_client_from_json_dict(client_class, config_dict, **kwargs): :return: An instantiated client """ is_graphrbac = client_class.__name__ == 'GraphRbacManagementClient' + is_keyvault = client_class.__name__ == 'KeyVaultClient' parameters = { 'subscription_id': config_dict.get('subscriptionId'), 'base_url': config_dict.get('resourceManagerEndpointUrl'), @@ -156,6 +157,8 @@ def get_client_from_json_dict(client_class, config_dict, **kwargs): # Get the right resource for Credentials if is_graphrbac: resource = config_dict['activeDirectoryGraphResourceId'] + elif is_keyvault: + resource = "https://vault.azure.net" else: if "activeDirectoryResourceId" not in config_dict and 'resourceManagerEndpointUrl' not in config_dict: raise ValueError("Need activeDirectoryResourceId or resourceManagerEndpointUrl key") diff --git a/sdk/core/azure-common/tests/test_client_factory.py b/sdk/core/azure-common/tests/test_client_factory.py index e794c0bcf6bc..59e14ef82056 100644 --- a/sdk/core/azure-common/tests/test_client_factory.py +++ b/sdk/core/azure-common/tests/test_client_factory.py @@ -204,7 +204,7 @@ def __init__(self, credentials): client = get_client_from_auth_file(KeyVaultClient, temp_auth_file.name) assert client.credentials._args == ( - 'https://management.azure.com/', + "https://vault.azure.net", 'a2ab11af-01aa-4759-8345-7803287dbd39', 'password' ) From ae559b9d7154a0f86608e9514f29faf8fc0e6f6e Mon Sep 17 00:00:00 2001 From: Laurent Mazuel Date: Thu, 6 Jun 2019 11:31:48 -0700 Subject: [PATCH 3/3] 1.1.22 --- sdk/core/azure-common/HISTORY.rst | 5 +++++ sdk/core/azure-common/azure/common/_version.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/sdk/core/azure-common/HISTORY.rst b/sdk/core/azure-common/HISTORY.rst index a9b3fea43c20..b81ec4774c1b 100644 --- a/sdk/core/azure-common/HISTORY.rst +++ b/sdk/core/azure-common/HISTORY.rst @@ -3,6 +3,11 @@ Release History =============== +1.1.22 (2019-06-06) ++++++++++++++++++++ + +- Fix KeyVaultClient support for get_client_from_auth_file + 1.1.21 (2019-05-21) +++++++++++++++++++ diff --git a/sdk/core/azure-common/azure/common/_version.py b/sdk/core/azure-common/azure/common/_version.py index 5e59067ce1d5..35cfcd913163 100644 --- a/sdk/core/azure-common/azure/common/_version.py +++ b/sdk/core/azure-common/azure/common/_version.py @@ -4,4 +4,4 @@ # license information. #-------------------------------------------------------------------------- -VERSION = "1.1.21" +VERSION = "1.1.22"