Skip to content
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

{KeyVault} Replace _token_retriever with get_raw_token #17812

Merged
merged 1 commit into from
Apr 22, 2021

Conversation

jiasli
Copy link
Member

@jiasli jiasli commented Apr 22, 2021

Split from #17738

Description

As pointed out by #15854, calling the protected method _token_retriever is simply wrong.

This PR replaces _token_retriever with azure.cli.core._profile.Profile.get_raw_token, as provided by #15805 (comment).

This is also the approach adopted by azure.cli.command_modules.keyvault._client_factory.keyvault_data_plane_factory:

def keyvault_data_plane_factory(cli_ctx, _):
from azure.keyvault import KeyVaultAuthentication, KeyVaultClient
from azure.cli.core.util import should_disable_connection_verify
version = str(get_api_version(cli_ctx, ResourceType.DATA_KEYVAULT))
def get_token(server, resource, scope): # pylint: disable=unused-argument
import adal
try:
return Profile(cli_ctx=cli_ctx).get_raw_token(resource)[0]

On the other hand, instead of implementing its own keyvault client factory, appconfig directly uses azure.cli.command_modules.keyvault._client_factory.keyvault_data_plane_factory (#15826):

from azure.cli.command_modules.keyvault._client_factory import keyvault_data_plane_factory
keyvault_client = keyvault_data_plane_factory(cli_ctx, None)

Other command modules may follow the same approach, but I will defer this decision to @houk-ms.

Comment on lines 10 to +11
def _get_token(cli_ctx, server, resource, scope): # pylint: disable=unused-argument
return Profile(cli_ctx=cli_ctx).get_login_credentials(resource)[0]._token_retriever() # pylint: disable=protected-access
return Profile(cli_ctx=cli_ctx).get_raw_token(resource)[0]
Copy link
Member Author

Choose a reason for hiding this comment

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

This _get_token never works because it doesn't comply with KeyVaultAuthentication's authorization_callback signature.

Also defer to @houk-ms to fix it in the future.

@qwordy
Copy link
Member

qwordy commented Apr 22, 2021

How about put _get_token to azure-cli-core?

@@ -106,7 +106,7 @@ def create_keyvault_data_plane_client(cli_ctx):
version = str(get_api_version(cli_ctx, ResourceType.DATA_KEYVAULT))

def get_token(server, resource, scope): # pylint: disable=unused-argument
return Profile(cli_ctx=cli_ctx).get_login_credentials(resource)[0]._token_retriever() # pylint: disable=protected-access
return Profile(cli_ctx=cli_ctx).get_raw_token(resource)[0]
Copy link
Member

Choose a reason for hiding this comment

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

Can we make Profile object a global singleton?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good suggestion. Will consider doing that in the future.

@houk-ms
Copy link
Contributor

houk-ms commented Apr 22, 2021

How about put _get_token to azure-cli-core?

We will consider to do that when KeyVault data-plane SDK decides to migrate to Track2. Before that, i prefer we keep the original implementation for simplicity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants