コード例 #1
0
    def _create_values_provider(self, values_config, type, constant):
        if constant:
            return NoneValuesProvider()

        if self._is_plain_server_file():
            return FilesProvider(self._list_files_dir, self.file_type,
                                 self.file_extensions)

        if (type != 'list') and (type != PARAM_TYPE_MULTISELECT):
            return NoneValuesProvider()

        if is_empty(values_config):
            return EmptyValuesProvider()

        if isinstance(values_config, list):
            return ConstValuesProvider(values_config)

        elif 'script' in values_config:
            script = values_config['script']

            if '${' not in script:
                return ScriptValuesProvider(script)

            return DependantScriptValuesProvider(script,
                                                 self._parameters_supplier)

        else:
            message = 'Unsupported "values" format for ' + self.name
            raise Exception(message)
コード例 #2
0
    def _create_values_provider(self, values_config, type, constant):
        if constant:
            return NoneValuesProvider()

        if self._is_plain_server_file():
            return FilesProvider(self._list_files_dir, self.file_type,
                                 self.file_extensions)

        if (type in [PARAM_TYPE_MULTISELECT, PARAM_TYPE_LIST]):

            if is_empty(values_config):
                return EmptyValuesProvider()

            if isinstance(values_config, list):
                return ConstValuesProvider(values_config)

            if PARAM_TYPE_DEPENDANT_LIST in values_config:
                return DependantValuesProvider(
                    self.name, values_config[PARAM_TYPE_DEPENDANT_LIST],
                    self._parameters_supplier)

            if 'script' in values_config:
                script = replace_auth_vars(values_config['script'],
                                           self._username, self._audit_name)
                if '${' not in script:
                    return ScriptValuesProvider(script)

                return DependantScriptValuesProvider(script,
                                                     self._parameters_supplier)

        elif (type in ["text"]):
            if is_empty(values_config):
                return NoneValuesProvider()

            if 'script' in values_config:
                script = values_config['script']

                if '${' not in script:
                    return ScriptValuesProvider(script)

                return DependantScriptValuesProvider(script,
                                                     self._parameters_supplier)
        else:
            return NoneValuesProvider()

        message = 'Unsupported "values" format for ' + self.name
        raise Exception(message)
コード例 #3
0
def _create_values_provider(values, parameter, parameters):
    if values:
        if isinstance(values, list):
            return ConstValuesProvider(values)

        elif 'script' in values:
            script = values['script']

            if '${' not in script:
                return ScriptValuesProvider(script)

            return DependantScriptValuesProvider(script, parameters)

        else:
            raise Exception('Unsupported "values" format for ' +
                            parameter.name)
    else:
        return EmptyValuesProvider()
コード例 #4
0
    def _create_values_provider(self, values_config, type, constant):
        if constant or ((type != 'list') and (type != 'multiselect')):
            return NoneValuesProvider()

        if is_empty(values_config):
            return EmptyValuesProvider()

        if isinstance(values_config, list):
            return ConstValuesProvider(values_config)

        elif 'script' in values_config:
            script = values_config['script']

            if '${' not in script:
                return ScriptValuesProvider(script)

            return DependantScriptValuesProvider(script, self._parameters_supplier)

        else:
            message = 'Unsupported "values" format for ' + self.name
            raise Exception(message)
コード例 #5
0
    def _create_values_provider(self, values_config, type, constant):
        if constant:
            return NoneValuesProvider()

        if self._is_plain_server_file():
            return FilesProvider(self._list_files_dir, self.file_type,
                                 self.file_extensions,
                                 self.excluded_files_matcher)

        if (type != 'list') and (type != PARAM_TYPE_MULTISELECT) and (
                type != PARAM_TYPE_EDITABLE_LIST):
            return NoneValuesProvider()

        if is_empty(values_config):
            return EmptyValuesProvider()

        if isinstance(values_config, list):
            return ConstValuesProvider(values_config)

        elif 'script' in values_config:
            original_script = values_config['script']
            has_variables = ('${' in original_script)

            script = replace_auth_vars(original_script, self._username,
                                       self._audit_name)
            shell = read_bool_from_config('shell',
                                          values_config,
                                          default=not has_variables)

            if '${' not in script:
                return ScriptValuesProvider(script, shell)

            return DependantScriptValuesProvider(script,
                                                 self._parameters_supplier,
                                                 shell)

        else:
            message = 'Unsupported "values" format for ' + self.name
            raise Exception(message)
コード例 #6
0
 def test_ls_3_files_when_bash_operator_and_shell(self):
     test_utils.create_files(['f1', 'f2', 'f3'])
     provider = ScriptValuesProvider('ls "' + test_utils.temp_folder +
                                     '" | grep 2',
                                     shell=True)
     self.assertEqual(['f2'], provider.get_values({}))
コード例 #7
0
 def test_ls_no_files(self, shell):
     provider = ScriptValuesProvider('ls "' + test_utils.temp_folder + '"',
                                     shell=shell)
     self.assertEqual([], provider.get_values({}))
コード例 #8
0
 def test_ls_3_files(self, shell):
     test_utils.create_files(['f1', 'f2', 'f3'])
     provider = ScriptValuesProvider('ls "' + test_utils.temp_folder + '"',
                                     shell=shell)
     self.assertEqual(['f1', 'f2', 'f3'], provider.get_values({}))