def main(args, output=sys.stdout, logging_stream=None): configure_logging(args, logging_stream) logger = get_az_logger(__name__) logger.debug('Command arguments %s', args) if args and (args[0] == '--version' or args[0] == '-v'): show_version_info_exit(output) azure_folder = get_config_dir() if not os.path.exists(azure_folder): os.makedirs(azure_folder) ACCOUNT.load(os.path.join(azure_folder, 'azureProfile.json')) CONFIG.load(os.path.join(azure_folder, 'az.json')) SESSION.load(os.path.join(azure_folder, 'az.sess'), max_age=3600) APPLICATION.initialize(Configuration()) try: cmd_result = APPLICATION.execute(args) # Commands can return a dictionary/list of results # If they do, we print the results. if cmd_result and cmd_result.result is not None: from azure.cli.core._output import OutputProducer formatter = OutputProducer.get_formatter( APPLICATION.configuration.output_format) OutputProducer(formatter=formatter, file=output).out(cmd_result) except Exception as ex: # pylint: disable=broad-except # TODO: include additional details of the exception in telemetry telemetry.set_exception( ex, 'outer-exception', 'Unexpected exception caught during application execution.') telemetry.set_failure() error_code = handle_exception(ex) return error_code
# -------------------------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- from __future__ import print_function from azure.cli.core.prompting import prompt_pass, NoTTYException from azure.cli.core import get_az_logger from azure.cli.core._profile import Profile from azure.cli.core.util import CLIError, in_cloud_console from azure.cli.core.cloud import get_active_cloud from azure.cli.core.commands.validators import DefaultStr logger = get_az_logger(__name__) _CLOUD_CONSOLE_WARNING_TEMPLATE = ("Azure Cloud Shell automatically authenticates the user account it was initially" " launched under, as a result 'az %s' is disabled.") def load_subscriptions(all_clouds=False, refresh=False): profile = Profile() if refresh: subscriptions = profile.refresh_accounts() subscriptions = profile.load_cached_subscriptions(all_clouds) return subscriptions def list_subscriptions(all=False, refresh=False): # pylint: disable=redefined-builtin """List the imported subscriptions."""
# -------------------------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- from __future__ import print_function from azure.cli.core.prompting import prompt_pass, NoTTYException from azure.cli.core import get_az_logger from azure.cli.core._profile import Profile from azure.cli.core.util import CLIError, in_cloud_console from azure.cli.core.cloud import get_active_cloud from azure.cli.core.commands.validators import DefaultStr logger = get_az_logger(__name__) _CLOUD_CONSOLE_WARNING_TEMPLATE = ( "Azure Cloud Shell automatically authenticates the user account it was initially" " launched under, as a result 'az %s' is disabled.") def load_subscriptions(all_clouds=False, refresh=False): profile = Profile() if refresh: subscriptions = profile.refresh_accounts() subscriptions = profile.load_cached_subscriptions(all_clouds) return subscriptions def list_subscriptions(all=False, refresh=False): # pylint: disable=redefined-builtin """List the imported subscriptions."""
def test_get_az_logger_module(self): az_module_logger = get_az_logger('azure.cli.module') self.assertEqual(az_module_logger.name, 'az.azure.cli.module')
def test_get_az_logger(self): az_logger = get_az_logger() self.assertEqual(az_logger.name, 'az')