Esempio n. 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)
Esempio n. 2
0
    def test_multiselect_when_single_not_matching_element(self):
        parameter = self.create_parameter('param')
        parameter.type = 'multiselect'
        parameter.values_provider = ConstValuesProvider(
            ['val1', 'val2', 'val3'])

        error = model_helper.validate_parameter(parameter, {'param': ['X']})
        self.assert_error(error)
Esempio n. 3
0
    def test_multiselect_when_not_list_value(self):
        parameter = self.create_parameter('param')
        parameter.type = 'multiselect'
        parameter.values_provider = ConstValuesProvider(
            ['val1', 'val2', 'val3'])

        error = model_helper.validate_parameter(parameter, {'param': 'val1'})
        self.assert_error(error)
Esempio n. 4
0
    def test_multiselect_when_empty_list(self):
        parameter = self.create_parameter('param')
        parameter.type = 'multiselect'
        parameter.values_provider = ConstValuesProvider(
            ['val1', 'val2', 'val3'])

        error = model_helper.validate_parameter(parameter, {'param': []})
        self.assertIsNone(error)
Esempio n. 5
0
    def test_list_parameter_when_matches(self):
        parameter = self.create_parameter('param')
        parameter.type = 'list'
        parameter.values_provider = ConstValuesProvider(
            ['val1', 'val2', 'val3'])

        error = model_helper.validate_parameter(parameter, {'param': 'val2'})
        self.assertIsNone(error)
Esempio n. 6
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)
Esempio n. 7
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()
Esempio n. 8
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)
Esempio n. 9
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)