Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Improve read parameters #2214

Merged
merged 10 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import django.utils.timezone
from django.db import migrations, models

import api_app.defaults
import api_app.fields
import api_app.validators

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@ def default_locations(cls) -> Tuple[str, str]:

def run(self):
result = {"found": False}
db_location, url = (
db_location, _ = (
self.recommend_locations
if self.use_recommended_url
else self.default_locations
)
if self.update_on_run or not os.path.exists(db_location):
if not self.update():
raise AnalyzerRunException("Unable to update database")
if self.update_on_run or not os.path.exists(db_location) and not self.update():
raise AnalyzerRunException("Unable to update database")
try:
with open(db_location, "r", encoding="utf-8") as f:
db = json.load(f)
Expand Down
8 changes: 4 additions & 4 deletions api_app/analyzers_manager/observable_analyzers/ip2location.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def run(self):
try:
payload = {"ip": self.observable_name}

""" There are two free versions of the service:
1. keyless : Requires No API key and has a daily limit of 500 queries
2. keyed: Requires API key.
"""
# There are two free versions of the service:
# 1. keyless : Requires No API key and has a daily limit of 500 queries
# 2. keyed: Requires API key.

if self.api_version == "keyed":
payload["key"] = self._api_key_name

Expand Down
13 changes: 3 additions & 10 deletions api_app/analyzers_manager/observable_analyzers/mmdb_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import requests

from api_app.analyzers_manager import classes
from api_app.analyzers_manager.exceptions import ( # AnalyzerConfigurationException
AnalyzerRunException,
)
from tests.mock_utils import MockUpResponse, if_mock_connections, patch

logger = logging.getLogger(__name__)
Expand All @@ -19,16 +16,12 @@ class MmdbServer(classes.ObservableAnalyzer):
def update(self) -> bool:
pass

base_url = str
base_url: str
observable_name: str

def run(self):
try:
response = requests.get(self.base_url + self.observable_name)
response.raise_for_status()
except requests.RequestException as e:
logger.exception("Error while querying mmdb server: {e}")
raise AnalyzerRunException(e)
response = requests.get(self.base_url + self.observable_name)
response.raise_for_status()
return response.json()

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion api_app/analyzers_manager/observable_analyzers/otx.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def run(self):
logger.warning(
f"Sections: {not_supported_requested_section_list}"
f" are not supported for indicator type: {otx_type}. "
f"We remove them from the search."
"We remove them from the search."
)
for not_supported in not_supported_requested_section_list:
self.sections.remove(not_supported)
Expand Down
Loading
Loading