Пример #1
0
    def get_scanner(self):
        """Returns the configured scanner for this Scan configuration

        :returns: The configured scanner
        :rtype: :class:`ingest.scan.scanners.scanner.Scanner`
        """

        scanner = factory.get_scanner(self.scanner_type)
        self.load_scanner_configuration(scanner)
        return scanner
Пример #2
0
    def validate(self):
        """Validates the Scan configuration

        :returns: A list of warnings discovered during validation
        :rtype: list[:class:`ingest.scan.configuration.scan_configuration.ValidationWarning`]

        :raises :class:`ingest.scan.configuration.exceptions.InvalidScanConfiguration`: If the configuration is
            invalid.
        """

        warnings = []

        scanner_type = self._configuration['scanner']['type']
        if scanner_type not in factory.get_scanner_types():
            raise InvalidScanConfiguration('\'%s\' is an invalid scanner' %
                                           scanner_type)

        scanned_workspace_name = self._configuration['workspace']
        workspace_names = {scanned_workspace_name}
        for rule in self._file_handler.rules:
            if rule.new_workspace:
                workspace_names.add(rule.new_workspace)

        for workspace in Workspace.objects.filter(name__in=workspace_names):
            if workspace.name == scanned_workspace_name:
                broker_type = workspace.get_broker().broker_type
                scanner = factory.get_scanner(scanner_type)
                if broker_type not in scanner.supported_broker_types:
                    msg = 'Scanner type %s does not support broker type %s'
                    raise InvalidScanConfiguration(msg %
                                                   (scanner_type, broker_type))
            if not workspace.is_active:
                raise InvalidScanConfiguration('Workspace is not active: %s' %
                                               workspace.name)
            workspace_names.remove(workspace.name)

        if workspace_names:
            raise InvalidScanConfiguration('Unknown workspace name: %s' %
                                           workspace_names.pop())

        return warnings
Пример #3
0
    def validate(self):
        """Validates the Scan configuration

        :returns: A list of warnings discovered during validation
        :rtype: list[:class:`ingest.scan.configuration.scan_configuration.ValidationWarning`]

        :raises :class:`ingest.scan.configuration.exceptions.InvalidScanConfiguration`: If the configuration is
            invalid.
        """

        warnings = []

        scanner_type = self.scanner_type
        if scanner_type not in factory.get_scanner_types():
            raise InvalidScanConfiguration('\'%s\' is an invalid scanner' %
                                           scanner_type)

        if 'recipe' in self.config_dict:
            recipe_name = self.config_dict['recipe'][
                'name'] if 'name' in self.config_dict['recipe'] else None
            revision_num = self.config_dict['recipe'][
                'revision_num'] if 'revision_num' in self.config_dict[
                    'recipe'] else None

            if not recipe_name:
                msg = 'Recipe Type name is not defined'
                raise InvalidScanConfiguration(msg)

            if RecipeType.objects.filter(name=recipe_name).count() == 0:
                msg = 'Recipe Type %s does not exist'
                raise InvalidScanConfiguration(msg % recipe_name)

            if revision_num:
                rt = RecipeType.objects.get(name=recipe_name)
                if RecipeTypeRevision.objects.filter(
                        recipe_type=rt,
                        revision_num=revision_num).count() == 0:
                    msg = 'Recipe Type revision number %s does not exist for recipe type %s'
                    raise InvalidScanConfiguration(msg %
                                                   (revision_num, recipe_name))

        scanned_workspace_name = self.workspace
        workspace_names = {scanned_workspace_name}
        for rule in self.file_handler.rules:
            if rule.new_workspace:
                workspace_names.add(rule.new_workspace)

        for workspace in Workspace.objects.filter(name__in=workspace_names):
            if workspace.name == scanned_workspace_name:
                broker_type = workspace.get_broker().broker_type
                scanner = factory.get_scanner(scanner_type)
                if broker_type not in scanner.supported_broker_types:
                    msg = 'Scanner type %s does not support broker type %s'
                    raise InvalidScanConfiguration(msg %
                                                   (scanner_type, broker_type))
            if not workspace.is_active:
                raise InvalidScanConfiguration('Workspace is not active: %s' %
                                               workspace.name)
            workspace_names.remove(workspace.name)

        if workspace_names:
            raise InvalidScanConfiguration('Unknown workspace name: %s' %
                                           workspace_names.pop())

        return warnings