Skip to content

Commit

Permalink
Merge pull request #1 from Patrowl/develop
Browse files Browse the repository at this point in the history
Update to 0.0.13
  • Loading branch information
bdoublet91 authored Mar 31, 2020
2 parents a6e584f + 20fe63d commit a4dd691
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions PatrowlEnginesUtils/PatrowlEngineTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"""This file manage tests on PatrowlEngine."""

import json
import requests
import time
import random
import requests


class PatrowlEngineTest:
Expand Down Expand Up @@ -97,11 +97,13 @@ def test_cleanscans(self):
finally:
return r.json()

def custom_test(self, test_name, assets, scan_policy={}, is_valid=True,
def custom_test(self, test_name, assets, scan_policy=None, is_valid=True,
max_timeout=1200):
"""Start a custom test."""
print("test-{}-custom: {}".format(self.engine_name, test_name))
TEST_SCAN_ID = random.randint(1000000, 1999999)
if(scan_policy == None):
scan_policy = {}
post_data = {
"assets": assets,
"options": scan_policy,
Expand All @@ -124,11 +126,17 @@ def custom_test(self, test_name, assets, scan_policy={}, is_valid=True,

# Wait until scan is finished
timeout_start = time.time()
# Mitigate PID error
retries = 0
has_error = False
while time.time() < timeout_start + max_timeout:
r = requests.get(
url="{}/status/{}".format(self.base_url, TEST_SCAN_ID))
if r.json()["status"] == "SCANNING":
if r.json()["status"] in ("SCANNING", "STARTED"):
time.sleep(3)
elif (r.json()["status"] == "ERROR" and "reason" in r.json() and
r.json()["reason"] == "No PID found" and retries < 3):
retries += 1
time.sleep(3)
else:
if r.json()["status"] == "FINISHED":
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name='PatrowlEnginesUtils',
version='0.0.12',
version='0.0.13',
description='Common classes for PatrowlEngines',
url='https://github.com/Patrowl/PatrowlEnginesUtils',
author='Nicolas Mattiocco',
Expand Down

0 comments on commit a4dd691

Please sign in to comment.