Skip to content

Commit

Permalink
Flake 8
Browse files Browse the repository at this point in the history
  • Loading branch information
U039b committed Sep 21, 2024
1 parent c4a6eff commit 5902c71
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 27 deletions.
2 changes: 1 addition & 1 deletion config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.urls import include, path
from django.views import defaults as default_views
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView
from drf_spectacular.views import SpectacularSwaggerView
from rest_framework.authtoken.views import obtain_auth_token
from rest_framework.schemas import get_schema_view

Expand Down
1 change: 0 additions & 1 deletion threatr/core/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def get_supported_types(self) -> dict[str, list[str]]:
self.supported_types[st] = list(t)
return self.supported_types


def get_candidate_classes(self, request: Request) -> {type}:
candidates = set()
if not self.module_classes:
Expand Down
6 changes: 3 additions & 3 deletions threatr/modules/module.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
from abc import abstractmethod, ABC
from functools import cache

from slugify import slugify

Expand Down Expand Up @@ -64,7 +63,7 @@ def save_results(self):
def get_results(self) -> ([Entity], [EntityRelation], [Event]):
pass

def fail_fast(self) -> bool:
def fail_fast(self) -> bool: # noqa: F811
if "api_key" not in self.credentials:
logger.error("Not API key provided")
return True
Expand All @@ -73,7 +72,8 @@ def fail_fast(self) -> bool:
f"This module cannot handle the requested super-type [{self.request.super_type.short_name}]"
)
return True
if self.request.type.short_name.lower() not in self.supported_types().get(self.request.super_type.short_name.lower()):
if self.request.type.short_name.lower() not in self.supported_types().get(
self.request.super_type.short_name.lower()): # noqa: E125
logger.error(
f"This module cannot handle the requested type [{self.request.type.short_name}]"
)
Expand Down
9 changes: 2 additions & 7 deletions threatr/modules/scarletshark_helpers/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(self, domain_name: str, client: ClientFactory):
self.client = client

@staticmethod
def create_entity(domain_data: dict, vendor: str='ScarletShark')-> Optional[Entity]:
def create_entity(domain_data: dict, vendor: str = 'ScarletShark') -> Optional[Entity]:
domain_name = domain_data.get('domain', None)
if not domain_name:
return None
Expand Down Expand Up @@ -39,9 +39,4 @@ def create_entity(domain_data: dict, vendor: str='ScarletShark')-> Optional[Enti
return None

def search(self):
domain: Entity = None
try:
data = self.client.search_domain(self.domain_name)
except Exception:
# Something bad happened or there is no result
return None
return None
4 changes: 0 additions & 4 deletions threatr/modules/scarletshark_module.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import json
import logging
from scarlet_shark_client.client import ClientFactory
import pytz
from dateutil.parser import parse

from threatr.core.models import (
Entity,
EntityRelation,
Request,
EntitySuperType,
EntityType,
Event,
)
from threatr.modules.module import AnalysisModule
Expand Down
20 changes: 9 additions & 11 deletions threatr/modules/shodan_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def execute_request(self):
except APIError as e:
logger.exception(e)
self.vendor_response = {}
with open(f"/app/shodan.json", mode="w") as out:
with open("/app/shodan.json", mode="w") as out:
json.dump(self.vendor_response, out)
return self.vendor_response

Expand Down Expand Up @@ -143,9 +143,9 @@ def __process_server_location(self, server: Entity) -> (list[Entity], list[Entit
country = self.vendor_response.get('country_name', '')
city = self.vendor_response.get('city', '')
location_info = []
if country: location_info.append(country)
if city: location_info.append(city)
if not location_info: location_info.append('Server location')
if country: location_info.append(country) # noqa: E701
if city: location_info.append(city) # noqa: E701
if not location_info: location_info.append('Server location') # noqa: E701
l, _ = Entity.objects.update_or_create(
name=' - '.join(location_info),
super_type=EntitySuperType.get_types().get("OBSERVABLE"),
Expand All @@ -170,7 +170,6 @@ def __process_server_location(self, server: Entity) -> (list[Entity], list[Entit
relations.append(relation)
return entities, relations


def __process_services(self, server: Entity) -> (list[Entity], list[EntityRelation]):
entities = []
relations = []
Expand All @@ -182,10 +181,10 @@ def __process_services(self, server: Entity) -> (list[Entity], list[EntityRelati
service_protocol = service.get('_shodan').get('module').split('-')[0].upper()
service_port = service.get('port', '')
service_transport = service.get('transport', '')
if service_protocol: service_name = f'{service_protocol} service'
if service_product: service_name += f' {service_product}'
if service_port: service_name += f' listening on port {service_port}'
if service_transport: service_name += f' [{service_transport.upper()}]'
if service_protocol: service_name = f'{service_protocol} service' # noqa: E701
if service_product: service_name += f' {service_product}' # noqa: E701
if service_port: service_name += f' listening on port {service_port}' # noqa: E701
if service_transport: service_name += f' [{service_transport.upper()}]' # noqa: E701
s, _ = Entity.objects.update_or_create(
name=service_name,
super_type=EntitySuperType.get_types().get("OBSERVABLE"),
Expand All @@ -210,12 +209,11 @@ def __process_services(self, server: Entity) -> (list[Entity], list[EntityRelati
relations.append(relation)
return entities, relations


def __process_server(self, root_entity: Entity) -> Entity:
server_name = f'Server @{root_entity.name}'
hostnames = self.vendor_response.get('hostnames', []).copy()
server_shorter_hostname, _ = ModuleUtils.get_shorter_entry(hostnames)
if server_shorter_hostname: server_name = server_shorter_hostname
if server_shorter_hostname: server_name = server_shorter_hostname # noqa: E701
s, _ = Entity.objects.update_or_create(
name=server_name,
super_type=EntitySuperType.get_types().get("DEVICE"),
Expand Down

0 comments on commit 5902c71

Please sign in to comment.