Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_set_config_value(self):
self.cli_config.set_value('test_section', 'test_option', 'a_value')
config = get_config_parser()
config.read(self.cli_config.config_path)
self.assertEqual(config.get('test_section', 'test_option'), 'a_value')
def _save_cloud(cloud, overwrite=False):
config = get_config_parser()
config.read(CLOUD_CONFIG_FILE)
_config_add_cloud(config, cloud, overwrite=overwrite)
if not os.path.isdir(GLOBAL_CONFIG_DIR):
os.makedirs(GLOBAL_CONFIG_DIR)
with open(CLOUD_CONFIG_FILE, 'w') as configfile:
config.write(configfile)
def get_cloud_subscription(cloud_name):
config = get_config_parser()
config.read(CLOUD_CONFIG_FILE)
try:
return config.get(cloud_name, 'subscription')
except (configparser.NoOptionError, configparser.NoSectionError):
return None
def print_current_configuration(file_config=None):
if file_config is None:
file_config = get_config_parser()
file_config.read([GLOBAL_CONFIG_PATH])
for section in file_config.sections():
print()
print('[{}]'.format(section))
for option in file_config.options(section):
print('{} = {}'.format(option, file_config.get(section, option)))
env_vars = [ev for ev in os.environ if ev.startswith(CLI_ENV_VARIABLE_PREFIX)]
if env_vars:
print(MSG_HEADING_ENV_VARS)
print('\n'.join(['{} = {}'.format(ev, os.environ[ev]) for ev in env_vars]))
def _handle_global_configuration(config):
# print location of global configuration
print(MSG_GLOBAL_SETTINGS_LOCATION.format(config.config_path))
# set up the config parsers
file_config = get_config_parser()
config_exists = file_config.read([config.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
with ConfiguredDefaultSetter(config, False):
output_index = prompt_choice_list(MSG_PROMPT_GLOBAL_OUTPUT, OUTPUT_LIST,
default=get_default_from_config(config,
'core', 'output',
OUTPUT_LIST))
answers['output_type_prompt'] = output_index
answers['output_type_options'] = str(OUTPUT_LIST)
def __init__(self, config_dir=AZ_DEVOPS_GLOBAL_CONFIG_DIR, config_env_var_prefix=CLI_ENV_VARIABLE_PREFIX):
super(AzDevopsConfig, self).__init__(config_dir=config_dir, config_env_var_prefix=config_env_var_prefix)
self.config_parser = get_config_parser()
def print_current_configuration(file_config=None):
from azext_devops.dev.repos.git_alias import are_git_aliases_setup
if file_config is None:
file_config = get_config_parser()
file_config.read([AZ_DEVOPS_GLOBAL_CONFIG_PATH])
for section in file_config.sections():
print()
print('[{}]'.format(section))
for option in file_config.options(section):
print('{} = {}'.format(option, file_config.get(section, option)))
# Print if git alias is setup or not
is_git_alias_setup = MSG_NO
if are_git_aliases_setup():
is_git_alias_setup = MSG_YES
print('{} = {}'.format(MSG_GIT_ALIAS_SETUP, is_git_alias_setup))
env_vars = [ev for ev in os.environ if ev.startswith(CLI_ENV_VARIABLE_PREFIX)]
if env_vars:
print(MSG_HEADING_ENV_VARS)
print('\n'.join(['{}'.format(ev) for ev in env_vars]))
def get_clouds(cli_ctx):
clouds = []
config = get_config_parser()
# Start off with known clouds and apply config file on top of current config
for c in KNOWN_CLOUDS:
_config_add_cloud(config, c)
try:
config.read(CLOUD_CONFIG_FILE)
except configparser.MissingSectionHeaderError:
os.remove(CLOUD_CONFIG_FILE)
logger.warning("'%s' is in bad format and has been removed.", CLOUD_CONFIG_FILE)
for section in config.sections():
c = Cloud(section)
for option in config.options(section):
if option == 'profile':
c.profile = config.get(section, option)
if option.startswith('endpoint_'):
setattr(c.endpoints, option.replace('endpoint_', ''), config.get(section, option))
elif option.startswith('suffix_'):