Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -134,7 +134,8 @@ def keyvault_data_plane_factory(cli_ctx, _):
def get_token(server, resource, scope): # pylint: disable=unused-argument
import adal
try:
return Profile(cli_ctx=cli_ctx).get_raw_token(resource)[0]
return Profile(cli_ctx=cli_ctx).get_raw_token(resource=resource,
subscription=cli_ctx.data.get('subscription_id'))[0]
Copy link
Member

Choose a reason for hiding this comment

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

[0] is magic code.

Copy link
Member Author

Choose a reason for hiding this comment

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

I just keep it as it is

except adal.AdalError as err:
# pylint: disable=no-member
if (hasattr(err, 'error_response') and
Expand Down Expand Up @@ -170,7 +171,8 @@ def keyvault_private_data_plane_factory_v7_2_preview(cli_ctx, _):
def get_token(server, resource, scope): # pylint: disable=unused-argument
import adal
try:
return Profile(cli_ctx=cli_ctx).get_raw_token(resource)[0]
return Profile(cli_ctx=cli_ctx).get_raw_token(resource=resource,
subscription=cli_ctx.data.get('subscription_id'))[0]
Copy link
Member

Choose a reason for hiding this comment

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

cli_ctx.data.get('subscription_id'))[0] appears multiple times. Can we extract it to a method? String literal 'subscription_id' is error prone. [0] is magic number.

except adal.AdalError as err:
# pylint: disable=no-member
if (hasattr(err, 'error_response') and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def keyvault_command_handler(command_args):

client_arg_name = resolve_client_arg_name(operations_tmpl.format(method_name), kwargs)
if client_arg_name in op_args:
client = client_factory(self.command_loader.cli_ctx, command_args)
client = client_factory(command_args['cmd'].cli_ctx, command_args)
command_args[client_arg_name] = client
if 'cmd' not in op_args:
command_args.pop('cmd')
Expand Down
12 changes: 3 additions & 9 deletions src/azure-cli/azure/cli/command_modules/role/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from knack.log import get_logger
from knack.util import CLIError, todict

from azure.cli.core.profiles import ResourceType, get_api_version
from azure.cli.core.profiles import ResourceType
from azure.graphrbac.models import GraphErrorException

from azure.cli.core.util import get_file_json, shell_safe_json_parse, is_guid
Expand Down Expand Up @@ -1538,14 +1538,8 @@ def _get_signed_in_user_object_id(graph_client):


def _get_keyvault_client(cli_ctx):
from azure.cli.core._profile import Profile
from azure.keyvault import KeyVaultAuthentication, KeyVaultClient
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_raw_token(resource)[0]

return KeyVaultClient(KeyVaultAuthentication(_get_token), api_version=version)
from azure.cli.command_modules.keyvault._client_factory import keyvault_data_plane_factory
return keyvault_data_plane_factory(cli_ctx, None)


def _create_self_signed_cert(start_date, end_date): # pylint: disable=too-many-locals
Expand Down
13 changes: 3 additions & 10 deletions src/azure-cli/azure/cli/command_modules/servicefabric/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
from azure.cli.core.util import CLIError, get_file_json, b64_to_hex, sdk_no_wait
from azure.cli.core.commands import LongRunningOperation
from azure.graphrbac import GraphRbacManagementClient
from azure.cli.core.profiles import ResourceType, get_sdk, get_api_version
from azure.keyvault import KeyVaultAuthentication, KeyVaultClient
from azure.cli.core.profiles import ResourceType, get_sdk
from azure.cli.command_modules.servicefabric._arm_deployment_utils import validate_and_deploy_arm_template
from azure.cli.command_modules.servicefabric._sf_utils import _get_resource_group_by_name, _create_resource_group_name

Expand Down Expand Up @@ -1598,14 +1597,8 @@ def _create_self_signed_key_vault_certificate(cli_ctx, vault_base_url, certifica


def _get_keyVault_not_arm_client(cli_ctx):
from azure.cli.core._profile import Profile
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_raw_token(resource)[0]

client = KeyVaultClient(KeyVaultAuthentication(get_token), api_version=version)
return client
from azure.cli.command_modules.keyvault._client_factory import keyvault_data_plane_factory
return keyvault_data_plane_factory(cli_ctx, None)


def _create_keyvault(cmd,
Expand Down
11 changes: 2 additions & 9 deletions src/azure-cli/azure/cli/command_modules/vm/_vm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,8 @@ def check_existence(cli_ctx, value, resource_group, provider_namespace, resource


def create_keyvault_data_plane_client(cli_ctx):
from azure.cli.core._profile import Profile
from azure.cli.core.profiles import get_api_version, ResourceType
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_raw_token(resource)[0]

from azure.keyvault import KeyVaultAuthentication, KeyVaultClient
return KeyVaultClient(KeyVaultAuthentication(get_token), api_version=version)
from azure.cli.command_modules.keyvault._client_factory import keyvault_data_plane_factory
return keyvault_data_plane_factory(cli_ctx, None)


def get_key_vault_base_url(cli_ctx, vault_name):
Expand Down