Skip to content

Add context manager API to Key Vault clients - #9906

Merged
chlowell merged 10 commits into
Azure:masterfrom
chlowell:context-managers
Feb 21, 2020
Merged

Add context manager API to Key Vault clients#9906
chlowell merged 10 commits into
Azure:masterfrom
chlowell:context-managers

Conversation

@chlowell

Copy link
Copy Markdown
Member

With this change Key Vault clients expose context manager APIs wrapping their autorest-generated clients (closes #7228). Implementing this would have required changes to the KeyVaultClient class wrapping those clients. Because that class is unnecessarily complex and the reason azure-keyvault-* depends on azure-common, I took this opportunity to replace it with simpler code (closes #8370).

Sorry for the large diff. Most of it is duplicating shared code across libraries. You can filter out the "copy shared code" commit to hide all that.

@chlowell chlowell added KeyVault Client This issue points to a problem in the data-plane of the library. labels Feb 19, 2020
@chlowell
chlowell requested a review from schaabs as a code owner February 19, 2020 18:07
@chlowell chlowell self-assigned this Feb 19, 2020
Comment thread sdk/keyvault/azure-keyvault-certificates/samples/issuers_async.py
client = CertificateClient(vault_url="https://localhost", credential=object(), transport=transport)

async with client:
assert transport.__aenter__.call_count == 1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is transport.aenter.call_count checked twice

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paranoid thoroughness 😸
__aenter__ should only be called once. Possibly client.__aenter__ calls it twice, or client.__aexit__ calls it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Client This issue points to a problem in the data-plane of the library. KeyVault

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[KV] azure-keyvault-xxx packages should not depend on azure-common aiohttp: Unclosed client session and connector

3 participants