-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathmodels.py
67 lines (60 loc) · 2.34 KB
/
models.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from django.db import models
from framework.models import BaseModel
from processes.models import Process
from rekono.settings import AUTH_USER_MODEL
from security.validators.input_validator import (
FutureDatetimeValidator,
TimeAmountValidator,
)
from targets.models import Target
from tasks.enums import TimeUnit
from tools.enums import Intensity
from tools.models import Configuration
from wordlists.models import Wordlist
# Create your models here.
class Task(BaseModel):
"""Task model."""
# Job Id in the tasks queue
rq_job_id = models.TextField(max_length=50, blank=True, null=True)
target = models.ForeignKey(Target, related_name="tasks", on_delete=models.CASCADE)
process = models.ForeignKey(
Process, blank=True, null=True, on_delete=models.SET_NULL
)
configuration = models.ForeignKey(
Configuration, on_delete=models.SET_NULL, blank=True, null=True
)
intensity = models.IntegerField(choices=Intensity.choices, default=Intensity.NORMAL)
executor = models.ForeignKey(
AUTH_USER_MODEL, on_delete=models.SET_NULL, blank=True, null=True
)
# Date when the task will be executed
scheduled_at = models.DateTimeField(
blank=True,
null=True,
validators=[FutureDatetimeValidator(code="scheduled_at")],
)
# Amount of time to wait until repeating the task execution
repeat_in = models.IntegerField(
blank=True,
null=True,
validators=[TimeAmountValidator(code="repeat_in")],
)
# Time unit to apply to the 'repeat in' value
repeat_time_unit = models.TextField(
max_length=10, choices=TimeUnit.choices, blank=True, null=True
)
creation = models.DateTimeField(auto_now_add=True)
# Date at task got enqueued
enqueued_at = models.DateTimeField(blank=True, null=True)
start = models.DateTimeField(blank=True, null=True)
end = models.DateTimeField(blank=True, null=True)
wordlists = models.ManyToManyField(Wordlist, related_name="wordlists", blank=True)
def __str__(self) -> str:
"""Instance representation in text format.
Returns:
str: String value that identifies this instance
"""
return f"{self.target.__str__()} - {(self.process or self.configuration).__str__()}"
@classmethod
def get_project_field(cls) -> str:
return "target__project"