summaryrefslogtreecommitdiffstats
path: root/django/validationmanager/tasks.py
blob: 87f414f6ce1fb8d5a5e8687d29059f5571bfa80f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from celery import Celery
from django.conf import settings

celery_app = Celery(
    broker='redis://redis',
    backend='redis://redis',
    )

# Celery signatures allow us to invoke the imagescanner celery task without
# importing or depending upon imagescanner's code here. (Because doing so would
# make all of imagescanner's dependencies get added to this Django project.)
#
# FIXME for some reason, requests submitted in this way do not show their
# arguments in the simple frontend's "Executing" and "Pending" lists. It
# appears only as "()"
_request_scan = celery_app.signature(
    'imagescanner.tasks.request_scan',
    queue='scans',
    ignore_result=True)


def request_scan(vf, checklist):
    """Issue a request (using Celery and Redis) for the imagescanner to run.

    This function issues the request asynchronously and returns quickly.

    vf:
        the VF corresponding to the image to be scanned. we use this to
        determine the radosgw bucket name to search for images and the jenkins
        job name to trigger with the image scan results.

    checklist:
        the checklist to be updated with the results of the scan.
    """
    # we can't necessarily look this up from the vf because there might be two
    # available at the time this method runs (the new one, and the old one
    # which will get changed to archive state)

    return _request_scan.delay(
        source="https://%s/%s_%s/" % (
            settings.AWS_S3_HOST, vf.engagement.engagement_manual_id, vf.name),
        path='',
        recipients=[],
        # this suffix should match the one in
        # validationmanager.em_integration.vm_api.get_jenkins_job_config
        jenkins_job_name=vf.jenkins_job_name() + '_scanner',
        checklist_uuid=checklist.uuid,
        )