Example #1
0
    def edit_scan(self, scan_id, title=None, description=None, configuration=None):
        """Edits the given Scan process and saves the changes in the database. All database changes occur in an atomic
        transaction. An argument of None for a field indicates that the field should not change.

        :param scan_id: The unique identifier of the Scan process to edit
        :type scan_id: int
        :param title: The human-readable name of this Scan process
        :type title: string
        :param description: A description of this Scan process
        :type description: string
        :param configuration: The Strike process configuration
        :type configuration: dict

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

        scan = Scan.objects.select_for_update().get(pk=scan_id)
        
        if scan.job:
            raise ScanIngestJobAlreadyLaunched

        # Validate the configuration, no exception is success
        if configuration:
            config = ScanConfiguration(configuration)
            config.validate()
            scan.configuration = config.get_dict()

        # Update editable fields
        if title:
            scan.title = title
        if description:
            scan.description = description
        scan.save()
Example #2
0
    def create_scan(self, name, title, description, configuration, dry_run=True):
        """Creates a new Scan process with the given configuration and returns 
        the new Scan model. All changes to the database will occur in an atomic transaction.

        :param name: The identifying name of this Scan process
        :type name: string
        :param title: The human-readable name of this Scan process
        :type title: string
        :param description: A description of this Scan process
        :type description: string
        :param configuration: The Scan configuration
        :type configuration: dict
        :param dry_run: Whether the scan will execute as a dry run
        :type dry_run: bool
        :returns: The new Scan process
        :rtype: :class:`ingest.models.Scan`

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

        # Validate the configuration, no exception is success
        config = ScanConfiguration(configuration)
        config.validate()

        scan = Scan()
        scan.name = name
        scan.title = title
        scan.description = description
        scan.configuration = config.get_dict()
        scan.save()

        return scan