Exemple #1
0
def async_find_and_attach(upload_id):
    """
    Task backend for Vscan upload
    """

    case = None

    try:
        upload_doc = VscanUpload.get(upload_id)
        files = get_files_from_doc(upload_doc)
        case = match_case(
            upload_doc.scanner_serial,
            upload_doc.scan_id,
        )

        if case:
            files = {}
            attachments = (upload_doc.blobs if isinstance(
                upload_doc, BlobMixin) else upload_doc._attachments)
            for f in attachments:
                files[f] = io.BytesIO(upload_doc.fetch_attachment(f))

            attach_images_to_case(case._id, files)
        else:
            return -1

        upload_doc.delete()
    except:
        # mark the case as having errored (if we know what it is)
        # but reraise the error since we don't want to hide it
        if case:
            submit_error_case(case._id)

        raise
Exemple #2
0
def async_find_and_attach(upload_id):
    """
    Task backend for Vscan upload
    """

    case = None

    try:
        upload_doc = VscanUpload.get(upload_id)
        files = get_files_from_doc(upload_doc)
        case = match_case(upload_doc.scanner_serial, upload_doc.scan_id)

        if case:
            files = {}
            for f in upload_doc._attachments.keys():
                files[f] = io.BytesIO(upload_doc.fetch_attachment(f))

            attach_images_to_case(case._id, files)
        else:
            return -1

        upload_doc.delete()
    except:
        # mark the case as having errored (if we know what it is)
        # but reraise the error since we don't want to hide it
        if case:
            submit_error_case(case._id)

        raise
Exemple #3
0
def vscan_upload(request, domain, **kwargs):
    """
    End point for uploading data from vscan.

    Expects scanner_serial and scan_id in params and
    a list of image/video files.
    """

    scanner_serial = request.POST.get('scanner_serial', None)
    scan_id = request.POST.get('scan_id', None)

    response_code = None

    if not (scanner_serial and scan_id):
        response_data = {}
        response_data['result'] = 'failed'
        response_data['message'] = 'Missing required parameters'
        response_code = 500
    else:
        upload = VscanUpload(
            scanner_serial=scanner_serial,
            scan_id=scan_id,
        )
        upload.save()

        put_request_files_in_doc(request, upload)

        async_find_and_attach.delay(upload._id)

        response_data = {}
        response_data['result'] = 'success'
        response_data['message'] = ''

    return HttpResponse(
        json.dumps(response_data),
        content_type="application/json",
        status=response_code or 200
    )
Exemple #4
0
def vscan_upload(request, domain, **kwargs):
    """
    End point for uploading data from vscan.

    Expects scanner_serial and scan_id in params and
    a list of image/video files.
    """

    scanner_serial = request.POST.get('scanner_serial', None)
    scan_id = request.POST.get('scan_id', None)

    response_code = None

    if not (scanner_serial and scan_id):
        response_data = {}
        response_data['result'] = 'failed'
        response_data['message'] = 'Missing required parameters'
        response_code = 500
    else:
        upload = VscanUpload(
            scanner_serial=scanner_serial,
            scan_id=scan_id,
        )
        upload.save()

        put_request_files_in_doc(request, upload)

        async_find_and_attach.delay(upload._id)

        response_data = {}
        response_data['result'] = 'success'
        response_data['message'] = ''

    return HttpResponse(
        json.dumps(response_data),
        content_type="application/json",
        status=response_code or 200
    )