Readd session
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Michel Roux 2022-12-21 17:37:27 +00:00
parent eb23799cd7
commit 4dee2ea36e

View File

@ -8,8 +8,22 @@ class FlareRequests(Session):
if not CLOUDPROXY_ENDPOINT:
return super().request(method, url, params, timeout=timeout, **kwargs)
sessions = post(CLOUDPROXY_ENDPOINT, json={"cmd": "sessions.list"}).json()
if "sessions" in sessions and len(sessions["sessions"]) > 0:
FLARESESSION = sessions["sessions"][0]
else:
response = post(CLOUDPROXY_ENDPOINT, json={"cmd": "sessions.create"})
session = response.json()
if "session" in session:
FLARESESSION = session["session"]
else:
raise RequestException(response)
post_data = {
"cmd": f"request.{method.lower()}",
"session": FLARESESSION,
"url": url,
"maxTimeout": timeout * 1000,
}
@ -17,6 +31,7 @@ class FlareRequests(Session):
if params:
post_data["postData"] = parse.urlencode(params)
try:
response = post(
CLOUDPROXY_ENDPOINT,
json=post_data,
@ -37,3 +52,10 @@ class FlareRequests(Session):
return resolved
raise RequestException(response)
except RequestException:
session = post(
CLOUDPROXY_ENDPOINT,
json={"cmd": "sessions.destroy", "session": FLARESESSION},
)
raise RequestException(solution)