def test_cloud_forbid_telemetry(self): from unittest import mock from azure.cli.core import telemetry from azure.cli.core.mock import DummyCli from knack.completion import ARGCOMPLETE_ENV_NAME az_cli = DummyCli() telemetry.set_application(az_cli, ARGCOMPLETE_ENV_NAME) # mock user turns off telemetry with mock.patch('knack.config.CLIConfig.getboolean', return_value=False): self.assertFalse(telemetry.is_telemetry_enabled()) # mock user turns on telemetry with mock.patch('knack.config.CLIConfig.getboolean', return_value=True): self.assertTrue(telemetry.is_telemetry_enabled()) # mock to add current cloud name in CLOUDS_FORBIDDING_TELEMETRY with mock.patch('azure.cli.core.cloud.CLOUDS_FORBIDDING_TELEMETRY', [az_cli.cloud.name]): self.assertFalse(telemetry.is_telemetry_enabled())
for value in values: new_ns = argparse.Namespace(**vars(args)) for key_index, key in enumerate(list_args.keys()): setattr(new_ns, key, value[key_index]) yield new_ns class IterateAction(argparse.Action): # pylint: disable=too-few-public-methods '''Action used to collect argument values in an IterateValue list The application will loop through each value in the IterateValue and execeute the associated handler for each ''' def __call__(self, parser, namespace, values, option_string=None): setattr(namespace, self.dest, IterateValue(values)) class IterateValue(list): '''Marker class to indicate that, when found as a value in the parsed namespace from argparse, the handler should be invoked once per value in the list with all other values in the parsed namespace frozen. Typical use is to allow multiple ID parameter to a show command etc. ''' pass APPLICATION = Application() telemetry.set_application(APPLICATION, ARGCOMPLETE_ENV_NAME)
try: uuid.uuid1() except ValueError: uuid.uuid1 = uuid.uuid4 logger = get_logger(__name__) def cli_main(cli, args): return cli.invoke(args) az_cli = get_default_cli() telemetry.set_application(az_cli, ARGCOMPLETE_ENV_NAME) try: telemetry.start() exit_code = cli_main(az_cli, sys.argv[1:]) if exit_code and exit_code != 0: telemetry.set_failure() else: telemetry.set_success() sys.exit(exit_code) except KeyboardInterrupt: telemetry.set_user_fault('keyboard interrupt') sys.exit(1)
for value in values: new_ns = argparse.Namespace(**vars(args)) for key_index, key in enumerate(list_args.keys()): setattr(new_ns, key, value[key_index]) yield new_ns class IterateAction(argparse.Action): # pylint: disable=too-few-public-methods '''Action used to collect argument values in an IterateValue list The application will loop through each value in the IterateValue and execeute the associated handler for each ''' def __call__(self, parser, namespace, values, option_string=None): setattr(namespace, self.dest, IterateValue(values)) class IterateValue(list): '''Marker class to indicate that, when found as a value in the parsed namespace from argparse, the handler should be invoked once per value in the list with all other values in the parsed namespace frozen. Typical use is to allow multiple ID parameter to a show command etc. ''' pass APPLICATION = Application() set_application(APPLICATION, ARGCOMPLETE_ENV_NAME)
new_ns = argparse.Namespace(**vars(args)) for key_index, key in enumerate(list_args.keys()): setattr(new_ns, key, value[key_index]) yield new_ns class IterateAction(argparse.Action): # pylint: disable=too-few-public-methods """Action used to collect argument values in an IterateValue list The application will loop through each value in the IterateValue and execeute the associated handler for each """ def __call__(self, parser, namespace, values, option_string=None): setattr(namespace, self.dest, IterateValue(values)) class IterateValue(list): """Marker class to indicate that, when found as a value in the parsed namespace from argparse, the handler should be invoked once per value in the list with all other values in the parsed namespace frozen. Typical use is to allow multiple ID parameter to a show command etc. """ pass APPLICATION = Application() set_application(APPLICATION, ARGCOMPLETE_ENV_NAME)