azure-sdk-for-net
azure-sdk-for-net copied to clipboard
[QUERY] Replacing KeyVaultClient with SecretClient
Library name and version
Azure.Security.KeyVault.Secrets
Query/Question
Hi,
We are using KeyVaultClient(Singleton) and used it to access multiple endpoints like below.
But we are currently migrating to use Azure.Security.KeyVault.Secrets. Looking at the way SecretClient is instantiated, we were supposed to supply endpoint(uri) at the time of instantiation itself and needs to call Defaultcredential(). I do know that I can try to cache a secret client per endpoint, but this raises a bit of complexity in our scenario since the endpoints can be dynamic.
Now:

Creating SecretClient everytime we access new endpoint may cause performance regression. So is there a way of using SecretClient to avoid such a regression?
Environment
No response
Thank you for your feedback. Tagging and routing to the team member best able to assist. Please be aware that due to the US holidays, responses are likely to be delayed.
Also is there a way to mock CertificateOperation? I see that CertificateModelFactory doesn't support it as of now
All our clients are thin clients. There's really not much overhead, so creating and caching one client per endpoint is not expensive, nor should instantiating one be - though more expensive than caching since we do instantiate a number of classes for the HTTP pipeline. If you want to decrease overhead more, you can use a shared HttpClient as described here: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/samples/Configuration.md#user-provided-httpclient-instance
As for mocking CertificateOperation, it's mockable in the same way our clients are. You could use Moq, for example, to mock a CertificateClient and return a Mock<CertificateOperation>. All the methods and properties are virtual so you can override them, like UpdateStatus and UpdateStatusAsync. See https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/samples/Mocking.md for how to return a pageable, for example. Returning a Mock<CertificateOperation> would be similar.
Hi @vidya123. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text “/unresolve” to remove the “issue-addressed” label and continue the conversation.
Hi @vidya123, since you haven’t asked that we “/unresolve” the issue, we’ll close this out. If you believe further discussion is needed, please add a comment “/unresolve” to reopen the issue.