Skip to content

KV client and auth file #5716

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions sdk/core/azure-common/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
+++++++++++++++++++

Expand Down
2 changes: 1 addition & 1 deletion sdk/core/azure-common/azure/common/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# license information.
#--------------------------------------------------------------------------

VERSION = "1.1.21"
VERSION = "1.1.22"
7 changes: 5 additions & 2 deletions sdk/core/azure-common/azure/common/client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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'),
Expand All @@ -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")
Expand Down
14 changes: 14 additions & 0 deletions sdk/core/azure-common/tests/test_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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://vault.azure.net",
'a2ab11af-01aa-4759-8345-7803287dbd39',
'password'
)

os.unlink(temp_auth_file.name)


Expand Down