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
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


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]
Comment on lines 10 to +11
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.



def get_keyvault_name_completion_list(resource_name):
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/azure/cli/command_modules/role/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1543,7 +1543,7 @@ def _get_keyvault_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]

return KeyVaultClient(KeyVaultAuthentication(_get_token), api_version=version)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1671,7 +1671,7 @@ def _get_keyVault_not_arm_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]

client = KeyVaultClient(KeyVaultAuthentication(get_token), api_version=version)
return client
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/azure/cli/command_modules/vm/_vm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.


from azure.keyvault import KeyVaultAuthentication, KeyVaultClient
return KeyVaultClient(KeyVaultAuthentication(get_token), api_version=version)
Expand Down