def login_account(client, resource_group_name, account_name, shared_key_auth=False): from azure.cli.core._config import az_config, set_global_config from azure.cli.core._profile import Profile account = client.get(resource_group_name=resource_group_name, account_name=account_name) if not az_config.config_parser.has_section('batch'): az_config.config_parser.add_section('batch') az_config.config_parser.set('batch', 'account', account.name) az_config.config_parser.set('batch', 'endpoint', 'https://{}/'.format(account.account_endpoint)) if shared_key_auth: keys = client.get_keys(resource_group_name=resource_group_name, account_name=account_name) az_config.config_parser.set('batch', 'auth_mode', 'shared_key') az_config.config_parser.set('batch', 'access_key', keys.primary) else: az_config.config_parser.set('batch', 'auth_mode', 'aad') az_config.config_parser.remove_option('batch', 'access_key') set_global_config(az_config.config_parser)
def login_account(client, resource_group_name, account_name, shared_key_auth=False): from azure.cli.core._config import az_config, set_global_config from azure.cli.core._profile import Profile account = client.get(resource_group_name=resource_group_name, account_name=account_name) if not az_config.config_parser.has_section("batch"): az_config.config_parser.add_section("batch") az_config.config_parser.set("batch", "account", account.name) az_config.config_parser.set("batch", "endpoint", "https://{}/".format(account.account_endpoint)) if shared_key_auth: keys = client.get_keys(resource_group_name=resource_group_name, account_name=account_name) az_config.config_parser.set("batch", "auth_mode", "shared_key") az_config.config_parser.set("batch", "access_key", keys.primary) else: az_config.config_parser.set("batch", "auth_mode", "aad") az_config.config_parser.remove_option("batch", "access_key") set_global_config(az_config.config_parser)
def _handle_global_configuration(): # print location of global configuration print(MSG_GLOBAL_SETTINGS_LOCATION.format(GLOBAL_CONFIG_PATH)) # set up the config parsers file_config = get_config_parser() config_exists = file_config.read([GLOBAL_CONFIG_PATH]) global_config = get_config_parser() global_config.read(GLOBAL_CONFIG_PATH) should_modify_global_config = False if config_exists: # print current config and prompt to allow global config modification _print_cur_configuration(file_config) should_modify_global_config = prompt_y_n(MSG_PROMPT_MANAGE_GLOBAL, default='n') answers['modify_global_prompt'] = should_modify_global_config if not config_exists or should_modify_global_config: # no config exists yet so configure global config or user wants to modify global config output_index = prompt_choice_list(MSG_PROMPT_GLOBAL_OUTPUT, OUTPUT_LIST, default=get_default_from_config( global_config, 'core', 'output', OUTPUT_LIST)) answers['output_type_prompt'] = output_index answers['output_type_options'] = str(OUTPUT_LIST) enable_file_logging = prompt_y_n(MSG_PROMPT_FILE_LOGGING, default='n') allow_telemetry = prompt_y_n(MSG_PROMPT_TELEMETRY, default='y') answers['telemetry_prompt'] = allow_telemetry # save the global config try: global_config.add_section('core') except configparser.DuplicateSectionError: pass try: global_config.add_section('logging') except configparser.DuplicateSectionError: pass global_config.set('core', 'output', OUTPUT_LIST[output_index]['name']) global_config.set('core', 'collect_telemetry', 'yes' if allow_telemetry else 'no') global_config.set('logging', 'enable_log_file', 'yes' if enable_file_logging else 'no') set_global_config(global_config)
def login_account(client, resource_group_name, account_name, shared_key_auth=False): from azure.cli.core._config import az_config, set_global_config account = client.get(resource_group_name=resource_group_name, account_name=account_name) if not az_config.config_parser.has_section('batch'): az_config.config_parser.add_section('batch') az_config.config_parser.set('batch', 'account', account.name) az_config.config_parser.set('batch', 'endpoint', 'https://{}/'.format(account.account_endpoint)) if shared_key_auth: keys = client.get_keys(resource_group_name=resource_group_name, account_name=account_name) az_config.config_parser.set('batch', 'auth_mode', 'shared_key') az_config.config_parser.set('batch', 'access_key', keys.primary) else: az_config.config_parser.set('batch', 'auth_mode', 'aad') az_config.config_parser.remove_option('batch', 'access_key') set_global_config(az_config.config_parser)
def _handle_global_configuration(): # print location of global configuration print(MSG_GLOBAL_SETTINGS_LOCATION.format(GLOBAL_CONFIG_PATH)) # set up the config parsers file_config = get_config_parser() config_exists = file_config.read([GLOBAL_CONFIG_PATH]) global_config = get_config_parser() global_config.read(GLOBAL_CONFIG_PATH) should_modify_global_config = False if config_exists: # print current config and prompt to allow global config modification _print_cur_configuration(file_config) should_modify_global_config = prompt_y_n(MSG_PROMPT_MANAGE_GLOBAL, default='n') answers['modify_global_prompt'] = should_modify_global_config if not config_exists or should_modify_global_config: # no config exists yet so configure global config or user wants to modify global config output_index = prompt_choice_list(MSG_PROMPT_GLOBAL_OUTPUT, OUTPUT_LIST, default=get_default_from_config(global_config, 'core', 'output', OUTPUT_LIST)) answers['output_type_prompt'] = output_index answers['output_type_options'] = str(OUTPUT_LIST) enable_file_logging = prompt_y_n(MSG_PROMPT_FILE_LOGGING, default='n') allow_telemetry = prompt_y_n(MSG_PROMPT_TELEMETRY, default='y') answers['telemetry_prompt'] = allow_telemetry # save the global config try: global_config.add_section('core') except configparser.DuplicateSectionError: pass try: global_config.add_section('logging') except configparser.DuplicateSectionError: pass global_config.set('core', 'output', OUTPUT_LIST[output_index]['name']) global_config.set('core', 'collect_telemetry', 'yes' if allow_telemetry else 'no') global_config.set('logging', 'enable_log_file', 'yes' if enable_file_logging else 'no') set_global_config(global_config)