Commit 2517fdf6 authored by Johan Bloemberg's avatar Johan Bloemberg

Creating a task might imply it being scheduled as well, compose implies making...

Creating a task might imply it being scheduled as well, compose implies making up a task for later execution.
parent 01fb9d9a
Pipeline #16159349 passed with stage
in 7 minutes and 6 seconds
......@@ -31,7 +31,7 @@ def rebuild_ratings(request):
name = 'Rebuild ratings'
# create a Task signature for rebuilding ratings, wrap this inside a Job
# to have it trackable by the user in the admin interface
task = rating.create_task()
task = rating.compose_task()
job = Job.create(task, name, request, priority=PRIO_HIGH)
# tell the user where to find the Job that was just created
......
......@@ -154,4 +154,4 @@ class ScannerTaskCommand(TaskCommand):
organization_filter = {'name__iregex': regex}
# compose set of tasks to be executed
return self.scanner_module.create_task(organization_filter)
return self.scanner_module.compose_task(organization_filter)
......@@ -70,10 +70,10 @@ class Job(models.Model):
def create_job(task_module: str):
"""Helper to allow Jobs to be created using Celery Beat.
task_module: module from which to call `create_task` which results in the task to be executed
task_module: module from which to call `compose_task` which results in the task to be executed
"""
module = importlib.import_module(task_module)
task = module.create_task()
task = module.compose_task()
return Job.create(task, task_module, None)
from failmap.app.management.commands._private import TaskCommand
from ...rating import create_task
from ...rating import compose_task
class Command(TaskCommand):
......@@ -8,4 +8,4 @@ class Command(TaskCommand):
help = __doc__
task = create_task()
task = compose_task()
......@@ -18,7 +18,7 @@ from .points_and_calculations import points_and_calculation
log = logging.getLogger(__package__)
def create_task(
def compose_task(
organizations_filter: dict = dict(),
urls_filter: dict = dict(),
endpoints_filter: dict = dict(),
......@@ -40,7 +40,7 @@ def create_task(
For example, to scan all urls/endpoints for one organization named 'example' run:
>>> task = create_task(organizations={'name__iexact': 'example'})
>>> task = compose_task(organizations={'name__iexact': 'example'})
>>> result = task.apply_async()
>>> print(result.get())
......@@ -48,7 +48,7 @@ def create_task(
Multiple filters can be applied, to scan only port 80 for organizations added today run:
>>> task = create_task(
>>> task = compose_task(
... organizations={'date_added__day': datetime.datetime.today().day},
... endpoints={'port': 80}
... )
......
......@@ -87,22 +87,22 @@ class ActionMixin:
actions = []
def scan_plain_http(self, *args, **kwargs):
return self.generic_action(scanner_plain_http.create_task, 'Scan Plain Http', *args, **kwargs)
return self.generic_action(scanner_plain_http.compose_task, 'Scan Plain Http', *args, **kwargs)
scan_plain_http.short_description = '🔬 Scan Plain Http'
actions.append(scan_plain_http)
def scan_security_headers(self, *args, **kwargs):
return self.generic_action(scanner_security_headers.create_task, 'Scan Security Headers', *args, **kwargs)
return self.generic_action(scanner_security_headers.compose_task, 'Scan Security Headers', *args, **kwargs)
scan_security_headers.short_description = '🔬 Scan Security Headers'
actions.append(scan_security_headers)
def scan_tls_qualys(self, *args, **kwargs):
return self.generic_action(scanner_tls_qualys.create_task, 'Scan TLS Qualys', *args, **kwargs)
return self.generic_action(scanner_tls_qualys.compose_task, 'Scan TLS Qualys', *args, **kwargs)
scan_tls_qualys.short_description = '🔬 Scan TLS Qualys'
actions.append(scan_tls_qualys)
def rebuild_ratings(self, *args, **kwargs):
return self.generic_action(rating.create_task, 'Rebuild rating', *args, **kwargs)
return self.generic_action(rating.compose_task, 'Rebuild rating', *args, **kwargs)
rebuild_ratings.short_description = '✅ Rebuild rating'
actions.append(rebuild_ratings)
......
......@@ -25,7 +25,7 @@ RETRY_DELAY = 1
EXPIRES = 5
def create_task(
def compose_task(
organizations_filter: dict = dict(),
urls_filter: dict = dict(),
endpoints_filter: dict = dict(),
......@@ -47,7 +47,7 @@ def create_task(
For example, to scan all urls/endpoints for one organization named 'example' run:
>>> task = create_task(organizations={'name__iexact': 'example'})
>>> task = compose_task(organizations={'name__iexact': 'example'})
>>> result = task.apply_async()
>>> print(result.get())
......@@ -55,7 +55,7 @@ def create_task(
Multiple filters can be applied, to scan only port 80 for organizations added today run:
>>> task = create_task(
>>> task = compose_task(
... organizations={'date_added__day': datetime.datetime.today().day},
... endpoints={'port': 80}
... )
......
......@@ -20,7 +20,7 @@ from .models import Endpoint
log = logging.getLogger(__package__)
def create_task(
def compose_task(
organizations_filter: dict = dict(),
urls_filter: dict = dict(),
endpoints_filter: dict = dict(),
......@@ -42,7 +42,7 @@ def create_task(
For example, to scan all urls/endpoints for one organization named 'example' run:
>>> task = create_task(organizations={'name__iexact': 'example'})
>>> task = compose_task(organizations={'name__iexact': 'example'})
>>> result = task.apply_async()
>>> print(result.get())
......@@ -50,7 +50,7 @@ def create_task(
Multiple filters can be applied, to scan only port 80 for organizations added today run:
>>> task = create_task(
>>> task = compose_task(
... organizations={'date_added__day': datetime.datetime.today().day},
... endpoints={'port': 80}
... )
......@@ -83,7 +83,7 @@ def create_task(
return task
# This needs to be refactored to move the Endpoint iteration to `create_task`
# This needs to be refactored to move the Endpoint iteration to `compose_task`
# and split this task up in a scan and store task so scans can be performed more
# distributed. For examples see scan_dummy.py
......
......@@ -20,7 +20,7 @@ from .models import Endpoint
log = logging.getLogger(__name__)
def create_task(
def compose_task(
organizations_filter: dict = dict(),
urls_filter: dict = dict(),
endpoints_filter: dict = dict(),
......@@ -42,7 +42,7 @@ def create_task(
For example, to scan all urls/endpoints for one organization named 'example' run:
>>> task = create_task(organizations={'name__iexact': 'example'})
>>> task = compose_task(organizations={'name__iexact': 'example'})
>>> result = task.apply_async()
>>> print(result.get())
......@@ -50,7 +50,7 @@ def create_task(
Multiple filters can be applied, to scan only port 80 for organizations added today run:
>>> task = create_task(
>>> task = compose_task(
... organizations={'date_added__day': datetime.datetime.today().day},
... endpoints={'port': 80}
... )
......
......@@ -44,7 +44,7 @@ from ..celery import PRIO_HIGH, app
log = logging.getLogger(__name__)
def create_task(
def compose_task(
organizations_filter: dict = dict(),
urls_filter: dict = dict(),
endpoints_filter: dict = dict(),
......@@ -66,7 +66,7 @@ def create_task(
For example, to scan all urls/endpoints for one organization named 'example' run:
>>> task = create_task(organizations={'name__iexact': 'example'})
>>> task = compose_task(organizations={'name__iexact': 'example'})
>>> result = task.apply_async()
>>> print(result.get())
......@@ -74,7 +74,7 @@ def create_task(
Multiple filters can be applied, to scan only port 80 for organizations added today run:
>>> task = create_task(
>>> task = compose_task(
... organizations={'date_added__day': datetime.datetime.today().day},
... endpoints={'port': 80}
... )
......
......@@ -144,7 +144,7 @@ def test_tls_scan_qualys_sample_result(db):
announce_testcase(1, "Creating a new scan, where everything has to go right.")
with freeze_time('2000-1-1', tick=True, tz_offset=1):
with HTTMock(qualys_mock_a):
scanner_tls_qualys.create_task()(urls_filter={'name__in': ["www.faalkaart.nl"]})
scanner_tls_qualys.compose_task()(urls_filter={'name__in': ["www.faalkaart.nl"]})
assert Endpoint.objects.filter(domain="www.faalkaart.nl").count() == 2 # ipv4 + ipv6
assert TlsQualysScan.objects.filter(qualys_rating="A").count() == 2
......@@ -152,7 +152,7 @@ def test_tls_scan_qualys_sample_result(db):
"or scan results. Scan results would only be updated after 24h.")
with freeze_time('2000-1-3', tick=True, tz_offset=1):
with HTTMock(qualys_mock_a):
scanner_tls_qualys.create_task()(urls_filter={'name__in': ["www.faalkaart.nl"]})
scanner_tls_qualys.compose_task()(urls_filter={'name__in': ["www.faalkaart.nl"]})
assert Endpoint.objects.filter(domain="www.faalkaart.nl").count() == 2
assert TlsQualysScan.objects.filter(qualys_rating="A").count() == 2
......@@ -161,7 +161,7 @@ def test_tls_scan_qualys_sample_result(db):
"should increase as only changes are recorded.")
with freeze_time('2000-1-5', tick=True, tz_offset=1):
with HTTMock(qualys_mock_b):
scanner_tls_qualys.create_task()(urls_filter={'name__in': ["www.faalkaart.nl"]})
scanner_tls_qualys.compose_task()(urls_filter={'name__in': ["www.faalkaart.nl"]})
assert Endpoint.objects.filter(domain="www.faalkaart.nl").count() == 2
assert TlsQualysScan.objects.filter(qualys_rating="A").count() == 2
assert TlsQualysScan.objects.filter(qualys_rating="B").count() == 2
......@@ -170,7 +170,7 @@ def test_tls_scan_qualys_sample_result(db):
"scan is dismissed")
with freeze_time('2000-1-5', tick=True, tz_offset=1):
with HTTMock(qualys_mock_c):
scanner_tls_qualys.create_task()(urls_filter={'name__in': ["www.faalkaart.nl"]})
scanner_tls_qualys.compose_task()(urls_filter={'name__in': ["www.faalkaart.nl"]})
assert Endpoint.objects.filter(domain="www.faalkaart.nl").count() == 2
assert TlsQualysScan.objects.filter(qualys_rating="A").count() == 2
assert TlsQualysScan.objects.filter(qualys_rating="B").count() == 2
......@@ -179,7 +179,7 @@ def test_tls_scan_qualys_sample_result(db):
announce_testcase(5, "Verify that it's possible to scan multiple domains.")
with freeze_time('2000-1-7', tick=True, tz_offset=1):
with HTTMock(qualys_mirror):
scanner_tls_qualys.create_task()(
scanner_tls_qualys.compose_task()(
urls_filter={
'name__in': [
"www.faalkaart.nl",
......@@ -200,7 +200,7 @@ def test_tls_scan_qualys_sample_result(db):
Counter().reset()
with freeze_time('2000-1-9', tick=True, tz_offset=1):
with HTTMock(qualys_realistic_scan):
scanner_tls_qualys.create_task()(urls_filter={'name__in': ["www.faalkaart.nl"]})
scanner_tls_qualys.compose_task()(urls_filter={'name__in': ["www.faalkaart.nl"]})
# no update on the rating, so no new scans.
assert TlsQualysScan.objects.filter(qualys_rating="A").count() == 8
......@@ -211,7 +211,7 @@ def test_tls_scan_qualys_sample_result(db):
Counter().reset()
with freeze_time('2000-1-11', tick=True, tz_offset=1):
with HTTMock(qualys_error_scan):
scanner_tls_qualys.create_task()(urls_filter={'name__in': ["www.faalkaart.nl"]})
scanner_tls_qualys.compose_task()(urls_filter={'name__in': ["www.faalkaart.nl"]})
# no update on the rating, so no new scan.
# the endpoints should now be set to dead...
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment