Skip to content

Commit 3ebc268

Browse files
committed
fixed linters
Signed-off-by: aryan <[email protected]>
1 parent 7966977 commit 3ebc268

File tree

19 files changed

+141
-36
lines changed

19 files changed

+141
-36
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[flake8]
2-
max-line-length = 88
2+
max-line-length = 140
33
ignore =
44
W503,
55
E231,

api_app/analyzers_manager/classes.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,24 @@ class BaseAnalyzerMixin(Plugin, metaclass=ABCMeta):
3838
@classmethod
3939
@property
4040
def config_exception(cls):
41+
"""Returns the AnalyzerConfigurationException class."""
4142
return AnalyzerConfigurationException
4243

4344
@property
4445
def analyzer_name(self) -> str:
46+
"""Returns the name of the analyzer."""
4547
return self._config.name
4648

4749
@classmethod
4850
@property
4951
def report_model(cls):
52+
"""Returns the AnalyzerReport model."""
5053
return AnalyzerReport
5154

5255
@classmethod
5356
@property
5457
def config_model(cls):
58+
"""Returns the AnalyzerConfig model."""
5559
return AnalyzerConfig
5660

5761
def get_exceptions_to_catch(self):
@@ -98,6 +102,12 @@ def _validate_result(self, result, level=0, max_recursion=190):
98102
return result
99103

100104
def after_run_success(self, content):
105+
"""
106+
Handles actions after a successful run.
107+
108+
Args:
109+
content (any): The content to process after a successful run.
110+
"""
101111
super().after_run_success(self._validate_result(content, max_recursion=15))
102112

103113

@@ -194,6 +204,11 @@ def read_file_bytes(self) -> bytes:
194204

