Example #1
0
 def test_set_config_value(self):
     with mock.patch('azure.cli.core._config.GLOBAL_CONFIG_DIR', self.config_dir), \
     mock.patch('azure.cli.core._config.GLOBAL_CONFIG_PATH', self.config_path):
         set_global_config_value('test_section', 'test_option', 'a_value')
         config = get_config_parser()
         config.read(os.path.join(self.config_dir, CONFIG_FILE_NAME))
         self.assertEqual(config.get('test_section', 'test_option'), 'a_value')
Example #2
0
 def test_set_config_value(self):
     with mock.patch('azure.cli.core._config.GLOBAL_CONFIG_DIR', self.config_dir), \
     mock.patch('azure.cli.core._config.GLOBAL_CONFIG_PATH', self.config_path):
         set_global_config_value('test_section', 'test_option', 'a_value')
         config = get_config_parser()
         config.read(os.path.join(self.config_dir, CONFIG_FILE_NAME))
         self.assertEqual(config.get('test_section', 'test_option'),
                          'a_value')
Example #3
0
    def firsttime(self):
        """ sets it as already done"""
        self.config.set('DEFAULT', 'firsttime', 'no')
        if az_config.getboolean('core', 'collect_telemetry', fallback=False):
            print(PRIVACY_STATEMENT)
        else:
            set_global_config_value('core', 'collect_telemetry', ask_user_for_telemetry())

        self.update()
Example #4
0
    def firsttime(self):
        """ sets it as already done"""
        self.config.set('DEFAULT', 'firsttime', 'no')
        if az_config.getboolean('core', 'collect_telemetry', fallback=False):
            print(PRIVACY_STATEMENT)
        else:
            set_global_config_value('core', 'collect_telemetry', ask_user_for_telemetry())

        self.update()
Example #5
0
 def test_set_config_value_file_permissions(self):
     with mock.patch('azure.cli.core._config.GLOBAL_CONFIG_DIR', self.config_dir), \
     mock.patch('azure.cli.core._config.GLOBAL_CONFIG_PATH', self.config_path):
         set_global_config_value('test_section', 'test_option', 'a_value')
         file_mode = os.stat(self.config_path).st_mode
         self.assertTrue(bool(file_mode & stat.S_IRUSR))
         self.assertTrue(bool(file_mode & stat.S_IWUSR))
         self.assertFalse(bool(file_mode & stat.S_IXUSR))
         self.assertFalse(bool(file_mode & stat.S_IRGRP))
         self.assertFalse(bool(file_mode & stat.S_IWGRP))
         self.assertFalse(bool(file_mode & stat.S_IXGRP))
         self.assertFalse(bool(file_mode & stat.S_IROTH))
         self.assertFalse(bool(file_mode & stat.S_IWOTH))
         self.assertFalse(bool(file_mode & stat.S_IXOTH))
Example #6
0
 def test_set_config_value_file_permissions(self):
     with mock.patch('azure.cli.core._config.GLOBAL_CONFIG_DIR', self.config_dir), \
     mock.patch('azure.cli.core._config.GLOBAL_CONFIG_PATH', self.config_path):
         set_global_config_value('test_section', 'test_option', 'a_value')
         file_mode = os.stat(self.config_path).st_mode
         self.assertTrue(bool(file_mode & stat.S_IRUSR))
         self.assertTrue(bool(file_mode & stat.S_IWUSR))
         self.assertFalse(bool(file_mode & stat.S_IXUSR))
         self.assertFalse(bool(file_mode & stat.S_IRGRP))
         self.assertFalse(bool(file_mode & stat.S_IWGRP))
         self.assertFalse(bool(file_mode & stat.S_IXGRP))
         self.assertFalse(bool(file_mode & stat.S_IROTH))
         self.assertFalse(bool(file_mode & stat.S_IWOTH))
         self.assertFalse(bool(file_mode & stat.S_IXOTH))
Example #7
0
def handle_configure(defaults=None):
    if defaults:
        for default in defaults:
            parts = default.split('=', 1)
            if len(parts) == 1:
                raise CLIError('usage error: --defaults STRING=STRING STRING=STRING ...')
            set_global_config_value(DEFAULTS_SECTION, parts[0], _normalize_config_value(parts[1]))
        return

    # if nothing supplied, we go interactively
    try:
        print(MSG_INTRO)
        _handle_global_configuration()
        print(MSG_CLOSING)
        # TODO: log_telemetry('configure', **answers)
    except NoTTYException:
        raise CLIError('This command is interactive and no tty available.')
    except (EOFError, KeyboardInterrupt):
        print()
Example #8
0
def handle_configure(defaults=None):
    if defaults:
        for default in defaults:
            parts = default.split('=', 1)
            if len(parts) == 1:
                raise CLIError('usage error: --defaults STRING=STRING STRING=STRING ...')
            set_global_config_value(DEFAULTS_SECTION, parts[0], _normalize_config_value(parts[1]))
        return

    # if nothing supplied, we go interactively
    try:
        print(MSG_INTRO)
        _handle_global_configuration()
        print(MSG_CLOSING)
        # TODO: log_telemetry('configure', **answers)
    except NoTTYException:
        raise CLIError('This command is interactive and no tty available.')
    except (EOFError, KeyboardInterrupt):
        print()
Example #9
0
def _set_active_cloud(cloud_name):
    set_global_config_value('cloud', 'name', cloud_name)
Example #10
0
def _set_active_cloud(cloud_name):
    set_global_config_value('cloud', 'name', cloud_name)
Example #11
0
 def test_set_config_value_not_string(self):
     with mock.patch('azure.cli.core._config.GLOBAL_CONFIG_DIR', self.config_dir), \
     mock.patch('azure.cli.core._config.GLOBAL_CONFIG_PATH', self.config_path), \
     self.assertRaises(TypeError):
         set_global_config_value('test_section', 'test_option', False)
def show_privacy_statement():
    from azure.cli.core._config import az_config, set_global_config_value
    first_ran = az_config.getboolean('core', 'first_run', fallback=False)
    if not first_ran:
        print(PRIVACY_STATEMENT, file=sys.stdout)
        set_global_config_value('core', 'first_run', 'yes')
Example #13
0
 def set_feedback(self, value):
     """ sets the feedback in the config """
     set_global_config_value('core', 'given feedback', value)
Example #14
0
def show_privacy_statement():
    from azure.cli.core._config import az_config, set_global_config_value
    first_ran = az_config.getboolean('core', 'first_run', fallback=False)
    if not first_ran:
        print(PRIVACY_STATEMENT, file=sys.stdout)
        set_global_config_value('core', 'first_run', 'yes')
Example #15
0
 def set_feedback(self, value):
     """ sets the feedback in the config """
     set_global_config_value('core', 'given feedback', value)
Example #16
0
 def test_set_config_value_not_string(self):
     with mock.patch('azure.cli.core._config.GLOBAL_CONFIG_DIR', self.config_dir), \
     mock.patch('azure.cli.core._config.GLOBAL_CONFIG_PATH', self.config_path), \
     self.assertRaises(TypeError):
         set_global_config_value('test_section', 'test_option', False)