def keyvault_command_handler(command_args): from azure.cli.core.commands.client_factory import resolve_client_arg_name from azure.cli.core.profiles import ResourceType from azure.cli.core.util import get_arg_list, poller_classes from msrest.paging import Paged op = get_op_handler() op_args = get_arg_list(op) command_type = merged_kwargs.get('command_type', None) client_factory = command_type.settings.get('client_factory', None) if command_type \ else merged_kwargs.get('client_factory', None) 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) command_args[client_arg_name] = client if 'cmd' not in op_args: command_args.pop('cmd') try: if command_type.settings.get( 'resource_type' ) == ResourceType.DATA_KEYVAULT_ADMINISTRATION_BACKUP: abandoned_args = ['identifier', 'vault_base_url'] for arg in abandoned_args: if arg in command_args: command_args.pop(arg) result = op(**command_args) # apply results transform if specified transform_result = merged_kwargs.get('transform', None) if transform_result: return _encode_hex(transform_result( result, **command_args)) # otherwise handle based on return type of results if isinstance(result, poller_classes()): return _encode_hex( LongRunningOperation( self.command_loader.cli_ctx, 'Starting {}'.format(name))(result)) if isinstance(result, Paged): try: return _encode_hex(list(result)) except TypeError: # TODO: Workaround for an issue in either KeyVault server-side or msrest # See https://github.com/Azure/autorest/issues/1309 return [] return _encode_hex(result) except Exception as ex: # pylint: disable=broad-except if name == 'show': # show_exception_handler needs to be called before the keyvault_exception_handler from azure.cli.core.commands.arm import show_exception_handler try: show_exception_handler(ex) except Exception: # pylint: disable=broad-except pass return keyvault_exception_handler(self.command_loader, ex)
def _build_kwargs(self, func, ns): # pylint: disable=no-self-use arg_list = get_arg_list(func) kwargs = {} if 'cmd' in arg_list: kwargs['cmd'] = ns._cmd # pylint: disable=protected-access if 'namespace' in arg_list: kwargs['namespace'] = ns if 'ns' in arg_list: kwargs['ns'] = ns return kwargs
def default_command_handler(command_args): from azure.cli.core.util import get_arg_list op = handler or self.get_op_handler(operation) op_args = get_arg_list(op) client = client_factory(self.cli_ctx, command_args) if client_factory else None if client: client_arg_name = kwargs.get('client_arg_name', 'client' if operation.startswith(('azure.cli', 'azext')) else 'self') if client_arg_name in op_args: command_args[client_arg_name] = client result = op(**command_args) return result
def default_command_handler(command_args): from azure.cli.core.util import get_arg_list from azure.cli.core.commands.client_factory import resolve_client_arg_name op = handler or self.get_op_handler(operation) op_args = get_arg_list(op) client = client_factory(self.cli_ctx, command_args) if client_factory else None if client: client_arg_name = resolve_client_arg_name(operation, kwargs) if client_arg_name in op_args: command_args[client_arg_name] = client result = op(**command_args) return result
def keyvault_command_handler(command_args): from azure.cli.core.util import get_arg_list from azure.cli.core.commands.client_factory import resolve_client_arg_name from msrest.paging import Paged from azure.cli.core.util import poller_classes op = get_op_handler() op_args = get_arg_list(op) command_type = merged_kwargs.get('command_type', None) client_factory = command_type.settings.get('client_factory', None) if command_type \ else merged_kwargs.get('client_factory', None) 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) command_args[client_arg_name] = client if 'cmd' not in op_args: command_args.pop('cmd') try: result = op(**command_args) # apply results transform if specified transform_result = merged_kwargs.get('transform', None) if transform_result: return _encode_hex(transform_result(result)) # otherwise handle based on return type of results if isinstance(result, poller_classes()): return _encode_hex( LongRunningOperation(self.command_loader.cli_ctx, 'Starting {}'.format(name))(result)) if isinstance(result, Paged): try: return _encode_hex(list(result)) except TypeError: # TODO: Workaround for an issue in either KeyVault server-side or msrest # See https://github.com/Azure/autorest/issues/1309 return [] return _encode_hex(result) except Exception as ex: # pylint: disable=broad-except if name == 'show': # show_exception_handler needs to be called before the keyvault_exception_handler from azure.cli.core.commands.arm import show_exception_handler try: show_exception_handler(ex) except Exception: # pylint: disable=broad-except pass return keyvault_exception_handler(self.command_loader, ex)
def default_command_handler(command_args): from azure.cli.core.util import get_arg_list, augment_no_wait_handler_args from azure.cli.core.commands.client_factory import resolve_client_arg_name op = handler or self.get_op_handler(operation) op_args = get_arg_list(op) cmd = command_args.get('cmd') if 'cmd' in op_args else command_args.pop('cmd') client = client_factory(cmd.cli_ctx, command_args) if client_factory else None supports_no_wait = kwargs.get('supports_no_wait', None) if supports_no_wait: no_wait_enabled = command_args.pop('no_wait', False) augment_no_wait_handler_args(no_wait_enabled, op, command_args) if client: client_arg_name = resolve_client_arg_name(operation, kwargs) if client_arg_name in op_args: command_args[client_arg_name] = client return op(**command_args)
def default_command_handler(command_args): from azure.cli.core.util import get_arg_list, augment_no_wait_handler_args from azure.cli.core.commands.client_factory import resolve_client_arg_name op = handler or self.get_op_handler(operation) op_args = get_arg_list(op) cmd = command_args.get('cmd') if 'cmd' in op_args else command_args.pop('cmd') client = client_factory(cmd.cli_ctx, command_args) if client_factory else None supports_no_wait = kwargs.get('supports_no_wait', None) if supports_no_wait: no_wait_enabled = command_args.pop('no_wait', False) augment_no_wait_handler_args(no_wait_enabled, op, command_args) if client: client_arg_name = resolve_client_arg_name(operation, kwargs) if client_arg_name in op_args: command_args[client_arg_name] = client return op(**command_args)
def keyvault_command_handler(command_args): from azure.cli.core.util import get_arg_list from azure.cli.core.commands.client_factory import resolve_client_arg_name from msrest.paging import Paged from msrestazure.azure_operation import AzureOperationPoller op = get_op_handler() op_args = get_arg_list(op) command_type = merged_kwargs.get('command_type', None) client_factory = command_type.settings.get('client_factory', None) if command_type \ else merged_kwargs.get('client_factory', None) 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) command_args[client_arg_name] = client try: result = op(**command_args) # apply results transform if specified transform_result = merged_kwargs.get('transform', None) if transform_result: return _encode_hex(transform_result(result)) # otherwise handle based on return type of results if isinstance(result, AzureOperationPoller): return _encode_hex( LongRunningOperation( self.command_loader.cli_ctx, 'Starting {}'.format(name))(result)) elif isinstance(result, Paged): try: return _encode_hex(list(result)) except TypeError: # TODO: Workaround for an issue in either KeyVault server-side or msrest # See https://github.com/Azure/autorest/issues/1309 return [] else: return _encode_hex(result) except Exception as ex: # pylint: disable=broad-except return keyvault_exception_handler(ex)
def handler(self, command_args): """ Callback function of CLICommand handler """ from azure.cli.core.util import get_arg_list, augment_no_wait_handler_args op = self.get_op_handler(self.op_path) op_args = get_arg_list(op) self.cmd = command_args.get( 'cmd') if 'cmd' in op_args else command_args.pop('cmd') client = self.client_factory( self.cli_ctx, command_args) if self.client_factory else None supports_no_wait = self.merged_kwargs.get('supports_no_wait', None) if supports_no_wait: no_wait_enabled = command_args.pop('no_wait', False) augment_no_wait_handler_args(no_wait_enabled, op, command_args) if client: client_arg_name = self.resolve_client_arg_name(self.op_path) if client_arg_name in op_args: command_args[client_arg_name] = client return op(**command_args)