Skip to content

Commit

Permalink
Adding logs for REST calls, giving MD some time to breathe (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
cccs-kevin authored Dec 11, 2020
1 parent 5fa3860 commit 4a8302d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions metadefender.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def _get_version_map(self, node: str):
url = urljoin(node, 'stat/engines')

try:
self.log.debug(f"_get_version_map: GET {url}")
r = self.session.get(url=url, timeout=self.timeout)
engines = r.json()

Expand Down Expand Up @@ -209,6 +210,7 @@ def get_scan_results_by_data_id(self, data_id: str):
url = urljoin(self.current_node, f"file/{data_id}")

try:
self.log.debug(f"get_scan_results_by_data_id: GET {url}")
return self.session.get(url=url, headers=self.headers, timeout=self.timeout)
except requests.exceptions.Timeout:
self.new_node(force=True, reset_queue=True)
Expand Down Expand Up @@ -261,6 +263,7 @@ def scan_file(self, filename: str):
data = f.read()

try:
self.log.debug(f"scan_file: POST {url}")
r = self.session.post(url=url, data=data, headers=self.headers, timeout=self.timeout)
except requests.exceptions.Timeout:
self.new_node(force=True, reset_queue=True)
Expand All @@ -274,6 +277,8 @@ def scan_file(self, filename: str):

if r.status_code == requests.codes.ok:
data_id = r.json()['data_id']
# Give MD some time to scan it!
time.sleep(1)
while True:
r = self.get_scan_results_by_data_id(data_id=data_id)
if r.status_code != requests.codes.ok:
Expand Down

0 comments on commit 4a8302d

Please sign in to comment.