From e96f180c82d86b1a8d443857e9cd2364b45da46e Mon Sep 17 00:00:00 2001 From: Matteo Lodi <30625432+mlodic@users.noreply.github.com> Date: Wed, 6 Dec 2023 20:06:32 +0100 Subject: [PATCH] deepsource fix --- api_app/analyzers_manager/classes.py | 2 +- .../observable_analyzers/maxmind.py | 13 +++++++------ .../analyzers_manager/observable_analyzers/tor.py | 5 ++--- api_app/classes.py | 2 +- api_app/signals.py | 9 ++++++--- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/api_app/analyzers_manager/classes.py b/api_app/analyzers_manager/classes.py index 25807c8ae1..f8bf565774 100644 --- a/api_app/analyzers_manager/classes.py +++ b/api_app/analyzers_manager/classes.py @@ -461,7 +461,7 @@ def _monkeypatch(self, patches: list = None): ) return super()._monkeypatch(patches) - def health_check(self, user: User) -> bool: + def health_check(self, user: User = None) -> bool: """ basic health check: if instance is up or not (timeout - 10s) """ diff --git a/api_app/analyzers_manager/observable_analyzers/maxmind.py b/api_app/analyzers_manager/observable_analyzers/maxmind.py index 2d09539675..3b502d49c7 100644 --- a/api_app/analyzers_manager/observable_analyzers/maxmind.py +++ b/api_app/analyzers_manager/observable_analyzers/maxmind.py @@ -33,12 +33,13 @@ def run(self): for db in db_names: try: db_location = _get_db_location(db) - if not os.path.isfile(db_location): - if not self._update_db(db, self._api_key_name): - raise AnalyzerRunException( - f"failed extraction of maxmind db {db}," - " reached max number of attempts" - ) + if not os.path.isfile(db_location) and not self._update_db( + db, self._api_key_name + ): + raise AnalyzerRunException( + f"failed extraction of maxmind db {db}," + " reached max number of attempts" + ) if not os.path.exists(db_location): raise maxminddb.InvalidDatabaseError( "database location does not exist" diff --git a/api_app/analyzers_manager/observable_analyzers/tor.py b/api_app/analyzers_manager/observable_analyzers/tor.py index 35b86e9a63..9cedc11569 100644 --- a/api_app/analyzers_manager/observable_analyzers/tor.py +++ b/api_app/analyzers_manager/observable_analyzers/tor.py @@ -21,9 +21,8 @@ class Tor(classes.ObservableAnalyzer): def run(self): result = {"found": False} - if not os.path.isfile(database_location): - if not self.update(): - raise AnalyzerRunException("Failed extraction of tor db") + if not os.path.isfile(database_location) and not self.update(): + raise AnalyzerRunException("Failed extraction of tor db") if not os.path.exists(database_location): raise AnalyzerRunException( diff --git a/api_app/classes.py b/api_app/classes.py index 1707c0fb86..594d0b1610 100644 --- a/api_app/classes.py +++ b/api_app/classes.py @@ -44,7 +44,7 @@ def name(self): @property @abstractmethod def python_base_path(cls) -> PosixPath: - ... + NotImplementedError() @classmethod def all_subclasses(cls): diff --git a/api_app/signals.py b/api_app/signals.py index 1900e140f0..aa33e68e8e 100644 --- a/api_app/signals.py +++ b/api_app/signals.py @@ -94,9 +94,12 @@ def post_delete_python_module_periodic_tasks( def post_delete_python_config_periodic_tasks( sender: Type[PythonConfig], instance: PythonConfig, using, origin, *args, **kwargs ): - if issubclass(sender, PythonConfig): - if hasattr(instance, "health_check_task") and instance.health_check_task: - instance.health_check_task.delete() + if ( + issubclass(sender, PythonConfig) + and hasattr(instance, "health_check_task") + and instance.health_check_task + ): + instance.health_check_task.delete() @receiver(models.signals.post_save)