def _execute_command(kwargs): from msrest.paging import Paged from msrest.exceptions import ValidationError, ClientRequestError from msrestazure.azure_operation import AzureOperationPoller from azure.cli.core._profile import Profile from azure.cli.command_modules.keyvault.keyvaultclient import \ (KeyVaultClient, KeyVaultAuthentication) from azure.cli.command_modules.keyvault.keyvaultclient.generated import \ (KeyVaultClient as BaseKeyVaultClient) from azure.cli.command_modules.keyvault.keyvaultclient.generated.models import \ (KeyVaultErrorException) try: def get_token(server, resource, scope): # pylint: disable=unused-argument return Profile().get_login_credentials( resource)[0]._token_retriever() # pylint: disable=protected-access op = get_op_handler(operation) # since the convenience client can be inconvenient, we have to check and create the # correct client version if 'generated' in op.__module__: client = BaseKeyVaultClient(KeyVaultAuthentication(get_token)) else: client = KeyVaultClient(KeyVaultAuthentication(get_token)) # pylint: disable=redefined-variable-type result = op(client, **kwargs) # apply results transform if specified 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('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 (ValidationError, KeyVaultErrorException) as ex: try: raise CLIError(ex.inner_exception.error.message) except AttributeError: raise CLIError(ex) except ClientRequestError as ex: if 'Failed to establish a new connection' in str( ex.inner_exception): raise CLIError( 'Max retries exceeded attempting to connect to vault. ' 'The vault may not exist or you may need to flush your DNS cache ' 'and try again later.') raise CLIError(ex)
def completer(prefix, action, parsed_args, **kwargs): # pylint: disable=unused-argument client = KeyVaultClient(KeyVaultAuthentication(_get_token)) # pylint: disable=redefined-variable-type func_name = 'get_{}s'.format(resource_name) vault = parsed_args.vault_base_url items = [] for y in list(getattr(client, func_name)(vault)): id_val = getattr(y, 'id', None) or getattr(y, 'kid', None) items.append(id_val.rsplit('/', 1)[1]) return items
def _execute_command(kwargs): try: def get_token(server, resource, scope): # pylint: disable=unused-argument return Profile().get_login_credentials(resource)[0]._token_retriever() # pylint: disable=protected-access # since the convenience client can be inconvenient, we have to check and create the # correct client version if 'generated' in operation.__module__: client = BaseKeyVaultClient(KeyVaultAuthentication(get_token)) else: client = KeyVaultClient(KeyVaultAuthentication(get_token)) # pylint: disable=redefined-variable-type result = operation(client, **kwargs) # apply results transform if specified 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('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 (ValidationError, KeyVaultErrorException) as ex: try: raise CLIError(ex.inner_exception.error.message) except AttributeError: raise CLIError(ex)