Add debug_mode to bootstrap.py and session_helper.py for debug token handling
This commit is contained in:
parent
91fac0c3bd
commit
999699c402
|
@ -17,6 +17,7 @@ import threading
|
|||
import hub_api.helpers.session_helper as sh
|
||||
from hub_api.session import SessionStart, SessionEnd, KeepSessionAlive
|
||||
from hub_api.uptime import Uptime
|
||||
from hub_api.buildings import GetBuildings
|
||||
|
||||
|
||||
sh.begin_time = datetime.datetime.now()
|
||||
|
@ -31,6 +32,9 @@ api.add_resource(SessionStart, '/v1.4/session/start')
|
|||
api.add_resource(SessionEnd, '/v1.4/session/end')
|
||||
api.add_resource(KeepSessionAlive, '/v1.4/session/keep_alive')
|
||||
|
||||
# Buildings
|
||||
api.add_resource(GetBuildings, '/v1.4/buildings')
|
||||
|
||||
with open("hub_api/docs/openapi-specs.yml", "r") as stream:
|
||||
swagger_config = {
|
||||
"headers": [],
|
||||
|
@ -56,5 +60,7 @@ with open("hub_api/docs/openapi-specs.yml", "r") as stream:
|
|||
def home():
|
||||
return Response(headers={'Access-Control-Allow-Origin': '*'})
|
||||
|
||||
sh.debug_mode = True
|
||||
|
||||
threading.Thread(target=sh.expired_sessions_collector, daemon=True, args="5").start()
|
||||
app.run(port=15789, host="0.0.0.0", debug=True)
|
||||
app.run(port=15789, host="0.0.0.0", debug=sh.debug_mode)
|
||||
|
|
|
@ -14,6 +14,7 @@ city = None
|
|||
greenery_catalog = None
|
||||
construction_catalog = None
|
||||
usage_catalog = None
|
||||
debug_mode = None
|
||||
|
||||
class SessionData:
|
||||
def __init__(self, session):
|
||||
|
@ -57,7 +58,9 @@ class SessionData:
|
|||
|
||||
|
||||
def expired_sessions_collector(session_timeout_duration):
|
||||
# loop through all sessions and remove expired sessions
|
||||
"""
|
||||
Goes through each session in sessions and removes expired session(s)
|
||||
"""
|
||||
while True:
|
||||
if bool(sessions):
|
||||
for session in list(sessions):
|
||||
|
@ -68,12 +71,18 @@ def expired_sessions_collector(session_timeout_duration):
|
|||
time.sleep(60*int(session_timeout_duration))
|
||||
|
||||
def _validate_session(session_id, token, application_uuid):
|
||||
"""
|
||||
Checks if session is valid
|
||||
"""
|
||||
try:
|
||||
if bool(sessions[session_id]) and sessions[session_id]['token'] == token and \
|
||||
sessions[session_id]['application_uuid'] == application_uuid:
|
||||
return True
|
||||
except KeyError:
|
||||
return False
|
||||
if debug_mode == True:
|
||||
return (bool(sessions[session_id]) and (sessions[session_id]['token'] == token or token == 'debug') and \
|
||||
sessions[session_id]['application_uuid'] == application_uuid)
|
||||
else:
|
||||
return(bool(sessions[session_id]) and sessions[session_id]['token'] == token and \
|
||||
sessions[session_id]['application_uuid'] == application_uuid)
|
||||
except:
|
||||
False
|
||||
|
||||
|
||||
def remove_session(session_id, token, application_uuid):
|
||||
|
@ -99,4 +108,4 @@ def refresh_session(session_id, token, application_uuid):
|
|||
return None
|
||||
|
||||
def active_session(session_id, token, application_uuid):
|
||||
return _validate_session(session_id = session_id, token = token, application_uuid = application_uuid)
|
||||
return _validate_session(session_id=session_id, token=token, application_uuid=application_uuid)
|
Loading…
Reference in New Issue
Block a user