示例#1
0
    def delete(self, scan_uuid):
        """Cancel the specified scan schedule"""
        scan = ScanResource.get_by_uuid(scan_uuid, withResults=False)

        if scan["scheduled"] == False:
            abort(400, "Already canceled")

        data = {
            "start_at": Utils.get_default_datetime(),
            "end_at": Utils.get_default_datetime(),
            "started_at": Utils.get_default_datetime(),
            "ended_at": Utils.get_default_datetime(),
            "scheduled": False,
            "task_uuid": None,
        }

        ScanTable.update(data).where(ScanTable.id == scan["id"]).execute()
        return ScanResource.get_by_uuid(scan_uuid, withResults=False)
示例#2
0
    def patch(self, scan_uuid):
        """Schedule the specified scan"""
        scan = ScanResource.get_by_uuid(scan_uuid, withResults=False)

        if scan["scheduled"] == True:
            abort(400, "Already scheduled")

        schema = ScanUpdateSchema(only=["target", "start_at", "end_at", "slack_webhook_url"])
        params, errors = schema.load(request.json)
        if errors:
            abort(400, errors)

        if "target" in params:
            scan["target"] = params["target"]

        if "slack_webhook_url" in params:
            scan["slack_webhook_url"] = params["slack_webhook_url"]

        with db.database.atomic():

            task = PendingTask().add(
                {
                    "audit_id": scan["audit_id"],
                    "scan_id": scan["id"],
                    "target": scan["target"],
                    "start_at": params["start_at"],
                    "end_at": params["end_at"],
                    "slack_webhook_url": scan["slack_webhook_url"],
                }
            )

            params["started_at"] = Utils.get_default_datetime()
            params["ended_at"] = Utils.get_default_datetime()
            params["task_uuid"] = task.uuid
            params["scheduled"] = True
            ScanTable.update(params).where(ScanTable.id == scan["id"]).execute()

        return ScanResource.get_by_uuid(scan_uuid, withResults=False)