195205
@property
196206
def filepath(self) -> str:
207+
"""Returns the file path, retrieving the file from storage if necessary.
208+
209+
Returns:
210+
str: The file path.
211+
"""
197212
if not self.__filepath:
198213
self.__filepath = self._job.file.storage.retrieve(
199214
file=self._job.file, analyzer=self.analyzer_name

api_app/decorators.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def prevent_signal_recursion(func):
5454
Returns:
5555
function: The wrapper function that prevents recursion.
5656
"""
57+
5758
@functools.wraps(func)
5859
def no_recursion(sender, instance=None, **kwargs):
5960
if not instance:

api_app/filters.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class JobFilter(filters.FilterSet):
3030
type (CharFilter): Custom filter method to filter by type (observable classification or file MIME type).
3131
name (CharFilter): Custom filter method to filter by name (observable or file name).
3232
"""
33+
3334
is_sample = filters.BooleanFilter()
3435
md5 = filters.CharFilter(lookup_expr="icontains")
3536
observable_name = filters.CharFilter(lookup_expr="icontains")

api_app/forms.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class MultilineJSONField(forms.JSONField):
1313
"""
1414
A custom JSONField that handles multiline JSON input.
15-
15+
1616
This field processes multiline input by replacing newline characters
1717
with the escape sequence '\\n', and also removes carriage returns and
1818
double quotes.
@@ -23,11 +23,12 @@ class MultilineJSONField(forms.JSONField):
2323
has_changed(initial, data): Checks if the field's data has changed from its initial value.
2424
bound_data(data, initial): Returns the data bound to the form field.
2525
"""
26+
2627
@staticmethod
2728
def _cleaning_and_multiline(value):
2829
"""
2930
Process multiline input to escape newline characters and remove carriage returns and quotes.
30-
31+
3132
Args:
3233
value (str): The input value to process.
3334
@@ -90,6 +91,7 @@ class ParameterInlineForm(forms.ModelForm):
9091
Attributes:
9192
default (MultilineJSONField): The default value for the parameter, processed for multiline JSON input.
9293
"""
94+
9395
default = MultilineJSONField(required=False)
9496

9597
class Meta:
@@ -116,6 +118,7 @@ class OrganizationPluginConfigurationForm(forms.ModelForm):
116118
playbook (ModelChoiceField): Field for selecting a PlaybookConfig.
117119
_plugins (list): List of plugin fields.
118120
"""
121+
119122
analyzer = forms.ModelChoiceField(
120123
queryset=AnalyzerConfig.objects.filter(orgs_configuration__isnull=True),
121124
required=False,

api_app/ingestors_manager/classes.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717

1818

1919
class Ingestor(Plugin, metaclass=abc.ABCMeta):
20+
"""
21+
Abstract Base class for Ingestors.
22+
Ingestors are responsible for ingesting data and generating reports.
23+
"""
24+
2025
def __init__(self, config: IngestorConfig, **kwargs):
2126
super().__init__(config, **kwargs)
2227

api_app/ingestors_manager/models.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@
2626

2727

2828
class IngestorReport(AbstractReport):
29+
"""
30+
Model representing an Ingestor Report.
31+
32+
Attributes:
33+
config (ForeignKey): Reference to the IngestorConfig.
34+
report (JSONField): JSON field storing the report data.
35+
name (CharField): Name of the report.
36+
task_id (UUIDField): Task ID associated with the report.
37+
job (ForeignKey): Reference to the related Job.
38+
max_size_report (IntegerField): Maximum size of the report.
39+
"""
40+
2941
objects = IngestorReportQuerySet.as_manager()
3042
config = models.ForeignKey(
3143
"IngestorConfig", related_name="reports", on_delete=models.CASCADE
@@ -47,6 +59,9 @@ class Meta:
4759
indexes = AbstractReport.Meta.indexes
4860

4961
def clean_report(self):
62+
"""
63+
Cleans the report by trimming it to the maximum size if necessary.
64+
"""
5065
if isinstance(self.report, list) and self.max_size_report is not None:
5166
len_report = len(self.report)
5267
if len_report > self.max_size_report:
@@ -62,6 +77,20 @@ def clean(self):
6277

6378

6479
class IngestorConfig(PythonConfig, CreateJobsFromPlaybookInterface):
80+
"""
81+
Model representing an Ingestor Configuration.
82+
83+
Attributes:
84+
python_module (ForeignKey): Reference to the PythonModule.
85+
playbooks_choice (ManyToManyField): Many-to-many relationship with PlaybookConfig.
86+
user (ForeignKey): Reference to the user.
87+
schedule (ForeignKey): Reference to the CrontabSchedule.
88+
periodic_task (OneToOneField): One-to-one relationship with PeriodicTask.
89+
maximum_jobs (IntegerField): Maximum number of jobs.
90+
delay (DurationField): Delay between jobs.
91+
org_configuration (None): Placeholder for organization configuration.
92+
"""
93+
6594
objects = IngestorQuerySet.as_manager()
6695
python_module = models.ForeignKey(
6796
PythonModule,

api_app/interfaces.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class CreateJobsFromPlaybookInterface:
3232
name (str): The name of the job.
3333
delay (datetime.timedelta): The delay before the job is executed.
3434
"""
35+
3536
playbooks_choice: QuerySet
3637
name: str
3738
delay: datetime.timedelta
@@ -228,6 +229,7 @@ class OwnershipAbstractModel(models.Model):
228229
for_organization (bool): Whether the model is for an organization.
229230
owner (ForeignKey): The owner of the model, linked to the user.
230231
"""
232+
231233
for_organization = models.BooleanField(default=False)
232234
owner = models.ForeignKey(
233235
settings.AUTH_USER_MODEL,

api_app/mixins.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class PaginationMixin:
1515
Attributes:
1616
pagination_class (CustomPageNumberPagination): The pagination class to use for paginating results.
1717
"""
18+
1819
pagination_class = CustomPageNumberPagination
1920

2021
def list(self, request, *args, **kwargs):

api_app/models.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class PythonModule(models.Model):
7777
update_task (PeriodicTask): The task associated with updating the module.
7878
health_check_schedule (CrontabSchedule): The schedule for health checks.
7979
"""
80+
8081
module = models.CharField(max_length=120, db_index=True)
8182
base_path = models.CharField(
8283
max_length=120, db_index=True, choices=PythonModuleBasePaths.choices
@@ -243,7 +244,8 @@ class Tag(models.Model):
243244
Attributes:
244245
label (str): The label of the tag.
245246
color (str): The color of the tag in hex format.
246-
"""
247+
"""
248+
247249
label = models.CharField(
248250
max_length=50,
249251
blank=False,
@@ -273,6 +275,7 @@ class Comment(models.Model):
273275
created_at (datetime): The date and time when the comment was created.
274276
updated_at (datetime): The date and time when the comment was last updated.
275277
"""
278+
276279
# make the user null if the user is deleted
277280
user = models.ForeignKey(
278281
settings.AUTH_USER_MODEL,
@@ -317,6 +320,7 @@ class Job(MP_Node):
317320
analyzers_report (ManyToManyField): The analyzers report for the job.
318321
analyzers_started (ManyToManyField): The analyzers started for the job.
319322
"""
323+
320324
objects = JobQuerySet.as_manager()
321325

322326
class Meta:
@@ -774,6 +778,7 @@ class Parameter(models.Model):
774778
required (bool): Indicates if the parameter is mandatory.
775779
python_module (ForeignKey): The Python module associated with the parameter.
776780
"""
781+
777782
objects = ParameterQuerySet.as_manager()
778783

779784
name = models.CharField(null=False, blank=False, max_length=50)
@@ -830,6 +835,7 @@ class PluginConfig(OwnershipAbstractModel):
830835
ingestor_config (ForeignKey): The ingestor configuration this config belongs to.
831836
pivot_config (ForeignKey): The pivot configuration this config belongs to.
832837
"""
838+
833839
objects = PluginConfigQuerySet.as_manager()
834840
value = models.JSONField(blank=True, null=True)
835841

@@ -1046,6 +1052,7 @@ class OrganizationPluginConfiguration(models.Model):
10461052
rate_limit_timeout (DurationField): The duration for which rate limits apply.
10471053
rate_limit_enable_task (ForeignKey): The task to re-enable the configuration after a rate limit.
10481054
"""
1055+
10491056
objects = OrganizationPluginConfigurationQuerySet.as_manager()
10501057
content_type = models.ForeignKey(
10511058
ContentType,
@@ -1074,7 +1081,7 @@ class Meta:
10741081
unique_together = [("object_id", "organization", "content_type")]
10751082

10761083
def __str__(self):
1077-
"""Returns a string representation of the organization plugin configuration."""
1084+
"""Returns a string representation of the organization plugin configuration."""
10781085
return f"{self.config} ({self.organization})"
10791086

10801087
def disable_for_rate_limit(self):
@@ -1166,6 +1173,7 @@ class ListCachable(models.Model):
11661173
delete_class_cache_keys(user: User): Deletes cached keys for the class.
11671174
python_path: Returns the Python path of the class.
11681175
"""
1176+
11691177
class Meta:
11701178
abstract = True
11711179

@@ -1204,6 +1212,7 @@ class AbstractConfig(ListCachable):
12041212
disabled (bool): Indicates if the configuration is disabled.
12051213
orgs_configuration (GenericRelation): The organization configurations for this config.
12061214
"""
1215+
12071216
objects = AbstractConfigQuerySet.as_manager()
12081217
name = models.CharField(
12091218
max_length=100,
@@ -1334,6 +1343,7 @@ class AbstractReport(models.Model):
13341343
parameters (JSONField): The parameters used for generating the report.
13351344
sent_to_bi (bool): Indicates if the report has been sent to business intelligence (BI) systems.
13361345
"""
1346+
13371347
objects = AbstractReportQuerySet.as_manager()
13381348
# constants
13391349
Status = ReportStatus
@@ -1421,6 +1431,7 @@ class PythonConfig(AbstractConfig):
14211431
health_check_task (OneToOneField): The periodic task for health checks.
14221432
health_check_status (bool): The current health check status of the plugin.
14231433
"""
1434+
14241435
objects = PythonConfigQuerySet.as_manager()
14251436
soft_time_limit = models.IntegerField(default=60, validators=[MinValueValidator(0)])
14261437
routing_key = models.CharField(max_length=50, default="default")

0 commit comments

Comments
 (0)